7 #include "flutter/fml/logging.h"
8 #include "flutter/shell/platform/embedder/embedder_struct_macros.h"
17 std::shared_ptr<egl::ProcTable> gl)
21 egl_manager_(egl_manager),
27 if (gl_texture_ != 0) {
28 gl_->DeleteTextures(1, &gl_texture_);
34 FlutterOpenGLTexture* opengl_texture) {
36 texture_callback_(width, height, user_data_);
38 if (!CreateOrUpdateTexture(descriptor)) {
43 opengl_texture->target = GL_TEXTURE_2D;
44 opengl_texture->name = gl_texture_;
45 opengl_texture->format = GL_RGBA8_OES;
46 opengl_texture->destruction_callback =
nullptr;
47 opengl_texture->user_data =
nullptr;
48 opengl_texture->width = SAFE_ACCESS(descriptor, visible_width, 0);
49 opengl_texture->height = SAFE_ACCESS(descriptor, visible_height, 0);
54 void ExternalTextureD3d::ReleaseImage() {
55 if (egl_surface_ != EGL_NO_SURFACE) {
56 eglReleaseTexImage(egl_manager_->
egl_display(), egl_surface_,
58 eglDestroySurface(egl_manager_->
egl_display(), egl_surface_);
59 egl_surface_ = EGL_NO_SURFACE;
63 bool ExternalTextureD3d::CreateOrUpdateTexture(
65 if (descriptor ==
nullptr ||
66 SAFE_ACCESS(descriptor, handle,
nullptr) ==
nullptr) {
71 if (gl_texture_ == 0) {
72 gl_->GenTextures(1, &gl_texture_);
74 gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
75 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
76 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
77 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
78 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
80 gl_->BindTexture(GL_TEXTURE_2D, gl_texture_);
83 auto handle = SAFE_ACCESS(descriptor, handle,
nullptr);
84 if (handle != last_surface_handle_) {
87 EGLint attributes[] = {
89 static_cast<EGLint
>(SAFE_ACCESS(descriptor, width, 0)),
91 static_cast<EGLint
>(SAFE_ACCESS(descriptor, height, 0)),
100 ? EGL_D3D_TEXTURE_ANGLE
101 : EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
104 if (egl_surface_ == EGL_NO_SURFACE ||
105 eglBindTexImage(egl_manager_->
egl_display(), egl_surface_,
106 EGL_BACK_BUFFER) == EGL_FALSE) {
107 FML_LOG(ERROR) <<
"Binding D3D surface failed.";
109 last_surface_handle_ = handle;
112 auto release_callback = SAFE_ACCESS(descriptor, release_callback,
nullptr);
113 if (release_callback) {
114 release_callback(SAFE_ACCESS(descriptor, release_context,
nullptr));
116 return egl_surface_ != EGL_NO_SURFACE;