[Mesa-dev] [PATCH] glsl: Fix typo nagivation -> navigation

2017-11-25 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/compiler/glsl/ir_hierarchical_visitor.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/compiler/glsl/ir_hierarchical_visitor.h 
b/src/compiler/glsl/ir_hierarchical_visitor.h
index 824b05e73d..5f5acd041b 100644
--- a/src/compiler/glsl/ir_hierarchical_visitor.h
+++ b/src/compiler/glsl/ir_hierarchical_visitor.h
@@ -54,7 +54,7 @@ enum ir_visitor_status {
  * returning \c visit_stop), or stop visiting sibling nodes (by returning \c
  * visit_continue_with_parent).
  *
- * These two changes combine to allow nagivation of children to be implemented
+ * These two changes combine to allow navigation of children to be implemented
  * in the composite's \c accept method.  The \c accept method for a leaf-node
  * class will simply call the \c visit method, as usual, and pass its return
  * value on.  The \c accept method for internal-node classes will call the \c
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] egl/wayland: add dri2_wl_free_buffers() helper (v3)

2017-11-15 Thread Gwan-gyeong Mun
This deduplicates free routines of color_buffers array.

v2:
 - Add clear_all argument to check clearing all of color_buffers or not.
 - Fixes from Eric's review:
   a) polish check routine of check_lock and color_buffers[i].locked
   b) move 'native_buffer = NULL' to avoid leaking locked buffers
 - Fixes from Emil's review:
   a) drop the unneeded cast
   b) apply dri2_wl_free_buffers to update_buffers() and swrast_update_buffers()

v3: Use a dri2_surface_free_image() helper

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_wayland.c | 85 +
 1 file changed, 33 insertions(+), 52 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index f03b6dc2ab..975596fc7d 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -252,6 +252,35 @@ dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay 
*disp,
return NULL;
 }
 
+static void
+dri2_wl_free_buffers(struct dri2_egl_surface *dri2_surf, bool check_lock,
+ bool clear_all)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  bool clear_buffer = false;
+
+  if (dri2_surf->color_buffers[i].native_buffer &&
+  (!check_lock || !dri2_surf->color_buffers[i].locked)) {
+ wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].locked = false;
+ clear_buffer = true;
+  }
+
+  if (clear_all || clear_buffer) {
+ dri2_surface_free_image(_surf->base,
+ _surf->color_buffers[i].dri_image);
+ dri2_surface_free_image(_surf->base,
+ _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].data = NULL;
+  }
+   }
+}
+
 /**
  * Called via eglDestroySurface(), drv->API.DestroySurface().
  */
@@ -265,17 +294,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay 
*disp, _EGLSurface *surf)
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-   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);
-  dri2_surface_free_image(_surf->base,
-  _surf->color_buffers[i].dri_image);
-  dri2_surface_free_image(_surf->base,
-  _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_wl_free_buffers(dri2_surf, false, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -307,22 +326,7 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer &&
-  !dri2_surf->color_buffers[i].locked)
- wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
-  dri2_surface_free_image(_surf->base,
-  _surf->color_buffers[i].dri_image);
-  dri2_surface_free_image(_surf->base,
-  _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].data = NULL;
-  dri2_surf->color_buffers[i].locked = false;
-   }
+   dri2_wl_free_buffers(dri2_surf, true, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -487,9 +491,6 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, 
__DRIbuffer *buffer)
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
if (dri2_surf->base.Width != dri2_surf->wl_win->width ||
dri2_surf->base.Height != dri2_surf->wl_win->height) {
 
@@ -509,18 +510,7 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
/* If we have an extra unlocked buffer at this point, we had to do triple
 * buffering for a while, but now can go back to just double buffering.
 * That means we can free any unlocked buffer now. */
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].locked &&
-  dri2_surf->color_buffers[i].native_buffer) 

[Mesa-dev] [PATCH] egl: add dri2_surface_free_image() helper (v4)

2017-11-15 Thread Gwan-gyeong Mun
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 
---
 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(>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(_surf->base, _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(_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, _surf->dri_image_back);
+   dri2_surface_free_image(surf, _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(_surf->base, _surf->front);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);

[Mesa-dev] [PATCH] egl: refactor color_buffers structure for deduplicating (v2)

2017-11-15 Thread Gwan-gyeong Mun
This is added for preventing adding of new color buffers structure and back*
when new platform backend is added.
This refactoring separates out the common and platform specific bits.
This makes odd casting in the platform_foo.c but it prevents adding of new
ifdef magic.
Because of color_buffers array size is different on android and wayland /drm,
it adds COLOR_BUFFERS_SIZE macro.
 - android's color buffers array size is 3.
   drm & wayland's color buffers array size is 4.

Fixes from Rob's review:
 - refactor to separate out the common and platform specific bits.

Fixes from Emil's review:
 - use suggested color buffers structure shape.
   it makes a buffer pointer of each platform to void pointer type.

v2: Fixes from Emil's review
  a) change ifdef macro of "HAVE_WAYLAND_PLATFORM or HAVE_DRM_PLATFORM" to
 "HAVE_ANDROID_PLATFORM" for COLOR_BUFFERS_SIZE.
  b) drop the unneeded indentation of comment.
  c) drop ifdef macro of HAVE_WAYLAND_PLATFORM from color_buffers structure
 for more generic and widespread helpers.
  d) drop unneeded $native_type -> void * cast and viceversa.
  e) create the local native_buffer of $native_type and cast on assignment.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h | 32 --
 src/egl/drivers/dri2/platform_android.c | 10 +++---
 src/egl/drivers/dri2/platform_drm.c | 60 ++---
 src/egl/drivers/dri2/platform_wayland.c | 41 +++---
 4 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 0ec8f44dce..cbeedadd4b 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,15 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_ANDROID_PLATFORM
+/* Usually Android uses at most triple buffers in ANativeWindow so hardcode
+ * the number of color_buffers to 3.
+ */
+#define COLOR_BUFFERS_SIZE 3
+#else
+#define COLOR_BUFFERS_SIZE 4
+#endif
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -280,39 +289,26 @@ struct dri2_egl_surface
/* EGL-owned buffers */
__DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+   /* Used to record all the buffers created by each platform's native window
+* and their ages.
+*/
struct {
-#ifdef HAVE_WAYLAND_PLATFORM
-  struct wl_buffer   *wl_buffer;
+  void *native_buffer; // aka wl_buffer/gbm_bo/ANativeWindowBuffer
   __DRIimage *dri_image;
   /* for is_different_gpu case. NULL else */
   __DRIimage *linear_copy;
   /* for swrast */
   void *data;
   int data_size;
-#endif
-#ifdef HAVE_DRM_PLATFORM
-  struct gbm_bo   *bo;
-#endif
   boollocked;
   int age;
-   } color_buffers[4], *back, *current;
-#endif
+   } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
-
-   /* Used to record all the buffers created by ANativeWindow and their ages.
-* Usually Android uses at most triple buffers in ANativeWindow
-* so hardcode the number of color_buffers to 3.
-*/
-   struct {
-  struct ANativeWindowBuffer *buffer;
-  int age;
-   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 63223e9a69..24e5ddebf9 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -193,10 +193,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
 */
EGLBoolean updated = EGL_FALSE;
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
   }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+  if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
  dri2_surf->back = _surf->color_buffers[i];
  updated = EGL_TRUE;
  break;
@@ -208,10 +208,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
* the color_buffers
*/
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].native_buffer = NULL;
  dri2_surf->color_buffers[i].age = 0;
   }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+  dri2_surf->color_buffers[0].native_buffer = 

[Mesa-dev] [PATCH] nir: fix a typo

2017-11-06 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/compiler/nir/nir.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 87c725625d..0174c30504 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -1155,7 +1155,7 @@ typedef enum {
nir_texop_tex,/**< Regular texture look-up */
nir_texop_txb,/**< Texture look-up with LOD bias */
nir_texop_txl,/**< Texture look-up with explicit LOD */
-   nir_texop_txd,/**< Texture look-up with partial derivatvies 
*/
+   nir_texop_txd,/**< Texture look-up with partial derivatives 
*/
nir_texop_txf,/**< Texel fetch with explicit LOD */
nir_texop_txf_ms,/**< Multisample texture fetch */
nir_texop_txf_ms_mcs, /**< Multisample compression value fetch */
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 7/9] egl: add dri2_surface_free_image() helper (v4)

2017-11-03 Thread Gwan-gyeong Mun
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 
---
 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 d381e52e86..13c86f87c2 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1142,6 +1142,17 @@ dri2_surface_update_age(_EGLSurface *surf)
   dri2_surf->back->age = 1;
 }
 
+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 58f8082509..9cc04930c8 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -460,6 +460,9 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer);
 void
 dri2_surface_update_age(_EGLSurface *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 45af871555..dc20bea319 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -228,10 +228,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>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(_surf->base, _surf->dri_image_back);
 
return EGL_TRUE;
 }
@@ -355,17 +352,8 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_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, _surf->dri_image_back);
+   dri2_surface_free_image(surf, _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(_surf->base, _surf->front);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
diff --git 

[Mesa-dev] [PATCH v4 9/9] egl/wayland: add dri2_wl_free_buffers() helper (v3)

2017-11-02 Thread Gwan-gyeong Mun
This deduplicates free routines of color_buffers array.

v2:
 - Add clear_all argument to check clearing all of color_buffers or not.
 - Fixes from Eric's review:
   a) polish check routine of check_lock and color_buffers[i].locked
   b) move 'native_buffer = NULL' to avoid leaking locked buffers
 - Fixes from Emil's review:
   a) drop the unneeded cast
   b) apply dri2_wl_free_buffers to update_buffers() and swrast_update_buffers()

v3: Use a dri2_surface_free_image() helper

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_wayland.c | 85 +
 1 file changed, 33 insertions(+), 52 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index d864355eb4..b77f05ca15 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -252,6 +252,35 @@ dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay 
*disp,
return NULL;
 }
 
+static void
+dri2_wl_free_buffers(struct dri2_egl_surface *dri2_surf, bool check_lock,
+ bool clear_all)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  bool clear_buffer = false;
+
+  if (dri2_surf->color_buffers[i].native_buffer &&
+  (!check_lock || !dri2_surf->color_buffers[i].locked)) {
+ wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].locked = false;
+ clear_buffer = true;
+  }
+
+  if (clear_all || clear_buffer) {
+ dri2_surface_free_image(_surf->base,
+ _surf->color_buffers[i].dri_image);
+ dri2_surface_free_image(_surf->base,
+ _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].data = NULL;
+  }
+   }
+}
+
 /**
  * Called via eglDestroySurface(), drv->API.DestroySurface().
  */
@@ -265,17 +294,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay 
*disp, _EGLSurface *surf)
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-   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);
-  dri2_surface_free_image(_surf->base,
-  _surf->color_buffers[i].dri_image);
-  dri2_surface_free_image(_surf->base,
-  _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_wl_free_buffers(dri2_surf, false, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -307,22 +326,7 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer &&
-  !dri2_surf->color_buffers[i].locked)
- wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
-  dri2_surface_free_image(_surf->base,
-  _surf->color_buffers[i].dri_image);
-  dri2_surface_free_image(_surf->base,
-  _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].data = NULL;
-  dri2_surf->color_buffers[i].locked = false;
-   }
+   dri2_wl_free_buffers(dri2_surf, true, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -487,9 +491,6 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, 
__DRIbuffer *buffer)
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
if (dri2_surf->base.Width != dri2_surf->wl_win->width ||
dri2_surf->base.Height != dri2_surf->wl_win->height) {
 
@@ -509,18 +510,7 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
/* If we have an extra unlocked buffer at this point, we had to do triple
 * buffering for a while, but now can go back to just double buffering.
 * That means we can free any unlocked buffer now. */
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].locked &&
-  dri2_surf->color_buffers[i].native_buffer) 

[Mesa-dev] [PATCH v4 8/9] egl: add dri2_surface_get_front_image() helper (v4)

2017-11-02 Thread Gwan-gyeong Mun
To share common get and create dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - 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:
  - Move dri_image_front to outside of android ifdef block for not to use of
ifdef magic on dri2_surface_get_front_image().

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 33 +++
 src/egl/drivers/dri2/egl_dri2.h |  6 +-
 src/egl/drivers/dri2/platform_android.c | 35 +
 3 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 13c86f87c2..c1a9392f68 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1153,6 +1153,39 @@ dri2_surface_free_image(_EGLSurface *surf, __DRIimage 
**img)
}
 }
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy = 
dri2_egl_display(surf->Resource.Display);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (surf->Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (surf->Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  surf->Width,
+  surf->Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+
+   return 0;
+}
+
 /**
  * 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 9cc04930c8..96c4a213df 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -303,11 +303,12 @@ struct dri2_egl_surface
   int age;
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
+   __DRIimage *dri_image_front;
+
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
-   __DRIimage *dri_image_front;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
@@ -463,6 +464,9 @@ dri2_surface_update_age(_EGLSurface *surf);
 void
 dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img);
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format);
+
 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 74b034b18f..707195f03d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -386,39 +386,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-  return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-  /* According current EGL spec, front buffer rendering
-   * for window surface is not supported now.
-   * and mesa doesn't have the implementation of this case.
-   * Add warning message, but not treat it as error.
-   */
-  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-  dri2_surf->dri_image_front =
-  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-  dri2_surf->base.Width,
-  dri2_surf->base.Height,
-  format,
-  

[Mesa-dev] [PATCH v4 7/9] egl: add dri2_surface_free_image() helper (v4)

2017-11-02 Thread Gwan-gyeong Mun
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 
---
 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 d381e52e86..13c86f87c2 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1142,6 +1142,17 @@ dri2_surface_update_age(_EGLSurface *surf)
   dri2_surf->back->age = 1;
 }
 
+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 58f8082509..9cc04930c8 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -460,6 +460,9 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer);
 void
 dri2_surface_update_age(_EGLSurface *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 45af871555..74b034b18f 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -228,10 +228,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>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(_surf->base, _surf->dri_image_back);
 
return EGL_TRUE;
 }
@@ -355,17 +352,8 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_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->base, _surf->dri_image_back);
+   dri2_surface_free_image(_surf->base, _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(_surf->base, _surf->front);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
diff --git 

[Mesa-dev] [PATCH v4 4/9] egl: add a missed initialization of buffer age.

2017-11-02 Thread Gwan-gyeong Mun
It add an initialization of buffer age on dri2_surface_set_back_buffer().

Fixes from Emil's review
 - Split out separated patch for adding of missed initialization of buffer
   age. [1]

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-October/173129.html

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 2063d1ca56..edb692c7e5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1104,6 +1104,7 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
   if (!dri2_surf->color_buffers[i].native_buffer) {
  dri2_surf->color_buffers[i].native_buffer = buffer;
+ dri2_surf->color_buffers[i].age = 0;
   }
   if (dri2_surf->color_buffers[i].native_buffer == buffer) {
  dri2_surf->back = _surf->color_buffers[i];
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 5/9] egl: add going out of the loop when color_buffer is set.

2017-11-02 Thread Gwan-gyeong Mun
If color_buffer is set once, we don't need to set a same native buffer to
remained free slot of color_buffers. So we can go out of the loop when
color_buffer is set first.

Fixes from Emil's review
 - Add setting "updated" and bailing out when the color_buffer is set.[1]

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-October/173129.html

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index edb692c7e5..a504978fda 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1105,6 +1105,8 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
   if (!dri2_surf->color_buffers[i].native_buffer) {
  dri2_surf->color_buffers[i].native_buffer = buffer;
  dri2_surf->color_buffers[i].age = 0;
+ updated = EGL_TRUE;
+ break;
   }
   if (dri2_surf->color_buffers[i].native_buffer == buffer) {
  dri2_surf->back = _surf->color_buffers[i];
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 6/9] egl: add dri2_surface_update_age() helper (v3)

2017-11-02 Thread Gwan-gyeong Mun
To share common update buffer age code.
This updates old buffer's age and sets current back buffer's age to 1.

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.
 - Fixes from Rob's review:
   Remove unneeded ifdef block

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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 16 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 11 +--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a504978fda..d381e52e86 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1126,6 +1126,22 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
}
 }
 
+void
+dri2_surface_update_age(_EGLSurface *surf)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+   }
+
+   /* "XXX: we don't use get_back_bo() since it causes regressions in
+* several dEQP tests.
+*/
+   if (dri2_surf->back)
+  dri2_surf->back->age = 1;
+}
+
 /**
  * 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 4c01959324..58f8082509 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -457,6 +457,9 @@ dri2_surface_fixup(_EGLSurface *surf, int width, int 
height);
 void
 dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
 
+void
+dri2_surface_update_age(_EGLSurface *surf);
+
 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 559672ff21..45af871555 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -567,16 +567,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
   return EGL_TRUE;
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].age > 0)
- dri2_surf->color_buffers[i].age++;
-   }
-
-   /* "XXX: we don't use get_back_bo() since it causes regressions in
-* several dEQP tests.
-*/
-   if (dri2_surf->back)
-  dri2_surf->back->age = 1;
+   dri2_surface_update_age(draw);
 
dri2_flush_drawable_for_swapbuffers(disp, draw);
 
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 2/9] egl: refactor color_buffers structure for deduplicating (v2)

2017-11-02 Thread Gwan-gyeong Mun
From: "Mun, Gwan-gyeong" 

This is added for preventing adding of new color buffers structure and back*
when new platform backend is added.
This refactoring separates out the common and platform specific bits.
This makes odd casting in the platform_foo.c but it prevents adding of new
ifdef magic.
Because of color_buffers array size is different on android and wayland /drm,
it adds COLOR_BUFFERS_SIZE macro.
 - android's color buffers array size is 3.
   drm & wayland's color buffers array size is 4.

Fixes from Rob's review:
 - refactor to separate out the common and platform specific bits.

Fixes from Emil's review:
 - use suggested color buffers structure shape.
   it makes a buffer pointer of each platform to void pointer type.

v2: Fixes from Emil's review
  a) change ifdef macro of "HAVE_WAYLAND_PLATFORM or HAVE_DRM_PLATFORM" to
 "HAVE_ANDROID_PLATFORM" for COLOR_BUFFERS_SIZE.
  b) drop the unneeded indentation of comment.
  c) drop ifdef macro of HAVE_WAYLAND_PLATFORM from color_buffers structure
 for more generic and widespread helpers.
  d) drop unneeded $native_type -> void * cast and viceversa.
  e) create the local native_buffer of $native_type and cast on assignment.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h | 32 --
 src/egl/drivers/dri2/platform_android.c | 10 +++---
 src/egl/drivers/dri2/platform_drm.c | 60 ++---
 src/egl/drivers/dri2/platform_wayland.c | 41 +++---
 4 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 208a03d73a..6a218b49aa 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,15 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_ANDROID_PLATFORM
+/* Usually Android uses at most triple buffers in ANativeWindow so hardcode
+ * the number of color_buffers to 3.
+ */
+#define COLOR_BUFFERS_SIZE 3
+#else
+#define COLOR_BUFFERS_SIZE 4
+#endif
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -279,39 +288,26 @@ struct dri2_egl_surface
/* EGL-owned buffers */
__DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+   /* Used to record all the buffers created by each platform's native window
+* and their ages.
+*/
struct {
-#ifdef HAVE_WAYLAND_PLATFORM
-  struct wl_buffer   *wl_buffer;
+  void *native_buffer; // aka wl_buffer/gbm_bo/ANativeWindowBuffer
   __DRIimage *dri_image;
   /* for is_different_gpu case. NULL else */
   __DRIimage *linear_copy;
   /* for swrast */
   void *data;
   int data_size;
-#endif
-#ifdef HAVE_DRM_PLATFORM
-  struct gbm_bo   *bo;
-#endif
   boollocked;
   int age;
-   } color_buffers[4], *back, *current;
-#endif
+   } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
-
-   /* Used to record all the buffers created by ANativeWindow and their ages.
-* Usually Android uses at most triple buffers in ANativeWindow
-* so hardcode the number of color_buffers to 3.
-*/
-   struct {
-  struct ANativeWindowBuffer *buffer;
-  int age;
-   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index d00aa2..c254173690 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -193,10 +193,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
 */
EGLBoolean updated = EGL_FALSE;
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
   }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+  if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
  dri2_surf->back = _surf->color_buffers[i];
  updated = EGL_TRUE;
  break;
@@ -208,10 +208,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
* the color_buffers
*/
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].native_buffer = NULL;
  dri2_surf->color_buffers[i].age = 0;
   }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+  

[Mesa-dev] [PATCH v4 3/9] egl: add dri2_surface_set_back_buffer() helper (v3)

2017-11-02 Thread Gwan-gyeong Mun
To share common record buffers and update back buffer code.
This records all the buffers created by each platform's native window and
update back buffer for updating buffer's age in swap_buffers.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - 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".
  - Fixes from Emil's review:
a) fix typo
b) drop the addition of initialization of buffer age.

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 31 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 24 +---
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 238e299aed..2063d1ca56 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1092,6 +1092,37 @@ dri2_surface_fixup(_EGLSurface *surf, int width, int 
height)
}
 }
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer)
+{
+   /* Record all the buffers created by each platform's native window and
+* update back buffer for updating buffer's age in swap_buffers.
+*/
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = buffer;
+  }
+  if (dri2_surf->color_buffers[i].native_buffer == buffer) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated, reset the color_buffers */
+  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  dri2_surf->color_buffers[0].native_buffer = buffer;
+  dri2_surf->back = _surf->color_buffers[0];
+   }
+}
+
 /**
  * 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 6a218b49aa..4c01959324 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -454,6 +454,9 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_surface_fixup(_EGLSurface *surf, int width, int height);
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
+
 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 c254173690..559672ff21 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
/* Record all the buffers created by ANativeWindow and update back buffer
 * for updating buffer's age in swap_buffers.
 */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].native_buffer) {
- dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
-  }
-  if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
- dri2_surf->back = _surf->color_buffers[i];
- updated = EGL_TRUE;
- break;
-  }
-   }
-
-   if (!updated) {
-  /* In case of all the buffers were recreated by ANativeWindow, reset
-   * the color_buffers
-   */
-  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].native_buffer = NULL;
- dri2_surf->color_buffers[i].age = 0;
-  }
-  dri2_surf->color_buffers[0].native_buffer = dri2_surf->buffer;
-  dri2_surf->back = _surf->color_buffers[0];
-   }
+   dri2_surface_set_back_buffer(_surf->base, dri2_surf->buffer);
 
return EGL_TRUE;
 }
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 1/9] egl: add dri2_surface_fixup() helper (v3)

2017-11-02 Thread Gwan-gyeong Mun
From: "Mun, Gwan-gyeong" 

