diff --git a/src/rendering/CompositionReader.cpp b/src/rendering/CompositionReader.cpp index 776803b20ce..092f86308da 100644 --- a/src/rendering/CompositionReader.cpp +++ b/src/rendering/CompositionReader.cpp @@ -38,7 +38,11 @@ CompositionReader::CompositionReader(std::shared_ptr bitmapDrawa } CompositionReader::~CompositionReader() { + auto result = drawable->lockDevice(); delete pagPlayer; + if (result) { + drawable->unlockDevice(); + } } std::shared_ptr CompositionReader::getComposition() { diff --git a/src/rendering/drawables/BitmapDrawable.cpp b/src/rendering/drawables/BitmapDrawable.cpp index 15f786b3a2d..22a3906c44c 100644 --- a/src/rendering/drawables/BitmapDrawable.cpp +++ b/src/rendering/drawables/BitmapDrawable.cpp @@ -41,6 +41,14 @@ void BitmapDrawable::setBitmap(std::shared_ptr buffer) { freeSurface(); } +bool BitmapDrawable::lockDevice() { + return device->lockContext() != nullptr; +} + +void BitmapDrawable::unlockDevice() { + device->unlock(); +} + void BitmapDrawable::present(tgfx::Context* context) { if (bitmap == nullptr) { return; diff --git a/src/rendering/drawables/BitmapDrawable.h b/src/rendering/drawables/BitmapDrawable.h index 11d92e57bb4..34c5cda3b9a 100644 --- a/src/rendering/drawables/BitmapDrawable.h +++ b/src/rendering/drawables/BitmapDrawable.h @@ -40,6 +40,10 @@ class BitmapDrawable : public Drawable { return pixelCopied; } + bool lockDevice(); + + void unlockDevice(); + protected: std::shared_ptr onCreateDevice() override { return device; diff --git a/src/rendering/drawables/Drawable.cpp b/src/rendering/drawables/Drawable.cpp index 0066c399cba..55eb7cd3f8b 100644 --- a/src/rendering/drawables/Drawable.cpp +++ b/src/rendering/drawables/Drawable.cpp @@ -60,7 +60,11 @@ std::shared_ptr Drawable::getSurface(tgfx::Context* context, bool } void Drawable::freeSurface() { + auto context = lockContext(false); surface = nullptr; + if (context != nullptr) { + device->unlock(); + } } } // namespace pag