| 137 | } |
| 138 | |
| 139 | void DrawingManager::addAtlasCellCodecTask(const std::shared_ptr<TextureProxy>& textureProxy, |
| 140 | const Point& atlasOffset, |
| 141 | std::shared_ptr<ImageCodec> codec) { |
| 142 | if (textureProxy == nullptr || codec == nullptr) { |
| 143 | return; |
| 144 | } |
| 145 | auto padding = Plot::CellPadding; |
| 146 | void* dstPixels = nullptr; |
| 147 | auto dstWidth = codec->width() + 2 * padding; |
| 148 | auto dstHeight = codec->height() + 2 * padding; |
| 149 | ImageInfo dstInfo = {}; |
| 150 | auto hardwareBuffer = textureProxy->getHardwareBuffer(); |
| 151 | if (hardwareBuffer != nullptr) { |
| 152 | auto hardwareInfo = HardwareBufferGetInfo(hardwareBuffer); |
| 153 | dstInfo = hardwareInfo.makeIntersect(0, 0, dstWidth, dstHeight); |
| 154 | void* pixels = nullptr; |
| 155 | if (auto iter = atlasHardwareBuffers.find(textureProxy.get()); |
| 156 | iter == atlasHardwareBuffers.end()) { |
| 157 | pixels = HardwareBufferLock(hardwareBuffer); |
| 158 | atlasHardwareBuffers.emplace(textureProxy.get(), std::make_pair(hardwareBuffer, pixels)); |
| 159 | } else { |
| 160 | pixels = iter->second.second; |
| 161 | } |
| 162 | auto offsetX = static_cast<int>(atlasOffset.x) - padding; |
| 163 | auto offsetY = static_cast<int>(atlasOffset.y) - padding; |
| 164 | dstPixels = hardwareInfo.computeOffset(pixels, offsetX, offsetY); |
| 165 | } else { |
| 166 | dstInfo = GetAtlasImageInfo(dstWidth, dstHeight, codec->isAlphaOnly()); |
| 167 | auto length = dstInfo.byteSize(); |
| 168 | dstPixels = drawingBuffer->allocate(length); |
| 169 | if (dstPixels == nullptr) { |
| 170 | return; |
| 171 | } |
| 172 | auto data = Data::MakeWithoutCopy(dstPixels, length); |
| 173 | auto uploadOffset = atlasOffset; |
| 174 | auto floatPadding = static_cast<float>(padding); |
| 175 | uploadOffset.offset(-floatPadding, -floatPadding); |
| 176 | atlasCellDatas[textureProxy].emplace_back(std::move(data), dstInfo, uploadOffset); |
| 177 | } |
| 178 | auto task = std::make_shared<AtlasCellDecodeTask>(std::move(codec), dstPixels, dstInfo, padding); |
| 179 | atlasCellCodecTasks.emplace_back(std::move(task)); |
| 180 | } |
| 181 | |
| 182 | void DrawingManager::addSemaphoreWaitTask(std::shared_ptr<Semaphore> semaphore) { |
| 183 | if (semaphore == nullptr) { |
no test coverage detected