- a/Source/WebCore/Headers.cmake -1 lines
Lines 2090-2096 set(WebCore_PRIVATE_FRAMEWORK_HEADERS a/Source/WebCore/Headers.cmake_sec1
2090
    platform/graphics/cv/ImageTransferSessionVT.h
2090
    platform/graphics/cv/ImageTransferSessionVT.h
2091
2091
2092
    platform/graphics/egl/GLContext.h
2092
    platform/graphics/egl/GLContext.h
2093
    platform/graphics/egl/GLContextWrapper.h
2094
2093
2095
    platform/graphics/filters/DistantLightSource.h
2094
    platform/graphics/filters/DistantLightSource.h
2096
    platform/graphics/filters/FEBlend.h
2095
    platform/graphics/filters/FEBlend.h
- a/Source/WebCore/PlatformPlayStation.cmake -1 lines
Lines 38-44 list(APPEND WebCore_SOURCES a/Source/WebCore/PlatformPlayStation.cmake_sec1
38
38
39
    platform/graphics/egl/GLContext.cpp
39
    platform/graphics/egl/GLContext.cpp
40
    platform/graphics/egl/GLContextLibWPE.cpp
40
    platform/graphics/egl/GLContextLibWPE.cpp
41
    platform/graphics/egl/GLContextWrapper.cpp
42
41
43
    platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
42
    platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
44
43
- a/Source/WebCore/PlatformWin.cmake -1 lines
Lines 55-61 list(APPEND WebCore_SOURCES a/Source/WebCore/PlatformWin.cmake_sec1
55
    platform/graphics/angle/PlatformDisplayANGLE.cpp
55
    platform/graphics/angle/PlatformDisplayANGLE.cpp
56
56
57
    platform/graphics/egl/GLContext.cpp
57
    platform/graphics/egl/GLContext.cpp
58
    platform/graphics/egl/GLContextWrapper.cpp
59
58
60
    platform/graphics/opentype/OpenTypeUtilities.cpp
59
    platform/graphics/opentype/OpenTypeUtilities.cpp
61
60
- a/Source/WebCore/SourcesGTK.txt -1 lines
Lines 60-66 platform/graphics/PlatformDisplay.cpp @no-unify a/Source/WebCore/SourcesGTK.txt_sec1
60
platform/graphics/angle/PlatformDisplayANGLE.cpp @no-unify
60
platform/graphics/angle/PlatformDisplayANGLE.cpp @no-unify
61
61
62
platform/graphics/egl/GLContext.cpp @no-unify
62
platform/graphics/egl/GLContext.cpp @no-unify
63
platform/graphics/egl/GLContextWrapper.cpp @no-unify
64
platform/graphics/egl/PlatformDisplaySurfaceless.cpp @no-unify
63
platform/graphics/egl/PlatformDisplaySurfaceless.cpp @no-unify
65
64
66
platform/graphics/gbm/GBMBufferSwapchain.cpp
65
platform/graphics/gbm/GBMBufferSwapchain.cpp
- a/Source/WebCore/SourcesWPE.txt -1 lines
Lines 61-67 platform/graphics/wpe/SystemFontDatabaseWPE.cpp a/Source/WebCore/SourcesWPE.txt_sec1
61
61
62
platform/graphics/egl/GLContext.cpp @no-unify
62
platform/graphics/egl/GLContext.cpp @no-unify
63
platform/graphics/egl/GLContextLibWPE.cpp @no-unify
63
platform/graphics/egl/GLContextLibWPE.cpp @no-unify
64
platform/graphics/egl/GLContextWrapper.cpp @no-unify
65
platform/graphics/egl/PlatformDisplaySurfaceless.cpp @no-unify
64
platform/graphics/egl/PlatformDisplaySurfaceless.cpp @no-unify
66
65
67
platform/graphics/gbm/GBMBufferSwapchain.cpp
66
platform/graphics/gbm/GBMBufferSwapchain.cpp
- a/Source/WebCore/platform/graphics/egl/GLContext.cpp -36 / +41 lines
Lines 22-27 a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec1
22
#if USE(EGL)
22
#if USE(EGL)
23
#include "GraphicsContextGL.h"
23
#include "GraphicsContextGL.h"
24
#include "Logging.h"
24
#include "Logging.h"
25
#include <wtf/ThreadSpecific.h>
25
#include <wtf/Vector.h>
26
#include <wtf/Vector.h>
26
#include <wtf/text/StringToIntegerConversion.h>
27
#include <wtf/text/StringToIntegerConversion.h>
27
28
Lines 37-42 a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec2
37
38
38
namespace WebCore {
39
namespace WebCore {
39
40
41
static ThreadSpecific<GLContext*>& currentContext()
42
{
43
    static ThreadSpecific<GLContext*>* context;
44
    static std::once_flag flag;
45
    std::call_once(flag, [] {
46
        context = new ThreadSpecific<GLContext*>();
47
    });
48
    return *context;
49
}
50
40
const char* GLContext::errorString(int statusCode)
51
const char* GLContext::errorString(int statusCode)
41
{
52
{
42
    static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int");
53
    static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int");
Lines 398-403 GLContext::~GLContext() a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec3
398
#if USE(WPE_RENDERER)
409
#if USE(WPE_RENDERER)
399
    destroyWPETarget();
410
    destroyWPETarget();
400
#endif
411
#endif
412
413
    if (this == *currentContext())
414
        *currentContext() = nullptr;
401
}
415
}
402
416
403
EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDisplay, EGLConfig config, EGLContext sharingContext)
417
EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDisplay, EGLConfig config, EGLContext sharingContext)
Lines 416-448 EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDispla a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec4
416
    return eglCreateContext(platformDisplay.eglDisplay(), config, sharingContext, contextAttributes);
430
    return eglCreateContext(platformDisplay.eglDisplay(), config, sharingContext, contextAttributes);
417
}
431
}
418
432
419
bool GLContext::makeCurrentImpl()
433
bool GLContext::makeContextCurrent()
420
{
434
{
421
    ASSERT(m_context);
435
    ASSERT(m_context);
422
    return eglMakeCurrent(m_display.eglDisplay(), m_surface, m_surface, m_context);
423
}
424
436
425
bool GLContext::unmakeCurrentImpl()
437
    *currentContext() = this;
426
{
438
    if (eglGetCurrentContext() == m_context)
427
    return eglMakeCurrent(m_display.eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
439
        return true;
428
}
429
440
430
bool GLContext::makeContextCurrent()
441
    return eglMakeCurrent(m_display.eglDisplay(), m_surface, m_surface, m_context);
431
{
432
    return makeCurrent();
433
}
442
}
434
443
435
bool GLContext::unmakeContextCurrent()
444
bool GLContext::unmakeContextCurrent()
436
{
445
{
437
    return unmakeCurrent();
446
    if (this != *currentContext())
447
        return false;
448
449
    eglMakeCurrent(m_display.eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
450
    *currentContext() = nullptr;
451
452
    return true;
438
}
453
}
439
454
440
GLContext* GLContext::current()
455
GLContext* GLContext::current()
441
{
456
{
442
    auto* context = currentContext();
457
    return *currentContext();
443
    if (context && context->type() == GLContextWrapper::Type::Native)
444
        return static_cast<GLContext*>(context);
445
    return nullptr;
446
}
458
}
447
459
448
void GLContext::swapBuffers()
460
void GLContext::swapBuffers()
Lines 515-529 const GLContext::GLExtensions& GLContext::glExtensions() const a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec5
515
GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context)
527
GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context)
516
    : m_context(WTFMove(context))
528
    : m_context(WTFMove(context))
517
{
529
{
518
    auto eglContext = eglGetCurrentContext();
530
    m_previous.context = eglGetCurrentContext();
519
    m_previous.glContext = GLContext::current();
531
    if (m_previous.context) {
520
    if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) {
532
        m_previous.display = eglGetCurrentDisplay();
521
        m_previous.context = eglContext;
533
        m_previous.readSurface = eglGetCurrentSurface(EGL_READ);
522
        if (m_previous.context != EGL_NO_CONTEXT) {
534
        m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW);
523
            m_previous.display = eglGetCurrentDisplay();
524
            m_previous.readSurface = eglGetCurrentSurface(EGL_READ);
525
            m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW);
526
        }
527
    }
535
    }
