Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wpe_fdo_egl_exported_image: add destroy-notify callback support. #45

Closed
Closed
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
5 changes: 5 additions & 0 deletions include/wpe-fdo/exported-image-egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ typedef void* EGLImageKHR;

struct wpe_fdo_egl_exported_image;

typedef void (*wpe_fdo_egl_exported_image_destroy_notify_t)(void *data, struct wpe_fdo_egl_exported_image *image);

void
wpe_fdo_egl_exported_image_set_destroy_notify(struct wpe_fdo_egl_exported_image*, wpe_fdo_egl_exported_image_destroy_notify_t, void*);

uint32_t
wpe_fdo_egl_exported_image_get_width(struct wpe_fdo_egl_exported_image*);

Expand Down
11 changes: 11 additions & 0 deletions src/exported-image-egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@

extern "C" {

__attribute__((visibility("default")))
void
wpe_fdo_egl_exported_image_set_destroy_notify(struct wpe_fdo_egl_exported_image* image, wpe_fdo_egl_exported_image_destroy_notify_t destroyNotify, void* destroyData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use an API documentation comment. If we the missing ones little by little with each PR we would incrementally tackle #27 — I wouldn't block merging this PR due to this, though 😉

{
image->destroyNotify = destroyNotify;
image->destroyData = destroyData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense that if a destroyNotify was already set previously, that the old callback is called before storing the new values? Not doing that could easily result in leaking the data passed as destroyData, if the callback is supposed to free it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I'll update it to do that.

}

__attribute__((visibility("default")))
uint32_t
wpe_fdo_egl_exported_image_get_width(struct wpe_fdo_egl_exported_image* image)
Expand All @@ -56,6 +64,9 @@ wpe_fdo_egl_exported_image_get_egl_image(struct wpe_fdo_egl_exported_image* imag
void
wpe_fdo_egl_exported_image_destroy(struct wpe_fdo_egl_exported_image* image)
{
if (image->destroyNotify)
image->destroyNotify(image->destroyData, image);

assert(image->eglImage);
WS::Instance::singleton().destroyImage(image->eglImage);
wl_list_remove(&image->bufferDestroyListener.link);
Expand Down
5 changes: 5 additions & 0 deletions src/view-backend-exportable-fdo-egl-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@

typedef void *EGLImageKHR;

typedef void (*wpe_fdo_egl_exported_image_destroy_notify_t)(void* data, struct wpe_fdo_egl_exported_image *image);

struct wpe_fdo_egl_exported_image {
EGLImageKHR eglImage { nullptr };
uint32_t width { 0 };
uint32_t height { 0 };
bool locked { false };
struct wl_resource* bufferResource { nullptr };
struct wl_listener bufferDestroyListener;

wpe_fdo_egl_exported_image_destroy_notify_t destroyNotify;
void* destroyData;
};

void wpe_fdo_egl_exported_image_destroy(struct wpe_fdo_egl_exported_image*);