To share common free outdated buffers and update size code.
This compares width and height arguments with current egl surface dimension,
if the compared surface dimension is differ, then it free local buffers and
updates dimension.

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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 13 +
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c |  8 ++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 503450542e..238e299aed 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1079,6 +1079,19 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_surface_fixup(_EGLSurface *surf, int width, int height)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   /* free outdated buffers and update the surface size */
+   if (surf->Width != width || surf->Height != height) {
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+  surf->Width = width;
+  surf->Height = height;
+   }
+}
+
 /**
  * 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 cd2487ab22..208a03d73a 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -455,6 +455,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_fixup(_EGLSurface *surf, int width, int height);
+
 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 e390365b8b..d00aa2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -414,12 +414,8 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
}
 
/* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-   dri2_surf->base.Height != dri2_surf->buffer->height) {
-  dri2_egl_surface_free_local_buffers(dri2_surf);
-  dri2_surf->base.Width = dri2_surf->buffer->width;
-  dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
+   dri2_surface_fixup(_surf->base, dri2_surf->buffer->width,
+  dri2_surf->buffer->height);
 
return 0;
 }
-- 
2.15.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 10/10] docs: add a high level info about Tizen / Tizen Porting Layer (TPL) for EGL / Tizen Buffer Manager (TBM) / etc (v2)

2017-10-25 Thread Gwan-gyeong Mun
It gives a quick overview and references of developing OpenGLES / EGL
Driver for Tizen.

v2:
 - Fixes from Eric's review:
   Change links of Setup build environment for Tizen (Raspberry Pi 3) and
   Tizen Binary Download Instructions for Raspberry Pi 3 to `tizen-` prefixed
   pages.

 - Add Setup Raspberry Pi 3 for Tizen Instruction link

Signed-off-by: Mun Gwan-gyeong 
---
 docs/systems.html |   1 +
 docs/tizen.html   | 251 ++
 2 files changed, 252 insertions(+)
 create mode 100644 docs/tizen.html

diff --git a/docs/systems.html b/docs/systems.html
index b97e1f0a79..ab6c9c3f74 100644
--- a/docs/systems.html
+++ b/docs/systems.html
@@ -63,6 +63,7 @@ drivers for the X Window System
 and Unix-like operating systems
 Microsoft Windows
 VMware guest OS driver
+Tizen
 
 
 
diff --git a/docs/tizen.html b/docs/tizen.html
new file mode 100644
index 00..06656c8f44
--- /dev/null
+++ b/docs/tizen.html
@@ -0,0 +1,251 @@
+http://www.w3.org/TR/html4/loose.dtd;>
+
+
+  
+  Tizen
+  
+
+
+
+
+  The Mesa 3D Graphics Library
+
+
+
+
+
+Introduction
+
+
+This document describes the essential elements of Tizen's platform-level
+graphics architecture related to OpenGL ES and EGL,
+and how it is used by the application framework and the display server.
+The focus is on how graphical data buffers move through the system.
+
+
+
+Tizen platform requires the OpenGL ES driver for the acceleration of
+the Wayland display server and wayland-eglclient.
+This platform demands OpenGL ES and EGL driver which is implemented by
+the Tizen EGL Porting Layer.
+
+
+
+Tizen OpenGL ES and EGL Architecture
+
+
+The following figure illustrates the Tizen OpenGL ES and EGL architecture.
+
+
+
+  https://wiki.tizen.org/images/d/d6/OPENGLES_STACK.png;
+  width="800" height="582" />
+
+
+
+CoreGL
+
+An injection layer of OpenGL ES that provides the following 
capabilities:
+
+
+   Support for driver-independent optimization (FastPath)
+   EGL/OpenGL ES debugging
+   Performance logging
+
+
+
+Tizen Porting Layer (TPL) for EGL
+
+
+TPL-EGL is an abstraction layer for surface and buffer management on Tizen
+platform. It is used for implementation of the EGL platform functions.
+
+
+
+  https://wiki.tizen.org/images/0/0e/Tpl_architecture.png;
+  width="800" height="204" />
+
+
+
+
+  
+  The background for the Tizen EGL Porting Layer for EGL is in various window
+  system protocols in Tizen. There was a need for separating common layer and
+  backend.
+  
+  
+  Tizen uses the Tizen Porting Layer for EGL, as the TPL-EGL APIs prevents
+  burdens of the EGL porting on various window system protocols.
+  The GPU GL Driver’s Window System Porting Layer can be implemented by
+  TPL-EGL APIs which are the corresponding window system APIs.
+  The TBM, Wayland, and GBM backends are supported.
+  
+
+
+
+Tizen Porting Layer for EGL Object Model
+
+
+TPL-EGL provides interfaces based of object driven model.
+Every TPL-EGL object can be represented as a generic tpl_object_t,
+which is reference-counted and provides common functions.
+Currently, display and surface types of TPL-EGL objects are provided.
+Display, like normal display, represents a display system which is usually
+used for connection to the server. Surface corresponds to a native surface
+like wl_surface. A surface might be configured to use N-buffers,
+but is usually double-buffered or triple-buffered.
+Buffer is actually something to render on, usually a set of pixels
+or a block of memory. For these 2 objects, the Wayland, GBM, TBM backend are
+defined, and they are corresponding to their own window systems.
+This means that you do not need to care about the window systems.
+
+
+
+TPL-EGL Core Object
+
+
+  TPL-EGL Object
+  
+Base class for all TPL-EGL objects
+  
+
+  TPL-EGL Display
+  
+
+Encapsulates the native display object (Display *, wl_display) Like a
+normal display, represents a display system which is usually used for
+connection to the server, scope for other objects.
+  
+  
+
+  TPL-EGL Surface
+  
+
+Encapsulates the native drawable object (Window, Pixmap, wl_surface)
+The surface corresponds to a native surface, such as tbm_surface_queue
+or wl_surface. A surface can be configured to use N-buffers,
+but they are usually double-buffered or triple-buffered.
+
+  
+
+
+
+TPL-EGL Objects and Corresponding EGL Objects
+
+Both TPL-EGL and vendor GLES/EGL driver handles the tbm_surface as
+TPL surface's corresponding buffer. It is represented by the TBM_Surface
+part in the following figure.
+
+
+
+  https://wiki.tizen.org/images/e/e6/Relationship_TPL_EGL_Gray.png;
+  width="800" height="403" />
+
+
+
+The following figure illustrates the GLES drawing API flow.
+
+
+  https://wiki.tizen.org/images/4/41/GLES_API_FLOW_GRAY.png;
+  width="800" height="480" />
+
+
+
+Tizen Buffer Manager (TBM)
+
+
+Tizen Buffer Manager (TBM) provides the abstraction interface for the 

[Mesa-dev] [PATCH v5 09/10] egl/tizen: add support of dri_image_loader (v3)

2017-10-25 Thread Gwan-gyeong Mun
It adds support of dri_image_loader to egl dri2 tizen backend.
   - referenced a basic buffer flow and management  implementation from 
android's.

It adds dri_image_back/dri_image_back member variables to dri_egl_surface for
a management of back/front buffers.

v2:
 - Fixes from Emil's review:
   a) Use dri2_surface_destroy_back_image() helper
   b) Use dri2_surface_destroy_front_image() helper
   c) Use dri2_surface_get_front_image() helper

 - Use get_stride helper on get_back_bo()

v3:
 - Use dri2_egl_surface's default dri_image_back and dri_image_front

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 143 +-
 1 file changed, 140 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 16a0c7c00d..e43691b7e5 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -224,6 +224,8 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
mtx_lock(>Mutex);
 
+   dri2_surface_destroy_back_image(_surf->base);
+
return EGL_TRUE;
 
 cleanup:
@@ -328,7 +330,9 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   if (dri2_dpy->dri2)
+   if (dri2_dpy->image_driver)
+  createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+   else if (dri2_dpy->dri2)
   createNewDrawable = dri2_dpy->dri2->createNewDrawable;
else
   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
@@ -379,6 +383,9 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->tbm_surface)
   tizen_window_cancel_buffer(disp, dri2_surf);
 
+   dri2_surface_destroy_back_image(surf);
+   dri2_surface_destroy_front_image(surf);
+
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
@@ -403,6 +410,119 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  if (!dri2_surf->tbm_surface) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer");
+ return -1;
+  }
+
+  fd = get_native_buffer_fd(dri2_surf->tbm_surface);
+  if (fd < 0) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer FD");
+ return -1;
+  }
+
+  pitch = get_stride(dri2_surf->tbm_surface);
+  fourcc = get_fourcc(dri2_surf->tbm_format);
+
+  if (fourcc == -1 || pitch == 0) {
+ _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
+ fourcc, pitch);
+ return -1;
+  }
+
+  dri2_surf->base.Width = surf_info.width;
+  dri2_surf->base.Height = surf_info.height;
+
+  dri2_surf->dri_image_back =
+ dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
+ dri2_surf->base.Width,
+ dri2_surf->base.Height,
+ fourcc,
+ ,
+ 1,
+ ,
+ ,
+ dri2_surf);
+
+  if (!dri2_surf->dri_image_back) {
+ _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
+ return -1;
+  }
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  /* The EGL 1.5 spec states that pbuffers are single-buffered. 
Specifically,
+   * the spec states that they have a back buffer but no front buffer, in
+   * contrast to pixmaps, which have a front buffer but no back buffer.
+   *
+   * Single-buffered surfaces with no front buffer confuse Mesa; so we 
deviate
+   * from the spec, following the precedent of Mesa's EGL X11 platform. The
+   * X11 platform correctly assigns pbuffers to single-buffered configs, 
but
+   * assigns the pbuffer a front buffer instead of a back buffer.
+   *
+   * Pbuffers in the X11 platform mostly work today, so let's just copy its
+   * behavior instead of trying to fix (and hence potentially breaking) the
+   * world.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for 
pbuffer surface");
+   }
+
+   return 0;
+}
+
+/* Some drivers will pass multiple bits in buffer_mask.
+ * For such case, will go through all the bits, and
+ * will not return error when unsupported buffer is 

[Mesa-dev] [PATCH v5 08/10] egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()

2017-10-25 Thread Gwan-gyeong Mun
It adds TIZEN_image_native_surface extension string to _EGLExtensions.
And it adds a routine of creating an EGLImage from a tbm_surface.

  - section overview
from 
https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt

"Tizen Buffer Manager (TBM) is a user space, generic memory management
 framework to create and share memory buffers between different system
 components. This extension enables using a Tizen Buffer Manager (TBM)
 surface object (struct tbm_surface_h) as an EGLImage source."

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 18 ++
 src/egl/main/eglapi.c |  2 ++
 src/egl/main/egldisplay.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index af6fb52205..16a0c7c00d 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -677,6 +677,20 @@ tizen_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf,
return _eglQuerySurface(drv, dpy, surf, attribute, value);
 }
 
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+  _EGLContext *ctx,
+  tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+  return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
 static _EGLImage *
 dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
   _EGLContext *ctx,
@@ -704,6 +718,9 @@ tizen_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
EGLClientBuffer buffer, const EGLint *attr_list)
 {
switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+  return dri2_create_image_tizen_native_buffer(disp, ctx,
+   (tbm_surface_h)buffer);
case EGL_WAYLAND_BUFFER_WL:
   return dri2_create_image_tizen_wl_buffer(disp, ctx, 
(tpl_handle_t)buffer);
default:
@@ -1248,6 +1265,7 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.TIZEN_image_native_surface = EGL_TRUE;
dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
 
drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 75790477e2..80c95c523d 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -538,6 +538,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
 
_EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+
_EGL_CHECK_EXTENSION(WL_bind_wayland_display);
_EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 869c6601a1..f1b286c31c 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -138,6 +138,8 @@ struct _egl_extensions
 
EGLBoolean NV_post_sub_buffer;
 
+   EGLBoolean TIZEN_image_native_surface;
+
EGLBoolean WL_bind_wayland_display;
EGLBoolean WL_create_wayland_buffer_from_image;
 };
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 06/10] egl/tizen: add tizen specific implementations for BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL (v2)

2017-10-25 Thread Gwan-gyeong Mun
Tizen platform (actually WL_TBM protocol) internally processes similiar actions
such as mesa's BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL.
So the platform_tizen.c needs to implemment BindWaylandDisplayWL,
UnbindWaylandDisplayWL and QueryWaylandBufferWL apart from mesa's.

  - tizen's enlightenment wayland display server calls wayland_tbm_server_init()
which processes described tasks.

  - section TPL-EGL and Wayland Server and Client
from https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL

"Tizen uses the wl_tbm protocol instead of wl_drm. The wl_tbm protocol is
 born for sharing the buffer(tbm_surface) between the wayland_client and
 wayland_server. Although the wayland_tbm_server_init and 
wayland_tbm_client_init
 pair is a role for the eglBindWaylandDisplayWL, the EGL driver is required
 to implement the entrypoints for the eglBindWaylandDisplayWL and
 eglUnbindWaylandDisplayWL as dummy."

v2: Fixes from Emil's review:
   a) Remove unneeded compiler pragma
   b) Add and use get_texture_format() helper
   c) Add switch's default case on tizen_query_wayland_buffer_wl()

referenced materials:
[1] https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL
[2] repository: git://git.tizen.org/platform/core/uifw/wayland-tbm (branch: 
tizen)

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 92 +++
 1 file changed, 92 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index addb7c8862..1b3b105fa3 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -64,6 +64,21 @@ static int get_format_bpp(tbm_format format)
}
 }
 
+static EGLBoolean get_texture_format(tbm_format format, EGLint *value)
+{
+   switch (format) {
+   case TBM_FORMAT_ARGB:
+  *value = EGL_TEXTURE_RGBA;
+  return EGL_TRUE;
+   case TBM_FORMAT_XRGB:
+   case TBM_FORMAT_RGB565:
+  *value = EGL_TEXTURE_RGB;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 static int get_stride(tbm_surface_h tbm_surface)
 {
tbm_surface_info_s surf_info;
@@ -734,6 +749,78 @@ static const __DRIextension 
*tizen_swrast_loader_extensions[] = {
NULL,
 };
 
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_resource *buffer_resource,
+  EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+(tpl_handle_t)buffer_resource,
+, , _format);
+   if (res != TPL_ERROR_NONE)
+  return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+  return get_texture_format(tbm_format, value);
+   case EGL_WIDTH:
+  *value = width;
+  return EGL_TRUE;
+   case EGL_HEIGHT:
+  *value = height;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 EGLBoolean
 dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -864,6 +951,11 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+
+   drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
+   drv->API.UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl;
+   drv->API.QueryWaylandBufferWL = tizen_query_wayland_buffer_wl;
 
return EGL_TRUE;
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 05/10] egl/tizen: add support of dri2_loader (v3)

2017-10-25 Thread Gwan-gyeong Mun
It adds support of dri2_loader to egl dri2 tizen backend.
  - referenced a basic buffer flow and management implementation from android.

And it implements a query buffer age extesion for tizen and turn on
swap_buffers_with_damage extension.
  - it add color buffer related member variables to dri_egl_surface for a
management of color buffers.

v2: Fixes from Emil's review:
   a) Remove a temporary variable and return directly on get_format_bpp()
   b) Remove unneeded compiler pragma
   c) Follow coding style
   d) Rename get_pitch() to get_stride() for using of consistent naming
   e) Remove mis-referencing from android implementation on treatment of buffer
  age.
  reference: 
https://lists.freedesktop.org/archives/mesa-dev/2017-June/158409.html
   f) Use dri2_surface_fixup() helper
   g) Use dri2_surface_set_back_buffer() helper
   h) Use dri2_surface_update_age() helper
   i) Use env_var_as_boolean for hw_accel variable on dri2_initialize_tizen()
   j) Remove getting of the device name and opening of the device node on 
dri2_initialize_tizen()
  And add duplicating of tbm_bufmgr_fd. As tbm_bufmgr_fd is managed by 
tbm_bufmgr,
  if mesa use this fd then we should duplicate it.
   k) Add comments why we can not drop the dri2 codepath on 
dri2_initialize_tizen()
  As some kernels ported for tizen don't support render node feature yet,
  currently we cannot drop the dri2 codepath.

v3: Fixes from Rob and Emil's review:
   - Use refactored color_buffers structure

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   6 +-
 src/egl/drivers/dri2/platform_tizen.c | 256 --
 2 files changed, 246 insertions(+), 16 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 3c1f7524e4..4d41613960 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -73,9 +73,11 @@ struct zwp_linux_dmabuf_v1;
 #include 
 #endif /* HAVE_TIZEN_PLATFORM */
 
-#ifdef HAVE_ANDROID_PLATFORM
+#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
 /* Usually Android uses at most triple buffers in ANativeWindow so hardcode
- * the number of color_buffers to 3.
+ * the number of color_buffers to 3. And usually Tizen uses at most triple
+ * buffers in tpl_surface (tbm_surface_queue) so hardcode the number of
+ * color_buffers to 3.
  */
 #define COLOR_BUFFERS_SIZE 3
 #else
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 7cee03f784..addb7c8862 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -46,6 +46,43 @@
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
+#include "util/debug.h"
+
+static int get_format_bpp(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_BGRA:
+   case TBM_FORMAT_RGBA:
+   case TBM_FORMAT_RGBX:
+   case TBM_FORMAT_ARGB:
+   case TBM_FORMAT_XRGB:
+  return 4;
+   case TBM_FORMAT_RGB565:
+  return 2;
+   default:
+  return 0;
+   }
+}
+
+static int get_stride(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, _info) != TBM_SURFACE_ERROR_NONE)
+  return 0;
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
 
 static EGLBoolean
 tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
@@ -60,10 +97,13 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
tbm_surface_internal_ref(dri2_surf->tbm_surface);
 
tpl_surface_get_size(dri2_surf->tpl_surface, , );
-   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
-  dri2_surf->base.Width = width;
-  dri2_surf->base.Height = height;
-   }
+
+   dri2_surface_fixup(_surf->base, width, height);
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+* and update back buffer for updating buffer's age in swap_buffers.
+*/
+   dri2_surface_set_back_buffer(_surf->base, dri2_surf->tbm_surface);
 
return EGL_TRUE;
 }
@@ -101,6 +141,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
tbm_surface_internal_unref(dri2_surf->tbm_surface);
dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
 
mtx_lock(>Mutex);
 
@@ -208,7 +249,10 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+   if (dri2_dpy->dri2)
+  createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+   else
+  createNewDrawable = dri2_dpy->swrast->createNewDrawable;
 
dri2_surf->dri_drawable = 

[Mesa-dev] [PATCH v5 07/10] egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL target of eglCreateImageKHR() (v2)

2017-10-25 Thread Gwan-gyeong Mun
In the tizen platform, a wl_buffer wraps a tbm_surface. The tbm_surface contains
gem name or prime fd. For creating dri_image, we need to extract the tbm_surface
from the wl_buffer and we use tpl_display_get_buffer_from_native_pixmap() api
for that.

v2:
   a) Add switch's default case to return on get_fourcc(), get_fourcc_yuv()
  and get_format()
   b) Use get_stride helper on tizen_create_image_from_name() and 
tizen_create_image_from_prime_fd()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 299 +-
 1 file changed, 298 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 1b3b105fa3..af6fb52205 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -48,6 +48,60 @@
 #include "loader.h"
 #include "util/debug.h"
 
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FOURCC_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FOURCC_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_NV21:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_YUV420: return __DRI_IMAGE_FOURCC_YUV420;
+   case TBM_FORMAT_YVU420: return __DRI_IMAGE_FOURCC_YVU420;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", 
format);
+  return -1;
+   }
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+  return false;
+   else
+  return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FORMAT_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FORMAT_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
 static int get_format_bpp(tbm_format format)
 {
switch (format) {
@@ -89,6 +143,16 @@ static int get_stride(tbm_surface_h tbm_surface)
return surf_info.planes[0].stride;
 }
 
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+ TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
 static int
 get_native_buffer_name(tbm_surface_h tbm_surface)
 {
@@ -384,6 +448,205 @@ tizen_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
return tizen_swap_buffers_with_damage (drv, disp, draw, NULL, 0);
 }
 
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+ tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+  return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+  tbm_bo_handle bo_handle;
+  int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+  bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+  if (bo[i] == NULL) {
+ _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+ return NULL;
+  }
+  bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+  bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+  _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+  return NULL;
+   }
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_NV12:
+  fds[0] = bo_fd[0];
+  fds[1] = bo_fd[1];
+  offsets[0] = surf_info.planes[0].offset;
+  

[Mesa-dev] [PATCH v5 04/10] configure.ac: Add tizen to supported platforms (v2)

2017-10-25 Thread Gwan-gyeong Mun
It checks tpl-egl/libtbm/libtdm packages and defines HAVE_PLATFORM_TIZEN.
This feature is enabled by the config option '--with-platforms=tizen'

v2: Fixes from Emil's review:
  - Add require_libdrm to tizen platform

Signed-off-by: Mun Gwan-gyeong 
---
 configure.ac | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index add3830f23..b50d0bc2ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1688,7 +1688,7 @@ dnl
 AC_ARG_WITH([platforms],
 [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
 [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
-"x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
+"x11,drm,wayland,surfaceless,tizen..." @<:@default=auto@:>@])],
 [with_platforms="$withval"],
 [with_platforms=auto])
 
@@ -1748,13 +1748,18 @@ for plat in $platforms; do
 DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
 ;;
 
+tizen)
+PKG_CHECK_MODULES([TIZEN], [tpl-egl libtbm libtdm])
+DEFINES="$DEFINES -DHAVE_TIZEN_PLATFORM"
+;;
+
 *)
 AC_MSG_ERROR([platform '$plat' does not exist])
 ;;
 esac
 
 case "$plat" in
-wayland|drm|surfaceless)
+wayland|drm|surfaceless|tizen)
 require_libdrm "Platform $plat"
 ;;
 esac
@@ -1778,6 +1783,7 @@ AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | 
grep -q 'wayland')
 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 
'surfaceless')
 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
+AM_CONDITIONAL(HAVE_PLATFORM_TIZEN, echo "$platforms" | grep -q 'tizen')
 
 dnl
 dnl More DRI setup
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 03/10] egl/tizen: add support of the swrast related features for tizen platform (v2)

2017-10-25 Thread Gwan-gyeong Mun
It implements the egl swrast related features for tizen platform on 
platform_tizen.c

It works with libtpl-egl (Tizen Porting Layer for egl) and libtbm (Tizen Buffer 
Manager)
where back buffers of windows are backed by GEM objects. In Tizen a native 
window
has a queue (tbm_surface_queue) of back buffers allocated by the WL_TBM
(wayland client case, WL_TBM is abbreviation of wayland-tbm protocol) or gbm
(tizen has implements gbm with tbm) or tbm through tbm_backend.

For each frame, EGL needs to

  dequeue the next back buffer - tizen_window_dequeue_buffer()
  render to the buffer
  enqueue the buffer - tizen_window_enqueue_buffer()

After enqueuing, the buffer is no longer valid to EGL.

v2:
 - Fixes from Emil's review:
   a) Add a treating of fail case on tizen_window_enqueue_buffer_with_damage()
   b) Follow coding style
   c) Remove unneeded compiler pragma
   d) Use a stride helper for tizen_swrast_get_image()
   e) Fix tizen_swrast_get_image() as drm platform's implementation
  referenced commit: fe2a6281b3b28fe7399e7dbcc2077d773824
   f) Fix tizen_swrast_put_image2() as drm platform's implementation
  referenced commit: 3a5e3aa5a53cff55a5e31766d713a41ffa5a93d7
   g) Add tizen_add_configs_for_surface_type() helper function which removes
  roundtrips.
   h) Refactor for tizen_add_configs()

 - Add image_image_lookup extension to tizen_swrast_loader_extensions

Referenced documents:
[1] 
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
[2] https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
[3] https://wiki.tizen.org/wiki/TBM

Signed-off-by: Mun Gwan-gyeong <elong...@gmail.com>
---
 src/egl/Makefile.am   |   6 +
 src/egl/drivers/dri2/platform_tizen.c | 646 ++
 2 files changed, 652 insertions(+)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
index eeb745f973..648672998e 100644
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -108,6 +108,12 @@ libEGL_common_la_LIBADD += $(ANDROID_LIBS)
 dri2_backend_FILES += drivers/dri2/platform_android.c
 endif
 
+if HAVE_PLATFORM_TIZEN
+AM_CFLAGS += $(TIZEN_CFLAGS)
+libEGL_common_la_LIBADD += $(TIZEN_LIBS)
+dri2_backend_FILES += drivers/dri2/platform_tizen.c
+endif
+
 AM_CFLAGS += \
-I$(top_srcdir)/src/loader \
-I$(top_builddir)/src/egl/drivers/dri2 \
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100644
index 00..7cee03f784
--- /dev/null
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -0,0 +1,646 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu <olva...@gmail.com>
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *Gwan-gyeong Mun <elong...@gmail.com>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "egl_dri2.h"
+#include "egl_dri2_fallbacks.h"
+#include "loader.h"
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+  return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, , );
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+
+   retu

[Mesa-dev] [PATCH v5 00/10] new series of Mesa for Tizen

2017-10-25 Thread Gwan-gyeong Mun
Hi,

These Patch v5 series modified with new helper function series [1]. 

These series only have mesa for tizen feature.

[1] https://patchwork.freedesktop.org/series/32577/

Thanks,
Gwan-gyeong.


Gwan-gyeong Mun (10):
  egl: add a treatment of tizen platform on egl display (v2)
  egl/dri2: Add some member variables for tizen platform on
dri2_egl_display and dri2_egl_surface (v2)
  egl/tizen: add support of the swrast related features for tizen
platform (v2)
  configure.ac: Add tizen to supported platforms (v2)
  egl/tizen: add support of dri2_loader (v3)
  egl/tizen: add tizen specific implementations for
BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL
(v2)
  egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL
target of eglCreateImageKHR() (v2)
  egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()
  egl/tizen: add support of dri_image_loader (v3)
  docs: add a high level info about Tizen / Tizen Porting Layer (TPL)
for EGL / Tizen Buffer Manager (TBM) / etc (v2)

 configure.ac  |   10 +-
 docs/systems.html |1 +
 docs/tizen.html   |  251 ++
 src/egl/Makefile.am   |6 +
 src/egl/drivers/dri2/egl_dri2.c   |   11 +
 src/egl/drivers/dri2/egl_dri2.h   |   28 +-
 src/egl/drivers/dri2/platform_tizen.c | 1418 +
 src/egl/main/eglapi.c |   15 +
 src/egl/main/egldisplay.c |   46 ++
 src/egl/main/egldisplay.h |9 +
 10 files changed, 1791 insertions(+), 4 deletions(-)
 create mode 100644 docs/tizen.html
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 02/10] egl/dri2: Add some member variables for tizen platform on dri2_egl_display and dri2_egl_surface (v2)

2017-10-25 Thread Gwan-gyeong Mun
It adds some member variables for tizen platform on dri2_egl_display and 
dri2_egl_surface.
  - tpl_display stores a object which encapsulates native disply (wl_display,
gbm_device, tbm_bufmgr) for tizen platfom.
  - native_win stores native window (wl_surface, gbm_surface, 
tbm_surface_queue_h
  - tpl_surface stores a object which encapsulates native drawable object
(wl_surface, gbm_surface, tbm_surface_queue_h) for tizen platfom.
  - tbm_surface stores a native platform buffer.
tpl-egl exposes the native platform buffer as a tbm_surface.

And it adds routines of initialize and finalize for tizen platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 11 +++
 src/egl/drivers/dri2/egl_dri2.h | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index e4ecd4ec09..355329d669 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -933,6 +933,11 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
case _EGL_PLATFORM_ANDROID:
   ret = dri2_initialize_android(drv, disp);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  ret = dri2_initialize_tizen(drv, disp);
+  break;
 #endif
default:
   _eglLog(_EGL_WARNING, "No EGL platform enabled.");
@@ -1027,6 +1032,12 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_display_disconnect(dri2_dpy->wl_dpy);
   }
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  if (dri2_dpy->tpl_display)
+ tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+  break;
 #endif
