| 84 | } |
| 85 | |
| 86 | ItemLoadingState videoHandler::needsLoading(int frameIdx, bool loadRawValues) |
| 87 | { |
| 88 | if (loadRawValues) |
| 89 | { |
| 90 | // First, let's check the raw values buffer. |
| 91 | auto state = needsLoadingRawValues(frameIdx); |
| 92 | if (state != ItemLoadingState::LoadingNotNeeded) |
| 93 | return state; |
| 94 | } |
| 95 | |
| 96 | // Lock the mutex for checking the cache |
| 97 | QMutexLocker lock(&imageCacheAccess); |
| 98 | |
| 99 | // The raw values are not needed. |
| 100 | if (frameIdx == currentImageIndex) |
| 101 | { |
| 102 | if (doubleBufferImageFrameIndex == frameIdx + 1) |
| 103 | { |
| 104 | DEBUG_VIDEO("videoHandler::needsLoading %d is current and %d found in double buffer", |
| 105 | frameIdx, |
| 106 | frameIdx + 1); |
| 107 | return ItemLoadingState::LoadingNotNeeded; |
| 108 | } |
| 109 | else if (cacheValid && imageCache.contains(frameIdx + 1)) |
| 110 | { |
| 111 | DEBUG_VIDEO( |
| 112 | "videoHandler::needsLoading %d is current and %d found in cache", frameIdx, frameIdx + 1); |
| 113 | return ItemLoadingState::LoadingNotNeeded; |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | // The next frame is not in the double buffer so that needs to be loaded. |
| 118 | DEBUG_VIDEO("videoHandler::needsLoading %d is current but %d not found in double buffer", |
| 119 | frameIdx, |
| 120 | frameIdx + 1); |
| 121 | return ItemLoadingState::LoadingNeededDoubleBuffer; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // Check the double buffer |
| 126 | if (doubleBufferImageFrameIndex == frameIdx) |
| 127 | { |
| 128 | // The frame in question is in the double buffer... |
| 129 | if (cacheValid && imageCache.contains(frameIdx + 1)) |
| 130 | { |
| 131 | // ... and the one after that is in the cache. |
| 132 | DEBUG_VIDEO("videoHandler::needsLoading %d found in double buffer. Next frame in cache.", |
| 133 | frameIdx); |
| 134 | return ItemLoadingState::LoadingNotNeeded; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | // .. and the one after that is not in the cache. |
| 139 | // Loading of the given frame index is not needed because it is in the double buffer but if |
| 140 | // you draw it, the double buffer needs an update. |
| 141 | DEBUG_VIDEO("videoHandler::needsLoading %d found in double buffer", frameIdx); |
| 142 | return ItemLoadingState::LoadingNeededDoubleBuffer; |
| 143 | } |