| 193 | } |
| 194 | |
| 195 | bool PAGSurface::draw(RenderCache* cache, std::shared_ptr<Graphic> graphic, |
| 196 | BackendSemaphore* signalSemaphore, bool autoClear) { |
| 197 | auto context = lockContext(); |
| 198 | if (!context) { |
| 199 | return false; |
| 200 | } |
| 201 | cache->prepareLayers(); |
| 202 | auto surface = drawable->getSurface(context, true); |
| 203 | if (surface != nullptr && autoClear && contentVersion == cache->getContentVersion()) { |
| 204 | unlockContext(); |
| 205 | return false; |
| 206 | } |
| 207 | if (surface == nullptr) { |
| 208 | surface = drawable->getSurface(context, false); |
| 209 | } |
| 210 | if (surface == nullptr) { |
| 211 | unlockContext(); |
| 212 | return false; |
| 213 | } |
| 214 | contentVersion = cache->getContentVersion(); |
| 215 | cache->attachToContext(context); |
| 216 | auto canvas = surface->getCanvas(); |
| 217 | if (autoClear) { |
| 218 | canvas->clear(); |
| 219 | } |
| 220 | onDraw(graphic, surface, cache); |
| 221 | if (signalSemaphore == nullptr) { |
| 222 | context->flush(); |
| 223 | } else { |
| 224 | tgfx::BackendSemaphore semaphore = {}; |
| 225 | context->flush(&semaphore); |
| 226 | tgfx::GLSyncInfo signalInfo = {}; |
| 227 | if (semaphore.getGLSync(&signalInfo)) { |
| 228 | signalSemaphore->initGL(signalInfo.sync); |
| 229 | } |
| 230 | } |
| 231 | cache->detachFromContext(); |
| 232 | context->submit(); |
| 233 | drawable->setTimeStamp(pagPlayer->getTimeStampInternal()); |
| 234 | drawable->present(context); |
| 235 | unlockContext(); |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | bool PAGSurface::wait(const BackendSemaphore& waitSemaphore) { |
| 240 | if (!waitSemaphore.isInitialized()) { |
no test coverage detected