default:
   break;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 26d0ee986e..3c1f7524e4 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,14 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #ifdef HAVE_ANDROID_PLATFORM
 /* Usually Android uses at most triple buffers in ANativeWindow so hardcode
  * the number of color_buffers to 3.
@@ -234,6 +242,10 @@ struct dri2_egl_display
const gralloc_module_t *gralloc;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t*tpl_display;
+#endif
+
bool  is_render_node;
bool  is_different_gpu;
 };
@@ -311,6 +323,13 @@ struct dri2_egl_surface
struct ANativeWindowBuffer *buffer;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void  *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format tbm_format;
+#endif
+
 #if defined(HAVE_SURFACELESS_PLATFORM)
   __DRIimage   *front;
   unsigned int visual;
@@ -408,6 +427,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+EGLBoolean
+dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *disp);
+
 EGLBoolean
 dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 01/10] egl: add a treatment of tizen platform on egl display (v2)

2017-10-25 Thread Gwan-gyeong Mun
It adds a _EGL_PLATFORM_TIZEN enum value to _EGLPlatformType for tizen platform.

It adds a detecting routine of tizen platform to 
_eglNativePlatformDetectNativeDisplay()
and _eglGetNativePlatform().

  - As tizen platform internally distinguishes native displays of tbm, drm/gbm
and wayland client, when EGL_PLATFORM_WAYLAND_EXT or EGL_PLATFORM_GBM_MESA
come from eglGetPlatformDisplayEXT(), it have call _eglGetTizenDisplay().

Tizen supports various display protocols (tbm / gbm / wayland-egl) and each
implementation is different from mesa's. Because of tizen specific 
scanout-buffer
management for hardware overlay compositing and optimization. And also tizen
has its own gbm implementation for tizen specific implementation.
(gbm_create_device function pointer is differ from mesa's implementation.)

Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which is
an abstraction layer for the surface and buffer management on Tizen platform
aimed to implement the EGL porting layer of the OpenGLES driver over the
various display protocols.
As the libtpl-egl detects native display, if mesa send native display to
the libtpl-egl then it  distinguishes tbm/gbm/wayland-egl native display
and loads appropriate backend.

  - If tizen platform is enabled at the configuration, _eglGetNativePlatform()
always detects _EGL_PLATFORM_TIZEN as a detected_platform.

v2:
 - Fixes from Emil's review:
   a) Add commit messages in detail for a needing of a separated tizen backend.
   b) Remove unneeded ifndef blocks.
   c) Add comments in detail.
   d) Remove an wrong detection routine on _eglGetNativePlatform()

 - Add a detection routine of Tizen platform on _eglGetNativePlatformFromEnv()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/main/eglapi.c | 13 +
 src/egl/main/egldisplay.c | 46 ++
 src/egl/main/egldisplay.h |  7 +++
 3 files changed, 66 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 215332f99c..75790477e2 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -402,6 +402,19 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void 
*native_display,
case EGL_PLATFORM_SURFACELESS_MESA:
   dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+/* Tizen supports various display protocols (tbm / gbm / wayland-egl) and
+ * each implementation is different from mesa's.
+ * (Tizen has its own gbm implementation for tizen specific implementation.)
+ *  Therefore, when Tizen platform is enabled, it has call 
_eglGetTizenDisplay().
+ */
+case EGL_PLATFORM_GBM_MESA:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+case EGL_PLATFORM_WAYLAND_EXT:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
 #endif
default:
   RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 690728d2f7..43e2d73e73 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 
@@ -92,7 +93,20 @@ _eglGetNativePlatformFromEnv(void)
 
for (i = 0; i < _EGL_NUM_PLATFORMS; i++) {
   if (strcmp(egl_platforms[i].name, plat_name) == 0) {
+#ifdef HAVE_TIZEN_PLATFORM
+ /* Some widget library (ex. efl) can set EGL_DISPLAY environment
+  * variable as wayland or drm. But when TIZEN platform is enabled,
+  * we should ignore this variable in mesa. Becasue libtpl-egl detects
+  * this enviromnet variable and loads appropriate backend for that.
+  */
+ if ((egl_platforms[i].platform == _EGL_PLATFORM_WAYLAND) ||
+ (egl_platforms[i].platform == _EGL_PLATFORM_DRM))
+plat = _EGL_PLATFORM_TIZEN;
+ else
+plat = egl_platforms[i].platform;
+#else
  plat = egl_platforms[i].platform;
+#endif
  break;
   }
}
@@ -115,6 +129,23 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
   (void) first_pointer; /* silence unused var warning */
 
+#ifdef HAVE_TIZEN_PLATFORM
+  /* Tizen supports various display protocols (tbm / gbm / wayland-egl)
+   * and each implementation is different from mesa's. Because of tizen
+   * specific scanout-buffer management for hardware overlay compositing
+   * and optimization. And also tizen has its own gbm implementation for
+   * tizen specific implementation. (gbm_create_device function pointer
+   * is differ from mesa's implementation.)
+   * Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which
+   * is an abstraction layer for the surface and buffer 

[Mesa-dev] [PATCH v3 04/10] egl: add a missed initialization of buffer age.

2017-10-24 Thread Gwan-gyeong Mun
It add an initialization of buffer age on dri2_surface_set_back_buffer().

Fixes from Emil's review
 - Split out separated patch for adding of missed initialization of buffer
   age. [1]

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-October/173129.html

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 2063d1ca56..edb692c7e5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1104,6 +1104,7 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
   if (!dri2_surf->color_buffers[i].native_buffer) {
  dri2_surf->color_buffers[i].native_buffer = buffer;
+ dri2_surf->color_buffers[i].age = 0;
   }
   if (dri2_surf->color_buffers[i].native_buffer == buffer) {
  dri2_surf->back = _surf->color_buffers[i];
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 09/10] egl: add dri2_surface_get_front_image() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
To share common get and create dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - 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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 33 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 35 +
 3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ed0fff199d..e4ecd4ec09 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1166,6 +1166,39 @@ dri2_surface_destroy_front_image(_EGLSurface *surf)
}
 }
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy = 
dri2_egl_display(surf->Resource.Display);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (surf->Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (surf->Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  surf->Width,
+  surf->Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+
+   return 0;
+}
+
 /**
  * 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 6415fb22e6..26d0ee986e 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -467,6 +467,9 @@ dri2_surface_destroy_back_image(_EGLSurface *surf);
 void
 dri2_surface_destroy_front_image(_EGLSurface *surf);
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format);
+
 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 0b84f7221d..3bb85ab4cd 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -386,39 +386,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-  return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-  /* According current EGL spec, front buffer rendering
-   * for window surface is not supported now.
-   * and mesa doesn't have the implementation of this case.
-   * Add warning message, but not treat it as error.
-   */
-  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-  dri2_surf->dri_image_front =
-  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-  dri2_surf->base.Width,
-  dri2_surf->base.Height,
-  format,
-  0,
-  dri2_surf);
-  if (!dri2_surf->dri_image_front) {
- _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
- return -1;
-  }
-   }
-
-   return 0;
-}
-
 static int
 get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
@@ -510,7 +477,7 @@ droid_image_get_buffers(__DRIdrawable *driDrawable,
   return 0;
 
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
-  if (get_front_bo(dri2_surf, format) < 0)
+  if 

[Mesa-dev] [PATCH v3 10/10] egl/wayland: add dri2_wl_free_buffers() helper (v2)

2017-10-24 Thread Gwan-gyeong Mun
This deduplicates free routines of color_buffers array.

v2:
 - Add clear_all argument to check clearing all of color_buffers or not.
 - Fixes from Eric's review:
   a) polish check routine of check_lock and color_buffers[i].locked
   b) move 'native_buffer = NULL' to avoid leaking locked buffers
 - Fixes from Emil's review:
   a) drop the unneeded cast
   b) apply dri2_wl_free_buffers to update_buffers() and swrast_update_buffers()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_wayland.c | 92 ++---
 1 file changed, 38 insertions(+), 54 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 21037b4547..ad72641478 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -252,6 +252,40 @@ dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay 
*disp,
return NULL;
 }
 
+static void
+dri2_wl_free_buffers(struct dri2_egl_surface *dri2_surf, bool check_lock,
+ bool clear_all)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  bool clear_buffer = false;
+
+  if (dri2_surf->color_buffers[i].native_buffer &&
+  (!check_lock || !dri2_surf->color_buffers[i].locked)) {
+ wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].locked = false;
+ clear_buffer = true;
+  }
+
+  if (clear_all || clear_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);
+ 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].dri_image = NULL;
+ dri2_surf->color_buffers[i].linear_copy = NULL;
+ dri2_surf->color_buffers[i].data = NULL;
+  }
+   }
+}
+
 /**
  * Called via eglDestroySurface(), drv->API.DestroySurface().
  */
@@ -265,17 +299,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay 
*disp, _EGLSurface *surf)
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-   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);
-  if (dri2_surf->color_buffers[i].data)
- munmap(dri2_surf->color_buffers[i].data,
-dri2_surf->color_buffers[i].data_size);
-   }
+   dri2_wl_free_buffers(dri2_surf, false, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -307,24 +331,7 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  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);
-  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;
-   }
+   dri2_wl_free_buffers(dri2_surf, true, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -489,9 +496,6 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, 
__DRIbuffer *buffer)
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
if (dri2_surf->base.Width != dri2_surf->wl_win->width ||
dri2_surf->base.Height != dri2_surf->wl_win->height) {
 
@@ -511,18 +515,7 @@ update_buffers(struct 

[Mesa-dev] [PATCH v3 08/10] egl: add dri2_surface_destroy_front_image() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
To share common destroy dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_front to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_front().
 - 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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  5 -
 src/egl/drivers/dri2/platform_android.c |  7 +--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index dc2aecef88..ed0fff199d 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1154,6 +1154,18 @@ dri2_surface_destroy_back_image(_EGLSurface *surf)
}
 }
 
+void
+dri2_surface_destroy_front_image(_EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = 
dri2_egl_display(surf->Resource.Display);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   if (dri2_surf->dri_image_front) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
+  dri2_surf->dri_image_front = 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 f13bdb6d12..6415fb22e6 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -304,11 +304,11 @@ struct dri2_egl_surface
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
__DRIimage *dri_image_back;
+   __DRIimage *dri_image_front;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_front;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
@@ -464,6 +464,9 @@ dri2_surface_update_age(_EGLSurface *surf);
 void
 dri2_surface_destroy_back_image(_EGLSurface *surf);
 
+void
+dri2_surface_destroy_front_image(_EGLSurface *surf);
+
 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 e0896ed1a0..0b84f7221d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -353,12 +353,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
}
 
dri2_surface_destroy_back_image(surf);
-
-   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_destroy_front_image(surf);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 03/10] egl: add dri2_surface_set_back_buffer() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
To share common record buffers and update back buffer code.
This records all the buffers created by each platform's native window and
update back buffer for updating buffer's age in swap_buffers.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - 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".
  - Fixes from Emil's review:
a) fix typo
b) drop the addition of initialization of buffer age.

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 31 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 24 +---
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 238e299aed..2063d1ca56 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1092,6 +1092,37 @@ dri2_surface_fixup(_EGLSurface *surf, int width, int 
height)
}
 }
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer)
+{
+   /* Record all the buffers created by each platform's native window and
+* update back buffer for updating buffer's age in swap_buffers.
+*/
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = buffer;
+  }
+  if (dri2_surf->color_buffers[i].native_buffer == buffer) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated, reset the color_buffers */
+  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  dri2_surf->color_buffers[0].native_buffer = buffer;
+  dri2_surf->back = _surf->color_buffers[0];
+   }
+}
+
 /**
  * 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 6a218b49aa..4c01959324 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -454,6 +454,9 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_surface_fixup(_EGLSurface *surf, int width, int height);
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
+
 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 c254173690..559672ff21 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
/* Record all the buffers created by ANativeWindow and update back buffer
 * for updating buffer's age in swap_buffers.
 */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].native_buffer) {
- dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
-  }
-  if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
- dri2_surf->back = _surf->color_buffers[i];
- updated = EGL_TRUE;
- break;
-  }
-   }
-
-   if (!updated) {
-  /* In case of all the buffers were recreated by ANativeWindow, reset
-   * the color_buffers
-   */
-  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].native_buffer = NULL;
- dri2_surf->color_buffers[i].age = 0;
-  }
-  dri2_surf->color_buffers[0].native_buffer = dri2_surf->buffer;
-  dri2_surf->back = _surf->color_buffers[0];
-   }
+   dri2_surface_set_back_buffer(_surf->base, dri2_surf->buffer);
 
return EGL_TRUE;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 07/10] egl: add dri2_surface_destroy_back_image() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
To share common destroy dri_image_back code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_back to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_back().
 - 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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  6 +-
 src/egl/drivers/dri2/platform_android.c | 11 ++-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index d381e52e86..dc2aecef88 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1142,6 +1142,18 @@ dri2_surface_update_age(_EGLSurface *surf)
   dri2_surf->back->age = 1;
 }
 
+void
+dri2_surface_destroy_back_image(_EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = 
dri2_egl_display(surf->Resource.Display);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   if (dri2_surf->dri_image_back) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+  dri2_surf->dri_image_back = 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 58f8082509..f13bdb6d12 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -303,10 +303,11 @@ struct dri2_egl_surface
   int age;
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
+   __DRIimage *dri_image_back;
+
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_back;
__DRIimage *dri_image_front;
 #endif
 
@@ -460,6 +461,9 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer);
 void
 dri2_surface_update_age(_EGLSurface *surf);
 
+void
+dri2_surface_destroy_back_image(_EGLSurface *surf);
+
 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 45af871555..e0896ed1a0 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -228,10 +228,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>Mutex);
 
-   if (dri2_surf->dri_image_back) {
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-  dri2_surf->dri_image_back = NULL;
-   }
+   dri2_surface_destroy_back_image(_surf->base);
 
return EGL_TRUE;
 }
@@ -355,11 +352,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_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;
-   }
+   dri2_surface_destroy_back_image(surf);
 
if (dri2_surf->dri_image_front) {
   _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, 
__LINE__);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 02/10] egl: refactor color_buffers structure for deduplicating (v2)

2017-10-24 Thread Gwan-gyeong Mun
From: "Mun, Gwan-gyeong" 

This is added for preventing adding of new color buffers structure and back*
when new platform backend is added.
This refactoring separates out the common and platform specific bits.
This makes odd casting in the platform_foo.c but it prevents adding of new
ifdef magic.
Because of color_buffers array size is different on android and wayland /drm,
it adds COLOR_BUFFERS_SIZE macro.
 - android's color buffers array size is 3.
   drm & wayland's color buffers array size is 4.

Fixes from Rob's review:
 - refactor to separate out the common and platform specific bits.

Fixes from Emil's review:
 - use suggested color buffers structure shape.
   it makes a buffer pointer of each platform to void pointer type.

v2: Fixes from Emil's review
  a) change ifdef macro of "HAVE_WAYLAND_PLATFORM or HAVE_DRM_PLATFORM" to
 "HAVE_ANDROID_PLATFORM" for COLOR_BUFFERS_SIZE.
  b) drop the unneeded indentation of comment.
  c) drop ifdef macro of HAVE_WAYLAND_PLATFORM from color_buffers structure
 for more generic and widespread helpers.
  d) drop unneeded $native_type -> void * cast and viceversa.
  e) create the local native_buffer of $native_type and cast on assignment.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h | 32 --
 src/egl/drivers/dri2/platform_android.c | 10 +++---
 src/egl/drivers/dri2/platform_drm.c | 60 ++---
 src/egl/drivers/dri2/platform_wayland.c | 41 +++---
 4 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 208a03d73a..6a218b49aa 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,15 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_ANDROID_PLATFORM
+/* Usually Android uses at most triple buffers in ANativeWindow so hardcode
+ * the number of color_buffers to 3.
+ */
+#define COLOR_BUFFERS_SIZE 3
+#else
+#define COLOR_BUFFERS_SIZE 4
+#endif
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -279,39 +288,26 @@ struct dri2_egl_surface
/* EGL-owned buffers */
__DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+   /* Used to record all the buffers created by each platform's native window
+* and their ages.
+*/
struct {
-#ifdef HAVE_WAYLAND_PLATFORM
-  struct wl_buffer   *wl_buffer;
+  void *native_buffer; // aka wl_buffer/gbm_bo/ANativeWindowBuffer
   __DRIimage *dri_image;
   /* for is_different_gpu case. NULL else */
   __DRIimage *linear_copy;
   /* for swrast */
   void *data;
   int data_size;
-#endif
-#ifdef HAVE_DRM_PLATFORM
-  struct gbm_bo   *bo;
-#endif
   boollocked;
   int age;
-   } color_buffers[4], *back, *current;
-#endif
+   } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
-
-   /* Used to record all the buffers created by ANativeWindow and their ages.
-* Usually Android uses at most triple buffers in ANativeWindow
-* so hardcode the number of color_buffers to 3.
-*/
-   struct {
-  struct ANativeWindowBuffer *buffer;
-  int age;
-   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index d00aa2..c254173690 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -193,10 +193,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
 */
EGLBoolean updated = EGL_FALSE;
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
   }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+  if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
  dri2_surf->back = _surf->color_buffers[i];
  updated = EGL_TRUE;
  break;
@@ -208,10 +208,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
* the color_buffers
*/
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].native_buffer = NULL;
  dri2_surf->color_buffers[i].age = 0;
   }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+  

[Mesa-dev] [PATCH v3 06/10] egl: add dri2_surface_update_age() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
To share common update buffer age code.
This updates old buffer's age and sets current back buffer's age to 1.

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.
 - Fixes from Rob's review:
   Remove unneeded ifdef block

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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 16 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 11 +--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a504978fda..d381e52e86 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1126,6 +1126,22 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
}
 }
 
+void
+dri2_surface_update_age(_EGLSurface *surf)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+   }
+
+   /* "XXX: we don't use get_back_bo() since it causes regressions in
+* several dEQP tests.
+*/
+   if (dri2_surf->back)
+  dri2_surf->back->age = 1;
+}
+
 /**
  * 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 4c01959324..58f8082509 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -457,6 +457,9 @@ dri2_surface_fixup(_EGLSurface *surf, int width, int 
height);
 void
 dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
 
+void
+dri2_surface_update_age(_EGLSurface *surf);
+
 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 559672ff21..45af871555 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -567,16 +567,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
   return EGL_TRUE;
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].age > 0)
- dri2_surf->color_buffers[i].age++;
-   }
-
-   /* "XXX: we don't use get_back_bo() since it causes regressions in
-* several dEQP tests.
-*/
-   if (dri2_surf->back)
-  dri2_surf->back->age = 1;
+   dri2_surface_update_age(draw);
 
dri2_flush_drawable_for_swapbuffers(disp, draw);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 05/10] egl: add going out of the loop when color_buffer is set.

2017-10-24 Thread Gwan-gyeong Mun
If color_buffer is set once, we don't need to set a same native buffer to
remained free slot of color_buffers. So we can go out of the loop when
color_buffer is set first.

Fixes from Emil's review
 - Add setting "updated" and bailing out when the color_buffer is set.[1]

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-October/173129.html

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index edb692c7e5..a504978fda 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1105,6 +1105,8 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void 
*buffer)
   if (!dri2_surf->color_buffers[i].native_buffer) {
  dri2_surf->color_buffers[i].native_buffer = buffer;
  dri2_surf->color_buffers[i].age = 0;
+ updated = EGL_TRUE;
+ break;
   }
   if (dri2_surf->color_buffers[i].native_buffer == buffer) {
  dri2_surf->back = _surf->color_buffers[i];
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 01/10] egl: add dri2_surface_fixup() helper (v3)

2017-10-24 Thread Gwan-gyeong Mun
From: "Mun, Gwan-gyeong" 

To share common free outdated buffers and update size code.
This compares width and height arguments with current egl surface dimension,
if the compared surface dimension is differ, then it free local buffers and
updates dimension.

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".

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 13 +
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c |  8 ++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 503450542e..238e299aed 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1079,6 +1079,19 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_surface_fixup(_EGLSurface *surf, int width, int height)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   /* free outdated buffers and update the surface size */
+   if (surf->Width != width || surf->Height != height) {
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+  surf->Width = width;
+  surf->Height = height;
+   }
+}
+
 /**
  * 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 cd2487ab22..208a03d73a 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -455,6 +455,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_fixup(_EGLSurface *surf, int width, int height);
+
 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 e390365b8b..d00aa2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -414,12 +414,8 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
}
 
/* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-   dri2_surf->base.Height != dri2_surf->buffer->height) {
-  dri2_egl_surface_free_local_buffers(dri2_surf);
-  dri2_surf->base.Width = dri2_surf->buffer->width;
-  dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
+   dri2_surface_fixup(_surf->base, dri2_surf->buffer->width,
+  dri2_surf->buffer->height);
 
return 0;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 01/10] egl: add a treatment of tizen platform on egl display (v2)

2017-10-06 Thread Gwan-gyeong Mun
It adds a _EGL_PLATFORM_TIZEN enum value to _EGLPlatformType for tizen platform.

It adds a detecting routine of tizen platform to 
_eglNativePlatformDetectNativeDisplay()
and _eglGetNativePlatform().

  - As tizen platform internally distinguishes native displays of tbm, drm/gbm
and wayland client, when EGL_PLATFORM_WAYLAND_EXT or EGL_PLATFORM_GBM_MESA
come from eglGetPlatformDisplayEXT(), it have call _eglGetTizenDisplay().

Tizen supports various display protocols (tbm / gbm / wayland-egl) and each
implementation is different from mesa's. Because of tizen specific 
scanout-buffer
management for hardware overlay compositing and optimization. And also tizen
has its own gbm implementation for tizen specific implementation.
(gbm_create_device function pointer is differ from mesa's implementation.)

Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which is
an abstraction layer for the surface and buffer management on Tizen platform
aimed to implement the EGL porting layer of the OpenGLES driver over the
various display protocols.
As the libtpl-egl detects native display, if mesa send native display to
the libtpl-egl then it  distinguishes tbm/gbm/wayland-egl native display
and loads appropriate backend.

  - If tizen platform is enabled at the configuration, _eglGetNativePlatform()
always detects _EGL_PLATFORM_TIZEN as a detected_platform.

v2:
 - Fixes from Emil's review:
   a) Add commit messages in detail for a needing of a separated tizen backend.
   b) Remove unneeded ifndef blocks.
   c) Add comments in detail.
   d) Remove an wrong detection routine on _eglGetNativePlatform()

 - Add a detection routine of Tizen platform on _eglGetNativePlatformFromEnv()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/main/eglapi.c | 13 +
 src/egl/main/egldisplay.c | 46 ++
 src/egl/main/egldisplay.h |  7 +++
 3 files changed, 66 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 4a9b3fe392..f3257eef4b 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -402,6 +402,19 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void 
*native_display,
case EGL_PLATFORM_SURFACELESS_MESA:
   dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+/* Tizen supports various display protocols (tbm / gbm / wayland-egl) and
+ * each implementation is different from mesa's.
+ * (Tizen has its own gbm implementation for tizen specific implementation.)
+ *  Therefore, when Tizen platform is enabled, it has call 
_eglGetTizenDisplay().
+ */
+case EGL_PLATFORM_GBM_MESA:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+case EGL_PLATFORM_WAYLAND_EXT:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
 #endif
default:
   RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 690728d2f7..43e2d73e73 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 
@@ -92,7 +93,20 @@ _eglGetNativePlatformFromEnv(void)
 
for (i = 0; i < _EGL_NUM_PLATFORMS; i++) {
   if (strcmp(egl_platforms[i].name, plat_name) == 0) {
+#ifdef HAVE_TIZEN_PLATFORM
+ /* Some widget library (ex. efl) can set EGL_DISPLAY environment
+  * variable as wayland or drm. But when TIZEN platform is enabled,
+  * we should ignore this variable in mesa. Becasue libtpl-egl detects
+  * this enviromnet variable and loads appropriate backend for that.
+  */
+ if ((egl_platforms[i].platform == _EGL_PLATFORM_WAYLAND) ||
+ (egl_platforms[i].platform == _EGL_PLATFORM_DRM))
+plat = _EGL_PLATFORM_TIZEN;
+ else
+plat = egl_platforms[i].platform;
+#else
  plat = egl_platforms[i].platform;
+#endif
  break;
   }
}
@@ -115,6 +129,23 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
   (void) first_pointer; /* silence unused var warning */
 
+#ifdef HAVE_TIZEN_PLATFORM
+  /* Tizen supports various display protocols (tbm / gbm / wayland-egl)
+   * and each implementation is different from mesa's. Because of tizen
+   * specific scanout-buffer management for hardware overlay compositing
+   * and optimization. And also tizen has its own gbm implementation for
+   * tizen specific implementation. (gbm_create_device function pointer
+   * is differ from mesa's implementation.)
+   * Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which
+   * is an abstraction layer for the surface and buffer 

[Mesa-dev] [PATCH v4 05/10] egl/tizen: add support of dri2_loader (v3)

2017-10-06 Thread Gwan-gyeong Mun
It adds support of dri2_loader to egl dri2 tizen backend.
  - referenced a basic buffer flow and management implementation from android.

And it implements a query buffer age extesion for tizen and turn on
swap_buffers_with_damage extension.
  - it add color buffer related member variables to dri_egl_surface for a
management of color buffers.

v2: Fixes from Emil's review:
   a) Remove a temporary variable and return directly on get_format_bpp()
   b) Remove unneeded compiler pragma
   c) Follow coding style
   d) Rename get_pitch() to get_stride() for using of consistent naming
   e) Remove mis-referencing from android implementation on treatment of buffer
  age.
  reference: 
https://lists.freedesktop.org/archives/mesa-dev/2017-June/158409.html
   f) Use dri2_egl_surface_free_outdated_buffers_and_update_size() helper
   g) Use dri2_egl_surface_record_buffers_and_update_back_buffer() helper
   h) Use add dri2_egl_surface_update_buffer_age() helper
   i) Use env_var_as_boolean for hw_accel variable on dri2_initialize_tizen()
   j) Remove getting of the device name and opening of the device node on 
dri2_initialize_tizen()
  And add duplicating of tbm_bufmgr_fd. As tbm_bufmgr_fd is managed by 
tbm_bufmgr,
  if mesa use this fd then we should duplicate it.
   k) Add comments why we can not drop the dri2 codepath on 
dri2_initialize_tizen()
  As some kernels ported for tizen don't support render node feature yet,
  currently we cannot drop the dri2 codepath.

v3: Fixes from Rob and Emil's review:
   - Use refactored color_buffers structure

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   2 +
 src/egl/drivers/dri2/platform_tizen.c | 257 --
 2 files changed, 245 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 4e1fead46b..12c46759d3 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -78,6 +78,8 @@ struct zwp_linux_dmabuf_v1;
 #else
/* Usually Android uses at most triple buffers in ANativeWindow
 * so hardcode the number of color_buffers to 3.
+* And usually Tizen uses at most triple buffers in tpl_surface
+* (tbm_surface_queue) so hardcode the number of color_buffers to 3.
 */
 #define COLOR_BUFFERS_SIZE 3
 #endif
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 7cee03f784..72cef25364 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -46,6 +46,43 @@
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
+#include "util/debug.h"
+
+static int get_format_bpp(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_BGRA:
+   case TBM_FORMAT_RGBA:
+   case TBM_FORMAT_RGBX:
+   case TBM_FORMAT_ARGB:
+   case TBM_FORMAT_XRGB:
+  return 4;
+   case TBM_FORMAT_RGB565:
+  return 2;
+   default:
+  return 0;
+   }
+}
+
+static int get_stride(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, _info) != TBM_SURFACE_ERROR_NONE)
+  return 0;
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
 
 static EGLBoolean
 tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
@@ -60,10 +97,14 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
tbm_surface_internal_ref(dri2_surf->tbm_surface);
 
tpl_surface_get_size(dri2_surf->tpl_surface, , );
-   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
-  dri2_surf->base.Width = width;
-  dri2_surf->base.Height = height;
-   }
+
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf, width, 
height);
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+* and update back buffer for updating buffer's age in swap_buffers.
+*/
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  
(void*)dri2_surf->tbm_surface);
 
return EGL_TRUE;
 }
@@ -101,6 +142,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
tbm_surface_internal_unref(dri2_surf->tbm_surface);
dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
 
mtx_lock(>Mutex);
 
@@ -208,7 +250,10 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+   if (dri2_dpy->dri2)
+  createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+   else
+  createNewDrawable = dri2_dpy->swrast->createNewDrawable;
 

[Mesa-dev] [PATCH v4 04/10] configure.ac: Add tizen to supported platforms (v2)

2017-10-06 Thread Gwan-gyeong Mun
It checks tpl-egl/libtbm/libtdm packages and defines HAVE_PLATFORM_TIZEN.
This feature is enabled by the config option '--with-platforms=tizen'

v2: Fixes from Emil's review:
  - Add require_libdrm to tizen platform

Signed-off-by: Mun Gwan-gyeong 
---
 configure.ac | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 903a3979d4..f350d3caa9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1695,7 +1695,7 @@ dnl
 AC_ARG_WITH([platforms],
 [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
 [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
-"x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
+"x11,drm,wayland,surfaceless,tizen..." @<:@default=auto@:>@])],
 [with_platforms="$withval"],
 [with_platforms=auto])
 
@@ -1755,13 +1755,18 @@ for plat in $platforms; do
 DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
 ;;
 
+tizen)
+PKG_CHECK_MODULES([TIZEN], [tpl-egl libtbm libtdm])
+DEFINES="$DEFINES -DHAVE_TIZEN_PLATFORM"
+;;
+
 *)
 AC_MSG_ERROR([platform '$plat' does not exist])
 ;;
 esac
 
 case "$plat" in
-wayland|drm|surfaceless)
+wayland|drm|surfaceless|tizen)
 require_libdrm "Platform $plat"
 ;;
 esac
@@ -1785,6 +1790,7 @@ AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | 
grep -q 'wayland')
 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 
'surfaceless')
 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
+AM_CONDITIONAL(HAVE_PLATFORM_TIZEN, echo "$platforms" | grep -q 'tizen')
 
 dnl
 dnl More DRI setup
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 10/10] docs: add a high level info about Tizen / Tizen Porting Layer (TPL) for EGL / Tizen Buffer Manager (TBM) / etc (v2)

2017-10-06 Thread Gwan-gyeong Mun
It gives a quick overview and references of developing OpenGLES / EGL
Driver for Tizen.

v2:
 - Fixes from Eric's review:
   Change links of Setup build environment for Tizen (Raspberry Pi 3) and
   Tizen Binary Download Instructions for Raspberry Pi 3 to `tizen-` prefixed
   pages.

 - Add Setup Raspberry Pi 3 for Tizen Instruction link

Signed-off-by: Mun Gwan-gyeong 
---
 docs/systems.html |   1 +
 docs/tizen.html   | 251 ++
 2 files changed, 252 insertions(+)
 create mode 100644 docs/tizen.html

diff --git a/docs/systems.html b/docs/systems.html
index b97e1f0a79..ab6c9c3f74 100644
--- a/docs/systems.html
+++ b/docs/systems.html
@@ -63,6 +63,7 @@ drivers for the X Window System
 and Unix-like operating systems
 Microsoft Windows
 VMware guest OS driver
+Tizen
 
 
 
diff --git a/docs/tizen.html b/docs/tizen.html
new file mode 100644
index 00..06656c8f44
--- /dev/null
+++ b/docs/tizen.html
@@ -0,0 +1,251 @@
+http://www.w3.org/TR/html4/loose.dtd;>
+
+
+  
+  Tizen
+  
+
+
+
+
+  The Mesa 3D Graphics Library
+
+
+
+
+
+Introduction
+
+
+This document describes the essential elements of Tizen's platform-level
+graphics architecture related to OpenGL ES and EGL,
+and how it is used by the application framework and the display server.
+The focus is on how graphical data buffers move through the system.
+
+
+
+Tizen platform requires the OpenGL ES driver for the acceleration of
+the Wayland display server and wayland-eglclient.
+This platform demands OpenGL ES and EGL driver which is implemented by
+the Tizen EGL Porting Layer.
+
+
+
+Tizen OpenGL ES and EGL Architecture
+
+
+The following figure illustrates the Tizen OpenGL ES and EGL architecture.
+
+
+
+  https://wiki.tizen.org/images/d/d6/OPENGLES_STACK.png;
+  width="800" height="582" />
+
+
+
+CoreGL
+
+An injection layer of OpenGL ES that provides the following 
capabilities:
+
+
+   Support for driver-independent optimization (FastPath)
+   EGL/OpenGL ES debugging
+   Performance logging
+
+
+
+Tizen Porting Layer (TPL) for EGL
+
+
+TPL-EGL is an abstraction layer for surface and buffer management on Tizen
+platform. It is used for implementation of the EGL platform functions.
+
+
+
+  https://wiki.tizen.org/images/0/0e/Tpl_architecture.png;
+  width="800" height="204" />
+
+
+
+
+  
+  The background for the Tizen EGL Porting Layer for EGL is in various window
+  system protocols in Tizen. There was a need for separating common layer and
+  backend.
+  
+  
+  Tizen uses the Tizen Porting Layer for EGL, as the TPL-EGL APIs prevents
+  burdens of the EGL porting on various window system protocols.
+  The GPU GL Driver’s Window System Porting Layer can be implemented by
+  TPL-EGL APIs which are the corresponding window system APIs.
+  The TBM, Wayland, and GBM backends are supported.
+  
+
+
+
+Tizen Porting Layer for EGL Object Model
+
+
+TPL-EGL provides interfaces based of object driven model.
+Every TPL-EGL object can be represented as a generic tpl_object_t,
+which is reference-counted and provides common functions.
+Currently, display and surface types of TPL-EGL objects are provided.
+Display, like normal display, represents a display system which is usually
+used for connection to the server. Surface corresponds to a native surface
+like wl_surface. A surface might be configured to use N-buffers,
+but is usually double-buffered or triple-buffered.
+Buffer is actually something to render on, usually a set of pixels
+or a block of memory. For these 2 objects, the Wayland, GBM, TBM backend are
+defined, and they are corresponding to their own window systems.
+This means that you do not need to care about the window systems.
+
+
+
+TPL-EGL Core Object
+
+
+  TPL-EGL Object
+  
+Base class for all TPL-EGL objects
+  
+
+  TPL-EGL Display
+  
+
+Encapsulates the native display object (Display *, wl_display) Like a
+normal display, represents a display system which is usually used for
+connection to the server, scope for other objects.
+  
+  
+
+  TPL-EGL Surface
+  
+
+Encapsulates the native drawable object (Window, Pixmap, wl_surface)
+The surface corresponds to a native surface, such as tbm_surface_queue
+or wl_surface. A surface can be configured to use N-buffers,
+but they are usually double-buffered or triple-buffered.
+
+  
+
+
+
+TPL-EGL Objects and Corresponding EGL Objects
+
+Both TPL-EGL and vendor GLES/EGL driver handles the tbm_surface as
+TPL surface's corresponding buffer. It is represented by the TBM_Surface
+part in the following figure.
+
+
+
+  https://wiki.tizen.org/images/e/e6/Relationship_TPL_EGL_Gray.png;
+  width="800" height="403" />
+
+
+
+The following figure illustrates the GLES drawing API flow.
+
+
+  https://wiki.tizen.org/images/4/41/GLES_API_FLOW_GRAY.png;
+  width="800" height="480" />
+
+
+
+Tizen Buffer Manager (TBM)
+
+
+Tizen Buffer Manager (TBM) provides the abstraction interface for the 

[Mesa-dev] [PATCH v4 09/10] egl/tizen: add support of dri_image_loader (v3)

2017-10-06 Thread Gwan-gyeong Mun
It adds support of dri_image_loader to egl dri2 tizen backend.
   - referenced a basic buffer flow and management  implementation from 
android's.

It adds dri_image_back/dri_image_back member variables to dri_egl_surface for
a management of back/front buffers.

v2:
 - Fixes from Emil's review:
   a) Use dri2_egl_surface_destroy_image_back() helper
   b) Use dri2_egl_surface_destroy_image_front() helper
   c) Use dri2_egl_surface_get_image_front() helper

 - Use get_stride helper on get_back_bo()

v3:
 - Use dri2_egl_surface's default dri_image_back and dri_image_front

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 143 +-
 1 file changed, 140 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 091ae4dcef..87c7e1e6a2 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -225,6 +225,8 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
mtx_lock(>Mutex);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+
return EGL_TRUE;
 
 cleanup:
@@ -329,7 +331,9 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   if (dri2_dpy->dri2)
+   if (dri2_dpy->image_driver)
+  createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+   else if (dri2_dpy->dri2)
   createNewDrawable = dri2_dpy->dri2->createNewDrawable;
else
   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
@@ -380,6 +384,9 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->tbm_surface)
   tizen_window_cancel_buffer(disp, dri2_surf);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+   dri2_egl_surface_destroy_image_front(dri2_surf);
+
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
@@ -404,6 +411,119 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  if (!dri2_surf->tbm_surface) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer");
+ return -1;
+  }
+
+  fd = get_native_buffer_fd(dri2_surf->tbm_surface);
+  if (fd < 0) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer FD");
+ return -1;
+  }
+
+  pitch = get_stride(dri2_surf->tbm_surface);
+  fourcc = get_fourcc(dri2_surf->tbm_format);
+
+  if (fourcc == -1 || pitch == 0) {
+ _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
+ fourcc, pitch);
+ return -1;
+  }
+
+  dri2_surf->base.Width = surf_info.width;
+  dri2_surf->base.Height = surf_info.height;
+
+  dri2_surf->dri_image_back =
+ dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
+ dri2_surf->base.Width,
+ dri2_surf->base.Height,
+ fourcc,
+ ,
+ 1,
+ ,
+ ,
+ dri2_surf);
+
+  if (!dri2_surf->dri_image_back) {
+ _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
+ return -1;
+  }
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  /* The EGL 1.5 spec states that pbuffers are single-buffered. 
Specifically,
+   * the spec states that they have a back buffer but no front buffer, in
+   * contrast to pixmaps, which have a front buffer but no back buffer.
+   *
+   * Single-buffered surfaces with no front buffer confuse Mesa; so we 
deviate
+   * from the spec, following the precedent of Mesa's EGL X11 platform. The
+   * X11 platform correctly assigns pbuffers to single-buffered configs, 
but
+   * assigns the pbuffer a front buffer instead of a back buffer.
+   *
+   * Pbuffers in the X11 platform mostly work today, so let's just copy its
+   * behavior instead of trying to fix (and hence potentially breaking) the
+   * world.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for 
pbuffer surface");
+   }
+
+   return 0;
+}
+
+/* Some drivers will pass multiple bits in buffer_mask.
+ * For such case, will go through all the bits, and
+ * will not return 

[Mesa-dev] [PATCH v4 00/10] Mesa for Tizen serises

2017-10-06 Thread Gwan-gyeong Mun
Hi,

Patch series split out refactors and "mesa for tizen".

Thease series only have mesa for tizen feature.

these depend on splited out refactors.
https://patchwork.freedesktop.org/patch/181055/
https://patchwork.freedesktop.org/patch/181056/
https://patchwork.freedesktop.org/patch/181060/
https://patchwork.freedesktop.org/patch/181057/
https://patchwork.freedesktop.org/patch/181058/
https://patchwork.freedesktop.org/patch/181061/
https://patchwork.freedesktop.org/patch/181062/


Gwan-gyeong Mun (10):
  egl: add a treatment of tizen platform on egl display (v2)
  egl/dri2: Add some member variables for tizen platform on
dri2_egl_display and dri2_egl_surface (v2)
  egl/tizen: add support of the swrast related features for tizen
platform (v2)
  configure.ac: Add tizen to supported platforms (v2)
  egl/tizen: add support of dri2_loader (v3)
  egl/tizen: add tizen specific implementations for
BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL
(v2)
  egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL
target of eglCreateImageKHR() (v2)
  egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()
  egl/tizen: add support of dri_image_loader (v3)
  docs: add a high level info about Tizen / Tizen Porting Layer (TPL)
for EGL / Tizen Buffer Manager (TBM) / etc (v2)

 configure.ac  |   10 +-
 docs/systems.html |1 +
 docs/tizen.html   |  251 ++
 src/egl/Makefile.am   |6 +
 src/egl/drivers/dri2/egl_dri2.c   |   11 +
 src/egl/drivers/dri2/egl_dri2.h   |   24 +
 src/egl/drivers/dri2/platform_tizen.c | 1419 +
 src/egl/main/eglapi.c |   15 +
 src/egl/main/egldisplay.c |   46 ++
 src/egl/main/egldisplay.h |9 +
 10 files changed, 1790 insertions(+), 2 deletions(-)
 create mode 100644 docs/tizen.html
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 07/10] egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL target of eglCreateImageKHR() (v2)

2017-10-06 Thread Gwan-gyeong Mun
In the tizen platform, a wl_buffer wraps a tbm_surface. The tbm_surface contains
gem name or prime fd. For creating dri_image, we need to extract the tbm_surface
from the wl_buffer and we use tpl_display_get_buffer_from_native_pixmap() api
for that.

v2:
   a) Add switch's default case to return on get_fourcc(), get_fourcc_yuv()
  and get_format()
   b) Use get_stride helper on tizen_create_image_from_name() and 
tizen_create_image_from_prime_fd()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 299 +-
 1 file changed, 298 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 6d872f9d3e..777b9ba9b3 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -48,6 +48,60 @@
 #include "loader.h"
 #include "util/debug.h"
 
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FOURCC_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FOURCC_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_NV21:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_YUV420: return __DRI_IMAGE_FOURCC_YUV420;
+   case TBM_FORMAT_YVU420: return __DRI_IMAGE_FOURCC_YVU420;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", 
format);
+  return -1;
+   }
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+  return false;
+   else
+  return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FORMAT_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FORMAT_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
 static int get_format_bpp(tbm_format format)
 {
switch (format) {
@@ -89,6 +143,16 @@ static int get_stride(tbm_surface_h tbm_surface)
return surf_info.planes[0].stride;
 }
 
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+ TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
 static int
 get_native_buffer_name(tbm_surface_h tbm_surface)
 {
@@ -385,6 +449,205 @@ tizen_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
return tizen_swap_buffers_with_damage (drv, disp, draw, NULL, 0);
 }
 
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+ tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+  return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+  tbm_bo_handle bo_handle;
+  int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+  bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+  if (bo[i] == NULL) {
+ _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+ return NULL;
+  }
+  bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+  bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+  _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+  return NULL;
+   }
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_NV12:
+  fds[0] = bo_fd[0];
+  fds[1] = bo_fd[1];
+  offsets[0] = surf_info.planes[0].offset;
+  

[Mesa-dev] [PATCH v4 06/10] egl/tizen: add tizen specific implementations for BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL (v2)

2017-10-06 Thread Gwan-gyeong Mun
Tizen platform (actually WL_TBM protocol) internally processes similiar actions
such as mesa's BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL.
So the platform_tizen.c needs to implemment BindWaylandDisplayWL,
UnbindWaylandDisplayWL and QueryWaylandBufferWL apart from mesa's.

  - tizen's enlightenment wayland display server calls wayland_tbm_server_init()
which processes described tasks.

  - section TPL-EGL and Wayland Server and Client
from https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL

"Tizen uses the wl_tbm protocol instead of wl_drm. The wl_tbm protocol is
 born for sharing the buffer(tbm_surface) between the wayland_client and
 wayland_server. Although the wayland_tbm_server_init and 
wayland_tbm_client_init
 pair is a role for the eglBindWaylandDisplayWL, the EGL driver is required
 to implement the entrypoints for the eglBindWaylandDisplayWL and
 eglUnbindWaylandDisplayWL as dummy."

v2: Fixes from Emil's review:
   a) Remove unneeded compiler pragma
   b) Add and use get_texture_format() helper
   c) Add switch's default case on tizen_query_wayland_buffer_wl()

referenced materials:
[1] https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL
[2] repository: git://git.tizen.org/platform/core/uifw/wayland-tbm (branch: 
tizen)

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 92 +++
 1 file changed, 92 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 72cef25364..6d872f9d3e 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -64,6 +64,21 @@ static int get_format_bpp(tbm_format format)
}
 }
 
+static EGLBoolean get_texture_format(tbm_format format, EGLint *value)
+{
+   switch (format) {
+   case TBM_FORMAT_ARGB:
+  *value = EGL_TEXTURE_RGBA;
+  return EGL_TRUE;
+   case TBM_FORMAT_XRGB:
+   case TBM_FORMAT_RGB565:
+  *value = EGL_TEXTURE_RGB;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 static int get_stride(tbm_surface_h tbm_surface)
 {
tbm_surface_info_s surf_info;
@@ -735,6 +750,78 @@ static const __DRIextension 
*tizen_swrast_loader_extensions[] = {
NULL,
 };
 
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_resource *buffer_resource,
+  EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+(tpl_handle_t)buffer_resource,
+, , _format);
+   if (res != TPL_ERROR_NONE)
+  return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+  return get_texture_format(tbm_format, value);
+   case EGL_WIDTH:
+  *value = width;
+  return EGL_TRUE;
+   case EGL_HEIGHT:
+  *value = height;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 EGLBoolean
 dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -865,6 +952,11 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+
+   drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
+   drv->API.UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl;
+   drv->API.QueryWaylandBufferWL = tizen_query_wayland_buffer_wl;
 
return EGL_TRUE;
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 03/10] egl/tizen: add support of the swrast related features for tizen platform (v2)

2017-10-06 Thread Gwan-gyeong Mun
It implements the egl swrast related features for tizen platform on 
platform_tizen.c

It works with libtpl-egl (Tizen Porting Layer for egl) and libtbm (Tizen Buffer 
Manager)
where back buffers of windows are backed by GEM objects. In Tizen a native 
window
has a queue (tbm_surface_queue) of back buffers allocated by the WL_TBM
(wayland client case, WL_TBM is abbreviation of wayland-tbm protocol) or gbm
(tizen has implements gbm with tbm) or tbm through tbm_backend.

For each frame, EGL needs to

  dequeue the next back buffer - tizen_window_dequeue_buffer()
  render to the buffer
  enqueue the buffer - tizen_window_enqueue_buffer()

After enqueuing, the buffer is no longer valid to EGL.

v2:
 - Fixes from Emil's review:
   a) Add a treating of fail case on tizen_window_enqueue_buffer_with_damage()
   b) Follow coding style
   c) Remove unneeded compiler pragma
   d) Use a stride helper for tizen_swrast_get_image()
   e) Fix tizen_swrast_get_image() as drm platform's implementation
  referenced commit: fe2a6281b3b28fe7399e7dbcc2077d773824
   f) Fix tizen_swrast_put_image2() as drm platform's implementation
  referenced commit: 3a5e3aa5a53cff55a5e31766d713a41ffa5a93d7
   g) Add tizen_add_configs_for_surface_type() helper function which removes
  roundtrips.
   h) Refactor for tizen_add_configs()

 - Add image_image_lookup extension to tizen_swrast_loader_extensions

Referenced documents:
[1] 
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
[2] https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
[3] https://wiki.tizen.org/wiki/TBM

Signed-off-by: Mun Gwan-gyeong <elong...@gmail.com>
---
 src/egl/Makefile.am   |   6 +
 src/egl/drivers/dri2/platform_tizen.c | 646 ++
 2 files changed, 652 insertions(+)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
index eeb745f973..648672998e 100644
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -108,6 +108,12 @@ libEGL_common_la_LIBADD += $(ANDROID_LIBS)
 dri2_backend_FILES += drivers/dri2/platform_android.c
 endif
 
+if HAVE_PLATFORM_TIZEN
+AM_CFLAGS += $(TIZEN_CFLAGS)
+libEGL_common_la_LIBADD += $(TIZEN_LIBS)
+dri2_backend_FILES += drivers/dri2/platform_tizen.c
+endif
+
 AM_CFLAGS += \
-I$(top_srcdir)/src/loader \
-I$(top_builddir)/src/egl/drivers/dri2 \
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100644
index 00..7cee03f784
--- /dev/null
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -0,0 +1,646 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu <olva...@gmail.com>
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *Gwan-gyeong Mun <elong...@gmail.com>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "egl_dri2.h"
+#include "egl_dri2_fallbacks.h"
+#include "loader.h"
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+  return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, , );
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+
+   retu

[Mesa-dev] [PATCH v4 08/10] egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()

2017-10-06 Thread Gwan-gyeong Mun
It adds TIZEN_image_native_surface extension string to _EGLExtensions.
And it adds a routine of creating an EGLImage from a tbm_surface.

  - section overview
from 
https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt

"Tizen Buffer Manager (TBM) is a user space, generic memory management
 framework to create and share memory buffers between different system
 components. This extension enables using a Tizen Buffer Manager (TBM)
 surface object (struct tbm_surface_h) as an EGLImage source."

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 18 ++
 src/egl/main/eglapi.c |  2 ++
 src/egl/main/egldisplay.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 777b9ba9b3..091ae4dcef 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -678,6 +678,20 @@ tizen_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf,
return _eglQuerySurface(drv, dpy, surf, attribute, value);
 }
 
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+  _EGLContext *ctx,
+  tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+  return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
 static _EGLImage *
 dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
   _EGLContext *ctx,
@@ -705,6 +719,9 @@ tizen_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
EGLClientBuffer buffer, const EGLint *attr_list)
 {
switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+  return dri2_create_image_tizen_native_buffer(disp, ctx,
+   (tbm_surface_h)buffer);
case EGL_WAYLAND_BUFFER_WL:
   return dri2_create_image_tizen_wl_buffer(disp, ctx, 
(tpl_handle_t)buffer);
default:
@@ -1249,6 +1266,7 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.TIZEN_image_native_surface = EGL_TRUE;
dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
 
drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index f3257eef4b..099ab18f15 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -536,6 +536,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
 
_EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+
_EGL_CHECK_EXTENSION(WL_bind_wayland_display);
_EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index c009462b82..1ff7b5a2d5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -133,6 +133,8 @@ struct _egl_extensions
 
EGLBoolean NV_post_sub_buffer;
 
+   EGLBoolean TIZEN_image_native_surface;
+
EGLBoolean WL_bind_wayland_display;
EGLBoolean WL_create_wayland_buffer_from_image;
 };
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v4 02/10] egl/dri2: Add some member variables for tizen platform on dri2_egl_display and dri2_egl_surface (v2)

2017-10-06 Thread Gwan-gyeong Mun
It adds some member variables for tizen platform on dri2_egl_display and 
dri2_egl_surface.
  - tpl_display stores a object which encapsulates native disply (wl_display,
gbm_device, tbm_bufmgr) for tizen platfom.
  - native_win stores native window (wl_surface, gbm_surface, 
tbm_surface_queue_h
  - tpl_surface stores a object which encapsulates native drawable object
(wl_surface, gbm_surface, tbm_surface_queue_h) for tizen platfom.
  - tbm_surface stores a native platform buffer.
tpl-egl exposes the native platform buffer as a tbm_surface.

And it adds routines of initialize and finalize for tizen platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 11 +++
 src/egl/drivers/dri2/egl_dri2.h | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index fd55dba7de..36b12ea2d5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -910,6 +910,11 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
case _EGL_PLATFORM_ANDROID:
   ret = dri2_initialize_android(drv, disp);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  ret = dri2_initialize_tizen(drv, disp);
+  break;
 #endif
default:
   _eglLog(_EGL_WARNING, "No EGL platform enabled.");
@@ -1004,6 +1009,12 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_display_disconnect(dri2_dpy->wl_dpy);
   }
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  if (dri2_dpy->tpl_display)
+ tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+  break;
 #endif
default:
   break;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 0f4ef763bd..4e1fead46b 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,14 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
 #define COLOR_BUFFERS_SIZE 4
 #else
@@ -241,6 +249,10 @@ struct dri2_egl_display
const gralloc_module_t *gralloc;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t*tpl_display;
+#endif
+
bool  is_render_node;
bool  is_different_gpu;
 };
@@ -320,6 +332,13 @@ struct dri2_egl_surface
struct ANativeWindowBuffer *buffer;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void  *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format tbm_format;
+#endif
+
 #if defined(HAVE_SURFACELESS_PLATFORM)
   __DRIimage   *front;
   unsigned int visual;
@@ -417,6 +436,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+EGLBoolean
+dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *disp);
+
 EGLBoolean
 dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 7/8] egl: add dri2_egl_surface_get_image_front() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common get and create dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - 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.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 34 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 35 +
 3 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 67ae33cdc9..fd55dba7de 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1139,6 +1139,40 @@ dri2_egl_surface_destroy_image_front(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  dri2_surf->base.Width,
+  dri2_surf->base.Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+
+   return 0;
+}
+
 /**
  * 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 83b9e368b2..0f4ef763bd 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -478,6 +478,9 @@ dri2_egl_surface_destroy_image_back(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format);
 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 c98802774c..ef55a6d085 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -388,39 +388,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-  return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-  /* According current EGL spec, front buffer rendering
-   * for window surface is not supported now.
-   * and mesa doesn't have the implementation of this case.
-   * Add warning message, but not treat it as error.
-   */
-  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-  dri2_surf->dri_image_front =
-  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-  dri2_surf->base.Width,
-  dri2_surf->base.Height,
-  format,
-  0,
-  dri2_surf);
-  if (!dri2_surf->dri_image_front) {
- _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
- return -1;
-  }
-   }
-
-   return 0;
-}
-
 static int
 get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
@@ -512,7 +479,7 @@ droid_image_get_buffers(__DRIdrawable *driDrawable,
   return 0;
 
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
-  if (get_front_bo(dri2_surf, format) < 0)
+  if (dri2_egl_surface_get_image_front(dri2_surf, format) < 0)
  return 0;
 
   if (dri2_surf->dri_image_front) {
-- 
2.14.2

___

[Mesa-dev] [PATCH v2 6/8] egl: add dri2_egl_surface_destroy_image_front() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common destroy dri_image_front code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_front to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_front().
 - 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.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  5 -
 src/egl/drivers/dri2/platform_android.c |  7 +--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bb4944358d..67ae33cdc9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1127,6 +1127,18 @@ dri2_egl_surface_destroy_image_back(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
+  dri2_surf->dri_image_front = 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 165749ebb1..83b9e368b2 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -313,11 +313,11 @@ struct dri2_egl_surface
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
__DRIimage *dri_image_back;
+   __DRIimage *dri_image_front;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_front;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
@@ -475,6 +475,9 @@ dri2_egl_surface_update_buffer_age(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
+
 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 421395b5d7..c98802774c 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -354,12 +354,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
}
 
dri2_egl_surface_destroy_image_back(dri2_surf);
-
-   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_egl_surface_destroy_image_front(dri2_surf);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 8/8] egl/wayland: add dri2_wl_free_buffers() helper

2017-10-06 Thread Gwan-gyeong Mun
This deduplicates free routines of color_buffers array.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_wayland.c | 60 +
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 1518a24b7c..cfe474cf58 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -253,6 +253,35 @@ dri2_wl_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay 
*disp,
return NULL;
 }
 
+static void
+dri2_wl_free_buffers(struct dri2_egl_surface *dri2_surf, bool check_lock)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].native_buffer) {
+ if (check_lock && !dri2_surf->color_buffers[i].locked)
+wl_buffer_destroy((struct wl_buffer 
*)dri2_surf->color_buffers[i].native_buffer);
+ else
+wl_buffer_destroy((struct wl_buffer 
*)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);
+  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;
+   }
+}
+
 /**
  * Called via eglDestroySurface(), drv->API.DestroySurface().
  */
@@ -266,17 +295,7 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay 
*disp, _EGLSurface *surf)
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer)
- wl_buffer_destroy((struct wl_buffer 
*)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);
-  if (dri2_surf->color_buffers[i].data)
- munmap(dri2_surf->color_buffers[i].data,
-dri2_surf->color_buffers[i].data_size);
-   }
+   dri2_wl_free_buffers(dri2_surf, false);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -308,24 +327,7 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
struct dri2_egl_display *dri2_dpy =
   dri2_egl_display(dri2_surf->base.Resource.Display);
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].native_buffer &&
-  !dri2_surf->color_buffers[i].locked)
- wl_buffer_destroy((struct wl_buffer 
*)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);
-  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;
-   }
+   dri2_wl_free_buffers(dri2_surf, true);
 
if (dri2_dpy->dri2)
   dri2_egl_surface_free_local_buffers(dri2_surf);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 5/8] egl: add dri2_egl_surface_destroy_image_back() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common destroy dri_image_back code.

In preparation to adding of new platform which uses this helper.

v2:
 - Move dri_image_back to outside of android ifdef block for removing of
   ifdef magic on dri2_egl_surface_destroy_image_back().
 - 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.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  6 +-
 src/egl/drivers/dri2/platform_android.c | 11 ++-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a0f58ca8e4..bb4944358d 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1115,6 +1115,18 @@ dri2_egl_surface_update_buffer_age(struct 
dri2_egl_surface *dri2_surf)
   dri2_surf->back->age = 1;
 }
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_back) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+  dri2_surf->dri_image_back = 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 fe3880ef89..165749ebb1 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -312,10 +312,11 @@ struct dri2_egl_surface
   int age;
} color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
+   __DRIimage *dri_image_back;
+
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
-   __DRIimage *dri_image_back;
__DRIimage *dri_image_front;
 #endif
 
@@ -471,6 +472,9 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
 void
 dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
+
 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 29ee12b140..421395b5d7 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -229,10 +229,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>Mutex);
 
-   if (dri2_surf->dri_image_back) {
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-  dri2_surf->dri_image_back = NULL;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
return EGL_TRUE;
 }
@@ -356,11 +353,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_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;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
if (dri2_surf->dri_image_front) {
   _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, 
__LINE__);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 2/8] egl: refactor color_buffers structure for deduplicating

2017-10-06 Thread Gwan-gyeong Mun
This is added for preventing adding of new color buffers structure and back*
when new platform backend is added.
This refactoring separates out the common and platform specific bits.
This makes odd casting in the platform_foo.c but it prevents adding of new
ifdef magic.
Because of color_buffers array size is different on android and wayland /drm,
it adds COLOR_BUFFERS_SIZE macro.
 - android's color buffers array size is 3.
   drm & wayland's color buffers array size is 4.

Fixes from Rob's review:
 - refactor to separate out the common and platform specific bits.

Fixes from Emil's review:
 - use suggested color buffers structure shape.
   it makes a buffer pointer of each platform to void pointer type.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h | 30 +-
 src/egl/drivers/dri2/platform_android.c | 10 +++---
 src/egl/drivers/dri2/platform_drm.c | 55 +
 src/egl/drivers/dri2/platform_wayland.c | 46 +--
 4 files changed, 71 insertions(+), 70 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 017895f0d9..08ccf24410 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,15 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+#define COLOR_BUFFERS_SIZE 4
+#else
+   /* Usually Android uses at most triple buffers in ANativeWindow
+* so hardcode the number of color_buffers to 3.
+*/
+#define COLOR_BUFFERS_SIZE 3
+#endif
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -286,39 +295,28 @@ struct dri2_egl_surface
/* EGL-owned buffers */
__DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
 
-#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
+   /* Used to record all the buffers created by each platform's native window
+* and their ages.
+*/
struct {
+  void *native_buffer; // aka wl_buffer/gbm_bo/ANativeWindowBuffer
 #ifdef HAVE_WAYLAND_PLATFORM
-  struct wl_buffer   *wl_buffer;
   __DRIimage *dri_image;
   /* for is_different_gpu case. NULL else */
   __DRIimage *linear_copy;
   /* for swrast */
   void *data;
   int data_size;
-#endif
-#ifdef HAVE_DRM_PLATFORM
-  struct gbm_bo   *bo;
 #endif
   boollocked;
   int age;
-   } color_buffers[4], *back, *current;
-#endif
+   } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
 #ifdef HAVE_ANDROID_PLATFORM
struct ANativeWindow *window;
struct ANativeWindowBuffer *buffer;
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
-
-   /* Used to record all the buffers created by ANativeWindow and their ages.
-* Usually Android uses at most triple buffers in ANativeWindow
-* so hardcode the number of color_buffers to 3.
-*/
-   struct {
-  struct ANativeWindowBuffer *buffer;
-  int age;
-   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 0acbb38bd8..67e739c1fc 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -193,10 +193,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
 */
EGLBoolean updated = EGL_FALSE;
for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = (void *)dri2_surf->buffer;
   }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
+  if (dri2_surf->color_buffers[i].native_buffer == (void 
*)dri2_surf->buffer) {
  dri2_surf->back = _surf->color_buffers[i];
  updated = EGL_TRUE;
  break;
@@ -208,10 +208,10 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
* the color_buffers
*/
   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].native_buffer = NULL;
  dri2_surf->color_buffers[i].age = 0;
   }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
+  dri2_surf->color_buffers[0].native_buffer = (void *)dri2_surf->buffer;
   dri2_surf->back = _surf->color_buffers[0];
}
 
diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index 9005f5dd9e..3527352bab 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -53,7 +53,7 @@ lock_front_buffer(struct gbm_surface *_surf)
   return NULL;
}
 
-   bo = 

[Mesa-dev] [PATCH v2 4/8] egl: add dri2_egl_surface_update_buffer_age() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common update buffer age code.
This updates old buffer's age and sets current back buffer's age to 1.

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.
 - Fixes from Rob's review:
   Remove unneeded ifdef block

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 15 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c | 11 +--
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3622d18a24..a0f58ca8e4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1100,6 +1100,21 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
}
 }
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+   }
+
+   /* "XXX: we don't use get_back_bo() since it causes regressions in
+* several dEQP tests.
+*/
+   if (dri2_surf->back)
+  dri2_surf->back->age = 1;
+}
+
 /**
  * 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 67d7b7f863..fe3880ef89 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -468,6 +468,9 @@ void
 dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
void *buffer);
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
+
 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 202db9a883..29ee12b140 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -569,16 +569,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
   return EGL_TRUE;
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].age > 0)
- dri2_surf->color_buffers[i].age++;
-   }
-
-   /* "XXX: we don't use get_back_bo() since it causes regressions in
-* several dEQP tests.
-*/
-   if (dri2_surf->back)
-  dri2_surf->back->age = 1;
+   dri2_egl_surface_update_buffer_age(dri2_surf);
 
dri2_flush_drawable_for_swapbuffers(disp, draw);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 3/8] egl: add dri2_egl_surface_record_buffers_and_update_back_buffer() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common record buffers and update back buffer code.
This records all the buffers created by each platform's native window and
update back buffer for updating buffer's age in swap_buffers.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unnedded ifdef magic
 - 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.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 32 
 src/egl/drivers/dri2/egl_dri2.h |  5 +
 src/egl/drivers/dri2/platform_android.c | 25 ++---
 3 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3c4e525040..3622d18a24 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1068,6 +1068,38 @@ 
dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface *
}
 }
 
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buffer)
+{
+   /* Record all the buffers created by each platform's native window and
+* update back buffer for updating buffer's age in swap_buffers.
+*/
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].native_buffer) {
+ dri2_surf->color_buffers[i].native_buffer = buffer;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  if (dri2_surf->color_buffers[i].native_buffer == buffer) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated, reset the color_buffers */
+  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ dri2_surf->color_buffers[i].native_buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  dri2_surf->color_buffers[0].native_buffer = buffer;
+  dri2_surf->back = _surf->color_buffers[0];
+   }
+}
+
 /**
  * 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 08ccf24410..67d7b7f863 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -463,6 +463,11 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf);
 void
 dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
int width, int height);
+
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buffer);
+
 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 67e739c1fc..202db9a883 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
/* Record all the buffers created by ANativeWindow and update back buffer
 * for updating buffer's age in swap_buffers.
 */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].native_buffer) {
- dri2_surf->color_buffers[i].native_buffer = (void *)dri2_surf->buffer;
-  }
-  if (dri2_surf->color_buffers[i].native_buffer == (void 
*)dri2_surf->buffer) {
- dri2_surf->back = _surf->color_buffers[i];
- updated = EGL_TRUE;
- break;
-  }
-   }
-
-   if (!updated) {
-  /* In case of all the buffers were recreated by ANativeWindow, reset
-   * the color_buffers
-   */
-  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].native_buffer = NULL;
- dri2_surf->color_buffers[i].age = 0;
-  }
-  dri2_surf->color_buffers[0].native_buffer = (void *)dri2_surf->buffer;
-  dri2_surf->back = _surf->color_buffers[0];
-   }
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  (void 
*)dri2_surf->buffer);
 
return EGL_TRUE;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 1/8] egl: add dri2_egl_surface_free_outdated_buffers_and_update_size() helper (v2)

2017-10-06 Thread Gwan-gyeong Mun
To share common free outdated buffers and update size code.
This compares width and height arguments with current egl surface dimension,
if the compared surface dimension is differ, then it free local buffers and
updates dimension.

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.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 src/egl/drivers/dri2/platform_android.c |  9 +++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0db80a091f..3c4e525040 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1056,6 +1056,18 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height)
+{
+   /* free outdated buffers and update the surface size */
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+}
+
 /**
  * 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 e3bdbb55f5..017895f0d9 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -462,6 +462,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_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height);
 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 e390365b8b..0acbb38bd8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -414,12 +414,9 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
}
 
/* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-   dri2_surf->base.Height != dri2_surf->buffer->height) {
-  dri2_egl_surface_free_local_buffers(dri2_surf);
-  dri2_surf->base.Width = dri2_surf->buffer->width;
-  dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf,
+  
dri2_surf->buffer->width,
+  
dri2_surf->buffer->height);
 
return 0;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 21/22] egl/android: apply dri2_egl_surface_get_image_front() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 35 +
 1 file changed, 1 insertion(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index a8e33fb3e2..ba7ab4cd98 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -388,39 +388,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-  return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-  /* According current EGL spec, front buffer rendering
-   * for window surface is not supported now.
-   * and mesa doesn't have the implementation of this case.
-   * Add warning message, but not treat it as error.
-   */
-  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-  dri2_surf->dri_image_front =
-  dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-  dri2_surf->base.Width,
-  dri2_surf->base.Height,
-  format,
-  0,
-  dri2_surf);
-  if (!dri2_surf->dri_image_front) {
- _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
- return -1;
-  }
-   }
-
-   return 0;
-}
-
 static int
 get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
@@ -512,7 +479,7 @@ droid_image_get_buffers(__DRIdrawable *driDrawable,
   return 0;
 
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
-  if (get_front_bo(dri2_surf, format) < 0)
+  if (dri2_egl_surface_get_image_front(dri2_surf, format) < 0)
  return 0;
 
   if (dri2_surf->dri_image_front) {
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 14/22] egl: add dri2_egl_surface_get_image_front() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common get and create dri_image_front code.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 36 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 2 files changed, 39 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 4070a80b23..890ed8138f 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1167,6 +1167,42 @@ dri2_egl_surface_destroy_image_front(struct 
dri2_egl_surface *dri2_surf)
 #endif
 }
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format)
+{
+#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  dri2_surf->base.Width,
+  dri2_surf->base.Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+#endif
+
+   return 0;
+}
+
 /**
  * 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 fbef031fb6..d24425dba1 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -512,6 +512,9 @@ dri2_egl_surface_destroy_image_back(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
 
+int
+dri2_egl_surface_get_image_front(struct dri2_egl_surface *dri2_surf,
+ unsigned int format);
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 11/22] egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()

2017-10-04 Thread Gwan-gyeong Mun
It adds TIZEN_image_native_surface extension string to _EGLExtensions.
And it adds a routine of creating an EGLImage from a tbm_surface.

  - section overview
from 
https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt

"Tizen Buffer Manager (TBM) is a user space, generic memory management
 framework to create and share memory buffers between different system
 components. This extension enables using a Tizen Buffer Manager (TBM)
 surface object (struct tbm_surface_h) as an EGLImage source."

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 18 ++
 src/egl/main/eglapi.c |  2 ++
 src/egl/main/egldisplay.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 777b9ba9b3..091ae4dcef 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -678,6 +678,20 @@ tizen_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf,
return _eglQuerySurface(drv, dpy, surf, attribute, value);
 }
 
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+  _EGLContext *ctx,
+  tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+  return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
 static _EGLImage *
 dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
   _EGLContext *ctx,
@@ -705,6 +719,9 @@ tizen_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
EGLClientBuffer buffer, const EGLint *attr_list)
 {
switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+  return dri2_create_image_tizen_native_buffer(disp, ctx,
+   (tbm_surface_h)buffer);
case EGL_WAYLAND_BUFFER_WL:
   return dri2_create_image_tizen_wl_buffer(disp, ctx, 
(tpl_handle_t)buffer);
default:
@@ -1249,6 +1266,7 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.TIZEN_image_native_surface = EGL_TRUE;
dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
 
drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index f3257eef4b..099ab18f15 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -536,6 +536,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
 
_EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+
_EGL_CHECK_EXTENSION(WL_bind_wayland_display);
_EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index c009462b82..1ff7b5a2d5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -133,6 +133,8 @@ struct _egl_extensions
 
EGLBoolean NV_post_sub_buffer;
 
+   EGLBoolean TIZEN_image_native_surface;
+
EGLBoolean WL_bind_wayland_display;
EGLBoolean WL_create_wayland_buffer_from_image;
 };
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 22/22] docs: add a high level info about Tizen / Tizen Porting Layer (TPL) for EGL / Tizen Buffer Manager (TBM) / etc

2017-10-04 Thread Gwan-gyeong Mun
It gives a quick overview and references of developing OpenGLES / EGL
Driver for Tizen.

Signed-off-by: Mun Gwan-gyeong 
---
 docs/systems.html |   1 +
 docs/tizen.html   | 245 ++
 2 files changed, 246 insertions(+)
 create mode 100644 docs/tizen.html

diff --git a/docs/systems.html b/docs/systems.html
index b97e1f0a79..ab6c9c3f74 100644
--- a/docs/systems.html
+++ b/docs/systems.html
@@ -63,6 +63,7 @@ drivers for the X Window System
 and Unix-like operating systems
 Microsoft Windows
 VMware guest OS driver
+Tizen
 
 
 
diff --git a/docs/tizen.html b/docs/tizen.html
new file mode 100644
index 00..bce3d05bda
--- /dev/null
+++ b/docs/tizen.html
@@ -0,0 +1,245 @@
+http://www.w3.org/TR/html4/loose.dtd;>
+
+
+  
+  Tizen
+  
+
+
+
+
+  The Mesa 3D Graphics Library
+
+
+
+
+
+Introduction
+
+
+This document describes the essential elements of Tizen's platform-level
+graphics architecture related to OpenGL ES and EGL,
+and how it is used by the application framework and the display server.
+The focus is on how graphical data buffers move through the system.
+
+
+
+Tizen platform requires the OpenGL ES driver for the acceleration of
+the Wayland display server and wayland-eglclient.
+This platform demands OpenGL ES and EGL driver which is implemented by
+the Tizen EGL Porting Layer.
+
+
+
+Tizen OpenGL ES and EGL Architecture
+
+
+The following figure illustrates the Tizen OpenGL ES and EGL architecture.
+
+
+
+  https://wiki.tizen.org/images/d/d6/OPENGLES_STACK.png;
+  width="800" height="582" />
+
+
+
+CoreGL
+
+An injection layer of OpenGL ES that provides the following 
capabilities:
+
+
+   Support for driver-independent optimization (FastPath)
+   EGL/OpenGL ES debugging
+   Performance logging
+
+
+
+Tizen Porting Layer (TPL) for EGL
+
+
+TPL-EGL is an abstraction layer for surface and buffer management on Tizen
+platform. It is used for implementation of the EGL platform functions.
+
+
+
+  https://wiki.tizen.org/images/0/0e/Tpl_architecture.png;
+  width="800" height="204" />
+
+
+
+
+  
+  The background for the Tizen EGL Porting Layer for EGL is in various window
+  system protocols in Tizen. There was a need for separating common layer and
+  backend.
+  
+  
+  Tizen uses the Tizen Porting Layer for EGL, as the TPL-EGL APIs prevents
+  burdens of the EGL porting on various window system protocols.
+  The GPU GL Driver’s Window System Porting Layer can be implemented by
+  TPL-EGL APIs which are the corresponding window system APIs.
+  The TBM, Wayland, and GBM backends are supported.
+  
+
+
+
+Tizen Porting Layer for EGL Object Model
+
+
+TPL-EGL provides interfaces based of object driven model.
+Every TPL-EGL object can be represented as a generic tpl_object_t,
+which is reference-counted and provides common functions.
+Currently, display and surface types of TPL-EGL objects are provided.
+Display, like normal display, represents a display system which is usually
+used for connection to the server. Surface corresponds to a native surface
+like wl_surface. A surface might be configured to use N-buffers,
+but is usually double-buffered or triple-buffered.
+Buffer is actually something to render on, usually a set of pixels
+or a block of memory. For these 2 objects, the Wayland, GBM, TBM backend are
+defined, and they are corresponding to their own window systems.
+This means that you do not need to care about the window systems.
+
+
+
+TPL-EGL Core Object
+
+
+  TPL-EGL Object
+  
+Base class for all TPL-EGL objects
+  
+
+  TPL-EGL Display
+  
+
+Encapsulates the native display object (Display *, wl_display) Like a
+normal display, represents a display system which is usually used for
+connection to the server, scope for other objects.
+  
+  
+
+  TPL-EGL Surface
+  
+
+Encapsulates the native drawable object (Window, Pixmap, wl_surface)
+The surface corresponds to a native surface, such as tbm_surface_queue
+or wl_surface. A surface can be configured to use N-buffers,
+but they are usually double-buffered or triple-buffered.
+
+  
+
+
+
+TPL-EGL Objects and Corresponding EGL Objects
+
+Both TPL-EGL and vendor GLES/EGL driver handles the tbm_surface as
+TPL surface's corresponding buffer. It is represented by the TBM_Surface
+part in the following figure.
+
+
+
+  https://wiki.tizen.org/images/e/e6/Relationship_TPL_EGL_Gray.png;
+  width="800" height="403" />
+
+
+
+The following figure illustrates the GLES drawing API flow.
+
+
+  https://wiki.tizen.org/images/4/41/GLES_API_FLOW_GRAY.png;
+  width="800" height="480" />
+
+
+
+Tizen Buffer Manager (TBM)
+
+
+Tizen Buffer Manager (TBM) provides the abstraction interface for the graphic
+buffer manager in Tizen.
+
+
+
+  
+  The TBM has a frontend libary and a backend module. The TBM frontend library
+  is hardware-independent and provides the generic buffer interface for users.
+  On the other hand, the TBM backend module is 

[Mesa-dev] [PATCH v3 20/22] egl/android: apply dri2_egl_surface_destroy_image_front() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 8dda0a8734..a8e33fb3e2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -354,12 +354,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
}
 
dri2_egl_surface_destroy_image_back(dri2_surf);
-
-   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_egl_surface_destroy_image_front(dri2_surf);
 
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 12/22] egl: add dri2_egl_surface_destroy_image_back() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common destroy dri_image_back code.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 14 ++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 8f6a8a62cb..e13b13c282 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1139,6 +1139,20 @@ dri2_egl_surface_update_buffer_age(struct 
dri2_egl_surface *dri2_surf)
 #endif
 }
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf)
+{
+#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_back) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+  dri2_surf->dri_image_back = NULL;
+   }
+#endif
+}
+
 /**
  * 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 7d047bf5dd..a990fa3d83 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -506,6 +506,9 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
 void
 dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 18/22] egl/android: apply dri2_egl_surface_update_buffer_age() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index d5ce48a34c..5c014268b1 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -569,16 +569,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
if (dri2_surf->base.Type != EGL_WINDOW_BIT)
   return EGL_TRUE;
 
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (dri2_surf->color_buffers[i].age > 0)
- dri2_surf->color_buffers[i].age++;
-   }
-
-   /* "XXX: we don't use get_back_bo() since it causes regressions in
-* several dEQP tests.
-*/
-   if (dri2_surf->back)
-  dri2_surf->back->age = 1;
+   dri2_egl_surface_update_buffer_age(dri2_surf);
 
dri2_flush_drawable_for_swapbuffers(disp, draw);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 15/22] egl/tizen: add support of dri_image_loader (v2)

2017-10-04 Thread Gwan-gyeong Mun
It adds support of dri_image_loader to egl dri2 tizen backend.
   - referenced a basic buffer flow and management  implementation from 
android's.

It adds dri_image_back/dri_image_back member variables to dri_egl_surface for
a management of back/front buffers.

v2:
 - Fixes from Emil's review:
   a) Use dri2_egl_surface_destroy_image_back() helper
   b) Use dri2_egl_surface_destroy_image_front() helper
   c) Use dri2_egl_surface_get_image_front() helper

 - Use get_stride helper on get_back_bo()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   2 +
 src/egl/drivers/dri2/platform_tizen.c | 143 +-
 2 files changed, 142 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index d24425dba1..d9215ea06e 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -340,6 +340,8 @@ struct dri2_egl_surface
tpl_surface_t *tpl_surface;
tbm_surface_h  tbm_surface;
tbm_format tbm_format;
+   __DRIimage*dri_image_back;
+   __DRIimage*dri_image_front;
 
