Skip to content

Commit 34c0708

Browse files
committed
[PageLifecycle] Move the cairo device used by Acc Canvas to the PlatformDisplay.
1 parent 7609a21 commit 34c0708

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

Source/WebCore/platform/graphics/PlatformDisplay.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,34 @@
8888
#include <wtf/glib/GRefPtr.h>
8989
#endif
9090

91+
#if USE(CAIRO)
92+
#include <cairo-gl.h>
93+
#endif
94+
9195
namespace WebCore {
9296

97+
#if USE(CAIRO)
98+
static cairo_device_t* s_cairoDevice { nullptr };
99+
100+
cairo_device_t* PlatformDisplay::cairoGLDevice()
101+
{
102+
if (s_cairoDevice)
103+
return s_cairoDevice;
104+
105+
auto* context = sharedDisplayForCompositing().sharingGLContext();
106+
if (is<GLContextEGL>(context))
107+
s_cairoDevice = cairo_egl_device_create(sharedDisplayForCompositing().eglDisplay(), downcast<GLContextEGL>(context)->context());
108+
109+
return s_cairoDevice;
110+
}
111+
112+
static void clearCairoGLDevice()
113+
{
114+
cairo_device_destroy(s_cairoDevice);
115+
s_cairoDevice = nullptr;
116+
}
117+
#endif
118+
93119
std::unique_ptr<PlatformDisplay> PlatformDisplay::createPlatformDisplay()
94120
{
95121
#if PLATFORM(GTK)
@@ -221,6 +247,9 @@ GLContext* PlatformDisplay::sharingGLContext()
221247

222248
void PlatformDisplay::clearSharingGLContext()
223249
{
250+
#if USE(CAIRO)
251+
clearCairoGLDevice();
252+
#endif
224253
m_sharingGLContext = nullptr;
225254
}
226255
#endif

Source/WebCore/platform/graphics/PlatformDisplay.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ typedef struct _GstGLDisplay GstGLDisplay;
5050
#include "LCMSUniquePtr.h"
5151
#endif
5252

53+
#if USE(CAIRO)
54+
#include <cairo.h>
55+
#endif
56+
5357
namespace WebCore {
5458

5559
class GLContext;
@@ -109,6 +113,10 @@ class PlatformDisplay {
109113
const String& accessibilityBusAddress() const;
110114
#endif
111115

116+
#if USE(CAIRO)
117+
cairo_device_t* cairoGLDevice();
118+
#endif
119+
112120
protected:
113121
PlatformDisplay();
114122
#if PLATFORM(GTK)

Source/WebCore/platform/graphics/cairo/ImageBufferCairoGLSurfaceBackend.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ namespace WebCore {
1717

1818
WTF_MAKE_ISO_ALLOCATED_IMPL(ImageBufferCairoGLSurfaceBackend);
1919

20-
static cairo_device_t* cairoDevice()
21-
{
22-
static cairo_device_t* s_device { nullptr };
23-
24-
static std::once_flag s_flag;
25-
std::call_once(s_flag,
26-
[&] {
27-
auto& platformDisplay = PlatformDisplay::sharedDisplayForCompositing();
28-
auto* context = platformDisplay.sharingGLContext();
29-
if (is<GLContextEGL>(context))
30-
s_device = cairo_egl_device_create(platformDisplay.eglDisplay(), downcast<GLContextEGL>(context)->context());
31-
});
32-
33-
return s_device;
34-
}
35-
3620
static RefPtr<cairo_surface_t>
3721
cairoGLSurfaceCopyToImageSurface(cairo_surface_t* surface)
3822
{
@@ -97,7 +81,7 @@ std::unique_ptr<ImageBufferCairoGLSurfaceBackend> ImageBufferCairoGLSurfaceBacke
9781
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
9882
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backendSize.width(), backendSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
9983

100-
auto* device = cairoDevice();
84+
auto* device = PlatformDisplay::sharedDisplayForCompositing().cairoGLDevice();
10185
if (!device) {
10286
glDeleteTextures(1, &textures[0]);
10387
return { };
@@ -162,7 +146,7 @@ void ImageBufferCairoGLSurfaceBackend::swapBuffersIfNeeded()
162146
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
163147
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
164148
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backendSize.width(), backendSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
165-
m_surfaces[1] = adoptRef(cairo_gl_surface_create_for_texture(cairoDevice(), CAIRO_CONTENT_COLOR_ALPHA, m_textures[1], backendSize.width(), backendSize.height()));
149+
m_surfaces[1] = adoptRef(cairo_gl_surface_create_for_texture(PlatformDisplay::sharedDisplayForCompositing().cairoGLDevice(), CAIRO_CONTENT_COLOR_ALPHA, m_textures[1], backendSize.width(), backendSize.height()));
166150
m_compositorContext = adoptRef(cairo_create(m_surfaces[1].get()));
167151
}
168152

0 commit comments

Comments
 (0)