Skip to content

Commit

Permalink
Create GLDisplay class to wrap each display.
Browse files Browse the repository at this point in the history
To accommodate multiple EGLDisplays in the GPU process, we need to
refactor the static functions and objects in gl_surface_egl to depend on
each display.
This CL creates a GLDisplay class to own each display.
Future CLs will give GLSurfaceEGL ownership of one GLDisplay, as well as
merge the static functions that query extensions from the display into
the GLDisplay class.

Bug: 1251724
Change-Id: I56be8f6be57b707427611d53b656c4094737f50c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3507204
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
Cr-Commit-Position: refs/heads/main@{#990026}
  • Loading branch information
jonahryandavis authored and Chromium LUCI CQ committed Apr 7, 2022
1 parent df55cd0 commit cb2b7cf
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 124 deletions.
13 changes: 7 additions & 6 deletions android_webview/browser/gfx/aw_gl_surface.cc
Expand Up @@ -30,15 +30,16 @@ bool AwGLSurface::Initialize(gl::GLSurfaceFormat format) {

EGLint attribs[] = {EGL_WIDTH, size_.width(), EGL_HEIGHT,
size_.height(), EGL_NONE, EGL_NONE};
surface_ = eglCreatePbufferFromClientBuffer(
GetDisplay(), EGL_EXTERNAL_SURFACE_ANGLE, nullptr, GetConfig(), attribs);
surface_ = eglCreatePbufferFromClientBuffer(GetGLDisplay()->GetDisplay(),
EGL_EXTERNAL_SURFACE_ANGLE,
nullptr, GetConfig(), attribs);
DCHECK_NE(surface_, EGL_NO_SURFACE);
return surface_ != EGL_NO_SURFACE;
}

void AwGLSurface::Destroy() {
if (surface_) {
eglDestroySurface(GetDisplay(), surface_);
eglDestroySurface(GetGLDisplay()->GetDisplay(), surface_);
surface_ = nullptr;
}
}
Expand Down Expand Up @@ -67,12 +68,12 @@ void* AwGLSurface::GetHandle() {
return surface_;
}

void* AwGLSurface::GetDisplay() {
gl::GLDisplay* AwGLSurface::GetGLDisplay() {
if (wrapped_surface_)
return wrapped_surface_->GetDisplay();
return wrapped_surface_->GetGLDisplay();
if (!is_angle_)
return nullptr;
return gl::GLSurfaceEGL::GetDisplay();
return gl::GLSurfaceEGL::GetGLDisplay();
}

gl::GLSurfaceFormat AwGLSurface::GetFormat() {
Expand Down
3 changes: 2 additions & 1 deletion android_webview/browser/gfx/aw_gl_surface.h
Expand Up @@ -7,6 +7,7 @@

#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gl/gl_display.h"
#include "ui/gl/gl_surface_egl.h"

namespace android_webview {
Expand All @@ -31,7 +32,7 @@ class AwGLSurface : public gl::GLSurfaceEGL {
bool OnMakeCurrent(gl::GLContext* context) override;
gfx::Size GetSize() override;
void* GetHandle() override;
void* GetDisplay() override;
gl::GLDisplay* GetGLDisplay() override;
gl::GLSurfaceFormat GetFormat() override;
bool Resize(const gfx::Size& size,
float scale_factor,
Expand Down
4 changes: 2 additions & 2 deletions android_webview/browser/gfx/test/fake_window.cc
Expand Up @@ -37,8 +37,8 @@ class FakeWindow::ScopedMakeCurrent {
// Release the underlying EGLContext. This is required because the real
// GLContextEGL may no longer be current here and to satisfy DCHECK in
// GLContextEGL::IsCurrent.
eglMakeCurrent(view_root_->surface_->GetDisplay(), EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglMakeCurrent(view_root_->surface_->GetGLDisplay()->GetDisplay(),
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
view_root_->context_->ReleaseCurrent(view_root_->surface_.get());
}

Expand Down
2 changes: 2 additions & 0 deletions ui/gl/BUILD.gn
Expand Up @@ -73,6 +73,8 @@ component("gl") {
"gl_context.h",
"gl_context_stub.cc",
"gl_context_stub.h",
"gl_display.cc",
"gl_display.h",
"gl_enums.cc",
"gl_enums.h",
"gl_enums_implementation_autogen.h",
Expand Down
10 changes: 5 additions & 5 deletions ui/gl/direct_composition_child_surface_win.cc
Expand Up @@ -101,7 +101,7 @@ bool DirectCompositionChildSurfaceWin::Initialize(GLSurfaceFormat format) {
if (!dcomp_device_)
return false;

EGLDisplay display = GetDisplay();
EGLDisplay display = GetEGLDisplay();

EGLint pbuffer_attribs[] = {
EGL_WIDTH,
Expand Down Expand Up @@ -138,7 +138,7 @@ bool DirectCompositionChildSurfaceWin::ReleaseDrawTexture(bool will_discard) {
DLOG_IF(ERROR, !result) << "Failed to make current in ReleaseDrawTexture";

if (egl_surface)
eglDestroySurface(GetDisplay(), egl_surface);
eglDestroySurface(GetEGLDisplay(), egl_surface);

if (dcomp_surface_.Get() == g_current_surface)
g_current_surface = nullptr;
Expand Down Expand Up @@ -252,14 +252,14 @@ void DirectCompositionChildSurfaceWin::Destroy() {
vsync_thread_->RemoveObserver(this);

if (default_surface_) {
if (!eglDestroySurface(GetDisplay(), default_surface_)) {
if (!eglDestroySurface(GetEGLDisplay(), default_surface_)) {
DLOG(ERROR) << "eglDestroySurface failed with error "
<< ui::GetLastEGLErrorString();
}
default_surface_ = nullptr;
}
if (real_surface_) {
if (!eglDestroySurface(GetDisplay(), real_surface_)) {
if (!eglDestroySurface(GetEGLDisplay(), real_surface_)) {
DLOG(ERROR) << "eglDestroySurface failed with error "
<< ui::GetLastEGLErrorString();
}
Expand Down Expand Up @@ -510,7 +510,7 @@ bool DirectCompositionChildSurfaceWin::SetDrawRectangle(
}

real_surface_ = eglCreatePbufferFromClientBuffer(
GetDisplay(), EGL_D3D_TEXTURE_ANGLE, buffer, GetConfig(),
GetEGLDisplay(), EGL_D3D_TEXTURE_ANGLE, buffer, GetConfig(),
pbuffer_attribs.data());
if (!real_surface_) {
DLOG(ERROR) << "eglCreatePbufferFromClientBuffer failed with error "
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_egl.cc
Expand Up @@ -121,7 +121,7 @@ bool GLContextEGL::Initialize(GLSurface* compatible_surface,
DCHECK(compatible_surface);
DCHECK(!context_);

display_ = compatible_surface->GetDisplay();
display_ = compatible_surface->GetGLDisplay()->GetDisplay();

EGLint context_client_major_version = attribs.client_major_es_version;
EGLint context_client_minor_version = attribs.client_minor_es_version;
Expand Down
53 changes: 53 additions & 0 deletions ui/gl/gl_display.cc
@@ -0,0 +1,53 @@
// Copyright (c) 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gl/gl_display.h"
#include "base/notreached.h"

#if defined(USE_GLX)
#include "ui/gl/glx_util.h"
#endif // defined(USE_GLX)

#if defined(USE_EGL)
#define EGL_NO_DISPLAY 0
#endif

namespace gl {

GLDisplay::GLDisplay() = default;

GLDisplay::~GLDisplay() = default;

#if defined(USE_EGL)
GLDisplayEGL::GLDisplayEGL() {
display_ = EGL_NO_DISPLAY;
}

GLDisplayEGL::GLDisplayEGL(EGLDisplay display) {
display_ = display;
}

GLDisplayEGL::~GLDisplayEGL() = default;

EGLDisplay GLDisplayEGL::GetDisplay() {
return display_;
}

void GLDisplayEGL::SetDisplay(EGLDisplay display) {
display_ = display;
}

#endif // defined(USE_EGL)

#if defined(USE_GLX)
GLDisplayX11::GLDisplayX11() = default;

GLDisplayX11::~GLDisplayX11() = default;

void* GLDisplayX11::GetDisplay() {
return x11::Connection::Get()->GetXlibDisplay();
}
#endif // defined(USE_GLX)

} // namespace gl
63 changes: 63 additions & 0 deletions ui/gl/gl_display.h
@@ -0,0 +1,63 @@
// Copyright (c) 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GL_GL_DISPLAY_H_
#define UI_GL_GL_DISPLAY_H_

#include "ui/gl/gl_export.h"

#if defined(USE_EGL)
typedef void* EGLDisplay;
#endif // defined(USE_EGL)

namespace gl {

class GL_EXPORT GLDisplay {
public:
GLDisplay();

GLDisplay(const GLDisplay&) = delete;
GLDisplay& operator=(const GLDisplay&) = delete;

virtual ~GLDisplay();

virtual void* GetDisplay() = 0;
};

#if defined(USE_EGL)
class GL_EXPORT GLDisplayEGL : public GLDisplay {
public:
GLDisplayEGL();
explicit GLDisplayEGL(EGLDisplay display);

GLDisplayEGL(const GLDisplayEGL&) = delete;
GLDisplayEGL& operator=(const GLDisplayEGL&) = delete;

~GLDisplayEGL() override;

EGLDisplay GetDisplay() override;
void SetDisplay(EGLDisplay display);

private:
EGLDisplay display_;
};
#endif // defined(USE_EGL)

#if defined(USE_GLX)
class GL_EXPORT GLDisplayX11 : public GLDisplay {
public:
GLDisplayX11();

GLDisplayX11(const GLDisplayX11&) = delete;
GLDisplayX11& operator=(const GLDisplayX11&) = delete;

~GLDisplayX11() override;

void* GetDisplay() override;
};
#endif // defined(USE_GLX)

} // namespace gl

#endif // UI_GL_GL_DISPLAY_H_
6 changes: 3 additions & 3 deletions ui/gl/gl_surface.cc
Expand Up @@ -135,7 +135,7 @@ void* GLSurface::GetShareHandle() {
return NULL;
}

void* GLSurface::GetDisplay() {
GLDisplay* GLSurface::GetGLDisplay() {
NOTIMPLEMENTED();
return NULL;
}
Expand Down Expand Up @@ -448,8 +448,8 @@ void* GLSurfaceAdapter::GetShareHandle() {
return surface_->GetShareHandle();
}

void* GLSurfaceAdapter::GetDisplay() {
return surface_->GetDisplay();
GLDisplay* GLSurfaceAdapter::GetGLDisplay() {
return surface_->GetGLDisplay();
}

void* GLSurfaceAdapter::GetConfig() {
Expand Down
5 changes: 3 additions & 2 deletions ui/gl/gl_surface.h
Expand Up @@ -23,6 +23,7 @@
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/surface_origin.h"
#include "ui/gfx/swap_result.h"
#include "ui/gl/gl_display.h"
#include "ui/gl/gl_export.h"
#include "ui/gl/gl_image.h"
#include "ui/gl/gl_implementation.h"
Expand Down Expand Up @@ -208,7 +209,7 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface>,

// Get the platform specific display on which this surface resides, if
// available.
virtual void* GetDisplay();
virtual GLDisplay* GetGLDisplay();

// Get the platfrom specific configuration for this surface, if available.
virtual void* GetConfig();
Expand Down Expand Up @@ -398,7 +399,7 @@ class GL_EXPORT GLSurfaceAdapter : public GLSurface {
bool SetBackbufferAllocation(bool allocated) override;
void SetFrontbufferAllocation(bool allocated) override;
void* GetShareHandle() override;
void* GetDisplay() override;
GLDisplay* GetGLDisplay() override;
void* GetConfig() override;
GLSurfaceFormat GetFormat() override;
gfx::VSyncProvider* GetVSyncProvider() override;
Expand Down

0 comments on commit cb2b7cf

Please sign in to comment.