Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions packages/skia/cpp/api/JsiSkImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,26 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
std::move(image)) {
// Get the dispatcher for the current thread
_dispatcher = Dispatcher::getDispatcher();
// Process any pending operations
// Process any pending operations (e.g. deletions of previous resources)
_dispatcher->processQueue();
}

protected:
void releaseResources() override {
// Queue deletion on the creation thread if needed
auto image = getObjectUnchecked();
if (image && _dispatcher) {
_dispatcher->run([image]() {
// Image will be deleted when this lambda is destroyed
});
}
// Clear the object
JsiSkWrappingSkPtrHostObject<SkImage>::releaseResources();
}

public:
~JsiSkImage() override {
// If already disposed, resources were already cleaned up
if (isDisposed()) {
return;
if (!isDisposed()) {
// This JSI Object is being deleted from a GC, which might happen
// on a separate Thread. GPU resources (like SkImage) must be deleted
// on the same Thread they were created on, so in this case we schedule
// deletion to run on the Thread this Object was created on.
auto image = getObjectUnchecked();
if (image && _dispatcher) {
_dispatcher->run([image]() {
// Image will be deleted when this lambda is destroyed, on the
// original Thread.
});
}
releaseResources();
}
Comment thread
wcandillon marked this conversation as resolved.
// Use the same cleanup path as dispose()
releaseResources();
}

size_t getMemoryPressure() const override {
Expand Down
31 changes: 13 additions & 18 deletions packages/skia/cpp/api/JsiSkPicture.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,22 @@ class JsiSkPicture : public JsiSkWrappingSkPtrHostObject<SkPicture> {
_dispatcher->processQueue();
}

protected:
void releaseResources() override {
// Queue deletion on the creation thread if needed
auto picture = getObjectUnchecked();
if (picture && _dispatcher) {
_dispatcher->run([picture]() {
// Picture will be deleted when this lambda is destroyed
});
}
// Clear the object
JsiSkWrappingSkPtrHostObject<SkPicture>::releaseResources();
}

public:
~JsiSkPicture() override {
// If already disposed, resources were already cleaned up
if (isDisposed()) {
return;
if (!isDisposed()) {
// This JSI Object is being deleted from a GC, which might happen
// on a separate Thread. GPU resources (like SkPicture) must be deleted
// on the same Thread they were created on, so in this case we schedule
// deletion to run on the Thread this Object was created on.
auto picture = getObjectUnchecked();
if (picture && _dispatcher) {
_dispatcher->run([picture]() {
// Picture will be deleted when this lambda is destroyed, on the
// original Thread.
});
}
releaseResources();
Comment thread
wcandillon marked this conversation as resolved.
}
// Use the same cleanup path as dispose()
releaseResources();
}

JSI_HOST_FUNCTION(makeShader) {
Expand Down
31 changes: 13 additions & 18 deletions packages/skia/cpp/api/JsiSkSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,22 @@ class JsiSkSurface : public JsiSkWrappingSkPtrHostObject<SkSurface> {
_dispatcher->processQueue();
}

protected:
void releaseResources() override {
// Queue deletion on the creation thread if needed
auto surface = getObjectUnchecked();
if (surface && _dispatcher) {
_dispatcher->run([surface]() {
// Surface will be deleted when this lambda is destroyed
});
}
// Clear the object
JsiSkWrappingSkPtrHostObject<SkSurface>::releaseResources();
}

public:
~JsiSkSurface() override {
// If already disposed, resources were already cleaned up
if (isDisposed()) {
return;
if (!isDisposed()) {
// This JSI Object is being deleted from a GC, which might happen
// on a separate Thread. GPU resources (like SkSurface) must be deleted
// on the same Thread they were created on, so in this case we schedule
// deletion to run on the Thread this Object was created on.
auto surface = getObjectUnchecked();
if (surface && _dispatcher) {
_dispatcher->run([surface]() {
// Surface will be deleted when this lambda is destroyed, on the
// original Thread.
});
}
releaseResources();
}
Comment thread
wcandillon marked this conversation as resolved.
// Use the same cleanup path as dispose()
releaseResources();
}

EXPORT_JSI_API_TYPENAME(JsiSkSurface, Surface)
Expand Down
Loading