/* Used to record all the tbm_surface created by tpl_surface and their ages.
 * Usually Tizen uses at most triple buffers in tpl_surface 
(tbm_surface_queue)
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 091ae4dcef..87c7e1e6a2 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -225,6 +225,8 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
mtx_lock(>Mutex);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+
return EGL_TRUE;
 
 cleanup:
@@ -329,7 +331,9 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   if (dri2_dpy->dri2)
+   if (dri2_dpy->image_driver)
+  createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+   else if (dri2_dpy->dri2)
   createNewDrawable = dri2_dpy->dri2->createNewDrawable;
else
   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
@@ -380,6 +384,9 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->tbm_surface)
   tizen_window_cancel_buffer(disp, dri2_surf);
 
+   dri2_egl_surface_destroy_image_back(dri2_surf);
+   dri2_egl_surface_destroy_image_front(dri2_surf);
+
dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
@@ -404,6 +411,119 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  if (!dri2_surf->tbm_surface) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer");
+ return -1;
+  }
+
+  fd = get_native_buffer_fd(dri2_surf->tbm_surface);
+  if (fd < 0) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer FD");
+ return -1;
+  }
+
+  pitch = get_stride(dri2_surf->tbm_surface);
+  fourcc = get_fourcc(dri2_surf->tbm_format);
+
+  if (fourcc == -1 || pitch == 0) {
+ _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",
+ fourcc, pitch);
+ return -1;
+  }
+
+  dri2_surf->base.Width = surf_info.width;
+  dri2_surf->base.Height = surf_info.height;
+
+  dri2_surf->dri_image_back =
+ dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
+ dri2_surf->base.Width,
+ dri2_surf->base.Height,
+ fourcc,
+ ,
+ 1,
+ ,
+ ,
+ dri2_surf);
+
+  if (!dri2_surf->dri_image_back) {
+ _eglLog(_EGL_WARNING, "failed to create DRI image from FD");
+ return -1;
+  }
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  /* The EGL 1.5 spec states that pbuffers are single-buffered. 
Specifically,
+   * the spec states that they have a back buffer but no front buffer, in
+   * contrast to pixmaps, which have a front buffer but no back buffer.
+   *
+   * Single-buffered surfaces with no front buffer confuse Mesa; so we 
deviate
+   * from the spec, following the precedent of Mesa's EGL X11 platform. The
+   * X11 platform 

[Mesa-dev] [PATCH v3 10/22] egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL target of eglCreateImageKHR() (v2)

2017-10-04 Thread Gwan-gyeong Mun
In the tizen platform, a wl_buffer wraps a tbm_surface. The tbm_surface contains
gem name or prime fd. For creating dri_image, we need to extract the tbm_surface
from the wl_buffer and we use tpl_display_get_buffer_from_native_pixmap() api
for that.

v2:
   a) Add switch's default case to return on get_fourcc(), get_fourcc_yuv()
  and get_format()
   b) Use get_stride helper on tizen_create_image_from_name() and 
tizen_create_image_from_prime_fd()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 299 +-
 1 file changed, 298 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 6d872f9d3e..777b9ba9b3 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -48,6 +48,60 @@
 #include "loader.h"
 #include "util/debug.h"
 
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FOURCC_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FOURCC_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_NV21:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_YUV420: return __DRI_IMAGE_FOURCC_YUV420;
+   case TBM_FORMAT_YVU420: return __DRI_IMAGE_FOURCC_YVU420;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", 
format);
+  return -1;
+   }
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+  return false;
+   else
+  return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FORMAT_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FORMAT_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+  return -1;
+   }
+}
+
 static int get_format_bpp(tbm_format format)
 {
switch (format) {
@@ -89,6 +143,16 @@ static int get_stride(tbm_surface_h tbm_surface)
return surf_info.planes[0].stride;
 }
 
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+ TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
 static int
 get_native_buffer_name(tbm_surface_h tbm_surface)
 {
@@ -385,6 +449,205 @@ tizen_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
return tizen_swap_buffers_with_damage (drv, disp, draw, NULL, 0);
 }
 
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+ tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+  return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+  tbm_bo_handle bo_handle;
+  int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+  bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+  if (bo[i] == NULL) {
+ _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+ return NULL;
+  }
+  bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+  bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+  _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+  return NULL;
+   }
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_NV12:
+  fds[0] = bo_fd[0];
+  fds[1] = bo_fd[1];
+  offsets[0] = surf_info.planes[0].offset;
+  

[Mesa-dev] [PATCH v3 19/22] egl/android: apply dri2_egl_surface_destroy_image_back() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 5c014268b1..8dda0a8734 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -229,10 +229,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 
mtx_lock(>Mutex);
 
-   if (dri2_surf->dri_image_back) {
-  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-  dri2_surf->dri_image_back = NULL;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
return EGL_TRUE;
 }
@@ -356,11 +353,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
   dri2_surf->window->common.decRef(_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;
-   }
+   dri2_egl_surface_destroy_image_back(dri2_surf);
 
if (dri2_surf->dri_image_front) {
   _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, 
__LINE__);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 16/22] egl/android: apply dri2_egl_surface_free_outdated_buffers_and_update_size() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index e390365b8b..0acbb38bd8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -414,12 +414,9 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
}
 
/* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-   dri2_surf->base.Height != dri2_surf->buffer->height) {
-  dri2_egl_surface_free_local_buffers(dri2_surf);
-  dri2_surf->base.Width = dri2_surf->buffer->width;
-  dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf,
+  
dri2_surf->buffer->width,
+  
dri2_surf->buffer->height);
 
return 0;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 13/22] egl: add dri2_egl_surface_destroy_image_front() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common destroy dri_image_front code.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 14 ++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index e13b13c282..4070a80b23 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1153,6 +1153,20 @@ dri2_egl_surface_destroy_image_back(struct 
dri2_egl_surface *dri2_surf)
 #endif
 }
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf)
+{
+#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
+  dri2_surf->dri_image_front = NULL;
+   }
+#endif
+}
+
 /**
  * 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 a990fa3d83..fbef031fb6 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -509,6 +509,9 @@ dri2_egl_surface_update_buffer_age(struct dri2_egl_surface 
*dri2_surf);
 void
 dri2_egl_surface_destroy_image_back(struct dri2_egl_surface *dri2_surf);
 
+void
+dri2_egl_surface_destroy_image_front(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 17/22] egl/android: apply dri2_egl_surface_record_buffers_and_update_back_buffer() helper

2017-10-04 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_android.c | 25 ++---
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 0acbb38bd8..d5ce48a34c 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
/* Record all the buffers created by ANativeWindow and update back buffer
 * for updating buffer's age in swap_buffers.
 */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-  if (!dri2_surf->color_buffers[i].buffer) {
- dri2_surf->color_buffers[i].buffer = dri2_surf->buffer;
-  }
-  if (dri2_surf->color_buffers[i].buffer == dri2_surf->buffer) {
- dri2_surf->back = _surf->color_buffers[i];
- updated = EGL_TRUE;
- break;
-  }
-   }
-
-   if (!updated) {
-  /* In case of all the buffers were recreated by ANativeWindow, reset
-   * the color_buffers
-   */
-  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
- dri2_surf->color_buffers[i].buffer = NULL;
- dri2_surf->color_buffers[i].age = 0;
-  }
-  dri2_surf->color_buffers[0].buffer = dri2_surf->buffer;
-  dri2_surf->back = _surf->color_buffers[0];
-   }
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  dri2_surf->buffer);
 
return EGL_TRUE;
 }
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 09/22] egl/tizen: add tizen specific implementations for BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL (v2)

2017-10-04 Thread Gwan-gyeong Mun
Tizen platform (actually WL_TBM protocol) internally processes similiar actions
such as mesa's BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL.
So the platform_tizen.c needs to implemment BindWaylandDisplayWL,
UnbindWaylandDisplayWL and QueryWaylandBufferWL apart from mesa's.

  - tizen's enlightenment wayland display server calls wayland_tbm_server_init()
which processes described tasks.

  - section TPL-EGL and Wayland Server and Client
from https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL

"Tizen uses the wl_tbm protocol instead of wl_drm. The wl_tbm protocol is
 born for sharing the buffer(tbm_surface) between the wayland_client and
 wayland_server. Although the wayland_tbm_server_init and 
wayland_tbm_client_init
 pair is a role for the eglBindWaylandDisplayWL, the EGL driver is required
 to implement the entrypoints for the eglBindWaylandDisplayWL and
 eglUnbindWaylandDisplayWL as dummy."

v2: Fixes from Emil's review:
   a) Remove unneeded compiler pragma
   b) Add and use get_texture_format() helper
   c) Add switch's default case on tizen_query_wayland_buffer_wl()

referenced materials:
[1] https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL
[2] repository: git://git.tizen.org/platform/core/uifw/wayland-tbm (branch: 
tizen)

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 92 +++
 1 file changed, 92 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 72cef25364..6d872f9d3e 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -64,6 +64,21 @@ static int get_format_bpp(tbm_format format)
}
 }
 
+static EGLBoolean get_texture_format(tbm_format format, EGLint *value)
+{
+   switch (format) {
+   case TBM_FORMAT_ARGB:
+  *value = EGL_TEXTURE_RGBA;
+  return EGL_TRUE;
+   case TBM_FORMAT_XRGB:
+   case TBM_FORMAT_RGB565:
+  *value = EGL_TEXTURE_RGB;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 static int get_stride(tbm_surface_h tbm_surface)
 {
tbm_surface_info_s surf_info;
@@ -735,6 +750,78 @@ static const __DRIextension 
*tizen_swrast_loader_extensions[] = {
NULL,
 };
 
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_resource *buffer_resource,
+  EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+(tpl_handle_t)buffer_resource,
+, , _format);
+   if (res != TPL_ERROR_NONE)
+  return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+  return get_texture_format(tbm_format, value);
+   case EGL_WIDTH:
+  *value = width;
+  return EGL_TRUE;
+   case EGL_HEIGHT:
+  *value = height;
+  return EGL_TRUE;
+   default:
+  return EGL_FALSE;
+   }
+}
+
 EGLBoolean
 dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -865,6 +952,11 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+
+   drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
+   drv->API.UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl;
+   drv->API.QueryWaylandBufferWL = tizen_query_wayland_buffer_wl;
 
return EGL_TRUE;
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 07/22] egl: add dri2_egl_surface_update_buffer_age() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common update buffer age code.
This updates old buffer's age and sets current back buffer's age to 1.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 19 +++
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 2 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 807403dc51..8f6a8a62cb 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1120,6 +1120,25 @@ 
dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface *
 #endif
 }
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf)
+{
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (dri2_surf->color_buffers[i].age > 0)
+ dri2_surf->color_buffers[i].age++;
+   }
+
+#ifdef HAVE_ANDROID_PLATFORM
+   /* "XXX: we don't use get_back_bo() since it causes regressions in
+* several dEQP tests.
+*/
+   if (dri2_surf->back)
+  dri2_surf->back->age = 1;
+#else
+   dri2_surf->back->age = 1;
+#endif
+}
+
 /**
  * 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 c3529589ab..6f9d936ca5 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -494,6 +494,9 @@ void
 dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
void *buf);
 
+void
+dri2_egl_surface_update_buffer_age(struct dri2_egl_surface *dri2_surf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 06/22] egl: add dri2_egl_surface_record_buffers_and_update_back_buffer() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common record buffers and update back buffer code.
This records all the buffers created by ANativeWindow [Android] or
tpl_surface (tbm_surface_queue) [TIZEN] and update back buffer for updating
buffer's age in swap_buffers.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 42 +
 src/egl/drivers/dri2/egl_dri2.h |  5 +
 2 files changed, 47 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 8d4bfa8c1a..807403dc51 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1078,6 +1078,48 @@ 
dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface *
}
 }
 
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buf)
+{
+#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_TIZEN_PLATFORM)
+   /* Record all the buffers created by ANativeWindow [Android] or
+* tpl_surface (tbm_surface_queue) [TIZEN] and update back buffer for 
updating
+* buffer's age in swap_buffers.
+*/
+
+#ifdef HAVE_ANDROID_PLATFORM
+   struct ANativeWindowBuffer *buffer = (struct ANativeWindowBuffer *)buf;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   tbm_surface_h buffer = (tbm_surface_h)buf;
+#endif
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].buffer) {
+ dri2_surf->color_buffers[i].buffer = buffer;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  if (dri2_surf->color_buffers[i].buffer == buffer) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated, reset the color_buffers */
+  for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+ dri2_surf->color_buffers[i].buffer = NULL;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  dri2_surf->color_buffers[0].buffer = buffer;
+  dri2_surf->back = _surf->color_buffers[0];
+   }
+#endif
+}
+
 /**
  * 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 4d2348e584..c3529589ab 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -489,6 +489,11 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf);
 void
 dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
int width, int height);
+
+void
+dri2_egl_surface_record_buffers_and_update_back_buffer(struct dri2_egl_surface 
*dri2_surf,
+   void *buf);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 05/22] egl: add dri2_egl_surface_free_outdated_buffers_and_update_size() helper

2017-10-04 Thread Gwan-gyeong Mun
To share common free outdated buffers and update size code.
This compares width and height arguments with current egl surface dimension,
if the compared surface dimension is differ, then it free local buffers and
updates dimension.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 12 
 src/egl/drivers/dri2/egl_dri2.h |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 89e18b6331..8d4bfa8c1a 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1066,6 +1066,18 @@ dri2_egl_surface_free_local_buffers(struct 
dri2_egl_surface *dri2_surf)
}
 }
 
+void
+dri2_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height)
+{
+   /* free outdated buffers and update the surface size */
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+}
+
 /**
  * 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 d3cd9e1fef..4d2348e584 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -486,6 +486,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_egl_surface_free_outdated_buffers_and_update_size(struct dri2_egl_surface 
*dri2_surf,
+   int width, int height);
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
 _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean 
enable_out_fence);
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 08/22] egl/tizen: add support of dri2_loader (v2)

2017-10-04 Thread Gwan-gyeong Mun
It adds support of dri2_loader to egl dri2 tizen backend.
  - referenced a basic buffer flow and management implementation from android.

And it implements a query buffer age extesion for tizen and turn on
swap_buffers_with_damage extension.
  - it add color buffer related member variables to dri_egl_surface for a
management of color buffers.

v2: Fixes from Emil's review:
   a) Remove a temporary variable and return directly on get_format_bpp()
   b) Remove unneeded compiler pragma
   c) Follow coding style
   d) Rename get_pitch() to get_stride() for using of consistent naming
   e) Remove mis-referencing from android implementation on treatment of buffer
  age.
  reference: 
https://lists.freedesktop.org/archives/mesa-dev/2017-June/158409.html
   f) Use dri2_egl_surface_free_outdated_buffers_and_update_size() helper
   g) Use dri2_egl_surface_record_buffers_and_update_back_buffer() helper
   h) Use add dri2_egl_surface_update_buffer_age() helper
   i) Use env_var_as_boolean for hw_accel variable on dri2_initialize_tizen()
   j) Remove getting of the device name and opening of the device node on 
dri2_initialize_tizen()
  And add duplicating of tbm_bufmgr_fd. As tbm_bufmgr_fd is managed by 
tbm_bufmgr,
  if mesa use this fd then we should duplicate it.
   k) Add comments why we can not drop the dri2 codepath on 
dri2_initialize_tizen()
  As some kernels ported for tizen don't support render node feature yet,
  currently we cannot drop the dri2 codepath.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   9 ++
 src/egl/drivers/dri2/platform_tizen.c | 257 --
 2 files changed, 252 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 6f9d936ca5..7d047bf5dd 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -340,6 +340,15 @@ struct dri2_egl_surface
tpl_surface_t *tpl_surface;
tbm_surface_h  tbm_surface;
tbm_format tbm_format;
+
+   /* Used to record all the tbm_surface created by tpl_surface and their ages.
+* Usually Tizen uses at most triple buffers in tpl_surface 
(tbm_surface_queue)
+* so hardcode the number of color_buffers to 3.
+*/
+   struct {
+  tbm_surface_h   buffer;
+  int age;
+   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 7cee03f784..72cef25364 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -46,6 +46,43 @@
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
+#include "util/debug.h"
+
+static int get_format_bpp(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_BGRA:
+   case TBM_FORMAT_RGBA:
+   case TBM_FORMAT_RGBX:
+   case TBM_FORMAT_ARGB:
+   case TBM_FORMAT_XRGB:
+  return 4;
+   case TBM_FORMAT_RGB565:
+  return 2;
+   default:
+  return 0;
+   }
+}
+
+static int get_stride(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, _info) != TBM_SURFACE_ERROR_NONE)
+  return 0;
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
 
 static EGLBoolean
 tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
@@ -60,10 +97,14 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
tbm_surface_internal_ref(dri2_surf->tbm_surface);
 
tpl_surface_get_size(dri2_surf->tpl_surface, , );
-   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
-  dri2_surf->base.Width = width;
-  dri2_surf->base.Height = height;
-   }
+
+   dri2_egl_surface_free_outdated_buffers_and_update_size(dri2_surf, width, 
height);
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+* and update back buffer for updating buffer's age in swap_buffers.
+*/
+   dri2_egl_surface_record_buffers_and_update_back_buffer(dri2_surf,
+  
(void*)dri2_surf->tbm_surface);
 
return EGL_TRUE;
 }
@@ -101,6 +142,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
tbm_surface_internal_unref(dri2_surf->tbm_surface);
dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
 
mtx_lock(>Mutex);
 
@@ -208,7 +250,10 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+   if (dri2_dpy->dri2)
+  createNewDrawable = 

[Mesa-dev] [PATCH v3 04/22] configure.ac: Add tizen to supported platforms (v2)

2017-10-04 Thread Gwan-gyeong Mun
It checks tpl-egl/libtbm/libtdm packages and defines HAVE_PLATFORM_TIZEN.
This feature is enabled by the config option '--with-platforms=tizen'

v2: Fixes from Emil's review:
  - Add require_libdrm to tizen platform

Signed-off-by: Mun Gwan-gyeong 
---
 configure.ac | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index cfc97d9f06..7299531d0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1695,7 +1695,7 @@ dnl
 AC_ARG_WITH([platforms],
 [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
 [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
-"x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
+"x11,drm,wayland,surfaceless,tizen..." @<:@default=auto@:>@])],
 [with_platforms="$withval"],
 [with_platforms=auto])
 
@@ -1755,13 +1755,18 @@ for plat in $platforms; do
 DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
 ;;
 
+tizen)
+PKG_CHECK_MODULES([TIZEN], [tpl-egl libtbm libtdm])
+DEFINES="$DEFINES -DHAVE_TIZEN_PLATFORM"
+;;
+
 *)
 AC_MSG_ERROR([platform '$plat' does not exist])
 ;;
 esac
 
 case "$plat" in
-wayland|drm|surfaceless)
+wayland|drm|surfaceless|tizen)
 require_libdrm "Platform $plat"
 ;;
 esac
@@ -1785,6 +1790,7 @@ AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | 
grep -q 'wayland')
 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 
'surfaceless')
 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
+AM_CONDITIONAL(HAVE_PLATFORM_TIZEN, echo "$platforms" | grep -q 'tizen')
 
 dnl
 dnl More DRI setup
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 02/22] egl/dri2: Add some member variables for tizen platform on dri2_egl_display and dri2_egl_surface

2017-10-04 Thread Gwan-gyeong Mun
It adds some member variables for tizen platform on dri2_egl_display and 
dri2_egl_surface.
  - tpl_display stores a object which encapsulates native disply (wl_display,
gbm_device, tbm_bufmgr) for tizen platfom.
  - native_win stores native window (wl_surface, gbm_surface, 
tbm_surface_queue_h
  - tpl_surface stores a object which encapsulates native drawable object
(wl_surface, gbm_surface, tbm_surface_queue_h) for tizen platfom.
  - tbm_surface stores a native platform buffer.
tpl-egl exposes the native platform buffer as a tbm_surface.

And it adds routines of initialize and finalize for tizen platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 11 +++
 src/egl/drivers/dri2/egl_dri2.h | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index adcaae0bab..89e18b6331 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -909,6 +909,11 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
case _EGL_PLATFORM_ANDROID:
   ret = dri2_initialize_android(drv, disp);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  ret = dri2_initialize_tizen(drv, disp);
+  break;
 #endif
default:
   _eglLog(_EGL_WARNING, "No EGL platform enabled.");
@@ -1003,6 +1008,12 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_display_disconnect(dri2_dpy->wl_dpy);
   }
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  if (dri2_dpy->tpl_display)
+ tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+  break;
 #endif
default:
   break;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 10a4151817..d3cd9e1fef 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,14 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -234,6 +242,10 @@ struct dri2_egl_display
const gralloc_module_t *gralloc;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t*tpl_display;
+#endif
+
bool  is_render_node;
bool  is_different_gpu;
 };
@@ -323,6 +335,13 @@ struct dri2_egl_surface
} color_buffers[3], *back;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void  *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format tbm_format;
+#endif
+
 #if defined(HAVE_SURFACELESS_PLATFORM)
   __DRIimage   *front;
   unsigned int visual;
@@ -420,6 +439,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+EGLBoolean
+dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *disp);
+
 EGLBoolean
 dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
 
-- 
2.14.2

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 03/22] egl/tizen: add support of the swrast related features for tizen platform (v2)

2017-10-04 Thread Gwan-gyeong Mun
It implements the egl swrast related features for tizen platform on 
platform_tizen.c

It works with libtpl-egl (Tizen Porting Layer for egl) and libtbm (Tizen Buffer 
Manager)
where back buffers of windows are backed by GEM objects. In Tizen a native 
window
has a queue (tbm_surface_queue) of back buffers allocated by the WL_TBM
(wayland client case, WL_TBM is abbreviation of wayland-tbm protocol) or gbm
(tizen has implements gbm with tbm) or tbm through tbm_backend.

For each frame, EGL needs to

  dequeue the next back buffer - tizen_window_dequeue_buffer()
  render to the buffer
  enqueue the buffer - tizen_window_enqueue_buffer()

After enqueuing, the buffer is no longer valid to EGL.

v2:
 - Fixes from Emil's review:
   a) Add a treating of fail case on tizen_window_enqueue_buffer_with_damage()
   b) Follow coding style
   c) Remove unneeded compiler pragma
   d) Use a stride helper for tizen_swrast_get_image()
   e) Fix tizen_swrast_get_image() as drm platform's implementation
  referenced commit: fe2a6281b3b28fe7399e7dbcc2077d773824
   f) Fix tizen_swrast_put_image2() as drm platform's implementation
  referenced commit: 3a5e3aa5a53cff55a5e31766d713a41ffa5a93d7
   g) Add tizen_add_configs_for_surface_type() helper function which removes
  roundtrips.
   h) Refactor for tizen_add_configs()

 - Add image_image_lookup extension to tizen_swrast_loader_extensions

Referenced documents:
[1] 
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
[2] https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
[3] https://wiki.tizen.org/wiki/TBM

Signed-off-by: Mun Gwan-gyeong <elong...@gmail.com>
---
 src/egl/Makefile.am   |   6 +
 src/egl/drivers/dri2/platform_tizen.c | 646 ++
 2 files changed, 652 insertions(+)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
index f140f5d641..2ae61f87fe 100644
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -106,6 +106,12 @@ libEGL_common_la_LIBADD += $(ANDROID_LIBS)
 dri2_backend_FILES += drivers/dri2/platform_android.c
 endif
 
+if HAVE_PLATFORM_TIZEN
+AM_CFLAGS += $(TIZEN_CFLAGS)
+libEGL_common_la_LIBADD += $(TIZEN_LIBS)
+dri2_backend_FILES += drivers/dri2/platform_tizen.c
+endif
+
 AM_CFLAGS += \
-I$(top_srcdir)/src/loader \
-I$(top_builddir)/src/egl/drivers/dri2 \
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100644
index 00..7cee03f784
--- /dev/null
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -0,0 +1,646 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu <olva...@gmail.com>
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *Gwan-gyeong Mun <elong...@gmail.com>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "egl_dri2.h"
+#include "egl_dri2_fallbacks.h"
+#include "loader.h"
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+  return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, , );
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+
+   retu

[Mesa-dev] [PATCH v3 01/22] egl: add a treatment of tizen platform on egl display (v2)

2017-10-04 Thread Gwan-gyeong Mun
It adds a _EGL_PLATFORM_TIZEN enum value to _EGLPlatformType for tizen platform.

It adds a detecting routine of tizen platform to 
_eglNativePlatformDetectNativeDisplay()
and _eglGetNativePlatform().

  - As tizen platform internally distinguishes native displays of tbm, drm/gbm
and wayland client, when EGL_PLATFORM_WAYLAND_EXT or EGL_PLATFORM_GBM_MESA
come from eglGetPlatformDisplayEXT(), it have call _eglGetTizenDisplay().

Tizen supports various display protocols (tbm / gbm / wayland-egl) and each
implementation is different from mesa's. Because of tizen specific 
scanout-buffer
management for hardware overlay compositing and optimization. And also tizen
has its own gbm implementation for tizen specific implementation.
(gbm_create_device function pointer is differ from mesa's implementation.)

Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which is
an abstraction layer for the surface and buffer management on Tizen platform
aimed to implement the EGL porting layer of the OpenGLES driver over the
various display protocols.
As the libtpl-egl detects native display, if mesa send native display to
the libtpl-egl then it  distinguishes tbm/gbm/wayland-egl native display
and loads appropriate backend.

  - If tizen platform is enabled at the configuration, _eglGetNativePlatform()
always detects _EGL_PLATFORM_TIZEN as a detected_platform.

v2:
 - Fixes from Emil's review:
   a) Add commit messages in detail for a needing of a separated tizen backend.
   b) Remove unneeded ifndef blocks.
   c) Add comments in detail.
   d) Remove an wrong detection routine on _eglGetNativePlatform()

 - Add a detection routine of Tizen platform on _eglGetNativePlatformFromEnv()

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/main/eglapi.c | 13 +
 src/egl/main/egldisplay.c | 46 ++
 src/egl/main/egldisplay.h |  7 +++
 3 files changed, 66 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 4a9b3fe392..f3257eef4b 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -402,6 +402,19 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void 
*native_display,
case EGL_PLATFORM_SURFACELESS_MESA:
   dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+/* Tizen supports various display protocols (tbm / gbm / wayland-egl) and
+ * each implementation is different from mesa's.
+ * (Tizen has its own gbm implementation for tizen specific implementation.)
+ *  Therefore, when Tizen platform is enabled, it has call 
_eglGetTizenDisplay().
+ */
+case EGL_PLATFORM_GBM_MESA:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+case EGL_PLATFORM_WAYLAND_EXT:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
 #endif
default:
   RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 690728d2f7..43e2d73e73 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 
@@ -92,7 +93,20 @@ _eglGetNativePlatformFromEnv(void)
 
for (i = 0; i < _EGL_NUM_PLATFORMS; i++) {
   if (strcmp(egl_platforms[i].name, plat_name) == 0) {
+#ifdef HAVE_TIZEN_PLATFORM
+ /* Some widget library (ex. efl) can set EGL_DISPLAY environment
+  * variable as wayland or drm. But when TIZEN platform is enabled,
+  * we should ignore this variable in mesa. Becasue libtpl-egl detects
+  * this enviromnet variable and loads appropriate backend for that.
+  */
+ if ((egl_platforms[i].platform == _EGL_PLATFORM_WAYLAND) ||
+ (egl_platforms[i].platform == _EGL_PLATFORM_DRM))
+plat = _EGL_PLATFORM_TIZEN;
+ else
+plat = egl_platforms[i].platform;
+#else
  plat = egl_platforms[i].platform;
+#endif
  break;
   }
}
@@ -115,6 +129,23 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
   (void) first_pointer; /* silence unused var warning */
 
