| Differences between
and this patch
- a/Source/WebCore/ChangeLog +39 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
        * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
14
        (WebCore::GraphicsContextGLANGLE::prepareTextureImpl):
15
        * platform/graphics/angle/GraphicsContextGLANGLE.h:
16
        * platform/graphics/egl/GLContextEGL.cpp:
17
        (WebCore::GLContextEGL::GLContextEGL):
18
        (WebCore::GLContextEGL::createImage const):
19
        (WebCore::GLContextEGL::destroyImage const):
20
        * platform/graphics/egl/GLContextEGL.h:
21
        * platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp:
22
        (Nicosia::GCGLANGLEPipeSource::swapBuffersIfNeeded):
23
        * platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
24
        (WebCore::GraphicsContextGLANGLE::GraphicsContextGLANGLE):
25
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking):
26
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::~EGLImageBacking):
27
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::format const):
28
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::stride const):
29
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::releaseResources):
30
        (WebCore::GraphicsContextGLANGLE::EGLImageBacking::reset):
31
        (WebCore::GraphicsContextGLANGLE::~GraphicsContextGLANGLE):
32
        (WebCore::GraphicsContextGLANGLE::reshapeDisplayBufferBacking):
33
        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
34
        (WebCore::TextureMapperPlatformLayerBuffer::createFromDmabuf):
35
        (WebCore::TextureMapperPlatformLayerBuffer::EGLImageTexture::EGLImageTexture):
36
        (WebCore::TextureMapperPlatformLayerBuffer::EGLImageTexture::~EGLImageTexture):
37
        (WebCore::TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer):
38
        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
39
1
2022-01-17  Youenn Fablet  <youenn@apple.com>
40
2022-01-17  Youenn Fablet  <youenn@apple.com>
2
41
3
        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
42
        Make ServiceWorkerClient.id a UUID instead of a string derived from a ScriptExecutionContextIdentifier
- 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 / +35 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
    gbm_device* m_device { nullptr };
485
    std::unique_ptr<EGLImageBacking> m_textureBacking;
486
    std::unique_ptr<EGLImageBacking> m_compositorTextureBacking;
487
    std::unique_ptr<EGLImageBacking> m_intermediateTextureBacking;
458
#elif USE(TEXTURE_MAPPER)
488
#elif USE(TEXTURE_MAPPER)
459
    std::unique_ptr<TextureMapperGCGLPlatformLayer> m_texmapLayer;
489
    std::unique_ptr<TextureMapperGCGLPlatformLayer> m_texmapLayer;
460
#endif
490
#endif
461
491
462
    friend class ExtensionsGLANGLE;
492
    friend class ExtensionsGLANGLE;
463
#if USE(NICOSIA)
493
#if USE(NICOSIA)
494
    friend class Nicosia::GCGLANGLEPipeSource;
464
    friend class Nicosia::GCGLLayer;
495
    friend class Nicosia::GCGLLayer;
465
#elif USE(TEXTURE_MAPPER)
496
#elif USE(TEXTURE_MAPPER)
466
    friend class TextureMapperGCGLPlatformLayer;
497
    friend class TextureMapperGCGLPlatformLayer;
- a/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp +17 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
    m_eglCreateImage = reinterpret_cast<PFNEGLCREATEIMAGEPROC>(eglGetProcAddress("eglCreateImage"));
369
    m_eglDestroyImage = reinterpret_cast<PFNEGLDESTROYIMAGEPROC>(eglGetProcAddress("eglDestroyImage"));
