Reviewed-by: Gurchetan Singh <gurchetansi...@chromium.org> On Wed, Nov 15, 2017 at 7:27 AM, Gwan-gyeong Mun <elong...@gmail.com> wrote:
> To share common free DRIimage code. > > In preparation to adding of new platform which uses this helper. > > v2: > - Fixes from Eric's review: > a) Split out series of refactor for helpers to a separate series. > b) Add the new helper function and use them to replace the old code in > the > same patch. > > v3: Fixes from Emil and Gurchetan's review > - Follow the naming convention which prevents too verbose name of > functions. > a) use a dri2_surface_$action_$object naming convention > b) change a first argument type "struct dri2_egl_surface" to > "_EGLSurface". > > v4: Fixes from Gurchetan's review > - add dri2_surface_free_image() helper for refactoring of almost > identical > functions. [1] > > [1] https://lists.freedesktop.org/archives/mesa-dev/2017- > October/173219.html > > Signed-off-by: Mun Gwan-gyeong <elong...@gmail.com> > --- > src/egl/drivers/dri2/egl_dri2.c | 11 +++++++++++ > src/egl/drivers/dri2/egl_dri2.h | 3 +++ > src/egl/drivers/dri2/platform_android.c | 18 +++--------------- > src/egl/drivers/dri2/platform_surfaceless.c | 14 +------------- > src/egl/drivers/dri2/platform_wayland.c | 26 > ++++++++++++-------------- > 5 files changed, 30 insertions(+), 42 deletions(-) > > diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_ > dri2.c > index 8861742c17..84367e69fd 100644 > --- a/src/egl/drivers/dri2/egl_dri2.c > +++ b/src/egl/drivers/dri2/egl_dri2.c > @@ -1085,6 +1085,17 @@ dri2_egl_surface_free_local_buffers(struct > dri2_egl_surface *dri2_surf) > } > } > > +void > +dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img) > +{ > + struct dri2_egl_display *dri2_dpy = dri2_egl_display(surf-> > Resource.Display); > + > + if (*img) { > + dri2_dpy->image->destroyImage(*img); > + *img = NULL; > + } > +} > + > /** > * Called via eglTerminate(), drv->API.Terminate(). > * > diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_ > dri2.h > index cbeedadd4b..dda41117c6 100644 > --- a/src/egl/drivers/dri2/egl_dri2.h > +++ b/src/egl/drivers/dri2/egl_dri2.h > @@ -452,6 +452,9 @@ dri2_egl_surface_alloc_local_buffer(struct > dri2_egl_surface *dri2_surf, > void > dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf); > > +void > +dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img); > + > EGLBoolean > dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type, > _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean > enable_out_fence); > diff --git a/src/egl/drivers/dri2/platform_android.c > b/src/egl/drivers/dri2/platform_android.c > index 24e5ddebf9..3d6dd2e1e7 100644 > --- a/src/egl/drivers/dri2/platform_android.c > +++ b/src/egl/drivers/dri2/platform_android.c > @@ -250,10 +250,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, > struct dri2_egl_surface *dri2_sur > > mtx_lock(&disp->Mutex); > > - if (dri2_surf->dri_image_back) { > - dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); > - dri2_surf->dri_image_back = NULL; > - } > + dri2_surface_free_image(&dri2_surf->base, &dri2_surf->dri_image_back); > > return EGL_TRUE; > } > @@ -377,17 +374,8 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay > *disp, _EGLSurface *surf) > dri2_surf->window->common.decRef(&dri2_surf->window->common); > } > > - if (dri2_surf->dri_image_back) { > - _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, > __LINE__); > - dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); > - dri2_surf->dri_image_back = NULL; > - } > - > - if (dri2_surf->dri_image_front) { > - _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, > __LINE__); > - dri2_dpy->image->destroyImage(dri2_surf->dri_image_front); > - dri2_surf->dri_image_front = NULL; > - } > + dri2_surface_free_image(surf, &dri2_surf->dri_image_back); > + dri2_surface_free_image(surf, &dri2_surf->dri_image_front); > > dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); > > diff --git a/src/egl/drivers/dri2/platform_surfaceless.c > b/src/egl/drivers/dri2/platform_surfaceless.c > index 977b046016..959d587c88 100644 > --- a/src/egl/drivers/dri2/platform_surfaceless.c > +++ b/src/egl/drivers/dri2/platform_surfaceless.c > @@ -50,18 +50,6 @@ surfaceless_alloc_image(struct dri2_egl_display > *dri2_dpy, > NULL); > } > > -static void > -surfaceless_free_images(struct dri2_egl_surface *dri2_surf) > -{ > - struct dri2_egl_display *dri2_dpy = > - dri2_egl_display(dri2_surf->base.Resource.Display); > - > - if (dri2_surf->front) { > - dri2_dpy->image->destroyImage(dri2_surf->front); > - dri2_surf->front = NULL; > - } > -} > - > static int > surfaceless_image_get_buffers(__DRIdrawable *driDrawable, > unsigned int format, > @@ -161,7 +149,7 @@ surfaceless_destroy_surface(_EGLDriver *drv, > _EGLDisplay *disp, _EGLSurface *sur > struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); > struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); > > - surfaceless_free_images(dri2_surf); > + dri2_surface_free_image(&dri2_surf->base, &dri2_surf->front); > > dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); > > diff --git a/src/egl/drivers/dri2/platform_wayland.c > b/src/egl/drivers/dri2/platform_wayland.c > index 3a52971f54..f03b6dc2ab 100644 > --- a/src/egl/drivers/dri2/platform_wayland.c > +++ b/src/egl/drivers/dri2/platform_wayland.c > @@ -268,10 +268,10 @@ dri2_wl_destroy_surface(_EGLDriver *drv, > _EGLDisplay *disp, _EGLSurface *surf) > for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { > if (dri2_surf->color_buffers[i].native_buffer) > wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer); > - if (dri2_surf->color_buffers[i].dri_image) > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > dri_image); > - if (dri2_surf->color_buffers[i].linear_copy) > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > linear_copy); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i].dri_image); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i].linear_copy); > if (dri2_surf->color_buffers[i].data) > munmap(dri2_surf->color_buffers[i].data, > dri2_surf->color_buffers[i].data_size); > @@ -311,17 +311,15 @@ dri2_wl_release_buffers(struct dri2_egl_surface > *dri2_surf) > if (dri2_surf->color_buffers[i].native_buffer && > !dri2_surf->color_buffers[i].locked) > wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer); > - if (dri2_surf->color_buffers[i].dri_image) > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > dri_image); > - if (dri2_surf->color_buffers[i].linear_copy) > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > linear_copy); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i].dri_image); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i].linear_copy); > if (dri2_surf->color_buffers[i].data) > munmap(dri2_surf->color_buffers[i].data, > dri2_surf->color_buffers[i].data_size); > > dri2_surf->color_buffers[i].native_buffer = NULL; > - dri2_surf->color_buffers[i].dri_image = NULL; > - dri2_surf->color_buffers[i].linear_copy = NULL; > dri2_surf->color_buffers[i].data = NULL; > dri2_surf->color_buffers[i].locked = false; > } > @@ -515,12 +513,12 @@ update_buffers(struct dri2_egl_surface *dri2_surf) > if (!dri2_surf->color_buffers[i].locked && > dri2_surf->color_buffers[i].native_buffer) { > wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer); > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > dri_image); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i].dri_image); > if (dri2_dpy->is_different_gpu) > - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i]. > linear_copy); > + dri2_surface_free_image(&dri2_surf->base, > + &dri2_surf->color_buffers[i]. > linear_copy); > dri2_surf->color_buffers[i].native_buffer = NULL; > - dri2_surf->color_buffers[i].dri_image = NULL; > - dri2_surf->color_buffers[i].linear_copy = NULL; > } > } > > -- > 2.15.0 > >
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev