| Differences between
and this patch
- a/Source/WebCore/ChangeLog +65 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2022-02-01  Chris Lord  <clord@igalia.com>
2
3
        [GTK][WPE] Use dmabuf when possible to transfer ANGLE rendering to the compositor
4
        https://bugs.webkit.org/show_bug.cgi?id=235946
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Use dmabuf when available to transfer ANGLE WebGL rendering contents
9
        to the compositor.
10
11
        No new tests, no change in behaviour.
12
13
        * PlatformGTK.cmake:
14
        * PlatformWPE.cmake:
15
        * SourcesGTK.txt:
16
        * SourcesWPE.txt:
17
        * platform/TextureMapper.cmake:
18
        * platform/ThreadGlobalData.cpp:
19
        (WebCore::ThreadGlobalData::initializeGbmDevice):
20
        * platform/ThreadGlobalData.h:
21
        (WebCore::ThreadGlobalData::gbmDevice):
22
        * platform/graphics/OpenGLShims.cpp:
23
        (WebCore::initializeOpenGLShims):
24
        * platform/graphics/OpenGLShims.h:
25
        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
26
        (WebCore::GraphicsContextGLANGLE::prepareTextureImpl):
27
        * platform/graphics/angle/GraphicsContextGLANGLE.h:
28
        * platform/graphics/egl/GLContextEGL.cpp:
29
        (WebCore::GLContextEGL::GLContextEGL):
30
        (WebCore::GLContextEGL::createImage const):
31
        (WebCore::GLContextEGL::destroyImage const):
32
        * platform/graphics/egl/GLContextEGL.h:
33
        * platform/graphics/gbm/GBMDevice.cpp: Added.
34
        (WebCore::GBMDevice::forCurrentThread):
35
        (WebCore::GBMDevice::GBMDevice):
36
        (WebCore::GBMDevice::~GBMDevice):
37
        * platform/graphics/gbm/GBMDevice.h: Added.
38
        (WebCore::GBMDevice::device const):
39
        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp:
40
        (Nicosia::GCGLANGLEPipeSource::swapBuffersIfNeeded):
41
        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
42
        (WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
43
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking):
44
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::~EGLImageBacking):
45
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::format const):
46
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::stride const):
47
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::releaseResources):
48
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::reset):
49
        (WebCore::GraphicsContextGLANGLE::~GraphicsContextGLANGLE):
50
        (WebCore::GraphicsContextGLANGLE::reshapeDisplayBufferBacking):
51
        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
52
        (WebCore::TextureMapperPlatformLayerBuffer::textureVariant const):
53
        (WebCore::TextureMapperPlatformLayerBuffer::size const):
54
        (WebCore::TextureMapperPlatformLayerBuffer::textureVariant): Deleted.
55
        * platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp: Added.
56
        (WebCore::fourCCToGLFormat):
57
        (WebCore::formatHasAlpha):
58
        (WebCore::TextureMapperPlatformLayerDmabuf::TextureMapperPlatformLayerDmabuf):
59
        (WebCore::m_fd):
60
        (WebCore::TextureMapperPlatformLayerDmabuf::~TextureMapperPlatformLayerDmabuf):
61
        (WebCore::TextureMapperPlatformLayerDmabuf::validateTexture):
62
        (WebCore::TextureMapperPlatformLayerDmabuf::paintToTextureMapper):
63
        (WebCore::TextureMapperPlatformLayerDmabuf::clone):
64
        * platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.h: Added.
65
1
2022-01-17  Youenn Fablet  <youenn@apple.com>
66
2022-01-17  Youenn Fablet  <youenn@apple.com>
2
67
3
        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
68
        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
- a/Source/WebCore/PlatformGTK.cmake +1 lines
Lines 26-31 list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES a/Source/WebCore/PlatformGTK.cmake_sec1
26
    "${WEBCORE_DIR}/platform/gtk"
26
    "${WEBCORE_DIR}/platform/gtk"
27
    "${WEBCORE_DIR}/platform/graphics/egl"
27
    "${WEBCORE_DIR}/platform/graphics/egl"
28
    "${WEBCORE_DIR}/platform/graphics/glx"
28
    "${WEBCORE_DIR}/platform/graphics/glx"
29
    "${WEBCORE_DIR}/platform/graphics/gbm"
29
    "${WEBCORE_DIR}/platform/graphics/gstreamer"
30
    "${WEBCORE_DIR}/platform/graphics/gstreamer"
30
    "${WEBCORE_DIR}/platform/graphics/gtk"
31
    "${WEBCORE_DIR}/platform/graphics/gtk"
31
    "${WEBCORE_DIR}/platform/graphics/opengl"
32
    "${WEBCORE_DIR}/platform/graphics/opengl"
- a/Source/WebCore/PlatformWPE.cmake +1 lines
Lines 23-28 list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES a/Source/WebCore/PlatformWPE.cmake_sec1
23
    "${WEBCORE_DIR}/platform/glib"
23
    "${WEBCORE_DIR}/platform/glib"
24
    "${WEBCORE_DIR}/platform/graphics/egl"
24
    "${WEBCORE_DIR}/platform/graphics/egl"
25
    "${WEBCORE_DIR}/platform/graphics/epoxy"
25
    "${WEBCORE_DIR}/platform/graphics/epoxy"
26
    "${WEBCORE_DIR}/platform/graphics/gbm"
26
    "${WEBCORE_DIR}/platform/graphics/glx"
27
    "${WEBCORE_DIR}/platform/graphics/glx"
27
    "${WEBCORE_DIR}/platform/graphics/gstreamer"
28
    "${WEBCORE_DIR}/platform/graphics/gstreamer"
28
    "${WEBCORE_DIR}/platform/graphics/opengl"
29
    "${WEBCORE_DIR}/platform/graphics/opengl"
- a/Source/WebCore/SourcesGTK.txt +2 lines
Lines 101-106 platform/graphics/egl/GLContextEGLLibWPE.cpp @no-unify a/Source/WebCore/SourcesGTK.txt_sec1
101
platform/graphics/egl/GLContextEGLWayland.cpp @no-unify
101
platform/graphics/egl/GLContextEGLWayland.cpp @no-unify
102
platform/graphics/egl/GLContextEGLX11.cpp @no-unify
102
platform/graphics/egl/GLContextEGLX11.cpp @no-unify
103
103
104
platform/graphics/gbm/GBMDevice.cpp
105
104
platform/graphics/glx/GLContextGLX.cpp
106
platform/graphics/glx/GLContextGLX.cpp
105
107
106
platform/graphics/gtk/ColorGtk.cpp
108
platform/graphics/gtk/ColorGtk.cpp
- a/Source/WebCore/SourcesWPE.txt +2 lines
Lines 72-77 platform/graphics/PlatformDisplay.cpp a/Source/WebCore/SourcesWPE.txt_sec1
72
platform/graphics/egl/GLContextEGL.cpp
72
platform/graphics/egl/GLContextEGL.cpp
73
platform/graphics/egl/GLContextEGLLibWPE.cpp
73
platform/graphics/egl/GLContextEGLLibWPE.cpp
74
74
75
platform/graphics/gbm/GBMDevice.cpp
76
75
platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
77
platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
76
78
77
platform/graphics/opentype/OpenTypeVerticalData.cpp
79
platform/graphics/opentype/OpenTypeVerticalData.cpp
- a/Source/WebCore/platform/TextureMapper.cmake +1 lines
Lines 59-64 if (USE_COORDINATED_GRAPHICS) a/Source/WebCore/platform/TextureMapper.cmake_sec1
59
    )
59
    )
60
    list(APPEND WebCore_SOURCES
60
    list(APPEND WebCore_SOURCES
61
        platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
61
        platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
62
        platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp
62
        platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
63
        platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
63
64
64
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp
65
        platform/graphics/texmap/coordinated/CoordinatedBackingStore.cpp
- a/Source/WebCore/platform/ThreadGlobalData.cpp +9 lines
Lines 30-35 a/Source/WebCore/platform/ThreadGlobalData.cpp_sec1
30
#include "CachedResourceRequestInitiators.h"
30
#include "CachedResourceRequestInitiators.h"
31
#include "EventNames.h"
31
#include "EventNames.h"
32
#include "FontCache.h"
32
#include "FontCache.h"
33
#include "GBMDevice.h"
33
#include "MIMETypeRegistry.h"
34
#include "MIMETypeRegistry.h"
34
#include "QualifiedNameCache.h"
35
#include "QualifiedNameCache.h"
35
#include "ThreadTimers.h"
36
#include "ThreadTimers.h"
Lines 146-151 void ThreadGlobalData::initializeFontCache() a/Source/WebCore/platform/ThreadGlobalData.cpp_sec2
146
    m_fontCache = makeUnique<FontCache>();
147
    m_fontCache = makeUnique<FontCache>();
147
}
148
}
148
149
150
#if USE(ANGLE) && USE(NICOSIA)
151
void ThreadGlobalData::initializeGbmDevice()
152
{
153
    ASSERT(!m_gbmDevice);
154
    m_gbmDevice = makeUnique<GBMDevice>();
155
}
156
#endif
157
149
} // namespace WebCore
158
} // namespace WebCore
150
159
151
namespace PAL {
160
namespace PAL {
- a/Source/WebCore/platform/ThreadGlobalData.h +17 lines
Lines 38-43 class JSGlobalObject; a/Source/WebCore/platform/ThreadGlobalData.h_sec1
38
namespace WebCore {
38
namespace WebCore {
39
39
40
class FontCache;
40
class FontCache;
41
class GBMDevice;
41
class QualifiedNameCache;
42
class QualifiedNameCache;
42
class ThreadTimers;
43
class ThreadTimers;
43
44
Lines 104-115 public: a/Source/WebCore/platform/ThreadGlobalData.h_sec2
104
105
105
    FontCache* fontCacheIfNotDestroyed() { return m_destroyed ? nullptr : &fontCache(); }
106
    FontCache* fontCacheIfNotDestroyed() { return m_destroyed ? nullptr : &fontCache(); }
106
107
108
#if USE(ANGLE) && USE(NICOSIA)
109
    GBMDevice& gbmDevice()
110
    {
111
        ASSERT(!m_destroyed);
112
        if (UNLIKELY(!m_gbmDevice))
113
            initializeGbmDevice();
114
        return *m_gbmDevice;
115
    }
116
#endif
117
107
private:
118
private:
108
    WEBCORE_EXPORT void initializeCachedResourceRequestInitiators();
119
    WEBCORE_EXPORT void initializeCachedResourceRequestInitiators();
109
    WEBCORE_EXPORT void initializeEventNames();
120
    WEBCORE_EXPORT void initializeEventNames();
110
    WEBCORE_EXPORT void initializeQualifiedNameCache();
121
    WEBCORE_EXPORT void initializeQualifiedNameCache();
111
    WEBCORE_EXPORT void initializeMimeTypeRegistryThreadGlobalData();
122
    WEBCORE_EXPORT void initializeMimeTypeRegistryThreadGlobalData();
112
    WEBCORE_EXPORT void initializeFontCache();
123
    WEBCORE_EXPORT void initializeFontCache();
124
#if USE(ANGLE) && USE(NICOSIA)
125
    WEBCORE_EXPORT void initializeGbmDevice();
126
#endif
113
127
114
    std::unique_ptr<CachedResourceRequestInitiators> m_cachedResourceRequestInitiators;
128
    std::unique_ptr<CachedResourceRequestInitiators> m_cachedResourceRequestInitiators;
115
    std::unique_ptr<EventNames> m_eventNames;
129
    std::unique_ptr<EventNames> m_eventNames;
Lines 118-123 private: a/Source/WebCore/platform/ThreadGlobalData.h_sec3
118
    JSC::JSGlobalObject* m_currentState { nullptr };
132
    JSC::JSGlobalObject* m_currentState { nullptr };
119
    std::unique_ptr<MIMETypeRegistryThreadGlobalData> m_MIMETypeRegistryThreadGlobalData;
133
    std::unique_ptr<MIMETypeRegistryThreadGlobalData> m_MIMETypeRegistryThreadGlobalData;
120
    std::unique_ptr<FontCache> m_fontCache;
134
    std::unique_ptr<FontCache> m_fontCache;
135
#if USE(ANGLE) && USE(NICOSIA)
136
    std::unique_ptr<GBMDevice> m_gbmDevice;
137
#endif
121
138
122
#ifndef NDEBUG
139
#ifndef NDEBUG
123
    bool m_isMainThread;
140
    bool m_isMainThread;
- a/Source/WebCore/platform/graphics/OpenGLShims.cpp +1 lines
Lines 143-148 bool initializeOpenGLShims() a/Source/WebCore/platform/graphics/OpenGLShims.cpp_sec1
143
    ASSIGN_FUNCTION_TABLE_ENTRY(glDrawBuffers, success);
143
    ASSIGN_FUNCTION_TABLE_ENTRY(glDrawBuffers, success);
144
    ASSIGN_FUNCTION_TABLE_ENTRY(glDrawElementsInstanced, success);
144
    ASSIGN_FUNCTION_TABLE_ENTRY(glDrawElementsInstanced, success);
145
    ASSIGN_FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray, success);
145
    ASSIGN_FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray, success);
146
    ASSIGN_FUNCTION_TABLE_ENTRY(glEGLImageTargetTexture2DOES, success);
146
    ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer, success);
147
    ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer, success);