528
    m_context->makeContextCurrent();
536
    m_context->makeContextCurrent();
529
}
537
}
Lines 531-555 GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec6
531
GLContext::ScopedGLContext::~ScopedGLContext()
539
GLContext::ScopedGLContext::~ScopedGLContext()
532
{
540
{
533
    m_context = nullptr;
541
    m_context = nullptr;
534
542
    if (m_previous.context)
535
    if (m_previous.context != EGL_NO_CONTEXT)
536
        eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context);
543
        eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context);
537
    else if (m_previous.glContext)
538
        m_previous.glContext->makeContextCurrent();
539
}
544
}
540
545
541
GLContext::ScopedGLContextCurrent::ScopedGLContextCurrent(GLContext& context)
546
GLContext::ScopedGLContextCurrent::ScopedGLContextCurrent(GLContext& context)
542
    : m_context(context)
547
    : m_context(context)
543
{
548
{
544
    auto eglContext = eglGetCurrentContext();
549
    auto eglContext = eglGetCurrentContext();
545
    m_previous.glContext = GLContext::current();
550
    m_previous.glContext = *currentContext();
546
    if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) {
551
    if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) {
547
        m_previous.context = eglContext;
552
        m_previous.context = eglContext;
548
        if (m_previous.context != EGL_NO_CONTEXT) {
553
        m_previous.display = eglGetCurrentDisplay();
549
            m_previous.display = eglGetCurrentDisplay();
554
        m_previous.readSurface = eglGetCurrentSurface(EGL_READ);
550
            m_previous.readSurface = eglGetCurrentSurface(EGL_READ);
555
        m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW);
551
            m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW);
552
        }
