File 0001-230623-Fold-NativePixmapEGLX11BindingHelper-into-binding-class.patch of Package chromium120
Index: chromium120/ui/gl/BUILD.gn
===================================================================
--- chromium120.orig/ui/gl/BUILD.gn
+++ chromium120/ui/gl/BUILD.gn
@@ -258,6 +258,8 @@ component("gl") {
"gl_surface_egl_x11.h",
"gl_surface_egl_x11_gles2.cc",
"gl_surface_egl_x11_gles2.h",
+ "native_pixmap_egl_x11_binding_helper.cc",
+ "native_pixmap_egl_x11_binding_helper.h",
]
deps += [
Index: chromium120/ui/gl/native_pixmap_egl_x11_binding_helper.cc
===================================================================
--- /dev/null
+++ chromium120/ui/gl/native_pixmap_egl_x11_binding_helper.cc
@@ -0,0 +1,89 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gl/native_pixmap_egl_x11_binding_helper.h"
+
+#include <memory>
+
+#include "ui/gfx/x/connection.h"
+#include "ui/gl/gl_bindings.h"
+
+namespace gl {
+
+inline EGLDisplay FromXDisplay() {
+ auto* x_display = x11::Connection::Get()->GetXlibDisplay().display();
+ return eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(x_display));
+}
+
+NativePixmapEGLX11BindingHelper::NativePixmapEGLX11BindingHelper()
+ : display_(FromXDisplay()) {}
+
+NativePixmapEGLX11BindingHelper::~NativePixmapEGLX11BindingHelper() {
+ if (surface_) {
+ eglDestroySurface(display_, surface_);
+ }
+}
+
+bool NativePixmapEGLX11BindingHelper::Initialize(x11::Pixmap pixmap) {
+ if (eglInitialize(display_, nullptr, nullptr) != EGL_TRUE) {
+ return false;
+ }
+
+ EGLint attribs[] = {EGL_BUFFER_SIZE,
+ 32,
+ EGL_ALPHA_SIZE,
+ 8,
+ EGL_BLUE_SIZE,
+ 8,
+ EGL_GREEN_SIZE,
+ 8,
+ EGL_RED_SIZE,
+ 8,
+ EGL_SURFACE_TYPE,
+ EGL_PIXMAP_BIT,
+ EGL_BIND_TO_TEXTURE_RGBA,
+ EGL_TRUE,
+ EGL_NONE};
+
+ EGLint num_configs;
+ EGLConfig config = nullptr;
+
+ if ((eglChooseConfig(display_, attribs, &config, 1, &num_configs) !=
+ EGL_TRUE) ||
+ !num_configs) {
+ return false;
+ }
+
+ std::vector<EGLint> attrs = {EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
+ EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_NONE};
+
+ surface_ = eglCreatePixmapSurface(
+ display_, config, static_cast<EGLNativePixmapType>(pixmap), attrs.data());
+ return surface_ != EGL_NO_SURFACE;
+}
+
+bool NativePixmapEGLX11BindingHelper::BindTexImage(unsigned target) {
+ if (!surface_) {
+ return false;
+ }
+
+ // Requires TEXTURE_2D target.
+ if (target != GL_TEXTURE_2D) {
+ return false;
+ }
+
+ if (eglBindTexImage(display_, surface_, EGL_BACK_BUFFER) != EGL_TRUE) {
+ return false;
+ }
+
+ return true;
+}
+
+void NativePixmapEGLX11BindingHelper::ReleaseEGLImage() {
+ DCHECK_NE(nullptr, surface_);
+
+ eglReleaseTexImage(display_, surface_, EGL_BACK_BUFFER);
+}
+
+} // namespace gl
Index: chromium120/ui/gl/native_pixmap_egl_x11_binding_helper.h
===================================================================
--- /dev/null
+++ chromium120/ui/gl/native_pixmap_egl_x11_binding_helper.h
@@ -0,0 +1,45 @@
+// Copyright 2023 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GL_NATIVE_PIXMAP_EGL_X11_BINDING_HELPER_H_
+#define UI_GL_NATIVE_PIXMAP_EGL_X11_BINDING_HELPER_H_
+
+#include <stdint.h>
+
+#include "ui/gfx/x/glx.h"
+#include "ui/gl/gl_export.h"
+
+typedef void* EGLSurface;
+typedef void* EGLDisplay;
+
+namespace gl {
+
+class GL_EXPORT NativePixmapEGLX11BindingHelper {
+ public:
+ NativePixmapEGLX11BindingHelper();
+
+ NativePixmapEGLX11BindingHelper(const NativePixmapEGLX11BindingHelper&) =
+ delete;
+ NativePixmapEGLX11BindingHelper& operator=(
+ const NativePixmapEGLX11BindingHelper&) = delete;
+
+ bool Initialize(x11::Pixmap pixmap);
+
+ // Binds image to texture currently bound to |target|. Returns true on
+ // success.
+ bool BindTexImage(unsigned target);
+
+ // Releases the image that was bound via BindTexImage().
+ void ReleaseEGLImage();
+
+ ~NativePixmapEGLX11BindingHelper();
+
+ private:
+ EGLSurface surface_ = nullptr;
+ EGLDisplay display_;
+};
+
+} // namespace gl
+
+#endif // UI_GL_NATIVE_PIXMAP_EGL_X11_BINDING_HELPER_H_
Index: chromium120/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.cc
===================================================================
--- chromium120.orig/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.cc
+++ chromium120/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.cc
@@ -18,6 +18,7 @@
#include "ui/gfx/x/future.h"
#include "ui/gl/buffer_format_utils.h"
#include "ui/gl/gl_bindings.h"
+#include "ui/gl/native_pixmap_egl_x11_binding_helper.h"
#include "ui/gl/scoped_binders.h"
namespace gl {
@@ -129,64 +130,17 @@ x11::Pixmap XPixmapFromNativePixmap(cons
return pixmap_id;
}
-
-inline EGLDisplay FromXDisplay() {
- auto* x_display = x11::Connection::Get()->GetXlibDisplay().display();
- return eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(x_display));
-}
-
} // namespace
} // namespace gl
namespace ui {
-NativePixmapEGLX11Binding::NativePixmapEGLX11Binding(gfx::BufferFormat format)
- : display_(gl::FromXDisplay()), format_(format) {}
-
-NativePixmapEGLX11Binding::~NativePixmapEGLX11Binding() {
- if (surface_) {
- eglDestroySurface(display_, surface_);
- }
-}
-
-bool NativePixmapEGLX11Binding::Initialize(x11::Pixmap pixmap) {
- if (eglInitialize(display_, nullptr, nullptr) != EGL_TRUE) {
- return false;
- }
-
- EGLint attribs[] = {EGL_BUFFER_SIZE,
- 32,
- EGL_ALPHA_SIZE,
- 8,
- EGL_BLUE_SIZE,
- 8,
- EGL_GREEN_SIZE,
- 8,
- EGL_RED_SIZE,
- 8,
- EGL_SURFACE_TYPE,
- EGL_PIXMAP_BIT,
- EGL_BIND_TO_TEXTURE_RGBA,
- EGL_TRUE,
- EGL_NONE};
-
- EGLint num_configs;
- EGLConfig config = nullptr;
-
- if ((eglChooseConfig(display_, attribs, &config, 1, &num_configs) !=
- EGL_TRUE) ||
- !num_configs) {
- return false;
- }
-
- std::vector<EGLint> attrs = {EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
- EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_NONE};
-
- surface_ = eglCreatePixmapSurface(
- display_, config, static_cast<EGLNativePixmapType>(pixmap), attrs.data());
- return surface_ != EGL_NO_SURFACE;
-}
+NativePixmapEGLX11Binding::NativePixmapEGLX11Binding(
+ std::unique_ptr<gl::NativePixmapEGLX11BindingHelper> binding_helper,
+ gfx::BufferFormat format)
+ : binding_helper_(std::move(binding_helper)), format_(format) {}
+NativePixmapEGLX11Binding::~NativePixmapEGLX11Binding() = default;
// static
std::unique_ptr<NativePixmapGLBinding> NativePixmapEGLX11Binding::Create(
@@ -217,7 +171,7 @@ std::unique_ptr<NativePixmapGLBinding> N
return nullptr;
}
- auto binding = std::make_unique<NativePixmapEGLX11Binding>(plane_format);
+ auto binding_helper = std::make_unique<gl::NativePixmapEGLX11BindingHelper>();
x11::Pixmap pixmap =
gl::XPixmapFromNativePixmap(*native_pixmap, plane_format);
if (pixmap == x11::Pixmap::None) {
@@ -227,11 +181,13 @@ std::unique_ptr<NativePixmapGLBinding> N
// TODO(https://crbug.com/1411749): if we early out below, should we call
// FreePixmap()?
- if (!binding->Initialize(std::move(pixmap))) {
+ if (!binding_helper->Initialize(std::move(pixmap))) {
VLOG(1) << "Unable to initialize binding from pixmap";
return nullptr;
}
+ auto binding = std::make_unique<NativePixmapEGLX11Binding>(
+ std::move(binding_helper), plane_format);
if (!binding->BindTexture(target, texture_id)) {
VLOG(1) << "Unable to bind the GL texture";
return nullptr;
@@ -250,19 +206,8 @@ bool NativePixmapEGLX11Binding::BindText
gl::ScopedTextureBinder binder(base::strict_cast<unsigned int>(target),
base::strict_cast<unsigned int>(texture_id));
- if (!surface_) {
- LOG(ERROR) << "No surface, cannot bind to target = " << target;
- return false;
- }
-
- // Requires TEXTURE_2D target.
- if (target != GL_TEXTURE_2D) {
- LOG(ERROR) << "Cannot bind to unsupported target = " << target;
- return false;
- }
-
- if (eglBindTexImage(display_, surface_, EGL_BACK_BUFFER) != EGL_TRUE) {
- LOG(ERROR) << "Unable to bind image to target = " << target;
+ if (!binding_helper_->BindTexImage(base::strict_cast<unsigned>(target))) {
+ LOG(ERROR) << "Unable to bind GL image to target = " << target;
return false;
}
Index: chromium120/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.h
===================================================================
--- chromium120.orig/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.h
+++ chromium120/ui/ozone/platform/x11/native_pixmap_egl_x11_binding.h
@@ -8,12 +8,11 @@
#include <memory>
#include "ui/gfx/native_pixmap.h"
-#include "ui/gfx/x/connection.h"
-#include "ui/gfx/x/glx.h"
#include "ui/ozone/public/native_pixmap_gl_binding.h"
-typedef void* EGLSurface;
-typedef void* EGLDisplay;
+namespace gl {
+class NativePixmapEGLX11BindingHelper;
+}
namespace ui {
@@ -21,7 +20,9 @@ namespace ui {
// within the context of X11.
class NativePixmapEGLX11Binding : public NativePixmapGLBinding {
public:
- explicit NativePixmapEGLX11Binding(gfx::BufferFormat format);
+ explicit NativePixmapEGLX11Binding(
+ std::unique_ptr<gl::NativePixmapEGLX11BindingHelper> binding_helper,
+ gfx::BufferFormat format);
~NativePixmapEGLX11Binding() override;
static std::unique_ptr<NativePixmapGLBinding> Create(
@@ -38,14 +39,11 @@ class NativePixmapEGLX11Binding : public
GLenum GetDataType() override;
private:
- bool Initialize(x11::Pixmap pixmap);
-
- // Binds image to texture currently bound to |target|. Returns true on
- // success.
bool BindTexture(GLenum target, GLuint texture_id);
- EGLSurface surface_ = nullptr;
- EGLDisplay display_;
+ // TODO(crbug.com/1412693): Fold the helper class into this class once
+ // GLImageEGLPixmap no longer exists.
+ std::unique_ptr<gl::NativePixmapEGLX11BindingHelper> binding_helper_;
gfx::BufferFormat format_;
};