44
55#include " external_texture_surface_gl.h"
66
7+ #include < tbm_surface.h>
8+
79#ifdef TIZEN_RENDERER_EVAS_GL
810#undef EFL_BETA_API_SUPPORT
911#include " tizen_evas_gl_helper.h"
@@ -14,9 +16,19 @@ EVAS_GL_GLOBAL_GLES3_DECLARE();
1416#include < EGL/eglext.h>
1517#include < GLES2/gl2ext.h>
1618#include < GLES3/gl32.h>
17- #endif
1819
19- #include < tbm_surface.h>
20+ #include < tbm_bufmgr.h>
21+ #include < tbm_surface_internal.h>
22+ #ifndef EGL_DMA_BUF_PLANE3_FD_EXT
23+ #define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
24+ #endif
25+ #ifndef EGL_DMA_BUF_PLANE3_OFFSET_EXT
26+ #define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
27+ #endif
28+ #ifndef EGL_DMA_BUF_PLANE3_PITCH_EXT
29+ #define EGL_DMA_BUF_PLANE3_PITCH_EXT 0x3442
30+ #endif
31+ #endif
2032
2133#include " flutter/shell/platform/tizen/logger.h"
2234
@@ -33,10 +45,11 @@ static void OnCollectTexture(void* textureGL) {
3345}
3446
3547ExternalTextureSurfaceGL::ExternalTextureSurfaceGL (
48+ ExternalTextureExtensionType gl_extention,
3649 FlutterDesktopGpuBufferTextureCallback texture_callback,
3750 FlutterDesktopGpuBufferDestructionCallback destruction_callback,
3851 void * user_data)
39- : ExternalTexture(),
52+ : ExternalTexture(gl_extention ),
4053 texture_callback_ (texture_callback),
4154 destruction_callback_(destruction_callback),
4255 user_data_(user_data) {}
@@ -76,10 +89,17 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
7689 }
7790
7891#ifdef TIZEN_RENDERER_EVAS_GL
79- int attribs[] = {EVAS_GL_IMAGE_PRESERVED, GL_TRUE, 0 };
80- EvasGLImage egl_src_image = evasglCreateImageForContext (
81- g_evas_gl, evas_gl_current_context_get (g_evas_gl),
82- EVAS_GL_NATIVE_SURFACE_TIZEN, tbm_surface, attribs);
92+ EvasGLImage egl_src_image = nullptr ;
93+ if (state_->gl_extention == ExternalTextureExtensionType::kNativeSurface ) {
94+ int attribs[] = {EVAS_GL_IMAGE_PRESERVED, GL_TRUE, 0 };
95+ egl_src_image = evasglCreateImageForContext (
96+ g_evas_gl, evas_gl_current_context_get (g_evas_gl),
97+ EVAS_GL_NATIVE_SURFACE_TIZEN, tbm_surface, attribs);
98+ } else if (state_->gl_extention == ExternalTextureExtensionType::kDmaBuffer ) {
99+ FT_LOG (Error)
100+ << " EGL_EXT_image_dma_buf_import is not supported this renderer." ;
101+ return false ;
102+ }
83103 if (!egl_src_image) {
84104 return false ;
85105 }
@@ -105,15 +125,60 @@ bool ExternalTextureSurfaceGL::PopulateTexture(
105125 PFNEGLCREATEIMAGEKHRPROC n_eglCreateImageKHR =
106126 reinterpret_cast <PFNEGLCREATEIMAGEKHRPROC>(
107127 eglGetProcAddress (" eglCreateImageKHR" ));
108- const EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE,
109- EGL_NONE};
110- EGLImageKHR egl_src_image =
111- n_eglCreateImageKHR (eglGetCurrentDisplay (), EGL_NO_CONTEXT,
112- EGL_NATIVE_SURFACE_TIZEN, tbm_surface, attribs);
128+ EGLImageKHR egl_src_image = nullptr ;
129+
130+ if (state_->gl_extention == ExternalTextureExtensionType::kNativeSurface ) {
131+ const EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE,
132+ EGL_NONE};
133+ egl_src_image =
134+ n_eglCreateImageKHR (eglGetCurrentDisplay (), EGL_NO_CONTEXT,
135+ EGL_NATIVE_SURFACE_TIZEN, tbm_surface, attribs);
136+ } else if (state_->gl_extention == ExternalTextureExtensionType::kDmaBuffer ) {
137+ EGLint attribs[50 ];
138+ int atti = 0 ;
139+ int plane_fd_ext[4 ] = {EGL_DMA_BUF_PLANE0_FD_EXT, EGL_DMA_BUF_PLANE1_FD_EXT,
140+ EGL_DMA_BUF_PLANE2_FD_EXT,
141+ EGL_DMA_BUF_PLANE3_FD_EXT};
142+ int plane_offset_ext[4 ] = {
143+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGL_DMA_BUF_PLANE1_OFFSET_EXT,
144+ EGL_DMA_BUF_PLANE2_OFFSET_EXT, EGL_DMA_BUF_PLANE3_OFFSET_EXT};
145+ int plane_pitch_ext[4 ] = {
146+ EGL_DMA_BUF_PLANE0_PITCH_EXT, EGL_DMA_BUF_PLANE1_PITCH_EXT,
147+ EGL_DMA_BUF_PLANE2_PITCH_EXT, EGL_DMA_BUF_PLANE3_PITCH_EXT};
148+
149+ attribs[atti++] = EGL_WIDTH;
150+ attribs[atti++] = info.width ;
151+ attribs[atti++] = EGL_HEIGHT;
152+ attribs[atti++] = info.height ;
153+ attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
154+ attribs[atti++] = info.format ;
155+
156+ int num_planes = tbm_surface_internal_get_num_planes (info.format );
157+ for (int i = 0 ; i < num_planes; i++) {
158+ int bo_idx = tbm_surface_internal_get_plane_bo_idx (tbm_surface, i);
159+ tbm_bo tbo = tbm_surface_internal_get_bo (tbm_surface, bo_idx);
160+ attribs[atti++] = plane_fd_ext[i];
161+ attribs[atti++] = static_cast <int >(
162+ reinterpret_cast <size_t >(tbm_bo_get_handle (tbo, TBM_DEVICE_3D).ptr ));
163+ attribs[atti++] = plane_offset_ext[i];
164+ attribs[atti++] = info.planes [i].offset ;
165+ attribs[atti++] = plane_pitch_ext[i];
166+ attribs[atti++] = info.planes [i].stride ;
167+ }
168+ attribs[atti++] = EGL_NONE;
169+ egl_src_image =
170+ n_eglCreateImageKHR (eglGetCurrentDisplay (), EGL_NO_CONTEXT,
171+ EGL_LINUX_DMA_BUF_EXT, nullptr , attribs);
172+ }
113173
114174 if (!egl_src_image) {
115- FT_LOG (Error) << " eglCreateImageKHR failed with an error " << eglGetError ()
116- << " for texture ID: " << texture_id_;
175+ if (state_->gl_extention != ExternalTextureExtensionType::kNone ) {
176+ FT_LOG (Error) << " eglCreateImageKHR failed with an error "
177+ << eglGetError () << " for texture ID: " << texture_id_;
178+ } else {
179+ FT_LOG (Error) << " Either EGL_TIZEN_image_native_surface or "
180+ " EGL_EXT_image_dma_buf_import shoule be supported." ;
181+ }
117182 return false ;
118183 }
119184 if (state_->gl_texture == 0 ) {
0 commit comments