553
    }
556
    }
554
    m_context.makeContextCurrent();
557
    m_context.makeContextCurrent();
555
}
558
}
Lines 561-570 GLContext::ScopedGLContextCurrent::~ScopedGLContextCurrent() a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec7
561
        return;
564
        return;
562
    }
565
    }
563
566
564
    m_context.unmakeContextCurrent();
565
566
    if (m_previous.context)
567
    if (m_previous.context)
567
        eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context);
568
        eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context);
569
    else
570
        m_context.unmakeContextCurrent();
571
572
    *currentContext() = m_previous.glContext;
568
}
573
}
569
574
570
} // namespace WebCore
575
} // namespace WebCore
- a/Source/WebCore/platform/graphics/egl/GLContext.h -8 / +1 lines
Lines 20-26 a/Source/WebCore/platform/graphics/egl/GLContext.h_sec1
20
#pragma once
20
#pragma once
21
21
22
#if USE(EGL)
22
#if USE(EGL)
23
#include "GLContextWrapper.h"
24
#include "IntSize.h"
23
#include "IntSize.h"
25
#include "PlatformDisplay.h"
24
#include "PlatformDisplay.h"
26
#include <wtf/Noncopyable.h>
25
#include <wtf/Noncopyable.h>
Lines 44-50 typedef void* EGLSurface; a/Source/WebCore/platform/graphics/egl/GLContext.h_sec2
44
43
45
namespace WebCore {
44
namespace WebCore {
46
45
47
class GLContext final : public GLContextWrapper {
46
class GLContext {
48
    WTF_MAKE_NONCOPYABLE(GLContext); WTF_MAKE_FAST_ALLOCATED;
47
    WTF_MAKE_NONCOPYABLE(GLContext); WTF_MAKE_FAST_ALLOCATED;
49
public:
48
public:
50
    WEBCORE_EXPORT static std::unique_ptr<GLContext> create(GLNativeWindowType, PlatformDisplay&);
49
    WEBCORE_EXPORT static std::unique_ptr<GLContext> create(GLNativeWindowType, PlatformDisplay&);
Lines 86-92 public: a/Source/WebCore/platform/graphics/egl/GLContext.h_sec3
86
        ~ScopedGLContext();
85
        ~ScopedGLContext();
87
    private:
86
    private:
88
        struct {
87
        struct {
89
            GLContext* glContext { nullptr };
90
            EGLDisplay display { nullptr };
88
            EGLDisplay display { nullptr };
91
            EGLContext context { nullptr };
89
            EGLContext context { nullptr };
92
            EGLSurface readSurface { nullptr };
90
            EGLSurface readSurface { nullptr };
Lines 125-135 private: a/Source/WebCore/platform/graphics/egl/GLContext.h_sec4
125
123
126
    static bool getEGLConfig(PlatformDisplay&, EGLConfig*, EGLSurfaceType);
124
    static bool getEGLConfig(PlatformDisplay&, EGLConfig*, EGLSurfaceType);
127
125
128
    // GLContextWrapper
129
    GLContextWrapper::Type type() const override { return GLContextWrapper::Type::Native; }
130
    bool makeCurrentImpl() override;
131
    bool unmakeCurrentImpl() override;
132
133
    PlatformDisplay& m_display;
126
    PlatformDisplay& m_display;
134
    unsigned m_version { 0 };
127
    unsigned m_version { 0 };
135
    EGLContext m_context { nullptr };
128
    EGLContext m_context { nullptr };
- a/Source/WebCore/platform/graphics/egl/GLContextWrapper.cpp -67 lines
Lines 1-67 a/Source/WebCore/platform/graphics/egl/GLContextWrapper.cpp_sec1
1
/*
2
 * Copyright (C) 2024 Igalia S.L.
3
 *
4
 *  This library is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU Lesser General Public
6
 *  License as published by the Free Software Foundation; either
7
 *  version 2 of the License, or (at your option) any later version.
8
 *
9
 *  This library is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 *  Lesser General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU Lesser General Public
15
 *  License along with this library; if not, write to the Free
16
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 *  Boston, MA 02110-1301 USA
18
 */
19
20
#include "config.h"
21
#include "GLContextWrapper.h"
22
23
#if USE(EGL)
24
namespace WebCore {
25
26
static thread_local constinit GLContextWrapper* s_currentContext = nullptr;
27
28
GLContextWrapper::~GLContextWrapper()
29
{
30
    if (s_currentContext == this)
31
        s_currentContext = nullptr;
32
}
33
34
GLContextWrapper* GLContextWrapper::currentContext()
35
{
36
    return s_currentContext;
37
}
38
39
bool GLContextWrapper::makeCurrent()
40
{
41
    if (s_currentContext == this)
42
        return true;
43
44
    if (makeCurrentImpl()) {
45
        s_currentContext = this;
46
        return true;
47
    }
48
49
    return false;
50
}
51
52
bool GLContextWrapper::unmakeCurrent()
53
{
54
    if (s_currentContext != this)
55
        return false;
56
57
    if (unmakeCurrentImpl()) {
58
        s_currentContext = nullptr;
59
        return true;
60
    }
61
62
    return false;
63
}
64
65
} // namespace WebCore
66
67
#endif // USE(EGL)
- a/Source/WebCore/platform/graphics/egl/GLContextWrapper.h -46 lines
Lines 1-46 a/Source/WebCore/platform/graphics/egl/GLContextWrapper.h_sec1
1
/*
2
 * Copyright (C) 2024 Igalia S.L.
3
 *
4
 *  This library is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU Lesser General Public
6
 *  License as published by the Free Software Foundation; either
7
 *  version 2 of the License, or (at your option) any later version.
8
 *
9
 *  This library is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 *  Lesser General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU Lesser General Public
15
 *  License along with this library; if not, write to the Free
16
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 *  Boston, MA 02110-1301 USA
18
 */
19
20
#pragma once
21
22
#if USE(EGL)
23
24
namespace WebCore {
25
26
class GLContextWrapper {
27
public:
28
    GLContextWrapper() = default;
29
    ~GLContextWrapper();
30
31
    enum class Type : uint8_t { Native, Angle };
32
    virtual Type type() const = 0;
33
34
    bool makeCurrent();
35
    bool unmakeCurrent();
36
37
protected:
38
    virtual bool makeCurrentImpl() = 0;
39
    virtual bool unmakeCurrentImpl() = 0;
40
41
    static GLContextWrapper* currentContext();
42
};
43
44
} // namespace WebCore
45
46
#endif // USE(EGL)
- a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp -16 / +1 lines
Lines 95-101 GraphicsContextGLANGLE::~GraphicsContextGLANGLE() a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec1
95
95
96
bool GraphicsContextGLANGLE::makeContextCurrent()
96
bool GraphicsContextGLANGLE::makeContextCurrent()
97
{
97
{
98
    return static_cast<GraphicsContextGLTextureMapperANGLE*>(this)->makeCurrent();
98
    return !!EGL_MakeCurrent(m_displayObj, m_surfaceObj, m_surfaceObj, m_contextObj);
99
}
99
}
100
100
101
void GraphicsContextGLANGLE::checkGPUStatus()
101
void GraphicsContextGLANGLE::checkGPUStatus()
Lines 353-373 void GraphicsContextGLTextureMapperANGLE::prepareForDisplay() a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp_sec2
353
    swapCompositorTexture();
353
    swapCompositorTexture();
354
}
354
}
355
355
356
GLContextWrapper::Type GraphicsContextGLTextureMapperANGLE::type() const
357
{
358
    return GLContextWrapper::Type::Angle;
359
}
360
361
bool GraphicsContextGLTextureMapperANGLE::makeCurrentImpl()
362
{
363
    return !!EGL_MakeCurrent(m_displayObj, m_surfaceObj, m_surfaceObj, m_contextObj);
364
}
365
366
bool GraphicsContextGLTextureMapperANGLE::unmakeCurrentImpl()
367
{
368
    return !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
369
}
370
371
} // namespace WebCore
356
} // namespace WebCore
372
357
373
#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER)
358
#endif // ENABLE(WEBGL) && USE(TEXTURE_MAPPER)
- a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h -7 / +1 lines
Lines 27-33 a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h_sec1
27
27
28
#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER)
28
#if ENABLE(WEBGL) && USE(TEXTURE_MAPPER)
29
29
30
#include "GLContextWrapper.h"
31
#include "GraphicsContextGLANGLE.h"
30
#include "GraphicsContextGLANGLE.h"
32
31
33
#if USE(NICOSIA)
32
#if USE(NICOSIA)
Lines 40-46 namespace WebCore { a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h_sec2
40
39
41
class TextureMapperGCGLPlatformLayer;
40
class TextureMapperGCGLPlatformLayer;
42
41
43
class WEBCORE_EXPORT GraphicsContextGLTextureMapperANGLE : public GraphicsContextGLANGLE, public GLContextWrapper {
42
class WEBCORE_EXPORT GraphicsContextGLTextureMapperANGLE : public GraphicsContextGLANGLE {
44
public:
43
public:
45
    static RefPtr<GraphicsContextGLTextureMapperANGLE> create(WebCore::GraphicsContextGLAttributes&&);
44
    static RefPtr<GraphicsContextGLTextureMapperANGLE> create(WebCore::GraphicsContextGLAttributes&&);
46
    virtual ~GraphicsContextGLTextureMapperANGLE();
45
    virtual ~GraphicsContextGLTextureMapperANGLE();
Lines 71-81 private: a/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.h_sec3
71
    GCGLuint setupCurrentTexture();
70
    GCGLuint setupCurrentTexture();
72
#endif
71
#endif
73
72
74
    // GLContextWrapper
75
    GLContextWrapper::Type type() const override;
76
    bool makeCurrentImpl() override;
77
    bool unmakeCurrentImpl() override;
78
79
    RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
73
    RefPtr<GraphicsLayerContentsDisplayDelegate> m_layerContentsDisplayDelegate;
80
74
81
    GCGLuint m_compositorTexture { 0 };
75
    GCGLuint m_compositorTexture { 0 };

Return to Bug 270113