367
}
370
}
368
371
369
GLContextEGL::~GLContextEGL()
372
GLContextEGL::~GLContextEGL()
Lines 386-391 GLContextEGL::~GLContextEGL() a/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp_sec2
386
#endif
389
#endif
387
}
390
}
388
391
392
EGLImage GLContextEGL::createImage(EGLenum target, EGLClientBuffer clientBuffer, const EGLAttrib* attribList) const
393
{
394
    if (m_eglCreateImage)
395
        return m_eglCreateImage(m_display.eglDisplay(), attribList ? EGL_NO_CONTEXT : m_context, target, clientBuffer, attribList);
396
    return EGL_NO_IMAGE;
397
}
398
399
bool GLContextEGL::destroyImage(EGLImage image) const
400
{
401
    if (m_eglDestroyImage)
402
        return m_eglDestroyImage(m_display.eglDisplay(), image);
403
    return false;
404
}
405
389
bool GLContextEGL::canRenderToDefaultFramebuffer()
406
bool GLContextEGL::canRenderToDefaultFramebuffer()
390
{
407
{
391
    return m_type == WindowSurface;
408
    return m_type == WindowSurface;
- a/Source/WebCore/platform/graphics/egl/GLContextEGL.h +12 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;
42
typedef void *EGLSurface;
46
typedef void *EGLSurface;
47
typedef unsigned EGLenum;
48
49
typedef EGLImage (*PFNEGLCREATEIMAGEPROC) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLAttrib*);
50
typedef EGLBoolean (*PFNEGLDESTROYIMAGEPROC) (EGLDisplay, EGLImage);
43
51
44
namespace WebCore {
52
namespace WebCore {
45
53
Lines 53-58 public: a/Source/WebCore/platform/graphics/egl/GLContextEGL.h_sec2
53
    static const char* lastErrorString();
61
    static const char* lastErrorString();
54
62
55
    EGLConfig config() const { return m_config; }
63
    EGLConfig config() const { return m_config; }
64
    EGLImage createImage(EGLenum target, EGLClientBuffer, const EGLAttrib*) const;
65
    bool destroyImage(EGLImage) const;
56
66
57
    virtual ~GLContextEGL();
67
    virtual ~GLContextEGL();
58
68
Lines 106-111 private: a/Source/WebCore/platform/graphics/egl/GLContextEGL.h_sec3
106
    EGLSurface m_surface { nullptr };
116
    EGLSurface m_surface { nullptr };
107
    EGLConfig m_config { nullptr };
117
    EGLConfig m_config { nullptr };
108
    EGLSurfaceType m_type;
118
    EGLSurfaceType m_type;
119
    PFNEGLCREATEIMAGEPROC m_eglCreateImage { nullptr };
120
    PFNEGLDESTROYIMAGEPROC m_eglDestroyImage { nullptr };
109
#if PLATFORM(X11)
121
#if PLATFORM(X11)
110
    XUniquePixmap m_pixmap;
122
    XUniquePixmap m_pixmap;
111
#endif
123
#endif
- a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp +22 lines
Lines 57-62 void GCGLANGLEPipeSource::swapBuffersIfNeeded() a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGCGLANGLEPipe.cpp_sec1
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 proxyOperation = [this, size, format, stride, fd = m_context.m_compositorTextureBacking->fd()] (TextureMapperPlatformLayerProxy& proxy) mutable {
66
            return proxy.scheduleUpdateOnCompositorThread([this, size, format, stride, fd] () mutable {
67
                auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(platformLayer()->impl()).proxy();
68
                Locker locker { proxy.lock() };
69
70
                if (!proxy.isActive())
71
                    return;
72
73
                proxy.pushNextBuffer(TextureMapperPlatformLayerBuffer::createFromDmabuf(size, format, stride, fd));
74
            });
75
        };
76
        proxyOperation(downcast<Nicosia::ContentLayerTextureMapperImpl>(platformLayer()->impl()).proxy());
77
        m_context.markLayerComposited();
78
        return;
79
    }
80
81
    // 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);
82
    RefPtr<WebCore::ImageBuffer> imageBuffer = ImageBuffer::create(m_context.getInternalFramebufferSize(), RenderingMode::Unaccelerated, 1, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
61
    if (!imageBuffer)
83
    if (!imageBuffer)
62
        return;
84
        return;
- a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp +126 lines
Lines 36-42 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 <fcntl.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"
42
#endif
44
#endif
Lines 51-56 GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attri a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec2
51
#endif
53
#endif
52
#if USE(NICOSIA)
54
#if USE(NICOSIA)
53
    m_nicosiaPipe = makeUnique<Nicosia::GCGLANGLEPipe>(*this);
55
    m_nicosiaPipe = makeUnique<Nicosia::GCGLANGLEPipe>(*this);
56
57
    int fd;
58
    char deviceName[30];
59
    for (int i = 128; i < 192; ++i) {
60
        snprintf(deviceName, sizeof(deviceName), "/dev/dri/renderD%d", i);
61
        fd = open(deviceName, O_RDWR | O_CLOEXEC);
62
        if (fd >= 0) {
63
            m_device = gbm_create_device(fd);
64
            if (m_device)
65
                break;
66
            close(fd);
67
        }
68
    }
69
70
    if (m_device) {
71
        m_textureBacking = makeUnique<EGLImageBacking>(m_device, platformDisplay());
72
        m_compositorTextureBacking = makeUnique<EGLImageBacking>(m_device, platformDisplay());
73
        m_intermediateTextureBacking = makeUnique<EGLImageBacking>(m_device, platformDisplay());
74
    }
54
#else
75
#else
55
    m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
76
    m_texmapLayer = makeUnique<TextureMapperGCGLPlatformLayer>(*this);
56
#endif
77
#endif
Lines 112-122 GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attri a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec3
112
    GL_ClearColor(0, 0, 0, 0);
133
    GL_ClearColor(0, 0, 0, 0);
113
}
134
}
114
135
136
#if USE(NICOSIA)
137
GraphicsContextGLANGLE::EGLImageBacking::EGLImageBacking(gbm_device* device, PlatformGraphicsContextGLDisplay display)
138
    : m_device(device)
139
    , m_display(display)
140
{
141
}
142
143
GraphicsContextGLANGLE::EGLImageBacking::~EGLImageBacking()
144
{
145
    releaseResources();
146
}
147
148
uint32_t GraphicsContextGLANGLE::EGLImageBacking::format() const
149
{
150
    if (m_BO)
151
        return gbm_bo_get_format(m_BO);
152
    return 0;
153
}
154
155
uint32_t GraphicsContextGLANGLE::EGLImageBacking::stride() const
156
{
157
    if (m_BO)
158
        return gbm_bo_get_stride(m_BO);
159
    return 0;
160
}
161
162
void GraphicsContextGLANGLE::EGLImageBacking::releaseResources()
163
{
164
    if (m_BO) {
165
        gbm_bo_destroy(m_BO);
166
        m_BO = nullptr;
167
    }
168
    if (m_image) {
169
        EGL_DestroyImageKHR(m_display, m_image);
170
        m_image = EGL_NO_IMAGE;
171
    }
172
    if (m_FD >= 0) {
173
        close(m_FD);
174
        m_FD = -1;
175
    }
176
}
177
178
bool GraphicsContextGLANGLE::EGLImageBacking::reset(int width, int height, bool hasAlpha)
179
{
180
    releaseResources();
181
182
    if (!width || !height)
183
        return false;
184
185
    m_BO = gbm_bo_create(m_device, width, height, hasAlpha ? GBM_BO_FORMAT_ARGB8888 : GBM_BO_FORMAT_XRGB8888, GBM_BO_USE_RENDERING);
186
    if (m_BO) {
187
        m_FD = gbm_bo_get_fd(m_BO);
188
        if (m_FD >= 0) {
189
            EGLint imageAttributes[] = {
190
                EGL_WIDTH, width,
191
                EGL_HEIGHT, height,
192
                EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLint>(gbm_bo_get_format(m_BO)),
193
                EGL_DMA_BUF_PLANE0_FD_EXT, m_FD,
194
                EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLint>(gbm_bo_get_stride(m_BO)),
195
                EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
196
                EGL_NONE
197
            };
198
            m_image = EGL_CreateImageKHR(m_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, imageAttributes);
199
            if (m_image)
200
                return true;
201
        }
202
    }
203
204
    releaseResources();
205
    return false;
206
}
207
#endif
208
115
GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
209
GraphicsContextGLANGLE::~GraphicsContextGLANGLE()
116
{
210
{
117
    GraphicsContextGLOpenGLManager::sharedManager().removeContext(this);
211
    GraphicsContextGLOpenGLManager::sharedManager().removeContext(this);
118
    bool success = makeContextCurrent();
212
    bool success = makeContextCurrent();
119
    ASSERT_UNUSED(success, success);
213
    ASSERT_UNUSED(success, success);
214
215
#if USE(NICOSIA)
216
    if (m_device)
217
        gbm_device_destroy(m_device);
218
#endif
219
120
    if (m_texture)
220
    if (m_texture)
121
        GL_DeleteTextures(1, &m_texture);
221
        GL_DeleteTextures(1, &m_texture);
122
#if USE(COORDINATED_GRAPHICS)
222
#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;
289
    GLuint colorFormat = attrs.alpha ? GL_RGBA : GL_RGB;
190
    GLenum textureTarget = drawingBufferTextureTarget();
290
    GLenum textureTarget = drawingBufferTextureTarget();
191
    GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
291
    GLuint internalColorFormat = textureTarget == GL_TEXTURE_2D ? colorFormat : m_internalColorFormat;
292
293
#if USE(NICOSIA)
294
    if (m_device) {
295
        ASSERT(m_textureBacking && m_compositorTextureBacking && m_intermediateTextureBacking);
296
        m_textureBacking->reset(width, height, attrs.alpha);
297
        m_compositorTextureBacking->reset(width, height, attrs.alpha);
298
        m_intermediateTextureBacking->reset(width, height, attrs.alpha);
299
    }
300
#endif
301
192
    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
302
    ScopedRestoreTextureBinding restoreBinding(drawingBufferTextureTargetQueryForDrawingTarget(textureTarget), textureTarget, textureTarget != TEXTURE_RECTANGLE_ARB);
193
#if USE(COORDINATED_GRAPHICS)
303
#if USE(COORDINATED_GRAPHICS)
194
    if (m_compositorTexture) {
304
    if (m_compositorTexture) {
195
        GL_BindTexture(textureTarget, m_compositorTexture);
305
        GL_BindTexture(textureTarget, m_compositorTexture);
306
#if USE(NICOSIA)
307
        if (m_compositorTextureBacking && m_compositorTextureBacking->image())
308
            GL_EGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_compositorTextureBacking->image());
309
        else
310
#endif
196
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
311
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
197
        GL_BindTexture(textureTarget, m_intermediateTexture);
312
        GL_BindTexture(textureTarget, m_intermediateTexture);
313
#if USE(NICOSIA)
314
        if (m_intermediateTextureBacking && m_intermediateTextureBacking->image())
315
            GL_EGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_intermediateTextureBacking->image());
316
        else
317
#endif
198
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
318
        GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
199
    }
319
    }
200
#endif
320
#endif
201
    GL_BindTexture(textureTarget, m_texture);
321
    GL_BindTexture(textureTarget, m_texture);
322
#if USE(NICOSIA)
323
    if (m_textureBacking && m_textureBacking->image())
324
        GL_EGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_textureBacking->image());
