Skip to content

Commit e0d81c7

Browse files
authored
Use EXT_image_dma_buf_import when making EGLImage with tbm_surface (#169)
* Use `EXT_image_dma_buf_import` when making EGLImage with tbm_surface Signed-off-by: MuHong Byun <[email protected]> * Check EGL extention capability Signed-off-by: MuHong Byun <[email protected]> * Clean-up code Signed-off-by: MuHong Byun <[email protected]> * Add review's comment Signed-off-by: MuHong Byun <[email protected]> * Add review's comment Signed-off-by: MuHong Byun <[email protected]> * Add review's comment Signed-off-by: MuHong Byun <[email protected]> * Add review's comment Signed-off-by: MuHong Byun <[email protected]>
1 parent 2be5f48 commit e0d81c7

10 files changed

+118
-21
lines changed

shell/platform/tizen/external_texture.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020

2121
namespace flutter {
2222

23+
enum class ExternalTextureExtensionType { kNone, kNativeSurface, kDmaBuffer };
24+
2325
struct ExternalTextureGLState {
2426
GLuint gl_texture;
27+
ExternalTextureExtensionType gl_extention;
2528
};
2629

2730
static std::atomic_long next_texture_id = {1};
2831

2932
// An adaptation class of flutter engine and external texture interface.
3033
class ExternalTexture : public std::enable_shared_from_this<ExternalTexture> {
3134
public:
32-
ExternalTexture()
35+
ExternalTexture(ExternalTextureExtensionType gl_extention =
36+
ExternalTextureExtensionType::kNone)
3337
: state_(std::make_unique<ExternalTextureGLState>()),
34-
texture_id_(next_texture_id++) {}
38+
texture_id_(next_texture_id++) {
39+
state_->gl_extention = gl_extention;
40+
}
3541
virtual ~ExternalTexture() = default;
3642

3743
/**

shell/platform/tizen/external_texture_surface_gl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace flutter {
1515
class ExternalTextureSurfaceGL : public ExternalTexture {
1616
public:
1717
ExternalTextureSurfaceGL(
18+
ExternalTextureExtensionType gl_extention,
1819
FlutterDesktopGpuBufferTextureCallback texture_callback,
1920
FlutterDesktopGpuBufferDestructionCallback destruction_callback,
2021
void* user_data);

shell/platform/tizen/external_texture_surface_gl_linux.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace flutter {
1313

1414
ExternalTextureSurfaceGL::ExternalTextureSurfaceGL(
15+
ExternalTextureExtensionType gl_extention,
1516
FlutterDesktopGpuBufferTextureCallback texture_callback,
1617
FlutterDesktopGpuBufferDestructionCallback destruction_callback,
1718
void* user_data)
18-
: ExternalTexture(),
19+
: ExternalTexture(gl_extention),
1920
texture_callback_(texture_callback),
2021
destruction_callback_(destruction_callback),
2122
user_data_(user_data) {}

shell/platform/tizen/external_texture_surface_gl_tizen.cc

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
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

3547
ExternalTextureSurfaceGL::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) {

shell/platform/tizen/flutter_tizen_texture_registrar.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,20 @@ FlutterTizenTextureRegistrar::CreateExternalTexture(
9595
texture_info->pixel_buffer_config.user_data);
9696
break;
9797
case kFlutterDesktopGpuBufferTexture:
98+
ExternalTextureExtensionType gl_extension =
99+
ExternalTextureExtensionType::kNone;
100+
if (engine_->renderer()->IsSupportedExtention(
101+
"EGL_TIZEN_image_native_surface")) {
102+
gl_extension = ExternalTextureExtensionType::kNativeSurface;
103+
} else if (engine_->renderer()->IsSupportedExtention(
104+
"EGL_EXT_image_dma_buf_import")) {
105+
gl_extension = ExternalTextureExtensionType::kDmaBuffer;
106+
}
98107
return std::make_unique<ExternalTextureSurfaceGL>(
99-
texture_info->gpu_buffer_config.callback,
108+
gl_extension, texture_info->gpu_buffer_config.callback,
100109
texture_info->gpu_buffer_config.destruction_callback,
101110
texture_info->gpu_buffer_config.user_data);
102111
break;
103-
default:
104-
FT_LOG(Error) << "Invalid texture type.";
105-
return nullptr;
106112
}
107113
}
108114

shell/platform/tizen/tizen_renderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TizenRenderer {
4444
int32_t height,
4545
int32_t degree) = 0;
4646
virtual void SetPreferredOrientations(const std::vector<int>& rotations) = 0;
47+
virtual bool IsSupportedExtention(const char* name) = 0;
4748

4849
protected:
4950
explicit TizenRenderer(WindowGeometry geometry,

shell/platform/tizen/tizen_renderer_ecore_wl2.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ bool TizenRendererEcoreWl2::SetupEglSurface() {
359359
FT_LOG(Error) << "ChooseEGLConfiguration() failed.";
360360
return false;
361361
}
362+
egl_extention_str_ = eglQueryString(egl_display_, EGL_EXTENSIONS);
362363

363364
const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
364365
egl_context_ = eglCreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT,
@@ -556,4 +557,11 @@ void TizenRendererEcoreWl2::SetPreferredOrientations(
556557
rotations.size());
557558
}
558559

560+
bool TizenRendererEcoreWl2::IsSupportedExtention(const char* name) {
561+
if (strstr(egl_extention_str_.c_str(), name)) {
562+
return true;
563+
}
564+
return false;
565+
}
566+
559567
} // namespace flutter

shell/platform/tizen/tizen_renderer_ecore_wl2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define EFL_BETA_API_SUPPORT
99
#include <EGL/egl.h>
1010
#include <Ecore_Wl2.h>
11+
#include <string>
1112

1213
#include "flutter/shell/platform/tizen/tizen_renderer.h"
1314

@@ -40,6 +41,7 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
4041
int32_t angle) override;
4142
void SetRotate(int angle) override;
4243
void SetPreferredOrientations(const std::vector<int>& rotations) override;
44+
bool IsSupportedExtention(const char* name) override;
4345

4446
private:
4547
bool InitializeRenderer();
@@ -73,6 +75,8 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
7375
EGLSurface egl_surface_ = EGL_NO_SURFACE;
7476
EGLContext egl_resource_context_ = EGL_NO_CONTEXT;
7577
EGLSurface egl_resource_surface_ = EGL_NO_SURFACE;
78+
79+
std::string egl_extention_str_;
7680
};
7781

7882
} // namespace flutter

shell/platform/tizen/tizen_renderer_evas_gl.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,8 @@ void TizenRendererEvasGL::SetPreferredOrientations(
736736
rotations.size());
737737
}
738738

739+
bool TizenRendererEvasGL::IsSupportedExtention(const char* name) {
740+
return strcmp(name, "EGL_TIZEN_image_native_surface") == 0;
741+
}
742+
739743
} // namespace flutter

shell/platform/tizen/tizen_renderer_evas_gl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TizenRendererEvasGL : public TizenRenderer {
4141
int32_t angle) override;
4242
void SetRotate(int angle) override;
4343
void SetPreferredOrientations(const std::vector<int>& rotations) override;
44+
bool IsSupportedExtention(const char* name) override;
4445

4546
Evas_Object* GetImageHandle();
4647

0 commit comments

Comments
 (0)