+#ifdef HAVE_TIZEN_PLATFORM
+  /* Tizen supports various display protocols (tbm / gbm / wayland-egl)
+   * and each implementation is different from mesa's. Because of tizen
+   * specific scanout-buffer management for hardware overlay compositing
+   * and optimization. And also tizen has its own gbm implementation for
+   * tizen specific implementation. (gbm_create_device function pointer
+   * is differ from mesa's implementation.)
+   * Therefore tizen provides libtpl-egl(Tizen Porting Layer for EGL) which
+   * is an abstraction layer for the surface and buffer 

[Mesa-dev] [PATCH 1/2] radv: add an assertion in radv_BeginCommandBuffer()

2017-09-26 Thread Gwan-gyeong Mun
To check a valid usage requirement.

CID: 1401616

Signed-off-by: Mun Gwan-gyeong 
---
 src/amd/vulkan/radv_cmd_buffer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 1e0e366820..4db9d7628c 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -2124,6 +2124,7 @@ VkResult radv_BeginCommandBuffer(
}
 
if (pBeginInfo->flags & 
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
+   assert(pBeginInfo->pInheritanceInfo);
cmd_buffer->state.framebuffer = 
radv_framebuffer_from_handle(pBeginInfo->pInheritanceInfo->framebuffer);
cmd_buffer->state.pass = 
radv_render_pass_from_handle(pBeginInfo->pInheritanceInfo->renderPass);
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] anv: add an assertion in genX(BeginCommandBuffer)

2017-09-26 Thread Gwan-gyeong Mun
To check a valid usage requirement.

Signed-off-by: Mun Gwan-gyeong 
---
 src/intel/vulkan/genX_cmd_buffer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/intel/vulkan/genX_cmd_buffer.c 
b/src/intel/vulkan/genX_cmd_buffer.c
index fbc1995709..3559399019 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -1006,6 +1006,7 @@ genX(BeginCommandBuffer)(
VkResult result = VK_SUCCESS;
if (cmd_buffer->usage_flags &
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
+  assert(pBeginInfo->pInheritanceInfo);
   cmd_buffer->state.pass =
  anv_render_pass_from_handle(pBeginInfo->pInheritanceInfo->renderPass);
   cmd_buffer->state.subpass =
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 4/9] configure.ac: Add tizen to supported platforms

2017-09-17 Thread Gwan-gyeong Mun
It checks tpl-egl/libtbm/libtdm packages and defines HAVE_PLATFORM_TIZEN.
This feature is enabled by the config option '--with-platforms=tizen'

Signed-off-by: Mun Gwan-gyeong 
---
 configure.ac | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index d0d4c0dfd1..04f6a4b165 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1677,7 +1677,7 @@ dnl
 AC_ARG_WITH([platforms],
 [AS_HELP_STRING([--with-platforms@<:@=DIRS...@:>@],
 [comma delimited native platforms libEGL/Vulkan/other supports, e.g.
-"x11,drm,wayland,surfaceless..." @<:@default=auto@:>@])],
+"x11,drm,wayland,surfaceless,tizen..." @<:@default=auto@:>@])],
 [with_platforms="$withval"],
 [with_platforms=auto])
 
@@ -1736,6 +1736,11 @@ for plat in $platforms; do
 DEFINES="$DEFINES -DHAVE_ANDROID_PLATFORM"
 ;;
 
+tizen)
+PKG_CHECK_MODULES([TIZEN], [tpl-egl libtbm libtdm])
+DEFINES="$DEFINES -DHAVE_TIZEN_PLATFORM"
+;;
+
 *)
 AC_MSG_ERROR([platform '$plat' does not exist])
 ;;
@@ -1766,6 +1771,7 @@ AM_CONDITIONAL(HAVE_PLATFORM_WAYLAND, echo "$platforms" | 
grep -q 'wayland')
 AM_CONDITIONAL(HAVE_PLATFORM_DRM, echo "$platforms" | grep -q 'drm')
 AM_CONDITIONAL(HAVE_PLATFORM_SURFACELESS, echo "$platforms" | grep -q 
'surfaceless')
 AM_CONDITIONAL(HAVE_PLATFORM_ANDROID, echo "$platforms" | grep -q 'android')
+AM_CONDITIONAL(HAVE_PLATFORM_TIZEN, echo "$platforms" | grep -q 'tizen')
 
 dnl
 dnl More DRI setup
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 6/9] egl/tizen: add tizen specific implementations for BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL

2017-09-17 Thread Gwan-gyeong Mun
Tizen platform (actually WL_TBM protocol) internally processes similiar actions
such as mesa's BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL.
So the platform_tizen.c needs to implemment BindWaylandDisplayWL,
UnbindWaylandDisplayWL and QueryWaylandBufferWL apart from mesa's.

  - tizen's enlightenment wayland display server calls wayland_tbm_server_init()
which processes described tasks.

  - section TPL-EGL and Wayland Server and Client
from https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL

"Tizen uses the wl_tbm protocol instead of wl_drm. The wl_tbm protocol is
 born for sharing the buffer(tbm_surface) between the wayland_client and
 wayland_server. Although the wayland_tbm_server_init and 
wayland_tbm_client_init
 pair is a role for the eglBindWaylandDisplayWL, the EGL driver is required
 to implement the entrypoints for the eglBindWaylandDisplayWL and
 eglUnbindWaylandDisplayWL as dummy."

referenced materials:
[1] https://wiki.tizen.org/3.0_Porting_Guide/Graphics_and_UI/OpenGL
[2] repository: git://git.tizen.org/platform/core/uifw/wayland-tbm (branch: 
tizen)

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 88 +++
 1 file changed, 88 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 77684d3c1a..19db84b553 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -746,6 +746,89 @@ static const __DRIextension 
*tizen_swrast_loader_extensions[] = {
NULL,
 };
 
+static EGLBoolean
+tizen_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
+struct wl_display *wl_dpy)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   (void) drv;
+   (void) wl_dpy;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_query_wayland_buffer_wl(_EGLDriver *drv, _EGLDisplay *disp,
+  struct wl_resource *buffer_resource,
+  EGLint attribute, EGLint *value)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   tbm_format tbm_format = 0;
+   int width = 0, height = 0;
+   tpl_result_t res;
+
+   if (!dri2_dpy->tpl_display)
+  return EGL_FALSE;
+
+   if (!tpl_display_get_native_handle(dri2_dpy->tpl_display))
+  return EGL_FALSE;
+
+   res = tpl_display_get_native_pixmap_info(dri2_dpy->tpl_display,
+(tpl_handle_t)buffer_resource,
+, , _format);
+   if (res != TPL_ERROR_NONE)
+  return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+  switch (tbm_format) {
+  case TBM_FORMAT_ARGB:
+ *value = EGL_TEXTURE_RGBA;
+ return EGL_TRUE;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+  case TBM_FORMAT_XRGB:
+  case TBM_FORMAT_RGB565:
+#pragma GCC diagnostic pop
+ *value = EGL_TEXTURE_RGB;
+ return EGL_TRUE;
+  }
+   case EGL_WIDTH:
+  *value = width;
+  return EGL_TRUE;
+   case EGL_HEIGHT:
+  *value = height;
+  return EGL_TRUE;
+   }
+
+   return EGL_FALSE;
+}
+
 EGLBoolean
 dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -879,6 +962,11 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+
+   drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
+   drv->API.UnbindWaylandDisplayWL = tizen_unbind_wayland_display_wl;
+   drv->API.QueryWaylandBufferWL = tizen_query_wayland_buffer_wl;
 
return EGL_TRUE;
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 9/9] egl/tizen: add support of dri_image_loader

2017-09-17 Thread Gwan-gyeong Mun
It adds support of dri_image_loader to egl dri2 tizen backend.
   - referenced a basic buffer flow and management  implementation from 
android's.

It adds dri_image_back/dri_image_back member variables to dri_egl_surface for
a management of back/front buffers.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   2 +
 src/egl/drivers/dri2/platform_tizen.c | 201 +-
 2 files changed, 200 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 46d56e93a2..8b85704065 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -340,6 +340,8 @@ struct dri2_egl_surface
tpl_surface_t *tpl_surface;
tbm_surface_h  tbm_surface;
tbm_format tbm_format;
+   __DRIimage*dri_image_back;
+   __DRIimage*dri_image_front;
 
/* Used to record all the tbm_surface created by tpl_surface and their ages.
 * Usually Tizen uses at most triple buffers in tpl_surface 
(tbm_surface_queue)
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 1efcb0e4fa..1840bade50 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -213,6 +213,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 EGLint n_rects)
 {
tpl_result_t ret;
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
 
/* To avoid blocking other EGL calls, release the display mutex before
 * we enter tizen_window_enqueue_buffer() and re-acquire the mutex upon
@@ -242,6 +243,11 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
mtx_lock(>Mutex);
 
+   if (dri2_surf->dri_image_back) {
+  dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
+  dri2_surf->dri_image_back = NULL;
+   }
+
return EGL_TRUE;
 }
 
@@ -339,7 +345,9 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   if (dri2_dpy->dri2)
+   if (dri2_dpy->image_driver)
+  createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+   else if (dri2_dpy->dri2)
   createNewDrawable = dri2_dpy->dri2->createNewDrawable;
else
   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
@@ -392,6 +400,18 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
  tizen_window_cancel_buffer(disp, dri2_surf);
}
 
+   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_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
tpl_object_unreference((tpl_object_t *)dri2_surf->tpl_surface);
@@ -416,6 +436,157 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (dri2_surf->dri_image_front)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  /* According current EGL spec, front buffer rendering
+   * for window surface is not supported now.
+   * and mesa doesn't have the implementation of this case.
+   * Add warning message, but not treat it as error.
+   */
+  _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for 
window surface");
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
+  dri2_surf->dri_image_front =
+ dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+  dri2_surf->base.Width,
+  dri2_surf->base.Height,
+  format,
+  0,
+  dri2_surf);
+  if (!dri2_surf->dri_image_front) {
+ _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+ return -1;
+  }
+   }
+
+   return 0;
+}
+
+static int
+get_back_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+   int fourcc, pitch;
+   int offset = 0, fd;
+   tbm_surface_info_s surf_info;
+
+   if (dri2_surf->dri_image_back)
+  return 0;
+
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
+  if (!dri2_surf->tbm_surface) {
+ _eglLog(_EGL_WARNING, "Could not get native buffer");
+ return -1;
+  }

[Mesa-dev] [PATCH v2 8/9] egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()

2017-09-17 Thread Gwan-gyeong Mun
It adds TIZEN_image_native_surface extension string to _EGLExtensions.
And it adds a routine of creating an EGLImage from a tbm_surface.

  - section overview
from 
https://www.khronos.org/registry/EGL/extensions/TIZEN/EGL_TIZEN_image_native_surface.txt

"Tizen Buffer Manager (TBM) is a user space, generic memory management
 framework to create and share memory buffers between different system
 components. This extension enables using a Tizen Buffer Manager (TBM)
 surface object (struct tbm_surface_h) as an EGLImage source."

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 18 ++
 src/egl/main/eglapi.c |  2 ++
 src/egl/main/egldisplay.h |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 3fe6cb504b..1efcb0e4fa 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -708,6 +708,20 @@ tizen_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf,
return _eglQuerySurface(drv, dpy, surf, attribute, value);
 }
 
+static _EGLImage *
+dri2_create_image_tizen_native_buffer(_EGLDisplay *disp,
+  _EGLContext *ctx,
+  tbm_surface_h tbm_surface)
+{
+   int fd;
+
+   fd = get_native_buffer_fd(tbm_surface);
+   if (fd >= 0)
+  return tizen_create_image_from_prime_fd(disp, ctx, tbm_surface, fd);
+
+   return tizen_create_image_from_name(disp, ctx, tbm_surface);
+}
+
 static _EGLImage *
 dri2_create_image_tizen_wl_buffer(_EGLDisplay *disp,
   _EGLContext *ctx,
@@ -735,6 +749,9 @@ tizen_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
EGLClientBuffer buffer, const EGLint *attr_list)
 {
switch (target) {
+   case EGL_NATIVE_SURFACE_TIZEN:
+  return dri2_create_image_tizen_native_buffer(disp, ctx,
+   (tbm_surface_h)buffer);
case EGL_WAYLAND_BUFFER_WL:
   return dri2_create_image_tizen_wl_buffer(disp, ctx, 
(tpl_handle_t)buffer);
default:
@@ -1269,6 +1286,7 @@ dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *dpy)
 
dpy->Extensions.EXT_buffer_age = EGL_TRUE;
dpy->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
+   dpy->Extensions.TIZEN_image_native_surface = EGL_TRUE;
dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
 
drv->API.BindWaylandDisplayWL = tizen_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 12e867ca72..1bcff72ae4 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -536,6 +536,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
 
_EGL_CHECK_EXTENSION(NV_post_sub_buffer);
 
+   _EGL_CHECK_EXTENSION(TIZEN_image_native_surface);
+
_EGL_CHECK_EXTENSION(WL_bind_wayland_display);
_EGL_CHECK_EXTENSION(WL_create_wayland_buffer_from_image);
 
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index c009462b82..1ff7b5a2d5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -133,6 +133,8 @@ struct _egl_extensions
 
EGLBoolean NV_post_sub_buffer;
 
+   EGLBoolean TIZEN_image_native_surface;
+
EGLBoolean WL_bind_wayland_display;
EGLBoolean WL_create_wayland_buffer_from_image;
 };
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 3/9] egl/tizen: add support of the swrast related features for tizen platform

2017-09-17 Thread Gwan-gyeong Mun
It implements the egl swrast related features for tizen platform on 
platform_tizen.c

It works with libtpl-egl (Tizen Porting Layer for egl) and libtbm (Tizen Buffer 
Manager)
where back buffers of windows are backed by GEM objects. In Tizen a native 
window
has a queue (tbm_surface_queue) of back buffers allocated by the WL_TBM
(wayland client case, WL_TBM is abbreviation of wayland-tbm protocol) or gbm
(tizen has implements gbm with tbm) or tbm through tbm_backend.

For each frame, EGL needs to

  dequeue the next back buffer - tizen_window_dequeue_buffer()
  render to the buffer
  enqueue the buffer - tizen_window_enqueue_buffer()

After enqueuing, the buffer is no longer valid to EGL.

Referenced documents:
[1] 
https://www.x.org/wiki/Events/XDC2016/Program/XDC2016_Tizen_Window_System_EGL_Vulkan.pdf
[2] https://wiki.tizen.org/wiki/3.0_Porting_Guide/Graphics_and_UI/libtpl-egl
[3] https://wiki.tizen.org/wiki/TBM

Signed-off-by: Mun Gwan-gyeong <elong...@gmail.com>
---
 src/egl/Makefile.am   |   6 +
 src/egl/drivers/dri2/platform_tizen.c | 618 ++
 2 files changed, 624 insertions(+)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
index 8ff1ffaba1..ef0c47ad76 100644
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -104,6 +104,12 @@ libEGL_common_la_LIBADD += $(ANDROID_LIBS)
 dri2_backend_FILES += drivers/dri2/platform_android.c
 endif
 
+if HAVE_PLATFORM_TIZEN
+AM_CFLAGS += $(TIZEN_CFLAGS)
+libEGL_common_la_LIBADD += $(TIZEN_LIBS)
+dri2_backend_FILES += drivers/dri2/platform_tizen.c
+endif
+
 AM_CFLAGS += \
-I$(top_srcdir)/src/loader \
-I$(top_builddir)/src/egl/drivers/dri2 \
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
new file mode 100644
index 00..efdf79682b
--- /dev/null
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -0,0 +1,618 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2017 Samsung Electronics co., Ltd. All Rights Reserved
+ *
+ * Based on platform_android, which has
+ *
+ * Copyright (C) 2010-2011 Chia-I Wu <olva...@gmail.com>
+ * Copyright (C) 2010-2011 LunarG Inc.
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *Gwan-gyeong Mun <elong...@gmail.com>
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "egl_dri2.h"
+#include "egl_dri2_fallbacks.h"
+#include "loader.h"
+
+static EGLBoolean
+tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
+{
+   int width, height;
+
+   dri2_surf->tbm_surface = tpl_surface_dequeue_buffer(dri2_surf->tpl_surface);
+
+   if (!dri2_surf->tbm_surface)
+  return EGL_FALSE;
+
+   tbm_surface_internal_ref(dri2_surf->tbm_surface);
+
+   tpl_surface_get_size(dri2_surf->tpl_surface, , );
+   if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
+  dri2_surf->base.Width = width;
+  dri2_surf->base.Height = height;
+   }
+
+   return EGL_TRUE;
+}
+
+static EGLBoolean
+tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
+struct dri2_egl_surface *dri2_surf,
+const EGLint *rects,
+EGLint n_rects)
+{
+   tpl_result_t ret;
+
+   /* To avoid blocking other EGL calls, release the display mutex before
+* we enter tizen_window_enqueue_buffer() and re-acquire the mutex upon
+* return.
+*/
+   mtx_unlock(>Mutex);
+
+   if (n_rects < 1 || rects == NULL) {
+  /* if there is no damage, call the normal API tpl_surface_enqueue_buffer 
*/
+  ret = tpl_surface_enqueue_buffer(dri2_surf->tpl_surface,
+  

[Mesa-dev] [PATCH v2 5/9] egl/tizen: add support of dri2_loader

2017-09-17 Thread Gwan-gyeong Mun
It adds support of dri2_loader to egl dri2 tizen backend.
  - referenced a basic buffer flow and management  implementation from android.

And it implements a query buffer age extesion for tizen and turn on
swap_buffers_with_damage extension.
  - it add color buffer related member variables to dri_egl_surface for a
management of color buffers.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.h   |   9 ++
 src/egl/drivers/dri2/platform_tizen.c | 289 --
 2 files changed, 289 insertions(+), 9 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 4b29b0d406..46d56e93a2 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -340,6 +340,15 @@ struct dri2_egl_surface
tpl_surface_t *tpl_surface;
tbm_surface_h  tbm_surface;
tbm_format tbm_format;
+
+   /* Used to record all the tbm_surface created by tpl_surface and their ages.
+* Usually Tizen uses at most triple buffers in tpl_surface 
(tbm_surface_queue)
+* so hardcode the number of color_buffers to 3.
+*/
+   struct {
+  tbm_surface_h   tbm_surface;
+  int age;
+   } color_buffers[3], *back;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index efdf79682b..77684d3c1a 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -47,6 +47,53 @@
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
 
+static int get_format_bpp(tbm_format format)
+{
+   int bpp;
+
+   switch (format) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+   case TBM_FORMAT_BGRA:
+   case TBM_FORMAT_RGBA:
+   case TBM_FORMAT_RGBX:
+   case TBM_FORMAT_ARGB:
+#pragma GCC diagnostic pop
+   case TBM_FORMAT_XRGB:
+  bpp = 4;
+  break;
+   case TBM_FORMAT_RGB565:
+  bpp = 2;
+  break;
+   default:
+  bpp = 0;
+  break;
+   }
+
+   return bpp;
+}
+
+static int get_pitch(tbm_surface_h tbm_surface)
+{
+   tbm_surface_info_s surf_info;
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  return 0;
+   }
+
+   return surf_info.planes[0].stride;
+}
+
+static int
+get_native_buffer_name(tbm_surface_h tbm_surface)
+{
+   uint32_t bo_name;
+
+   bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0));
+
+   return (bo_name != 0 ) ? (int)bo_name : -1;
+}
+
 static EGLBoolean
 tizen_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
 {
@@ -63,6 +110,33 @@ tizen_window_dequeue_buffer(struct dri2_egl_surface 
*dri2_surf)
if (dri2_surf->base.Width != width || dri2_surf->base.Height != height) {
   dri2_surf->base.Width = width;
   dri2_surf->base.Height = height;
+  dri2_egl_surface_free_local_buffers(dri2_surf);
+   }
+
+   /* Record all the buffers created by tpl_surface (tbm_surface_queue)
+*   and update back buffer * for updating buffer's age in swap_buffers.
+*/
+   EGLBoolean updated = EGL_FALSE;
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+  if (!dri2_surf->color_buffers[i].tbm_surface) {
+ dri2_surf->color_buffers[i].tbm_surface = dri2_surf->tbm_surface;
+ dri2_surf->color_buffers[i].age = 0;
+  }
+  if (dri2_surf->color_buffers[i].tbm_surface == dri2_surf->tbm_surface) {
+ dri2_surf->back = _surf->color_buffers[i];
+ updated = EGL_TRUE;
+ break;
+  }
+   }
+
+   if (!updated) {
+  /* In case of all the buffers were recreated , reset the color_buffers */
+  for (int 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->color_buffers[0].tbm_surface = dri2_surf->tbm_surface;
+  dri2_surf->back = _surf->color_buffers[0];
}
 
return EGL_TRUE;
@@ -100,6 +174,7 @@ tizen_window_enqueue_buffer_with_damage(_EGLDisplay *disp,
 
tbm_surface_internal_unref(dri2_surf->tbm_surface);
dri2_surf->tbm_surface = NULL;
+   dri2_surf->back = NULL;
 
mtx_lock(>Mutex);
 
@@ -200,7 +275,10 @@ tizen_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
if (!dri2_surf->tpl_surface)
   goto cleanup_surface;
 
-   createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+   if (dri2_dpy->dri2)
+  createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+   else
+  createNewDrawable = dri2_dpy->swrast->createNewDrawable;
 
dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,
   dri2_surf);
@@ -243,6 +321,8 @@ tizen_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface 

[Mesa-dev] [PATCH v2 7/9] egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL target of eglCreateImageKHR()

2017-09-17 Thread Gwan-gyeong Mun
In the tizen platform, a wl_buffer wraps a tbm_surface. The tbm_surface contains
gem name or prime fd. For creating dri_image, we need to extract the tbm_surface
from the wl_buffer and we use tpl_display_get_buffer_from_native_pixmap() api
for that.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/platform_tizen.c | 309 +-
 1 file changed, 308 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/platform_tizen.c 
b/src/egl/drivers/dri2/platform_tizen.c
index 19db84b553..3fe6cb504b 100644
--- a/src/egl/drivers/dri2/platform_tizen.c
+++ b/src/egl/drivers/dri2/platform_tizen.c
@@ -47,6 +47,60 @@
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
 
+/* createImageFromFds requires fourcc format */
+static int get_fourcc(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FOURCC_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FOURCC_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FOURCC_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FOURCC_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FOURCC_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+   }
+   return -1;
+}
+
+static int get_fourcc_yuv(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_NV12:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_NV21:   return __DRI_IMAGE_FOURCC_NV12;
+   case TBM_FORMAT_YUV420: return __DRI_IMAGE_FOURCC_YUV420;
+   case TBM_FORMAT_YVU420: return __DRI_IMAGE_FOURCC_YVU420;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native yuv buffer format 0x%x", 
format);
+   }
+   return -1;
+}
+
+static bool is_yuv_format(tbm_format format)
+{
+   if (get_fourcc_yuv(format) == -1)
+  return false;
+   else
+  return true;
+}
+
+static int get_format(tbm_format format)
+{
+   switch (format) {
+   case TBM_FORMAT_RGB565:   return __DRI_IMAGE_FORMAT_RGB565;
+   case TBM_FORMAT_BGRA: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_RGBA: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_ARGB: return __DRI_IMAGE_FORMAT_ARGB;
+   case TBM_FORMAT_ABGR: return __DRI_IMAGE_FORMAT_ABGR;
+   case TBM_FORMAT_RGBX: return __DRI_IMAGE_FORMAT_XBGR;
+   case TBM_FORMAT_XRGB: return __DRI_IMAGE_FORMAT_XRGB;
+   default:
+  _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
+   }
+   return -1;
+}
+
 static int get_format_bpp(tbm_format format)
 {
int bpp;
@@ -84,6 +138,16 @@ static int get_pitch(tbm_surface_h tbm_surface)
return surf_info.planes[0].stride;
 }
 
+static int
+get_native_buffer_fd(tbm_surface_h tbm_surface)
+{
+   tbm_bo_handle bo_handle;
+   bo_handle = tbm_bo_get_handle(tbm_surface_internal_get_bo(tbm_surface, 0),
+ TBM_DEVICE_3D);
+
+   return (bo_handle.ptr != NULL) ? (int)bo_handle.u32 : -1;
+}
+
 static int
 get_native_buffer_name(tbm_surface_h tbm_surface)
 {
@@ -403,6 +467,215 @@ tizen_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
return tizen_swap_buffers_with_damage (drv, disp, draw, NULL, 0);
 }
 