325
    else
326
#endif
202
    GL_TexImage2D(textureTarget, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
327
    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);
328
    GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, m_texture, 0);
329
204
    return true;
330
    return true;
205
}
331
}
206
332
- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp +57 lines
Lines 31-36 a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp_sec1
31
#include "FloatRect.h"
31
#include "FloatRect.h"
32
#include "NotImplemented.h"
32
#include "NotImplemented.h"
33
33
34
#if USE(ANGLE) && USE(NICOSIA)
35
#include "GLContextEGL.h"
36
#include "GraphicsContextGLANGLE.h"
37
#include "gbm.h"
38
#endif
39
34
namespace WebCore {
40
namespace WebCore {
35
41
36
TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&& texture, TextureMapperGL::Flags flags)
42
TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&& texture, TextureMapperGL::Flags flags)
Lines 46-51 TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(GLuint textur a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp_sec2
46
{
52
{
47
}
53
}
48
54
55
#if USE(ANGLE) && USE(NICOSIA)
56
std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerBuffer::createFromDmabuf(IntSize size, uint32_t format, uint32_t stride, int fd)
57
{
58
    auto* context = GLContext::current();
59
    ASSERT(context->isEGLContext());
60
61
    EGLAttrib imageAttributes[] = {
62
        EGL_WIDTH, size.width(),
63
        EGL_HEIGHT, size.height(),
64
        EGL_LINUX_DRM_FOURCC_EXT, static_cast<EGLAttrib>(format),
65
        EGL_DMA_BUF_PLANE0_FD_EXT, fd,
66
        EGL_DMA_BUF_PLANE0_PITCH_EXT, static_cast<EGLAttrib>(stride),
67
        EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
68
        EGL_NONE
69
    };
70
    auto image = downcast<GLContextEGL>(*context).createImage(EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)nullptr, imageAttributes);
71
    if (!image)
72
        return nullptr;
73
74
    auto texmapFormat = (format == GBM_BO_FORMAT_ARGB8888) ? GL_RGBA : GL_RGB;
75
    int texmapFlags = TextureMapperGL::ShouldFlipTexture;
76
    if (texmapFormat == GL_RGBA)
77
        texmapFlags |= TextureMapperGL::ShouldBlend;
78
79
    return std::unique_ptr<TextureMapperPlatformLayerBuffer>(new TextureMapperPlatformLayerBuffer(image, size, texmapFlags, texmapFormat));
80
}
81
82
TextureMapperPlatformLayerBuffer::EGLImageTexture::EGLImageTexture(EGLImage image)
83
    : image(image)
