Fix resize issue
authorXuelian Bai <xuelian.bai@samsung.com>
Tue, 28 May 2019 16:01:10 +0000 (00:01 +0800)
committerXuelian Bai <xuelian.bai@samsung.com>
Thu, 18 Jan 2024 01:29:10 +0000 (09:29 +0800)
Handle 1x1 issue for driimage

When evas resize window after dequeue, then draw and swapbuffers,
window is shown with old size until next makecurrent.
Add validate_drawable function to check if resize happen each time
makecurrent is called.

For RPI4, render node is used, so buffer is allocated on another
device, when 1x1 issue happen, we need to make sure if driimage
size is changed, then created new if yes.

Merged Commit:
commit 2dc471b0e167693b81c24c9a3f89b985cb98249f
Author: Zhaowei Yuan <zhaowei.yuan@samsung.com>
    - Check if stdraw is NULL before access
      Variable "stdraw" could be NULL in some case, check it before access.

commit cc2dc99365906ea52b645be3bb10f50708d67e84
Author: Xuelian Bai <xuelian.bai@samsung.com>
    - Fix 1x1 issue of task-mgr
      Makecurrent is called just before resize callback is called, so we
      have to check if size is changed when drawcall.

commit 670d77331c986a92bcf2459567ccd6dfc181bc66
Author: Xuelian Bai <xuelian.bai@samsung.com>
    - Fix resize issue

Change-Id: Ieaebe72661a081d496ab6214c1c1526f7d16f19b
Signed-Off-by: Xuelian Bai <xuelian.bai@samsung.com>
    - Handle 1x1 issue for driimage

Change-Id: Id5a463a8db290ca5b80c130ebcdcb13c7786d70c
Signed-off-by: Xuelian Bai <xuelian.bai@samsung.com>
include/GL/internal/dri_interface.h
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_tizen.c
src/gallium/frontends/dri/dri2.c
src/gallium/frontends/dri/dri_drawable.c
src/gallium/frontends/dri/dri_drawable.h
src/gallium/include/frontend/api.h
src/mesa/main/blit.c
src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_manager.c [changed mode: 0644->0755]
src/mesa/state_tracker/st_manager.h

index ad3ce1c..b634291 100644 (file)
@@ -42,7 +42,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
-
+#include <stdbool.h>
 /**
  * \name DRI interface structures
  *
@@ -1099,6 +1099,9 @@ struct __DRIdri2LoaderExtensionRec {
      * \since 5
      */
     void (*destroyLoaderImageState)(void *loaderPrivate);
+#ifdef HAVE_TIZEN_PLATFORM
+    bool (*validate)(__DRIdrawable *driDrawable, void *loaderPrivate);
+#endif
 };
 
 /**
@@ -2073,6 +2076,10 @@ struct __DRIimageLoaderExtensionRec {
      * \since 4
      */
     void (*destroyLoaderImageState)(void *loaderPrivate);