147
    ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferTexture2D, success);
148
    ASSIGN_FUNCTION_TABLE_ENTRY(glFramebufferTexture2D, success);
148
    ASSIGN_FUNCTION_TABLE_ENTRY(glGenBuffers, success);
149
    ASSIGN_FUNCTION_TABLE_ENTRY(glGenBuffers, success);
- a/Source/WebCore/platform/graphics/OpenGLShims.h +3 lines
Lines 78-83 typedef void (GLAPIENTRY *glDisableVertexAttribArrayType) (GLuint); a/Source/WebCore/platform/graphics/OpenGLShims.h_sec1
78
typedef void (GLAPIENTRY *glDrawArraysInstancedType) (GLenum, GLint, GLsizei, GLsizei);
78
typedef void (GLAPIENTRY *glDrawArraysInstancedType) (GLenum, GLint, GLsizei, GLsizei);
79
typedef void (GLAPIENTRY *glDrawBuffersType) (GLsizei, const GLenum*);
79
typedef void (GLAPIENTRY *glDrawBuffersType) (GLsizei, const GLenum*);
80
typedef void (GLAPIENTRY *glDrawElementsInstancedType) (GLenum, GLsizei, GLenum, const GLvoid*, GLsizei);
80
typedef void (GLAPIENTRY *glDrawElementsInstancedType) (GLenum, GLsizei, GLenum, const GLvoid*, GLsizei);
81
typedef void (GLAPIENTRY *glEGLImageTargetTexture2DOESType) (GLenum target, GLeglImageOES);
81
typedef void (GLAPIENTRY *glEnableVertexAttribArrayType) (GLuint);
82
typedef void (GLAPIENTRY *glEnableVertexAttribArrayType) (GLuint);
82
typedef void (GLAPIENTRY *glFramebufferRenderbufferType) (GLenum, GLenum, GLenum, GLuint);
83
typedef void (GLAPIENTRY *glFramebufferRenderbufferType) (GLenum, GLenum, GLenum, GLuint);
83
typedef void (GLAPIENTRY *glFramebufferTexture2DType) (GLenum, GLenum, GLenum, GLuint, GLint);
84
typedef void (GLAPIENTRY *glFramebufferTexture2DType) (GLenum, GLenum, GLenum, GLuint, GLint);
Lines 186-191 typedef struct _OpenGLFunctionTable { a/Source/WebCore/platform/graphics/OpenGLShims.h_sec2
186
    FUNCTION_TABLE_ENTRY(glDrawArraysInstanced);
187
    FUNCTION_TABLE_ENTRY(glDrawArraysInstanced);
187
    FUNCTION_TABLE_ENTRY(glDrawBuffers);
188
    FUNCTION_TABLE_ENTRY(glDrawBuffers);
188
    FUNCTION_TABLE_ENTRY(glDrawElementsInstanced);
189
    FUNCTION_TABLE_ENTRY(glDrawElementsInstanced);
190
    FUNCTION_TABLE_ENTRY(glEGLImageTargetTexture2DOES);
189
    FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray);
191
    FUNCTION_TABLE_ENTRY(glEnableVertexAttribArray);
190
    FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer);
192
    FUNCTION_TABLE_ENTRY(glFramebufferRenderbuffer);
191
    FUNCTION_TABLE_ENTRY(glFramebufferTexture2D);
193
    FUNCTION_TABLE_ENTRY(glFramebufferTexture2D);
Lines 306-311 typedef struct _OpenGLFunctionTable { a/Source/WebCore/platform/graphics/OpenGLShims.h_sec3
306
#define glDrawBuffers                          LOOKUP_GL_FUNCTION(glDrawBuffers)
308
#define glDrawBuffers                          LOOKUP_GL_FUNCTION(glDrawBuffers)
307
#define glDrawElementsInstancedEXT             glDrawElementsInstanced
309
#define glDrawElementsInstancedEXT             glDrawElementsInstanced
308
#define glDrawElementsInstanced                LOOKUP_GL_FUNCTION(glDrawElementsInstanced)
310
#define glDrawElementsInstanced                LOOKUP_GL_FUNCTION(glDrawElementsInstanced)
311
#define glEGLImageTargetTexture2DOES           LOOKUP_GL_FUNCTION(glEGLImageTargetTexture2DOES)
309
#define glEnableVertexAttribArray              LOOKUP_GL_FUNCTION(glEnableVertexAttribArray)
312
#define glEnableVertexAttribArray              LOOKUP_GL_FUNCTION(glEnableVertexAttribArray)
310
#define glFramebufferRenderbufferEXT           glFramebufferRenderbuffer
313
#define glFramebufferRenderbufferEXT           glFramebufferRenderbuffer
311
#define glFramebufferRenderbuffer              LOOKUP_GL_FUNCTION(glFramebufferRenderbuffer)
314
#define glFramebufferRenderbuffer              LOOKUP_GL_FUNCTION(glFramebufferRenderbuffer)
- a/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp -3 / +5 lines
Lines 541-554 void GraphicsContextGLANGLE::prepareTextureImpl() a/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp_sec1
541
#if USE(COORDINATED_GRAPHICS)
541
#if USE(COORDINATED_GRAPHICS)
542
    std::swap(m_texture, m_compositorTexture);
542
    std::swap(m_texture, m_compositorTexture);
543
    std::swap(m_texture, m_intermediateTexture);
543
    std::swap(m_texture, m_intermediateTexture);
544
#if USE(NICOSIA)
545
    std::swap(m_textureBacking, m_compositorTextureBacking);
546
    std::swap(m_textureBacking, m_intermediateTextureBacking);
547
#endif
544
    GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
548
    GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
545
    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ANGLE, m_texture, 0);
549
    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
546
    GL_Flush();
550
    GL_Flush();
547
551
548
    if (m_state.boundDrawFBO != m_fbo)
552
    if (m_state.boundDrawFBO != m_fbo)
549
        GL_BindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_state.boundDrawFBO);
553
        GL_BindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_state.boundDrawFBO);
550
    else
551
        GL_BindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_fbo);
552
#else
554
#else
553
    if (m_preserveDrawingBufferTexture) {
555
    if (m_preserveDrawingBufferTexture) {
554
        // Blit m_preserveDrawingBufferTexture into m_texture.
556
        // Blit m_preserveDrawingBufferTexture into m_texture.
- a/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h -4 / +34 lines
Lines 43-56 a/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h_sec1
43
#if USE(NICOSIA)
43
#if USE(NICOSIA)
44
namespace Nicosia {
44
namespace Nicosia {
45
class GCGLANGLEPipe;
45
class GCGLANGLEPipe;
46
class GCGLANGLEPipeSource;
46
class GCGLLayer;
47
class GCGLLayer;
47
}
48
}
49
50
struct gbm_device;
51
struct gbm_bo;
48
#endif
52
#endif
49
53
50
namespace WebCore {
54
namespace WebCore {
51
55
52
class ExtensionsGL;
56
class ExtensionsGL;
53
class ExtensionsGLANGLE;
57
class ExtensionsGLANGLE;
58
class GLContext;
54
class HostWindow;
59
class HostWindow;
55
class ImageBuffer;
60
class ImageBuffer;
56
class MediaPlayer;
61
class MediaPlayer;
Lines 450-466 protected: a/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.h_sec2
450
    GCGLuint m_intermediateTexture { 0 };
455
    GCGLuint m_intermediateTexture { 0 };
451
#endif
456
#endif
452
#if USE(NICOSIA)
457
#if USE(NICOSIA)
453
#if USE(ANGLE)
454
    std::unique_ptr<Nicosia::GCGLANGLEPipe> m_nicosiaPipe;
458
    std::unique_ptr<Nicosia::GCGLANGLEPipe> m_nicosiaPipe;
455
#else
459
456
    std::unique_ptr<Nicosia::GCGLLayer> m_nicosiaLayer;
460
    class EGLImageBacking {
457
#endif
461
    WTF_MAKE_FAST_ALLOCATED;
462
    public:
463
        EGLImageBacking(gbm_device*, PlatformGraphicsContextGLDisplay);
464
        ~EGLImageBacking();
465
466
        bool reset(int width, int height, bool hasAlpha);
467
468
        EGLImage image() const { return m_image; }
469
        int fd() const { return m_FD; }
470
471
        uint32_t format() const;
472
        uint32_t stride() const;
473
    private:
474
        void releaseResources();
475
476
        gbm_device* m_device;
477
        PlatformGraphicsContextGLDisplay m_display;
478
479
        gbm_bo* m_BO { nullptr };
480
        int m_FD { -1 };
481
        EGLImage m_image { EGL_NO_IMAGE };
482
    };
483
484
    std::unique_ptr<EGLImageBacking> m_textureBacking;
485
    std::unique_ptr<EGLImageBacking> m_compositorTextureBacking;
486
    std::unique_ptr<EGLImageBacking> m_intermediateTextureBacking;
458
#elif USE(TEXTURE_MAPPER)
487
#elif USE(TEXTURE_MAPPER)
459
    std::unique_ptr<TextureMapperGCGLPlatformLayer> m_texmapLayer;
488
    std::unique_ptr<TextureMapperGCGLPlatformLayer> m_texmapLayer;
460
#endif
489
#endif
461
490
462
    friend class ExtensionsGLANGLE;
491
    friend class ExtensionsGLANGLE;
463
#if USE(NICOSIA)
492
#if USE(NICOSIA)
493
    friend class Nicosia::GCGLANGLEPipeSource;
464
    friend class Nicosia::GCGLLayer;
494
    friend class Nicosia::GCGLLayer;
465
#elif USE(TEXTURE_MAPPER)
495
#elif USE(TEXTURE_MAPPER)
466
    friend class TextureMapperGCGLPlatformLayer;
496
    friend class TextureMapperGCGLPlatformLayer;
- a/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp +38 lines
Lines 364-369 GLContextEGL::GLContextEGL(PlatformDisplay& display, EGLContext context, EGLSurf a/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp_sec1
364
    ASSERT(type == Surfaceless || surface != EGL_NO_SURFACE);
364
    ASSERT(type == Surfaceless || surface != EGL_NO_SURFACE);
365
    RELEASE_ASSERT(m_display.eglDisplay() != EGL_NO_DISPLAY);
365
    RELEASE_ASSERT(m_display.eglDisplay() != EGL_NO_DISPLAY);
366
    RELEASE_ASSERT(context != EGL_NO_CONTEXT);
366
    RELEASE_ASSERT(context != EGL_NO_CONTEXT);
367
368
    if (display.eglCheckVersion(1, 5)) {
369
        m_eglCreateImage = reinterpret_cast<PFNEGLCREATEIMAGEPROC>(eglGetProcAddress("eglCreateImage"));
370
        m_eglDestroyImage = reinterpret_cast<PFNEGLDESTROYIMAGEPROC>(eglGetProcAddress("eglDestroyImage"));
371
        RELEASE_ASSERT(!m_eglCreateImage == !m_eglDestroyImage);
372
    } else {
373
        const char* extensions = eglQueryString(display.eglDisplay(), EGL_EXTENSIONS);
374
        if (GLContext::isExtensionSupported(extensions, "EGL_KHR_image_base")) {
375
            m_eglCreateImageKHR = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
376
            m_eglDestroyImageKHR = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
377
        }
378
        RELEASE_ASSERT(!m_eglCreateImageKHR == !m_eglDestroyImageKHR);
379
    }
367
}
380
}
368
381
369
GLContextEGL::~GLContextEGL()
382
GLContextEGL::~GLContextEGL()
Lines 386-391 GLContextEGL::~GLContextEGL() a/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp_sec2
386
#endif
399
#endif
387
}
400
}
388
401
402
EGLImage GLContextEGL::createImage(EGLenum target, EGLClientBuffer clientBuffer, const EGLAttrib* attribList) const
403
{
404
    if (m_eglCreateImage)
405
        return m_eglCreateImage(m_display.eglDisplay(), attribList ? EGL_NO_CONTEXT : m_context, target, clientBuffer, attribList);
406
    if (m_eglCreateImageKHR) {
407
        Vector<EGLint> intAttribList;
408
        for (int i = 0; attribList[i] != EGL_NONE; i += 2) {
409
            intAttribList.append(attribList[i]);
410
            intAttribList.append(attribList[i+1]);
411
        }
412
        intAttribList.append(EGL_NONE);
413
        return m_eglCreateImageKHR(m_display.eglDisplay(), attribList ? EGL_NO_CONTEXT : m_context, target, clientBuffer, intAttribList.data());
414
    }
415
    return EGL_NO_IMAGE;
416
}
417
418
bool GLContextEGL::destroyImage(EGLImage image) const
419
{
420
    if (m_eglDestroyImage)
421
        return m_eglDestroyImage(m_display.eglDisplay(), image);
422
    if (m_eglDestroyImageKHR)
423
        return m_eglDestroyImageKHR(m_display.eglDisplay(), image);
424
    return false;
425
}
426
389
bool GLContextEGL::canRenderToDefaultFramebuffer()
427
bool GLContextEGL::canRenderToDefaultFramebuffer()
390
{
428
{
391
    return m_type == WindowSurface;
429
    return m_type == WindowSurface;
- a/Source/WebCore/platform/graphics/egl/GLContextEGL.h +25 lines
Lines 36-45 struct wl_egl_window; a/Source/WebCore/platform/graphics/egl/GLContextEGL.h_sec1
36
struct wpe_renderer_backend_egl_offscreen_target;
36
struct wpe_renderer_backend_egl_offscreen_target;
37
#endif
37
#endif
38
38
39
typedef intptr_t EGLAttrib;
40
typedef unsigned EGLBoolean;
41
typedef void *EGLClientBuffer;
39
typedef void *EGLConfig;
42
typedef void *EGLConfig;
40
typedef void *EGLContext;
43
typedef void *EGLContext;
41
typedef void *EGLDisplay;
44
typedef void *EGLDisplay;
45
typedef void *EGLImage;
46
typedef void *EGLImageKHR;
42
typedef void *EGLSurface;
47
typedef void *EGLSurface;
48
typedef unsigned EGLenum;
49
50
#if !defined(PFNEGLCREATEIMAGEPROC)
51
typedef EGLImage (*PFNEGLCREATEIMAGEPROC) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLAttrib*);
52
#endif
53
#if !defined(PFNEGLDESTROYIMAGEPROC)
54
typedef EGLBoolean (*PFNEGLDESTROYIMAGEPROC) (EGLDisplay, EGLImage);
55
#endif
56
#if !defined(PFNEGLCREATEIMAGEKHRPROC)
57
typedef EGLImageKHR (*PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay, EGLContext, EGLenum target, EGLClientBuffer, const EGLint* attribList);
58
#endif
59
#if !defined(PFNEGLDESTROYIMAGEKHRPROC)
60
typedef EGLBoolean (*PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay, EGLImageKHR);
61
#endif
43
62
44
namespace WebCore {
63
namespace WebCore {
45
64
Lines 53-58 public: a/Source/WebCore/platform/graphics/egl/GLContextEGL.h_sec2
53
    static const char* lastErrorString();
72
    static const char* lastErrorString();
54
73
55
    EGLConfig config() const { return m_config; }
74
    EGLConfig config() const { return m_config; }
75
    EGLImage createImage(EGLenum target, EGLClientBuffer, const EGLAttrib*) const;
76
    bool destroyImage(EGLImage) const;
56
77
57
    virtual ~GLContextEGL();
78
    virtual ~GLContextEGL();
58
79
Lines 106-111 private: a/Source/WebCore/platform/graphics/egl/GLContextEGL.h_sec3
106
    EGLSurface m_surface { nullptr };
127
    EGLSurface m_surface { nullptr };
107
    EGLConfig m_config { nullptr };
128
    EGLConfig m_config { nullptr };
108
    EGLSurfaceType m_type;
129
    EGLSurfaceType m_type;
130
    PFNEGLCREATEIMAGEPROC m_eglCreateImage { nullptr };
131
    PFNEGLDESTROYIMAGEPROC m_eglDestroyImage { nullptr };
132
    PFNEGLCREATEIMAGEKHRPROC m_eglCreateImageKHR { nullptr };
133
    PFNEGLDESTROYIMAGEKHRPROC m_eglDestroyImageKHR { nullptr };
109
#if PLATFORM(X11)
134
#if PLATFORM(X11)
110
    XUniquePixmap m_pixmap;
135
    XUniquePixmap m_pixmap;
111
#endif
136
#endif
- a/Source/WebCore/platform/graphics/gbm/GBMDevice.cpp +71 lines
Line 0 a/Source/WebCore/platform/graphics/gbm/GBMDevice.cpp_sec1
1
/*
2
 * Copyright (C) 2022 Metrological Group B.V.
3
 * Copyright (C) 2022 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "config.h"
28
#include "GBMDevice.h"
29
30
#if USE(ANGLE) && USE(NICOSIA)
31
32
#include "ThreadGlobalData.h"
33
34
#include <fcntl.h>
35
#include <gbm.h>
36
#include <mutex>
37
38
namespace WebCore {
39
40
const GBMDevice& GBMDevice::forCurrentThread()
41
{
42
    return threadGlobalData().gbmDevice();
43
}
44
45
GBMDevice::GBMDevice()
46
{
47
    int fd;
48
    char deviceName[30];
49
    for (int i = 128; i < 192; ++i) {
50
        snprintf(deviceName, sizeof(deviceName), "/dev/dri/renderD%d", i);
51
        fd = open(deviceName, O_RDWR | O_CLOEXEC);
52
        if (fd >= 0) {
53
            m_device = gbm_create_device(fd);
54
            if (m_device)
55
                break;
56
            close(fd);
57
        }
58
    }
59
}
60
61
GBMDevice::~GBMDevice()
62
{
63
    if (m_device) {
64
        gbm_device_destroy(m_device);
65
        m_device = nullptr;
66
    }
67
}
68
69
} // namespace WebCore
70
71
#endif // USE(ANGLE) && USE(NICOSIA)
- a/Source/WebCore/platform/graphics/gbm/GBMDevice.h +54 lines
Line 0 a/Source/WebCore/platform/graphics/gbm/GBMDevice.h_sec1
1
/*
2
 * Copyright (C) 2022 Metrological Group B.V.
3
 * Copyright (C) 2022 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#pragma once
28
29
#if USE(ANGLE) && USE(NICOSIA)
30
31
struct gbm_device;
32
33
namespace WebCore {
34
35
class ThreadGlobalData;
36
37
class GBMDevice {
38
    WTF_MAKE_NONCOPYABLE(GBMDevice);
39
    WTF_MAKE_FAST_ALLOCATED();
40
public:
41
    static const GBMDevice& forCurrentThread();
42
43
    GBMDevice();
44
    ~GBMDevice();
45
46
    struct gbm_device* device() const { return m_device; }
47
48
private:
49
    struct gbm_device* m_device { nullptr };
50
};
51
52
} // namespace WebCore
53
54
#endif // USE(ANGLE) && USE(NICOSIA)
- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp -1 / +19 lines
Lines 35-41 a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp_sec1
35
#include "ImageBuffer.h"
35
#include "ImageBuffer.h"
36
#include "Logging.h"
36
#include "Logging.h"
37
#include "TextureMapperGL.h"
37
#include "TextureMapperGL.h"
38
#include "TextureMapperPlatformLayerBuffer.h"
38
#include "TextureMapperPlatformLayerDmabuf.h"
39
#include "TextureMapperPlatformLayerProxy.h"
39
#include "TextureMapperPlatformLayerProxy.h"
40
40
41
namespace Nicosia {
41
namespace Nicosia {
Lines 57-62 void GCGLANGLEPipeSource::swapBuffersIfNeeded() a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp_sec2
57
        return;
57
        return;
58
58
59
    m_context.prepareTexture();
59
    m_context.prepareTexture();
60
61
    if (m_context.m_compositorTextureBacking) {
62
        auto size = m_context.getInternalFramebufferSize();
63
        auto format = m_context.m_compositorTextureBacking->format();
64
        auto stride = m_context.m_compositorTextureBacking->stride();
65
        auto fd = m_context.m_compositorTextureBacking->fd();
66
67
        auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(platformLayer()->impl()).proxy();
68
        {
69
            Locker locker { proxy.lock() };
70
            proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerDmabuf>(size, format, stride, fd));
71
        }
72
73
        m_context.markLayerComposited();
74
        return;
75
    }
76
77
    // Fallback path, read back texture to main memory
60
    RefPtr<WebCore::ImageBuffer> imageBuffer = ImageBuffer::create(m_context.getInternalFramebufferSize(), RenderingMode::Unaccelerated, 1, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
78
    RefPtr<WebCore::ImageBuffer> imageBuffer = ImageBuffer::create(m_context.getInternalFramebufferSize(), RenderingMode::Unaccelerated, 1, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
61
    if (!imageBuffer)
79
    if (!imageBuffer)
62
        return;
80
        return;
- a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp +111 lines
Lines 36-44 a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec1
36
#include "PixelBuffer.h"
36
#include "PixelBuffer.h"
37
37
38
#if USE(NICOSIA)
38
#if USE(NICOSIA)
39
#include "GBMDevice.h"
39
#include "NicosiaGCGLANGLEPipe.h"
40
#include "NicosiaGCGLANGLEPipe.h"
41
#include "gbm.h"
40
#else
42
#else
41
#include "TextureMapperGCGLPlatformLayer.h"
43
#include "TextureMapperGCGLPlatformLayer.h"
44
45
#include <fcntl.h>
42
#endif
46
#endif
43
47
44
namespace WebCore {
48
namespace WebCore {
Lines 51-56 GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attri a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec2
51
#endif
55
#endif
52
#if USE(NICOSIA)
56
#if USE(NICOSIA)
53
    m_nicosiaPipe = makeUnique<Nicosia::GCGLANGLEPipe>(*this);
57
    m_nicosiaPipe = makeUnique<Nicosia::GCGLANGLEPipe>(*this);
58
59
    auto& gbmDevice = GBMDevice::forCurrentThread();
60
    if (auto* device = gbmDevice.device()) {
61
        m_textureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
62
        m_compositorTextureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
63
        m_intermediateTextureBacking = makeUnique<EGLImageBacking>(device, platformDisplay());
64
    }
54
#else
65
#else
55
    m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
66
    m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
56
#endif
67
#endif
Lines 112-122 GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attri a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec3
112
    GL_ClearColor(0, 0, 0, 0);
123
    GL_ClearColor(0, 0, 0, 0);
113
}
124
}
114
125
126
#if USE(NICOSIA)
127
GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking(gbm_device* device, PlatformGraphicsContextGLDisplay display)
128
    : m_device(device)
129
    , m_display(display)
130
{
131
}
132
133
GraphicsContextGLANGLE::EGLImageBacking::~EGLImageBacking()
134
{
135
    releaseResources();
136
}
137
138
uint32_t GraphicsContextGLANGLE::EGLImageBacking::format() const
139
{
140
    if (m_BO)
141
        return gbm_bo_get_format(m_BO);
142
    return 0;
143
}
144
145
uint32_t GraphicsContextGLANGLE::EGLImageBacking::stride() const
146
{
147
    if (m_BO)
148
        return gbm_bo_get_stride(m_BO);
149
    return 0;
150
}
151
152
void GraphicsContextGLANGLE::EGLImageBacking::releaseResources()
153
{
154
    if (m_BO) {
155
        gbm_bo_destroy(m_BO);
156
        m_BO = nullptr;
157
    }
158
    if (m_image) {
159
        EGL_DestroyImageKHR(m_display, m_image);
160
        m_image = EGL_NO_IMAGE;
161
    }
162
    if (m_FD >= 0) {
163
        close(m_FD);
164
        m_FD = -1;
165
    }
166
}
167
168
bool GraphicsContextGLANGLE::EGLImageBacking::reset(int width, int height, bool hasAlpha)
169
{
170
    releaseResources();
171
172
    if (!width || !height)
173
        return false;
174
175
    m_BO = gbm_bo_create(m_device, width, height, hasAlpha ? GBM_BO_FORMAT_ARGB8888 : GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_RENDERING);
176
    if (m_BO) {
177
        m_FD = gbm_bo_get_fd(m_BO);
178
        if (m_FD >= 0) {
179
            EGLint imageAttributes[] = {
180
                EGL_WIDTH, width,
181
                EGL_HEIGHT, height,
182
                EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLint>(gbm_bo_get_format(m_BO)),
183
                EGL_DMA_BUF_PLANE0_FD_EXT, m_FD,
184
                EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(gbm_bo_get_stride(m_BO)),
185
                EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
186
                EGL_NONE
187
            };
188
            m_image = EGL_CreateImageKHR(m_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, imageAttributes);
189
            if (m_image)
190
                return true;
191
        }
192
    }
193
194
    releaseResources();
195
    return false;
196
}
197
#endif
198
115
GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
199
GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
116
{
200
{
117
    GraphicsContextGLOpenGLManager::sharedManager().removeContext(this);
201
    GraphicsContextGLOpenGLManager::sharedManager().removeContext(this);
118
    bool success = makeContextCurrent();
202
    bool success = makeContextCurrent();
119
    ASSERT_UNUSED(success, success);
203
    ASSERT_UNUSED(success, success);
204
120
    if (m_texture)
205
    if (m_texture)
121
        GL_DeleteTextures(1, &m_texture);
206
        GL_DeleteTextures(1, &m_texture);
122
#if USE(COORDINATED_GRAPHICS)
207
#if USE(COORDINATED_GRAPHICS)
Lines 189-206 bool GraphicsContextGLANGLE::reshapeDisplayBufferBacking() a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec4
189
    GLuint colorFormat = attrs.alpha ? GL_RGBA : GL_RGB;
274
    GLuint colorFormat = attrs.alpha ? GL_RGBA : GL_RGB;
190
    GLenum textureTarget = drawingBufferTextureTarget();
275
    GLenum textureTarget = drawingBufferTextureTarget();
191
    GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
276
    GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
277
278
#if USE(NICOSIA)
279
    if (m_textureBacking)
280
        m_textureBacking->reset(width, height, attrs.alpha);
281
    if (m_compositorTextureBacking)
282
        m_compositorTextureBacking->reset(width, height, attrs.alpha);
283
    if (m_intermediateTextureBacking)
284
        m_intermediateTextureBacking->reset(width, height, attrs.alpha);
285
#endif
286
192
    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
287
    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
193
#if USE(COORDINATED_GRAPHICS)
288
#if USE(COORDINATED_GRAPHICS)
194
    if (m_compositorTexture) {
289
    if (m_compositorTexture) {
195
        GL_BindTexture(textureTarget, m_compositorTexture);
290
        GL_BindTexture(textureTarget, m_compositorTexture);
291
#if USE(NICOSIA)
292
        if (m_compositorTextureBacking && m_compositorTextureBacking->image())
293
            GL_EGLImageTargetTexture2DOES(textureTarget, m_compositorTextureBacking->image());
294
        else
295
#endif
196
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
296
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
197
        GL_BindTexture(textureTarget, m_intermediateTexture);
297
        GL_BindTexture(textureTarget, m_intermediateTexture);
298
#if USE(NICOSIA)
299
        if (m_intermediateTextureBacking && m_intermediateTextureBacking->image())
300
            GL_EGLImageTargetTexture2DOES(textureTarget, m_intermediateTextureBacking->image());
301
        else
302
#endif
198
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
303
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
199
    }
304
    }
200
#endif
305
#endif
201
    GL_BindTexture(textureTarget, m_texture);
306
    GL_BindTexture(textureTarget, m_texture);
307
#if USE(NICOSIA)
308
    if (m_textureBacking && m_textureBacking->image())
309
        GL_EGLImageTargetTexture2DOES(textureTarget, m_textureBacking->image());
310
    else
311
#endif
202
    GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
312
    GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
203
    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
313
    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
314
204
    return true;
315
    return true;
205
}
316
}
206
317
- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h -5 / +7 lines
Lines 62-68 public: a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec1
62
62
63
    virtual ~TextureMapperPlatformLayerBuffer();
63
    virtual ~TextureMapperPlatformLayerBuffer();
64
64
65
    void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) final;
65
    void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) override;
66
66
67
    bool canReuseWithoutReset(const IntSize&, GLint internalFormat);
67
    bool canReuseWithoutReset(const IntSize&, GLint internalFormat);
68
    BitmapTextureGL& textureGL() { return static_cast<BitmapTextureGL&>(*m_texture); }
68
    BitmapTextureGL& textureGL() { return static_cast<BitmapTextureGL&>(*m_texture); }
Lines 86-92 public: a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec2
86
    void setUnmanagedBufferDataHolder(std::unique_ptr<UnmanagedBufferDataHolder> holder) { m_unmanagedBufferDataHolder = WTFMove(holder); }
86
    void setUnmanagedBufferDataHolder(std::unique_ptr<UnmanagedBufferDataHolder> holder) { m_unmanagedBufferDataHolder = WTFMove(holder); }
87
    void setExtraFlags(TextureMapperGL::Flags flags) { m_extraFlags = flags; }
87
    void setExtraFlags(TextureMapperGL::Flags flags) { m_extraFlags = flags; }
88
88
89
    std::unique_ptr<TextureMapperPlatformLayerBuffer> clone();
89
    virtual std::unique_ptr<TextureMapperPlatformLayerBuffer> clone();
90
90
91
    class HolePunchClient {
91
    class HolePunchClient {
92
        WTF_MAKE_FAST_ALLOCATED();
92
        WTF_MAKE_FAST_ALLOCATED();
Lines 97-110 public: a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec3
97
97
98
    void setHolePunchClient(std::unique_ptr<HolePunchClient>&& client) { m_holePunchClient = WTFMove(client); }
98
    void setHolePunchClient(std::unique_ptr<HolePunchClient>&& client) { m_holePunchClient = WTFMove(client); }
99
99
100
    const TextureVariant& textureVariant() { return m_variant; }
100
    const TextureVariant& textureVariant() const { return m_variant; }
101
    IntSize size() const { return m_size; }
101
102
102
private:
103
protected:
104
    TextureVariant m_variant;
103
105
106
private:
104
    RefPtr<BitmapTexture> m_texture;
107
    RefPtr<BitmapTexture> m_texture;
105
    MonotonicTime m_timeLastUsed;
108
    MonotonicTime m_timeLastUsed;
106
109
107
    TextureVariant m_variant;
108
    IntSize m_size;
110
    IntSize m_size;
109
    GLint m_internalFormat;
111
    GLint m_internalFormat;
110
    TextureMapperGL::Flags m_extraFlags;
112
    TextureMapperGL::Flags m_extraFlags;
- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp +128 lines
Line 0 a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.cpp_sec1
1
/*
2
 * Copyright (C) 2022 Metrological Group B.V.
3
 * Copyright (C) 2022 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "config.h"
28
#include "TextureMapperPlatformLayerDmabuf.h"
29
30
#if USE(ANGLE) && USE(NICOSIA)
31
32
#include "GLContextEGL.h"
33
34
#if USE(LIBEPOXY)
35
#include "EpoxyEGL.h"
36
#else
37
#include <EGL/egl.h>
38
#include <EGL/eglext.h>
39
#endif
40
41
#include <unistd.h>
42
43
namespace WebCore {
44
45
static constexpr uint32_t createFourCC(char a, char b, char c, char d)
46
{
47
    return uint32_t(a) | (uint32_t(b) << 8) | (uint32_t(c) << 16) | (uint32_t(d) << 24);
48
}
49
50
static GLint fourCCToGLFormat(uint32_t format)
51
{
52
    ASSERT((format == createFourCC('X', 'R', '2', '4')) || (format == createFourCC('A', 'R', '2', '4')));
53
    return (format == createFourCC('A', 'R', '2', '4')) ? GL_RGBA : GL_RGB;
54
}
55
56
static bool formatHasAlpha(uint32_t format)
57
{
58
    ASSERT((format == createFourCC('X', 'R', '2', '4')) || (format == createFourCC('A', 'R', '2', '4')));
59
    return (format == createFourCC('A', 'R', '2', '4')) ? true : false;
60
}
61
62
TextureMapperPlatformLayerDmabuf::TextureMapperPlatformLayerDmabuf(const IntSize& size, uint32_t format, uint32_t stride, int fd)
63
    : TextureMapperPlatformLayerBuffer({ RGBTexture { 0 } }, size, TextureMapperGL::ShouldFlipTexture | (formatHasAlpha(format) ? TextureMapperGL::ShouldBlend : 0), fourCCToGLFormat(format))
64
    , m_format(format)
65
    , m_stride(stride)
66
    , m_fd(dup(fd))
67
{
68
}
69
70
TextureMapperPlatformLayerDmabuf::~TextureMapperPlatformLayerDmabuf()
71
{
72
    ASSERT(std::holds_alternative<RGBTexture>(m_variant));
73
    auto& texture = std::get<RGBTexture>(m_variant);
74
    if (texture.id)
75
        glDeleteTextures(1, &texture.id);
76
    close(m_fd);
77
}
78
79
void TextureMapperPlatformLayerDmabuf::validateTexture()
80
{
81
    ASSERT(std::holds_alternative<RGBTexture>(m_variant));
82
    auto& texture = std::get<RGBTexture>(m_variant);
83
    if (texture.id)
84
        return;
85
86
    auto* context = GLContext::current();
87
    ASSERT(context->isEGLContext());
88
89
    context->makeContextCurrent();
90
91
    auto size = TextureMapperPlatformLayerBuffer::size();
92
    EGLAttrib imageAttributes[] = {
93
        EGL_WIDTH, size.width(),
94
        EGL_HEIGHT, size.height(),
95
        EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLAttrib>(m_format),
96
        EGL_DMA_BUF_PLANE0_FD_EXT, m_fd,
97
        EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLAttrib>(m_stride),
98
        EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
99
        EGL_NONE
100
    };
101
    auto image = downcast<GLContextEGL>(*context).createImage(EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, imageAttributes);
102
    if (!image)
103
        return;
104
105
    glGenTextures(1, &texture.id);
106
    glBindTexture(GL_TEXTURE_2D, texture.id);
107
    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
108
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
109
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
110
111
    RELEASE_ASSERT(downcast<GLContextEGL>(*context).destroyImage(image));
112
}
113
114
void TextureMapperPlatformLayerDmabuf::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity)
115
{
116
    validateTexture();
117
    TextureMapperPlatformLayerBuffer::paintToTextureMapper(textureMapper, targetRect, modelViewMatrix, opacity);
118
}
119
120
std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerDmabuf::clone()
121
{
122
    validateTexture();
123
    return TextureMapperPlatformLayerBuffer::clone();
124
}
125
126
} // namespace WebCore
127
128
#endif // USE(ANGLE) && USE(NICOSIA)
- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.h +56 lines
Line 0 a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerDmabuf.h_sec1
1
/*
2
 * Copyright (C) 2022 Metrological Group B.V.
3
 * Copyright (C) 2022 Igalia S.L.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#pragma once
28
29
#if USE(ANGLE) && USE(NICOSIA)
30
31
#include "TextureMapperPlatformLayerBuffer.h"
32
33
namespace WebCore {
34
35
class TextureMapperPlatformLayerDmabuf : public TextureMapperPlatformLayerBuffer {
36
    WTF_MAKE_NONCOPYABLE(TextureMapperPlatformLayerDmabuf);
37
    WTF_MAKE_FAST_ALLOCATED();
38
public:
39
    TextureMapperPlatformLayerDmabuf(const IntSize&, uint32_t format, uint32_t stride, int fd);
40
41
    virtual ~TextureMapperPlatformLayerDmabuf();
42
43
private:
44
    void validateTexture();
45
46
    void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix, float opacity) final;
47
    std::unique_ptr<TextureMapperPlatformLayerBuffer> clone() final;
48
49
    uint32_t m_format;
50
    uint32_t m_stride;
51
    int m_fd;
52
};
53
54
} // namespace WebCore
55
56
#endif // USE(ANGLE) && USE(NICOSIA)

Return to Bug 235946