+static _EGLImage *
+tizen_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
+ tbm_surface_h tbm_surface)
+
+{
+   tbm_surface_info_s surf_info;
+   tbm_fd bo_fd[TBM_SURF_PLANE_MAX];
+   tbm_bo bo[TBM_SURF_PLANE_MAX];
+   int num_planes;
+   int i;
+   int fourcc;
+   size_t offsets[3] = {0, 0, 0};
+   size_t pitches[3] = {0, 0, 0};
+   int fds[3] = {-1, -1, -1};
+
+   if (tbm_surface_get_info(tbm_surface, _info) != 
TBM_SURFACE_ERROR_NONE) {
+  _eglLog(_EGL_WARNING, "Could not get tbm_surface_info");
+  return NULL;
+   }
+
+   num_planes = surf_info.num_planes;
+   for (i = 0; i < num_planes; i++) {
+  tbm_bo_handle bo_handle;
+  int bo_idx = tbm_surface_internal_get_plane_bo_idx(tbm_surface, i);
+  bo[i] = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
+  if (bo[i] == NULL) {
+ _eglLog(_EGL_WARNING, "Could not get tbm_surface_internal_bo");
+ return NULL;
+  }
+  bo_handle = tbm_bo_get_handle(bo[i], TBM_DEVICE_3D);
+  bo_fd[i] = bo_handle.u32;
+   }
+
+   fourcc = get_fourcc_yuv(tbm_surface_get_format(tbm_surface));
+   if (fourcc == -1) {
+  _eglLog(_EGL_WARNING, "Unsupported native yuv format");
+  return NULL;
+   }
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_NV12:
+  fds[0] = bo_fd[0];
+  fds[1] = bo_fd[1];
+  offsets[0] = surf_info.planes[0].offset;
+  offsets[1] = surf_info.planes[1].offset;
+  pitches[0] = surf_info.planes[0].stride;
+  pitches[1] = surf_info.planes[1].stride;
+  break;
+   case __DRI_IMAGE_FOURCC_YUV420:
+  fds[0] = bo_fd[0];
+  

[Mesa-dev] [PATCH v2 2/9] egl/dri2: Add some member variables for tizen platform on dri2_egl_display and dri2_egl_surface

2017-09-17 Thread Gwan-gyeong Mun
It adds some member variables for tizen platform on dri2_egl_display and 
dri2_egl_surface.
  - tpl_display stores a object which encapsulates native disply (wl_display,
gbm_device, tbm_bufmgr) for tizen platfom.
  - native_win stores native window (wl_surface, gbm_surface, 
tbm_surface_queue_h
  - tpl_surface stores a object which encapsulates native drawable object
(wl_surface, gbm_surface, tbm_surface_queue_h) for tizen platfom.
  - tbm_surface stores a native platform buffer.
tpl-egl exposes the native platform buffer as a tbm_surface.

And it adds routines of initialize and finalize for tizen platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 11 +++
 src/egl/drivers/dri2/egl_dri2.h | 22 ++
 2 files changed, 33 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 2667aa5d64..a2c2b120ef 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -899,6 +899,11 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
case _EGL_PLATFORM_ANDROID:
   ret = dri2_initialize_android(drv, disp);
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  ret = dri2_initialize_tizen(drv, disp);
+  break;
 #endif
default:
   _eglLog(_EGL_WARNING, "No EGL platform enabled.");
@@ -993,6 +998,12 @@ dri2_display_destroy(_EGLDisplay *disp)
  wl_display_disconnect(dri2_dpy->wl_dpy);
   }
   break;
+#endif
+#ifdef HAVE_TIZEN_PLATFORM
+   case _EGL_PLATFORM_TIZEN:
+  if (dri2_dpy->tpl_display)
+ tpl_object_unreference((tpl_object_t *)(dri2_dpy->tpl_display));
+  break;
 #endif
default:
   break;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 4a52b490a8..4b29b0d406 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -65,6 +65,14 @@ struct zwp_linux_dmabuf_v1;
 
 #endif /* HAVE_ANDROID_PLATFORM */
 
+#ifdef HAVE_TIZEN_PLATFORM
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* HAVE_TIZEN_PLATFORM */
+
 #include "eglconfig.h"
 #include "eglcontext.h"
 #include "egldisplay.h"
@@ -234,6 +242,10 @@ struct dri2_egl_display
const gralloc_module_t *gralloc;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   tpl_display_t*tpl_display;
+#endif
+
bool  is_render_node;
bool  is_different_gpu;
 };
@@ -323,6 +335,13 @@ struct dri2_egl_surface
} color_buffers[3], *back;
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+   void  *native_win;
+   tpl_surface_t *tpl_surface;
+   tbm_surface_h  tbm_surface;
+   tbm_format tbm_format;
+#endif
+
 #if defined(HAVE_SURFACELESS_PLATFORM)
   __DRIimage   *front;
   unsigned int visual;
@@ -418,6 +437,9 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+EGLBoolean
+dri2_initialize_tizen(_EGLDriver *drv, _EGLDisplay *disp);
+
 EGLBoolean
 dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 1/9] egl: add a treatment of tizen platform on egl display

2017-09-17 Thread Gwan-gyeong Mun
It adds a _EGL_PLATFORM_TIZEN enum value to _EGLPlatformType for tizen platform.

It adds a detecting routine of tizen platform to 
_eglNativePlatformDetectNativeDisplay()
and _eglGetNativePlatform().
  - As tizen platform internally distinguishes native displays of drm/gbm and 
wayland
client, when EGL_PLATFORM_WAYLAND_EXT or EGL_PLATFORM_GBM_MESA come from
eglGetPlatformDisplayEXT(), it have call _eglGetTizenDisplay().
  - If tizen platform is enabled at the configuration, _eglGetNativePlatform()
always detects _EGL_PLATFORM_TIZEN as a detected_platform.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/main/eglapi.c | 12 
 src/egl/main/egldisplay.c | 30 ++
 src/egl/main/egldisplay.h |  7 +++
 3 files changed, 49 insertions(+)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index e3f10fcbe2..12e867ca72 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -404,6 +404,18 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void 
*native_display,
   dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
   break;
 #endif
+#ifdef HAVE_TIZEN_PLATFORM
+#ifndef HAVE_DRM_PLATFORM
+case EGL_PLATFORM_GBM_MESA:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+#endif /* not HAVE_DRM_PLATFORM */
+#ifndef HAVE_WAYLAND_PLATFORM
+case EGL_PLATFORM_WAYLAND_EXT:
+   dpy = _eglGetTizenDisplay(native_display, attrib_list);
+   break;
+#endif /* not HAVE_WAYLAND_PLATFORM */
+#endif /* HAVE_TIZEN_PLATFORM */
default:
   RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
}
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 690728d2f7..b55d243015 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -70,6 +70,7 @@ static const struct {
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
+   { _EGL_PLATFORM_TIZEN, "tizen" },
 };
 
 
@@ -115,6 +116,13 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
   (void) first_pointer; /* silence unused var warning */
 
+#ifdef HAVE_TIZEN_PLATFORM
+  /* In Tizen Platform, _EGL_PLATFORM_TIZEN treats together DRM(gbm) 
platform
+   * and wayland egl platform.
+   */
+  return _EGL_PLATFORM_TIZEN;
+#endif
+
 #ifdef HAVE_WAYLAND_PLATFORM
   /* wl_display is a wl_proxy, which is a wl_object.
* wl_object's first element points to the interfacetype. */
@@ -157,6 +165,13 @@ _eglGetNativePlatform(void *nativeDisplay)
   detected_platform = _eglGetNativePlatformFromEnv();
   detection_method = "environment overwrite";
 
+#ifdef HAVE_TIZEN_PLATFORM
+  if (detected_platform != _EGL_PLATFORM_TIZEN) {
+ detected_platform = _EGL_PLATFORM_TIZEN;
+ detection_method = "build-time configuration";
+  }
+#endif
+
   if (detected_platform == _EGL_INVALID_PLATFORM) {
  detected_platform = 
_eglNativePlatformDetectNativeDisplay(nativeDisplay);
  detection_method = "autodetected";
@@ -541,3 +556,18 @@ _eglGetSurfacelessDisplay(void *native_display,
return _eglFindDisplay(_EGL_PLATFORM_SURFACELESS, native_display);
 }
 #endif /* HAVE_SURFACELESS_PLATFORM */
+
+#ifdef HAVE_TIZEN_PLATFORM
+_EGLDisplay*
+_eglGetTizenDisplay(void *native_display,
+const EGLint *attrib_list)
+{
+   /* EGL_EXT_platform_wayland recognizes no attributes. */
+   if (attrib_list != NULL && attrib_list[0] != EGL_NONE) {
+  _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
+  return NULL;
+   }
+
+   return _eglFindDisplay(_EGL_PLATFORM_TIZEN, native_display);
+}
+#endif /* HAVE_TIZEN_PLATFORM */
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 9a0b9b672a..c009462b82 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -50,6 +50,7 @@ enum _egl_platform_type {
_EGL_PLATFORM_ANDROID,
_EGL_PLATFORM_HAIKU,
_EGL_PLATFORM_SURFACELESS,
+   _EGL_PLATFORM_TIZEN,
 
_EGL_NUM_PLATFORMS,
_EGL_INVALID_PLATFORM = -1
@@ -285,6 +286,12 @@ _eglGetSurfacelessDisplay(void *native_display,
   const EGLint *attrib_list);
 #endif
 
+#ifdef HAVE_TIZEN_PLATFORM
+_EGLDisplay*
+_eglGetTizenDisplay(void *native_display,
+const EGLint *attrib_list);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 0/9] Introduce supporting of Tizen to mesa's egl platform

2017-09-17 Thread Gwan-gyeong Mun
Hi, 

these commit series modified some items from previous version.

1. patches are seperated by feature implementation.
2. remove unclearly relevant pbuffer surface-creation code.
3. refactored for removing duplicated codes.
4. rebased for lastest code base.

Gwan-gyeong Mun (9):
  egl: add a treatment of tizen platform on egl display
  egl/dri2: Add some member variables for tizen platform on
dri2_egl_display and dri2_egl_surface
  egl/tizen: add support of the swrast related features for tizen
platform
  configure.ac: Add tizen to supported platforms
  egl/tizen: add support of dri2_loader
  egl/tizen: add tizen specific implementations for
BindWaylandDisplayWL/UnbindWaylandDisplayWL/QueryWaylandBufferWL
  egl/tizen: add tizen specific implementation for EGL_WAYLAND_BUFFER_WL
target of eglCreateImageKHR()
  egl/tizen: add EGL_NATIVE_SURFACE_TIZEN target of eglCreateImageKHR()
  egl/tizen: add support of dri_image_loader

 configure.ac  |8 +-
 src/egl/Makefile.am   |6 +
 src/egl/drivers/dri2/egl_dri2.c   |   11 +
 src/egl/drivers/dri2/egl_dri2.h   |   33 +
 src/egl/drivers/dri2/platform_tizen.c | 1497 +
 src/egl/main/eglapi.c |   14 +
 src/egl/main/egldisplay.c |   30 +
 src/egl/main/egldisplay.h |9 +
 8 files changed, 1607 insertions(+), 1 deletion(-)
 create mode 100644 src/egl/drivers/dri2/platform_tizen.c

-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: fix a typo

2017-08-26 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/context.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/context.rst 
b/src/gallium/docs/source/context.rst
index 7002802248..6ac45819a6 100644
--- a/src/gallium/docs/source/context.rst
+++ b/src/gallium/docs/source/context.rst
@@ -118,7 +118,7 @@ If texture format is different than template format, it is 
said the texture
 is being cast to another format. Casting can be done only between compatible
 formats, that is formats that have matching component order and sizes.
 
-Swizzle fields specify they way in which fetched texel components are placed
+Swizzle fields specify the way in which fetched texel components are placed
 in the result register. For example, ``swizzle_r`` specifies what is going to 
be
 placed in first component of result register.
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: add reference links for resource_create method

2017-08-24 Thread Gwan-gyeong Mun
It adds reference links for arguments usage and bind of resource_create().

Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/screen.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 930e5bd5f0..426edadf7f 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -739,9 +739,9 @@ For cube maps this must be 6, for other textures 1.
 **nr_samples** the nr of msaa samples. 0 (or 1) specifies a resource
 which isn't multisampled.
 
-**usage** one of the PIPE_USAGE flags.
+**usage** one of the :ref:`PIPE_USAGE` flags.
 
-**bind** bitmask of the PIPE_BIND flags.
+**bind** bitmask of the :ref:`PIPE_BIND` flags.
 
 **flags** bitmask of PIPE_RESOURCE_FLAG flags.
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: fix a reference link for get_paramf

2017-08-24 Thread Gwan-gyeong Mun
Previous get_paramf links same as get_param. It changes the reference link to
PIPE_CAPF_*

Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/screen.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index be14ddd0c0..930e5bd5f0 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -670,7 +670,7 @@ get_paramf
 
 Get a floating-point screen parameter.
 
-**param** is one of the :ref:`PIPE_CAP` names.
+**param** is one of the :ref:`PIPE_CAPF` names.
 
 context_create
 ^^
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: Fix an inequality sign of TGSI_SEMANTIC_SUBGROUP_LT_MASK

2017-08-23 Thread Gwan-gyeong Mun
A previous expression presents same as TGSI_SEMANTIC_SUBGROUP_GT_MASK.
It fixes a direction of an inequality for TGSI_SEMANTIC_SUBGROUP_LT_MASK.

before:
  bit index > TGSI_SEMANTIC_SUBGROUP_INVOCATION

after:
  bit index < TGSI_SEMANTIC_SUBGROUP_INVOCATION

Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/tgsi.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index 31331ef511..0bd9964a98 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -3397,7 +3397,7 @@ A bit mask of ``bit index <= 
TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
 TGSI_SEMANTIC_SUBGROUP_LT_MASK
 ""
 
-A bit mask of ``bit index > TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
+A bit mask of ``bit index < TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
 ``(1 << subgroup_invocation) - 1`` in arbitrary precision arithmetic.
 
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: Fix the math formula of U2I64

2017-08-22 Thread Gwan-gyeong Mun
before:
  dst.xy = (uint64_t) src0.x
  dst.zw = (uint64_t) src0.y

after:
  dst.xy = (int64_t) src0.x
  dst.zw = (int64_t) src0.y

Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/tgsi.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index f9b1385e55..31331ef511 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -2199,9 +2199,9 @@ two-component vectors with 64-bits in each component.
 
 .. math::
 
-   dst.xy = (uint64_t) src0.x
+   dst.xy = (int64_t) src0.x
 
-   dst.zw = (uint64_t) src0.y
+   dst.zw = (int64_t) src0.y
 
 .. opcode:: I2I64 - Signed Integer to 64-bit Integer
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] gallium/docs: Add missing word "Not"

2017-08-22 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 src/gallium/docs/source/tgsi.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/docs/source/tgsi.rst b/src/gallium/docs/source/tgsi.rst
index b148c3c939..f9b1385e55 100644
--- a/src/gallium/docs/source/tgsi.rst
+++ b/src/gallium/docs/source/tgsi.rst
@@ -1762,7 +1762,7 @@ two-component vectors with doubled precision in each 
component.
 
   dst.z = src0.zw == src1.zw ? \sim 0 : 0
 
-.. opcode:: DSNE - Set on Equal
+.. opcode:: DSNE - Set on Not Equal
 
 .. math::
 
-- 
2.14.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] dri: fix typo in comment

2017-08-10 Thread Gwan-gyeong Mun
Signed-off-by: Mun Gwan-gyeong 
---
 include/GL/internal/dri_interface.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 2cbd738439..b90c9b2c66 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1190,7 +1190,7 @@ struct __DRIdri2ExtensionRec {
  * by the driver (YUV planar formats) but serve as a base image for
  * creating sub-images for the different planes within the image.
  *
- * R8, GR88 and NONE should not be used with createImageFormName or
+ * R8, GR88 and NONE should not be used with createImageFromName or
  * createImage, and are returned by query from sub images created with
  * createImageFromNames (NONE, see above) and fromPlane (R8 & GR88).
  */
-- 
2.13.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] egl: deduplicate allocations of local buffer over each platform backend (v2)

2017-08-04 Thread Gwan-gyeong Mun
platform_drm, platform_wayland and platform_android have similiar local buffer
allocation routines. For deduplicating, it unifies dri2_egl_surface's
local buffer allocation routines. And it polishes inconsistent indentations.

Note that as dri2_wl_get_buffers_with_format() have not make a 
__DRI_BUFFER_BACK_LEFT
attachment buffer for local_buffers, new helper function, 
dri2_egl_surface_free_local_buffers(),
will drop the __DRI_BUFFER_BACK_LEFT check.
So if other platforms use new helper functions, we have to ensure not to make
__DRI_BUFFER_BACK_LEFT attachment buffer for local_buffers.

v2: Fixes from Emil's review:
   a) Make local_buffers variable, dri2_egl_surface_alloc_local_buffer() and
  dri2_egl_surface_free_local_buffers() unconditionally.
   b) Preserve the original codeflow for error_path and normal_path.
   c) Add note on commit messages for dropping of __DRI_BUFFER_BACK_LEFT check.
   c) Rollback the unrelated whitespace changes.
   d) Add a missing blank line.

Signed-off-by: Mun Gwan-gyeong 
Reviewed-by: Emil Velikov 
---
 src/egl/drivers/dri2/egl_dri2.c | 34 +
 src/egl/drivers/dri2/egl_dri2.h | 14 ++---
 src/egl/drivers/dri2/platform_android.c | 40 ++---
 src/egl/drivers/dri2/platform_drm.c | 46 -
 src/egl/drivers/dri2/platform_wayland.c | 52 -
 5 files changed, 71 insertions(+), 115 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 733659d547..129cc35872 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -972,6 +972,40 @@ dri2_display_destroy(_EGLDisplay *disp)
disp->DriverData = NULL;
 }
 
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+unsigned int att, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
+  return NULL;
+
+   if (!dri2_surf->local_buffers[att]) {
+  dri2_surf->local_buffers[att] =
+ dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
+dri2_surf->base.Width, 
dri2_surf->base.Height);
+   }
+
+   return dri2_surf->local_buffers[att];
+}
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
+  if (dri2_surf->local_buffers[i]) {
+ dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
+   dri2_surf->local_buffers[i]);
+ dri2_surf->local_buffers[i] = 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 ccfefef61f..6c7d75587a 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -283,8 +283,10 @@ struct dri2_egl_surface
struct gbm_dri_surface *gbm_surf;
 #endif
 
+   /* EGL-owned buffers */
+   __DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
+
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
-   __DRIbuffer   *dri_buffers[__DRI_BUFFER_COUNT];
struct {
 #ifdef HAVE_WAYLAND_PLATFORM
   struct wl_buffer   *wl_buffer;
@@ -309,9 +311,6 @@ struct dri2_egl_surface
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
 
-   /* EGL-owned buffers */
-   __DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
-
/* Used to record all the buffers created by ANativeWindow and their ages.
 * Usually Android uses at most triple buffers in ANativeWindow
 * so hardcode the number of color_buffers to 3.
@@ -451,4 +450,11 @@ dri2_set_WL_bind_wayland_display(_EGLDriver *drv, 
_EGLDisplay *disp)
 void
 dri2_display_destroy(_EGLDisplay *disp);
 
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+unsigned int att, unsigned int format);
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
+
 #endif /* EGL_DRI2_INCLUDED */
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 50a8248695..71dd1594c7 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -271,40 +271,6 @@ droid_window_cancel_buffer(struct dri2_egl_surface 
*dri2_surf)
}
 }
 
-static __DRIbuffer *
-droid_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
- unsigned int att, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (att >= 

[Mesa-dev] [PATCH] egl: deduplicate allocations of local buffer over each platform backend.

2017-08-02 Thread Gwan-gyeong Mun
platform_drm, platform_wayland and platform_android have similiar local buffer
allocation routines. For deduplicating, it unifies dri2_egl_surface's
local buffer allocation routines. And it polishes inconsistent indentations.

Signed-off-by: Mun Gwan-gyeong 
---
 src/egl/drivers/dri2/egl_dri2.c | 40 
 src/egl/drivers/dri2/egl_dri2.h | 16 ++--
 src/egl/drivers/dri2/platform_android.c | 40 ++--
 src/egl/drivers/dri2/platform_drm.c | 65 +++--
 src/egl/drivers/dri2/platform_wayland.c | 52 ++
 5 files changed, 89 insertions(+), 124 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a197e0456f..6ee3b36739 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -972,6 +972,46 @@ dri2_display_destroy(_EGLDisplay *disp)
disp->DriverData = NULL;
 }
 
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+unsigned int att, unsigned int format)
+{
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) || 
defined(HAVE_ANDROID_PLATFORM)
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
+  return NULL;
+
+   if (!dri2_surf->local_buffers[att]) {
+  dri2_surf->local_buffers[att] =
+ dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
+dri2_surf->base.Width, 
dri2_surf->base.Height);
+   }
+
+   return dri2_surf->local_buffers[att];
+#else
+   return NULL;
+#endif
+}
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf)
+{
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) || 
defined(HAVE_ANDROID_PLATFORM)
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf->base.Resource.Display);
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->local_buffers); i++) {
+  if (dri2_surf->local_buffers[i]) {
+ dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen,
+   dri2_surf->local_buffers[i]);
+ dri2_surf->local_buffers[i] = NULL;
+  }
+   }
+#endif
+}
+
 /**
  * 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 ccfefef61f..eca178b1a6 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -283,8 +283,12 @@ struct dri2_egl_surface
struct gbm_dri_surface *gbm_surf;
 #endif
 
+#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) || 
defined(HAVE_ANDROID_PLATFORM)
+   /* EGL-owned buffers */
+   __DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
+#endif
+
 #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
-   __DRIbuffer   *dri_buffers[__DRI_BUFFER_COUNT];
struct {
 #ifdef HAVE_WAYLAND_PLATFORM
   struct wl_buffer   *wl_buffer;
@@ -309,9 +313,6 @@ struct dri2_egl_surface
__DRIimage *dri_image_back;
__DRIimage *dri_image_front;
 
-   /* EGL-owned buffers */
-   __DRIbuffer   *local_buffers[__DRI_BUFFER_COUNT];
-
/* Used to record all the buffers created by ANativeWindow and their ages.
 * Usually Android uses at most triple buffers in ANativeWindow
 * so hardcode the number of color_buffers to 3.
@@ -451,4 +452,11 @@ dri2_set_WL_bind_wayland_display(_EGLDriver *drv, 
_EGLDisplay *disp)
 void
 dri2_display_destroy(_EGLDisplay *disp);
 
+__DRIbuffer *
+dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
+unsigned int att, unsigned int format);
+
+void
+dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
+
 #endif /* EGL_DRI2_INCLUDED */
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index 50a8248695..71dd1594c7 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -271,40 +271,6 @@ droid_window_cancel_buffer(struct dri2_egl_surface 
*dri2_surf)
}
 }
 
-static __DRIbuffer *
-droid_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
- unsigned int att, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-  dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (att >= ARRAY_SIZE(dri2_surf->local_buffers))
-  return NULL;
-
-   if (!dri2_surf->local_buffers[att]) {
-  dri2_surf->local_buffers[att] =
- dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, att, format,
-   dri2_surf->base.Width, dri2_surf->base.Height);
-   }
-
-   return dri2_surf->local_buffers[att];
-}
-
-static void
-droid_free_local_buffers(struct dri2_egl_surface *dri2_surf)
-{
-   struct dri2_egl_display *dri2_dpy =
-  

[Mesa-dev] [PATCH] genxml: Remove a redundant identical code for different branches

2017-07-25 Thread Gwan-gyeong Mun
Before, it generates functions like this,

static inline uint32_t ATTRIBUTE_PURE
RENDER_SURFACE_STATE_RedClearColor_start(const struct gen_device_info *devinfo)
{
   switch (devinfo->gen) {
   case 10: return 384;
   case 9: return 384;
   case 8: return 255;
   case 7:
  if (devinfo->is_haswell) {
 return 255;
  } else {
 return 255;
  }
   case 6: return 0;
   case 5: return 0;
   case 4:
  if (devinfo->is_g4x) {
 return 0;
  } else {
 return 0;
  }
   default:
  unreachable("Invalid hardware generation");
   }
}

After, it generates fuctions without a redundant identical code for different
branches.

static inline uint32_t ATTRIBUTE_PURE
RENDER_SURFACE_STATE_RedClearColor_start(const struct gen_device_info *devinfo)
{
   switch (devinfo->gen) {
   case 10: return 384;
   case 9: return 384;
   case 8: return 255;
   case 7: return 255;
   case 6: return 0;
   case 5: return 0;
   case 4: return 0;
   default:
  unreachable("Invalid hardware generation");
   }
}

Signed-off-by: Mun Gwan-gyeong 
---
 src/intel/genxml/gen_bits_header.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/intel/genxml/gen_bits_header.py 
b/src/intel/genxml/gen_bits_header.py
index 1b3504073b..8084facdb7 100644
--- a/src/intel/genxml/gen_bits_header.py
+++ b/src/intel/genxml/gen_bits_header.py
@@ -83,20 +83,28 @@ ${item.token_name}_${prop}(const struct gen_device_info 
*devinfo)
case 10: return ${item.get_prop(prop, 10)};
case 9: return ${item.get_prop(prop, 9)};
case 8: return ${item.get_prop(prop, 8)};
+% if item.get_prop(prop, 7) == item.get_prop(prop, 7.5):
+   case 7: return ${item.get_prop(prop, 7)};
+% else:
case 7:
   if (devinfo->is_haswell) {
  return ${item.get_prop(prop, 7.5)};
   } else {
  return ${item.get_prop(prop, 7)};
   }
+% endif
case 6: return ${item.get_prop(prop, 6)};
case 5: return ${item.get_prop(prop, 5)};
+% if item.get_prop(prop, 4) == item.get_prop(prop, 4.5):
+   case 4: return ${item.get_prop(prop, 4)};
+% else:
case 4:
   if (devinfo->is_g4x) {
  return ${item.get_prop(prop, 4.5)};
   } else {
  return ${item.get_prop(prop, 4)};
   }
+% endif
default:
   unreachable("Invalid hardware generation");
}
-- 
2.13.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] radv: Change a linking order of AMDGPU_LIBS

2017-07-24 Thread Gwan-gyeong Mun
Because of "libvulkan_common.la" directly links libdrm_amdgpu api prior to
"libvulkan_radeon.la", it change a linking order of AMDGPU_LIBS from
"libvulkan_radeon.la" to "libvulkan_common.la".

Signed-off-by: Mun Gwan-gyeong 
---
 src/amd/vulkan/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/amd/vulkan/Makefile.am b/src/amd/vulkan/Makefile.am
index 3350f54540..1fc574b5e6 100644
--- a/src/amd/vulkan/Makefile.am
+++ b/src/amd/vulkan/Makefile.am
@@ -70,7 +70,6 @@ VULKAN_LIB_DEPS = \
$(LLVM_LIBS) \
$(LIBELF_LIBS) \
$(PTHREAD_LIBS) \
-   $(AMDGPU_LIBS) \
$(LIBDRM_LIBS) \
$(PTHREAD_LIBS) \
$(DLOPEN_LIBS) \
@@ -101,6 +100,7 @@ endif
 
 noinst_LTLIBRARIES = libvulkan_common.la
 libvulkan_common_la_SOURCES = $(VULKAN_SOURCES)
+libvulkan_common_la_LIBADD = $(AMDGPU_LIBS)
 
 nodist_EXTRA_libvulkan_radeon_la_SOURCES = dummy.cpp
 libvulkan_radeon_la_SOURCES = $(VULKAN_GEM_FILES)
-- 
2.13.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


  1   2   >