+#ifdef HAVE_TIZEN_PLATFORM
+    bool (*validate)(__DRIdrawable *driDrawable, void *loaderPrivate);
+#endif
+
 };
 
 /**
index ea4001c..d4db936 100644 (file)
@@ -383,6 +383,7 @@ struct dri2_egl_surface {
    __DRIimage    *dri_image_front;
 
    int buffer_count;
+   bool  valid;
 #endif
 
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
index 3059dc3..b313f13 100755 (executable)
@@ -176,6 +176,7 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
    if (!dri2_surf->tbm_surface)
      return EGL_FALSE;
 
+   dri2_surf->valid = true;
    tbm_surface_internal_ref(dri2_surf->tbm_surface);
 
    tpl_surface_get_size(dri2_surf->tpl_surface, &width, &height);
@@ -342,7 +343,7 @@ tizen_create_surface(_EGLDisplay *disp, EGLint type,
          goto cleanup_surface;
       }
       dri2_surf->native_win = native_window;
-
+      dri2_surf->valid = true;
       dri2_dpy->core->getConfigAttrib(config, __DRI_ATTRIB_DEPTH_SIZE, &depth);
       dri2_dpy->core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SIZE, &alpha);
 
@@ -473,6 +474,21 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
    if (dri2_surf->base.Type != EGL_WINDOW_BIT)
       return 0;
 
+   if (dri2_surf->valid == false) {
+       int i;
+       if (dri2_surf->tbm_surface) {
+           tpl_surface_cancel_dequeued_buffer(dri2_surf->tpl_surface,
+                                              dri2_surf->tbm_surface);
+           tbm_surface_internal_unref(dri2_surf->tbm_surface);
+           for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+               dri2_surf->color_buffers[i].tbm_surface = NULL;
+               dri2_surf->color_buffers[i].age = 0;
+           }
+
+       dri2_surf->back = NULL;
+       dri2_surf->tbm_surface = NULL;
+      }
+   }
    /* try to dequeue the next back buffer */
    if (!dri2_surf->tbm_surface && !tizen_window_dequeue_buffer(dri2_surf)) {
       _eglLog(_EGL_WARNING, "Could not dequeue buffer from native window");
@@ -523,9 +539,20 @@ get_back_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
    int fourcc, pitch;
    int offset = 0, fd;
    tbm_surface_info_s surf_info;
+   EGLBoolean query;
+   int width, height;
 
-   if (dri2_surf->dri_image_back)
-      return 0;
+   if (dri2_surf->dri_image_back) {
+      query = dri2_dpy->image->queryImage(dri2_surf->dri_image_back, __DRI_IMAGE_ATTRIB_WIDTH, &width);
+      query &= dri2_dpy->image->queryImage(dri2_surf->dri_image_back, __DRI_IMAGE_ATTRIB_HEIGHT, &height);
+
+      if (width == dri2_surf->base.Width && height == dri2_surf->base.Height)
+         return 0;
+      else {
+         dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+         dri2_surf->dri_image_back = NULL;
+      }
+   }
 
    if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
       if (!dri2_surf->tbm_surface) {
@@ -1011,6 +1038,16 @@ tizen_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
 {
 }
 
+static bool
+tizen_validate_drawable(__DRIdrawable * driDrawable, void *loaderPrivate)
+{
+    struct dri2_egl_surface *dri2_surf = loaderPrivate;
+    bool v = tpl_surface_validate(dri2_surf->tpl_surface);
+
+    dri2_surf->valid = v;
+    return v;
+}
+
 static int
 tizen_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
                                     unsigned int *attachments, int count)
@@ -1340,6 +1377,7 @@ static const __DRIdri2LoaderExtension tizen_dri2_loader_extension = {
    .getBuffers           = NULL,
    .getBuffersWithFormat = tizen_get_buffers_with_format,
    .flushFrontBuffer     = tizen_flush_front_buffer,
+   .validate            = tizen_validate_drawable,
 };
 
 static const __DRIimageLoaderExtension tizen_image_loader_extension = {
@@ -1347,6 +1385,7 @@ static const __DRIimageLoaderExtension tizen_image_loader_extension = {
 
    .getBuffers          = tizen_image_get_buffers,
    .flushFrontBuffer    = tizen_flush_front_buffer,
+   .validate            = tizen_validate_drawable,
 };
 
 static const __DRIswrastLoaderExtension tizen_swrast_loader_extension = {
index a018ef7..608ca0a 100644 (file)
@@ -466,6 +466,35 @@ handle_in_fence(struct dri_context *ctx, __DRIimage *img)
 /*
  * Backend functions for pipe_frontend_drawable.
  */
+#ifdef HAVE_TIZEN_PLATFORM
+static bool dri2_validate_drawable(struct dri_drawable *drawable)
+{
+    const __DRIdri2LoaderExtension *loader = drawable->screen->dri2.loader;
+
+    if (loader && loader->validate != NULL) {
+        bool valid = (loader->validate)(opaque_dri_drawable(drawable), drawable->loaderPrivate);
+        if (valid == false) /*drawable may be resized, not valid anymore*/ {
+            drawable->lastStamp = drawable->base.stamp;
+            drawable->texture_mask = 0;
+        }
+        return valid;
+    }
+    else {
+       const __DRIimageLoaderExtension *image_loader = drawable->screen->image.loader;
+       if (image_loader && image_loader->validate != NULL) {
+          bool valid = (image_loader->validate)(opaque_dri_drawable(drawable),drawable->loaderPrivate);
+          if (valid == false) /*drawable may be resized, not valid anymore*/ {
+             drawable->lastStamp = drawable->base.stamp;
+             drawable->texture_mask = 0;
+          }
+          return valid;
+       }
+       return true;
+    }
+
+}
+#endif
+
 
 static void
 dri2_allocate_textures(struct dri_context *ctx,
@@ -2364,7 +2393,9 @@ dri2_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
    drawable->flush_frontbuffer = dri2_flush_frontbuffer;
    drawable->update_tex_buffer = dri2_update_tex_buffer;
    drawable->flush_swapbuffers = dri2_flush_swapbuffers;
-
+#ifdef HAVE_TIZEN_PLATFORM
+   drawable->validate_drawable = dri2_validate_drawable;
+#endif
    return drawable;
 }
 
index 58008b3..f81ee5c 100644 (file)
 
 static uint32_t drifb_ID = 0;
 
+#ifdef HAVE_TIZEN_PLATFORM
+static bool
+dri_st_framebuffer_validate_drawable(struct pipe_frontend_drawable *pdrawable)
+{
+   struct dri_drawable *drawable = (struct dri_drawable *)pdrawable;
+   if (drawable->validate_drawable == NULL)
+        return true;
+    else
+        return drawable->validate_drawable(drawable);
+}
+#endif
+
 static bool
 dri_st_framebuffer_validate(struct st_context *st,
                             struct pipe_frontend_drawable *pdrawable,
@@ -174,6 +186,9 @@ dri_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
    drawable->base.flush_front = dri_st_framebuffer_flush_front;
    drawable->base.validate = dri_st_framebuffer_validate;
    drawable->base.flush_swapbuffers = dri_st_framebuffer_flush_swapbuffers;
+#ifdef HAVE_TIZEN_PLATFORM
+   drawable->base.validate_drawable = dri_st_framebuffer_validate_drawable;
+#endif
 
    drawable->screen = screen;
 
index d759fcf..d54b046 100644 (file)
@@ -109,6 +109,9 @@ struct dri_drawable
                              struct dri_drawable *drawable);
 
    void (*swap_buffers)(struct dri_drawable *drawable);
+#ifdef HAVE_TIZEN_PLATFORM
+   bool (*validate_drawable)(struct dri_drawable *drawable);
+#endif
 };
 
 /* Typecast the opaque pointer to our own type. */
index 712cbe9..d8d2979 100644 (file)
@@ -279,6 +279,9 @@ struct pipe_frontend_drawable
                     unsigned count,
                     struct pipe_resource **out,
                     struct pipe_resource **resolve);
+#ifdef HAVE_TIZEN_PLATFORM
+   bool (*validate_drawable)(struct pipe_frontend_drawable *drawable);
+#endif
 
    bool (*flush_swapbuffers)(struct st_context *st,
                              struct pipe_frontend_drawable *drawable);
index c71aa14..ed1bf09 100644 (file)
@@ -371,7 +371,11 @@ do_blit_framebuffer(struct gl_context *ctx,
    } clip;
    struct pipe_blit_info blit;
 
+#ifdef HAVE_TIZEN_PLATFORM
+   st_manager_validate_framebuffers(st, true);
+#else
    st_manager_validate_framebuffers(st);
+#endif
 
    /* Make sure bitmap rendering has landed in the framebuffers */
    st_flush_bitmap_cache(st);
index 16542bb..72e5b66 100644 (file)
@@ -117,7 +117,11 @@ st_update_framebuffer_state( struct st_context *st )
    GLuint i;
 
    /* Window framebuffer changes are received here. */
+#ifdef HAVE_TIZEN_PLATFORM
+   st_manager_validate_framebuffers(st, true);
+#else
    st_manager_validate_framebuffers(st);
+#endif
 
    st_flush_bitmap_cache(st);
    st_invalidate_readpix_cache(st);
old mode 100644 (file)
new mode 100755 (executable)
index 34938b4..83aab8a
@@ -78,6 +78,7 @@ struct st_screen
  * We'll only return non-null for window system framebuffers.
  * Note that this function may fail.
  */
+#if 0 /*Move this function to header file to be used by other files*/
 static inline struct gl_framebuffer *
 st_ws_framebuffer(struct gl_framebuffer *fb)
 {
@@ -87,6 +88,7 @@ st_ws_framebuffer(struct gl_framebuffer *fb)
       return fb;
    return NULL;
 }
+#endif
 
 /**
  * Map an attachment to a buffer index.
@@ -219,7 +221,11 @@ st_set_ws_renderbuffer_surface(struct gl_renderbuffer *rb,
  */
 static void
 st_framebuffer_validate(struct gl_framebuffer *stfb,
-                        struct st_context *st)
+                        struct st_context *st
+#ifdef HAVE_TIZEN_PLATFORM
+                        , bool valid
+#endif
+                        )
 {
    struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
    struct pipe_resource *resolve = NULL;
@@ -229,7 +235,11 @@ st_framebuffer_validate(struct gl_framebuffer *stfb,
    int32_t new_stamp;
 
    new_stamp = p_atomic_read(&stfb->drawable->stamp);
+#ifdef HAVE_TIZEN_PLATFORM
+   if (valid == GL_TRUE && stfb->drawable_stamp == new_stamp)
+#else
    if (stfb->drawable_stamp == new_stamp)
+#endif
       return;
 
    memset(textures, 0, stfb->num_statts * sizeof(textures[0]));
@@ -1128,6 +1138,9 @@ st_api_make_current(struct st_context *st,
 {
    struct gl_framebuffer *stdraw, *stread;
    bool ret;
+#ifdef HAVE_TIZEN_PLATFORM
+   bool valid = true;
+#endif
 
    if (st) {
       /* reuse or create the draw fb */
@@ -1147,10 +1160,24 @@ st_api_make_current(struct st_context *st,
       if ((stdrawi && !stdraw) || (streadi && !stread))
          return false;
 
+#ifdef HAVE_TIZEN_PLATFORM
+      if (stdraw && stdraw->drawable->validate_drawable)
+         valid = stdraw->drawable->validate_drawable(stdraw->drawable);
+#endif
+
       if (stdraw && stread) {
+#ifdef HAVE_TIZEN_PLATFORM
+         st_framebuffer_validate(stdraw, st, valid);
+#else
          st_framebuffer_validate(stdraw, st);
+#endif
+
          if (stread != stdraw)
+#ifdef HAVE_TIZEN_PLATFORM
+            st_framebuffer_validate(stread, st, true);
+#else
             st_framebuffer_validate(stread, st);
+#endif
 
          ret = _mesa_make_current(st->ctx, stdraw, stread);
 
@@ -1236,16 +1263,28 @@ st_manager_flush_frontbuffer(struct st_context *st)
 /**
  * Re-validate the framebuffers.
  */
+#ifdef HAVE_TIZEN_PLATFORM
+void
+st_manager_validate_framebuffers(struct st_context *st, bool valid)
+#else
 void
 st_manager_validate_framebuffers(struct st_context *st)
+#endif
 {
    struct gl_framebuffer *stdraw = st_ws_framebuffer(st->ctx->DrawBuffer);
    struct gl_framebuffer *stread = st_ws_framebuffer(st->ctx->ReadBuffer);
 
+#ifdef HAVE_TIZEN_PLATFORM
+   if (stdraw)
+      st_framebuffer_validate(stdraw, st, valid);
+   if (stread && stread != stdraw)
+      st_framebuffer_validate(stread, st, GL_TRUE);
+#else
    if (stdraw)
       st_framebuffer_validate(stdraw, st);
    if (stread && stread != stdraw)
       st_framebuffer_validate(stread, st);
+#endif
 
    st_context_validate(st, stdraw, stread);
 }
index 4a617ed..abf75c5 100644 (file)
@@ -38,11 +38,27 @@ struct st_context;
 struct gl_renderbuffer;
 struct pipe_surface;
 
+
+static inline struct gl_framebuffer *
+st_ws_framebuffer(struct gl_framebuffer *fb)
+{
+   /* FBO cannot be casted.  See st_new_framebuffer */
+   if (fb && _mesa_is_winsys_fbo(fb) &&
+       fb != _mesa_get_incomplete_framebuffer())
+      return fb;
+   return NULL;
+}
+
 void
 st_manager_flush_frontbuffer(struct st_context *st);
 
+#ifdef HAVE_TIZEN_PLATFORM
+void
+st_manager_validate_framebuffers(struct st_context *st, bool valid);
+#else
 void
 st_manager_validate_framebuffers(struct st_context *st);
+#endif
 
 bool
 st_manager_add_color_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,