84
{
85
    glGenTextures(1, &id);
86
    glBindTexture(GL_TEXTURE_2D, id);
87
    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
88
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90
}
91
92
TextureMapperPlatformLayerBuffer::EGLImageTexture::~EGLImageTexture()
93
{
94
    auto* ctx = GLContext::current();
95
96
    ASSERT(ctx && is<GLContextEGL>(*ctx));
97
    RELEASE_ASSERT(downcast<GLContextEGL>(*ctx).destroyImage(image));
98
}
99
100
TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(EGLImage image, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat)
101
    : TextureMapperPlatformLayerBuffer({ EGLImageTexture { image } }, size, flags, internalFormat)
102
{
103
}
104
#endif
105
49
TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(TextureVariant&& variant, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat)
106
TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(TextureVariant&& variant, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat)
50
    : m_variant(WTFMove(variant))
107
    : m_variant(WTFMove(variant))
51
    , m_size(size)
108
    , m_size(size)
- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h +16 lines
Lines 33-38 a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec1
33
#include <variant>
33
#include <variant>
34
#include <wtf/MonotonicTime.h>
34
#include <wtf/MonotonicTime.h>
35
35
36
typedef void *EGLImage;
37
36
namespace WebCore {
38
namespace WebCore {
37
39
38
class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer {
40
class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer {
Lines 60-65 public: a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec2
60
62
61
    TextureMapperPlatformLayerBuffer(TextureVariant&&, const IntSize&, TextureMapperGL::Flags, GLint internalFormat);
63
    TextureMapperPlatformLayerBuffer(TextureVariant&&, const IntSize&, TextureMapperGL::Flags, GLint internalFormat);
62
64
65
#if USE(ANGLE) && USE(NICOSIA)
66
    static std::unique_ptr<TextureMapperPlatformLayerBuffer> createFromDmabuf(IntSize, uint32_t format, uint32_t stride, int fd);
67
#endif
68
63
    virtual ~TextureMapperPlatformLayerBuffer();
69
    virtual ~TextureMapperPlatformLayerBuffer();
64
70
65
    void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) final;
71
    void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) final;
Lines 100-105 public: a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h_sec3
100
    const TextureVariant& textureVariant() { return m_variant; }
106
    const TextureVariant& textureVariant() { return m_variant; }
101
107
102
private:
108
private:
109
#if USE(ANGLE) && USE(NICOSIA)
110
    struct EGLImageTexture : public RGBTexture {
111
        EGLImageTexture(EGLImage);
112
        ~EGLImageTexture();
113
114
        EGLImage image;
115
    };
116
117
    TextureMapperPlatformLayerBuffer(EGLImage, const IntSize&, TextureMapperGL::Flags, GLint internalFormat);
118
#endif
103
119
104
    RefPtr<BitmapTexture> m_texture;
120
    RefPtr<BitmapTexture> m_texture;
105
    MonotonicTime m_timeLastUsed;
121
    MonotonicTime m_timeLastUsed;

Return to Bug 235946