[GTK] Add ANGLE backend to GTK port
authorchangseok@webkit.org <changseok@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Nov 2019 23:59:11 +0000 (23:59 +0000)
committerchangseok@webkit.org <changseok@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Nov 2019 23:59:11 +0000 (23:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199060

Reviewed by Žan Doberšek.

.:

This change brings ANGLE support for WebGL to GTK port. USE_ANGLE_WEBGL
is newly defined in OptionGTK.cmake, and turns on the USE_ANGLE_EGL flag.

* Source/cmake/OptionsGTK.cmake: USE_ANGLE_WEBGL added.

Source/ThirdParty/ANGLE:

* CMakeLists.txt: When USE_ANGLE_WEBGL is enabled, necessary glesv2 entry points headers
  are installed in the derived source directory. And then adjust-angle-include-path.sh is applied
  to change include paths in the entry points header files.
* GLESv2.cmake: libglesv2_entry_points_headers is newly defined, which is a gathering of
  entry point headers of libGLESv2.
* PlatformGTK.cmake: In this file, we append gl and glx related angle code as a build target.
  Since we want gl context and gles context simultaneously, we remove gl prototype calls
  from the generated libGLESv2 library. Instead, we invoke egl and gl calls of ANGLE
  via their non-prototype function names.
* adjust-angle-include-paths.sh: sed is slightly different in unix and linux systems.
  In particular, its inplace option needs to be changed for better compatibility on linux.
* include/CMakeLists.txt: ANGLE_WEBGL_HEADERS is newly defined. It gathers header files of ANGLE
  for WebGL support.

Source/WebCore:

This change aims to bring ANGLE support for WebGL to GTK port. The port
wants to have a gl context for texture mapper and a gles/egl context for webgl
simultaneously, we adopt the readPixel-copyToTexture approach for now because
sharing textures between the two different contextes is not a feasible direction.
Also, to avoid conflicts between gl and gles calls, we use non-prototype functions
of ANGLE for WebGL context (i.e., GraphicsContext3D). Although many combinations
of graphic configurations exist, only default configuration (Nicosia layers
running on ANGLE + GLX is supported. Other combinations like ANGLE + GLES or WPE
will be covered by following patches.

No new tests since no functionality changed.

* Headers.cmake:
* PlatformGTK.cmake:
* SourcesGTK.txt:
* platform/TextureMapper.cmake:
* platform/graphics/ANGLEWebKitBridge.h:
* platform/graphics/GLContext.cpp:
* platform/graphics/GLContext.h:
* platform/graphics/GraphicsContext3D.h:
* platform/graphics/OpenGLShims.cpp:
(WebCore::initializeOpenGLShims):
* platform/graphics/OpenGLShims.h:
* platform/graphics/PlatformDisplay.cpp:
* platform/graphics/angle/GraphicsContext3DANGLE.cpp:
(WebCore::GraphicsContext3D::reshapeFBOs):
(WebCore::GraphicsContext3D::prepareTexture):
* platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp: Added.
(Nicosia::GC3DANGLELayer::ANGLEContext::errorString):
(Nicosia::GC3DANGLELayer::ANGLEContext::lastErrorString):
(Nicosia::GC3DANGLELayer::ANGLEContext::createContext):
(Nicosia::GC3DANGLELayer::ANGLEContext::ANGLEContext):
(Nicosia::GC3DANGLELayer::ANGLEContext::~ANGLEContext):
(Nicosia::GC3DANGLELayer::ANGLEContext::makeContextCurrent):
(Nicosia::GC3DANGLELayer::ANGLEContext::platformContext):
(Nicosia::GC3DANGLELayer::GC3DANGLELayer):
(Nicosia::GC3DANGLELayer::~GC3DANGLELayer):
(Nicosia::GC3DANGLELayer::makeContextCurrent):
(Nicosia::GC3DANGLELayer::platformContext):
* platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h: Copied from Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h.
* platform/graphics/nicosia/texmap/NicosiaGC3DLayer.cpp:
(Nicosia::GC3DLayer::GC3DLayer):
(Nicosia::GC3DLayer::swapBuffersIfNeeded):
* platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h:
* platform/graphics/texmap/BitmapTextureGL.cpp:
(WebCore::BitmapTextureGL::setPendingContents):
(WebCore::BitmapTextureGL::updatePendingContents):
* platform/graphics/texmap/BitmapTextureGL.h:
* platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp:
(WebCore::GraphicsContext3D::create):
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::GraphicsContext3D::~GraphicsContext3D):
* platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
(WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper):
* platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
(WebCore::TextureMapperPlatformLayerProxy::pushNextBuffer):

Source/WebKit:

* UIProcess/API/glib/WebKitProtocolHandler.cpp: Extention3DANGLE is used instead
  where ANGLE for WebGL is enabled.
* UIProcess/gtk/AcceleratedBackingStoreWayland.cpp: Append gl extensions for ANGLE.
(WebKit::AcceleratedBackingStoreWayland::checkRequirements):

Source/WTF:

The GTK port uses TEXTURE_MAPPER that has a gl context for accelerated rendering,
and ANGLE has an egl context for WebGL. We want to make both live together
so an exception is made where TEXTURE_MAPPER is enabled.

* wtf/Platform.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252717 268f45cc-cd09-0410-ab3c-d52691b4dbfc

35 files changed:
ChangeLog
Source/ThirdParty/ANGLE/CMakeLists.txt
Source/ThirdParty/ANGLE/ChangeLog
Source/ThirdParty/ANGLE/GLESv2.cmake
Source/ThirdParty/ANGLE/PlatformGTK.cmake
Source/ThirdParty/ANGLE/adjust-angle-include-paths.sh
Source/ThirdParty/ANGLE/include/CMakeLists.txt
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/Headers.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/SourcesGTK.txt
Source/WebCore/platform/TextureMapper.cmake
Source/WebCore/platform/graphics/ANGLEWebKitBridge.h
Source/WebCore/platform/graphics/GLContext.cpp
Source/WebCore/platform/graphics/GLContext.h
Source/WebCore/platform/graphics/GraphicsContext3D.h
Source/WebCore/platform/graphics/OpenGLShims.cpp
Source/WebCore/platform/graphics/OpenGLShims.h
Source/WebCore/platform/graphics/PlatformDisplay.cpp
Source/WebCore/platform/graphics/angle/GraphicsContext3DANGLE.cpp
Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h [new file with mode: 0644]
Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.cpp
Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h
Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp
Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h
Source/WebCore/platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/glib/WebKitProtocolHandler.cpp
Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp
Source/cmake/OptionsGTK.cmake

index 4f5188f..309af19 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2019-11-20  ChangSeok Oh  <changseok@webkit.org>
+
+        [GTK] Add ANGLE backend to GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=199060
+
+        Reviewed by Žan Doberšek.
+
+        This change brings ANGLE support for WebGL to GTK port. USE_ANGLE_WEBGL
+        is newly defined in OptionGTK.cmake, and turns on the USE_ANGLE_EGL flag.
+
+        * Source/cmake/OptionsGTK.cmake: USE_ANGLE_WEBGL added.
+
 2019-11-19  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: DOM.highlightSelector should work for "div, div::before"
index ab6902a..43fddf8 100644 (file)
@@ -136,6 +136,27 @@ else ()
     )
 endif ()
 
+if (USE_ANGLE_WEBGL)
+    WEBKIT_COPY_FILES(LibGLESv2EntryPointsHeaders
+        DESTINATION ${ANGLE_FRAMEWORK_HEADERS_DIR}/ANGLE
+        FILES ${libglesv2_entry_points_headers}
+        FLATTENED
+    )
+
+    add_custom_command(
+        OUTPUT ${ANGLE_FRAMEWORK_HEADERS_DIR}/ANGLE/angle.timestamp
+        DEPENDS LibGLESv2EntryPointsHeaders ANGLEWebGLHeaders
+        COMMAND BUILT_PRODUCTS_DIR=${ANGLE_FRAMEWORK_HEADERS_DIR}
+            PUBLIC_HEADERS_FOLDER_PATH=ANGLE
+            ${CMAKE_CURRENT_SOURCE_DIR}/adjust-angle-include-paths.sh
+        VERBATIM
+    )
+    add_custom_target(ANGLE-webgl-headers
+        DEPENDS ${ANGLE_FRAMEWORK_HEADERS_DIR}/ANGLE/angle.timestamp
+    )
+    add_dependencies(ANGLEFramework ANGLE-webgl-headers)
+endif ()
+
 if (COMPILER_IS_GCC_OR_CLANG)
     WEBKIT_ADD_TARGET_CXX_FLAGS(ANGLE -Wno-cast-align
                                       -Wno-suggest-attribute=format
index 6d2a9f1..c5a302d 100644 (file)
@@ -1,3 +1,24 @@
+2019-11-20  ChangSeok Oh  <changseok@webkit.org>
+
+        [GTK] Add ANGLE backend to GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=199060
+
+        Reviewed by Žan Doberšek.
+
+        * CMakeLists.txt: When USE_ANGLE_WEBGL is enabled, necessary glesv2 entry points headers
+          are installed in the derived source directory. And then adjust-angle-include-path.sh is applied
+          to change include paths in the entry points header files.
+        * GLESv2.cmake: libglesv2_entry_points_headers is newly defined, which is a gathering of
+          entry point headers of libGLESv2.
+        * PlatformGTK.cmake: In this file, we append gl and glx related angle code as a build target.
+          Since we want gl context and gles context simultaneously, we remove gl prototype calls
+          from the generated libGLESv2 library. Instead, we invoke egl and gl calls of ANGLE
+          via their non-prototype function names.
+        * adjust-angle-include-paths.sh: sed is slightly different in unix and linux systems.
+          In particular, its inplace option needs to be changed for better compatibility on linux.
+        * include/CMakeLists.txt: ANGLE_WEBGL_HEADERS is newly defined. It gathers header files of ANGLE
+          for WebGL support.
+
 2019-11-08  Dean Jackson  <dino@apple.com>
 
         Add ANGLE backend for iOS device
index e4be625..aa5cc3c 100644 (file)
@@ -1101,6 +1101,13 @@ set(libglesv2_sources
     src/libGLESv2/resource.h
 )
 
+set(libglesv2_entry_points_headers
+    src/libGLESv2/entry_points_egl.h
+    src/libGLESv2/entry_points_gles_2_0_autogen.h
+    src/libGLESv2/entry_points_gles_3_0_autogen.h
+    src/libGLESv2/entry_points_gles_ext_autogen.h
+)
+
 set(libglesv1_cm_sources
     src/libGLESv1_CM/libGLESv1_CM.cpp
     src/libGLESv1_CM/libGLESv1_CM.def
index e35cdb1..33e4c60 100644 (file)
@@ -13,3 +13,27 @@ elseif (NOT ENABLE_X11_TARGET)
     # Allow building ANGLE on platforms which may not provide X11 headers.
     list(APPEND ANGLE_DEFINITIONS USE_SYSTEM_EGL)
 endif ()
+
+if (USE_ANGLE_EGL)
+    list(APPEND ANGLE_SOURCES
+        ${angle_system_utils_sources_linux}
+        ${angle_system_utils_sources_posix}
+        ${libangle_gl_sources}
+        ${libangle_gl_glx_sources}
+    )
+
+    list(APPEND ANGLE_DEFINITIONS
+        ANGLE_ENABLE_OPENGL
+        ANGLE_USE_X11
+    )
+
+    list(APPEND ANGLEGLESv2_LIBRARIES
+        dl
+        pthread
+        X11
+    )
+
+    string(REPLACE src/libGLESv2/libGLESv2_autogen.cpp "" libglesv2_sources "${libglesv2_sources}")
+    string(REPLACE src/libEGL/libEGL.cpp "" libegl_sources "${libegl_sources}")
+endif ()
+
index fad9ba0..17fa7fe 100755 (executable)
@@ -27,6 +27,12 @@ else
     output_dir=$BUILT_PRODUCTS_DIR/$PUBLIC_HEADERS_FOLDER_PATH
 fi
 
+if [ $(uname) == "Linux" ]; then
+    inplace_opt="-i"
+else
+    inplace_opt="-i ''"
+fi
+
 for i in $output_dir/*.h ; do
     if [ ! -f $output_dir/angle.timestamp ] || [ $i -nt $output_dir/angle.timestamp ] ; then
         sed -e '
@@ -37,7 +43,7 @@ s/^#include [<"]GLES3\/\(.*\)[>"]/#include <ANGLE\/\1>/
 s/^#include [<"]KHR\/\(.*\)[>"]/#include <ANGLE\/\1>/
 s/^#include [<"]export.h[>"]/#include <ANGLE\/export.h>/
 s/^#include "\(eglext_angle\|gl2ext_angle\|ShaderVars\).h"/#include <ANGLE\/\1.h>/
-' -i "" $i
+' $inplace_opt $i
         echo Postprocessed ANGLE header3 $i
     fi
 done
index f84eec7..fc00291 100644 (file)
@@ -49,6 +49,23 @@ if (USE_ANGLE_EGL)
     )
 endif ()
 
+if (USE_ANGLE_WEBGL)
+    set(ANGLE_WEBGL_HEADERS
+        export.h
+        ${khr_headers}
+        ${egl_headers}
+        ${gles_headers}
+        ${gles2_headers}
+        ${gles3_headers}
+    )
+
+    WEBKIT_COPY_FILES(ANGLEWebGLHeaders
+        DESTINATION ${ANGLE_FRAMEWORK_HEADERS_DIR}/ANGLE
+        FILES ${ANGLE_WEBGL_HEADERS}
+        FLATTENED
+    )
+endif ()
+
 # Cocoa expects headers in an ANGLE directory
 WEBKIT_COPY_FILES(GLSLANGHeaders
     DESTINATION ${ANGLE_FRAMEWORK_HEADERS_DIR}/ANGLE
index ef6f769..4549f72 100644 (file)
@@ -1,3 +1,16 @@
+2019-11-20  ChangSeok Oh  <changseok@webkit.org>
+
+        [GTK] Add ANGLE backend to GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=199060
+
+        Reviewed by Žan Doberšek.
+
+        The GTK port uses TEXTURE_MAPPER that has a gl context for accelerated rendering,
+        and ANGLE has an egl context for WebGL. We want to make both live together
+        so an exception is made where TEXTURE_MAPPER is enabled.
+
+        * wtf/Platform.h:
+
 2019-11-20  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win] Implement WTF::ThreadSpecific in WTF::Thread
index b0966df..0d47b02 100644 (file)
 #define USE_ANGLE 0
 #endif
 
-#if (USE_ANGLE && (USE_OPENGL || USE_OPENGL_ES || (defined(USE_EGL) && USE_EGL)))
+#if (USE_ANGLE && (USE_OPENGL || USE_OPENGL_ES || (defined(USE_EGL) && USE_EGL))) && !USE(TEXTURE_MAPPER)
 #error USE_ANGLE is incompatible with USE_OPENGL, USE_OPENGL_ES and USE_EGL
 #endif
 #endif
index 892d2ef..f4f7d23 100644 (file)
@@ -1,3 +1,67 @@
+2019-11-20  ChangSeok Oh  <changseok@webkit.org>
+
+        [GTK] Add ANGLE backend to GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=199060
+
+        Reviewed by Žan Doberšek.
+
+        This change aims to bring ANGLE support for WebGL to GTK port. The port
+        wants to have a gl context for texture mapper and a gles/egl context for webgl
+        simultaneously, we adopt the readPixel-copyToTexture approach for now because
+        sharing textures between the two different contextes is not a feasible direction.
+        Also, to avoid conflicts between gl and gles calls, we use non-prototype functions
+        of ANGLE for WebGL context (i.e., GraphicsContext3D). Although many combinations
+        of graphic configurations exist, only default configuration (Nicosia layers
+        running on ANGLE + GLX is supported. Other combinations like ANGLE + GLES or WPE
+        will be covered by following patches.
+
+        No new tests since no functionality changed.
+
+        * Headers.cmake:
+        * PlatformGTK.cmake:
+        * SourcesGTK.txt:
+        * platform/TextureMapper.cmake:
+        * platform/graphics/ANGLEWebKitBridge.h:
+        * platform/graphics/GLContext.cpp:
+        * platform/graphics/GLContext.h:
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/OpenGLShims.cpp:
+        (WebCore::initializeOpenGLShims):
+        * platform/graphics/OpenGLShims.h:
+        * platform/graphics/PlatformDisplay.cpp:
+        * platform/graphics/angle/GraphicsContext3DANGLE.cpp:
+        (WebCore::GraphicsContext3D::reshapeFBOs):
+        (WebCore::GraphicsContext3D::prepareTexture):
+        * platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp: Added.
+        (Nicosia::GC3DANGLELayer::ANGLEContext::errorString):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::lastErrorString):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::createContext):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::ANGLEContext):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::~ANGLEContext):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::makeContextCurrent):
+        (Nicosia::GC3DANGLELayer::ANGLEContext::platformContext):
+        (Nicosia::GC3DANGLELayer::GC3DANGLELayer):
+        (Nicosia::GC3DANGLELayer::~GC3DANGLELayer):
+        (Nicosia::GC3DANGLELayer::makeContextCurrent):
+        (Nicosia::GC3DANGLELayer::platformContext):
+        * platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h: Copied from Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h.
+        * platform/graphics/nicosia/texmap/NicosiaGC3DLayer.cpp:
+        (Nicosia::GC3DLayer::GC3DLayer):
+        (Nicosia::GC3DLayer::swapBuffersIfNeeded):
+        * platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h:
+        * platform/graphics/texmap/BitmapTextureGL.cpp:
+        (WebCore::BitmapTextureGL::setPendingContents):
+        (WebCore::BitmapTextureGL::updatePendingContents):
+        * platform/graphics/texmap/BitmapTextureGL.h:
+        * platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp:
+        (WebCore::GraphicsContext3D::create):
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+        * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
+        (WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper):
+        * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:
+        (WebCore::TextureMapperPlatformLayerProxy::pushNextBuffer):
+
 2019-11-20  Zalan Bujtas  <zalan@apple.com>
 
         Flexbox sizing logic triggers full repaint on the flex items.
index 402623f..efc275f 100644 (file)
@@ -1121,6 +1121,8 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
     platform/graphics/WidthCache.h
     platform/graphics/WindRule.h
 
+    platform/graphics/angle/Extensions3DANGLE.h
+
     platform/graphics/cv/ImageTransferSessionVT.h
 
     platform/graphics/filters/FilterOperation.h
index 787f49c..a30a545 100644 (file)
@@ -36,6 +36,12 @@ list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/text/gtk"
 )
 
+if (USE_ANGLE_WEBGL)
+    list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
+        "${WEBCORE_DIR}/platform/graphics/angle"
+    )
+endif ()
+
 if (USE_WPE_RENDERER)
     list(APPEND WebCore_INCLUDE_DIRECTORIES
         "${WEBCORE_DIR}/platform/graphics/libwpe"
@@ -117,20 +123,38 @@ if (USE_WPE_RENDERER)
     )
 endif ()
 
-if (USE_OPENGL_ES)
+if (USE_OPENGL)
     list(APPEND WebCore_SOURCES
-        platform/graphics/opengl/Extensions3DOpenGLES.cpp
-        platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
+        platform/graphics/OpenGLShims.cpp
     )
 endif ()
 
-if (USE_OPENGL)
+if (USE_ANGLE_WEBGL)
     list(APPEND WebCore_SOURCES
-        platform/graphics/OpenGLShims.cpp
-
-        platform/graphics/opengl/Extensions3DOpenGL.cpp
-        platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
+        platform/graphics/angle/Extensions3DANGLE.cpp
+        platform/graphics/angle/GraphicsContext3DANGLE.cpp
+        platform/graphics/angle/TemporaryANGLESetting.cpp
     )
+else ()
+    list(APPEND WebCore_SOURCES
+        platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
+        platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
+        platform/graphics/opengl/TemporaryOpenGLSetting.cpp
+    )
+
+    if (USE_OPENGL_ES)
+        list(APPEND WebCore_SOURCES
+            platform/graphics/opengl/Extensions3DOpenGLES.cpp
+            platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
+        )
+    endif ()
+
+    if (USE_OPENGL)
+        list(APPEND WebCore_SOURCES
+            platform/graphics/opengl/Extensions3DOpenGL.cpp
+            platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
+        )
+    endif ()
 endif ()
 
 if (ENABLE_WAYLAND_TARGET)
index 7006696..c2c2709 100644 (file)
@@ -92,10 +92,6 @@ platform/graphics/gstreamer/ImageGStreamerCairo.cpp
 
 platform/graphics/libwpe/PlatformDisplayLibWPE.cpp
 
-platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
-platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
-platform/graphics/opengl/TemporaryOpenGLSetting.cpp
-
 platform/graphics/opentype/OpenTypeVerticalData.cpp
 
 platform/graphics/wayland/PlatformDisplayWayland.cpp
index 4f3d6ea..353c141 100644 (file)
@@ -115,3 +115,9 @@ else ()
         platform/graphics/texmap/TextureMapperTiledBackingStore.cpp
     )
 endif ()
+
+if (USE_ANGLE_WEBGL)
+    list(APPEND WebCore_SOURCES
+        platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp
+    )
+endif ()
index d4a60ba..d14ec4f 100644 (file)
 #include <ANGLE/ShaderLang.h>
 #include <wtf/text/WTFString.h>
 
-#if PLATFORM(COCOA)
+#if USE(ANGLE)
+#include <ANGLE/gl2.h>
 
+#elif PLATFORM(COCOA)
 #if USE(OPENGL_ES)
 #import <OpenGLES/ES2/glext.h>
 #elif USE(OPENGL)
 #include <OpenGL/gl.h>
-#elif USE(ANGLE)
-#include <ANGLE/gl2.h>
 #else
 #error Unsupported configuration
 #endif
index 1e46783..27fb206 100644 (file)
 #include "GLContextEGL.h"
 #endif
 
-#if USE(LIBEPOXY)
-#include <epoxy/gl.h>
-#elif USE(OPENGL_ES)
-#include <GLES2/gl2.h>
-#endif
-
 #if USE(GLX)
 #include "GLContextGLX.h"
 #include "OpenGLShims.h"
index b4a2670..9a44efc 100644 (file)
 #ifndef GLContext_h
 #define GLContext_h
 
-#include "ANGLEWebKitBridge.h"
 #include "IntSize.h"
 #include "PlatformDisplay.h"
 #include <wtf/Noncopyable.h>
 
+#if USE(LIBEPOXY)
+#include <epoxy/gl.h>
+#elif USE(OPENGL_ES)
+#include <GLES2/gl2.h>
+#endif
+
 #if USE(EGL) && !PLATFORM(GTK)
 #if PLATFORM(WPE)
 // FIXME: For now default to the GBM EGL platform, but this should really be
index 8adb636..619fb4a 100644 (file)
@@ -101,12 +101,12 @@ const Platform3DObject NullPlatform3DObject = 0;
 
 namespace WebCore {
 class Extensions3D;
-#if !PLATFORM(COCOA) && USE(OPENGL_ES)
+#if USE(ANGLE)
+class Extensions3DANGLE;
+#elif !PLATFORM(COCOA) && USE(OPENGL_ES)
 class Extensions3DOpenGLES;
 #elif USE(OPENGL) || (PLATFORM(COCOA) && USE(OPENGL_ES))
 class Extensions3DOpenGL;
-#elif USE(ANGLE)
-class Extensions3DANGLE;
 #endif
 class HostWindow;
 class Image;
@@ -1456,7 +1456,10 @@ private:
     std::unique_ptr<ShaderNameHash> nameHashMapForShaders;
 #endif // !USE(ANGLE)
 
-#if !PLATFORM(COCOA) && USE(OPENGL_ES)
+#if USE(ANGLE)
+    friend class Extensions3DANGLE;
+    std::unique_ptr<Extensions3DANGLE> m_extensions;
+#elif !PLATFORM(COCOA) && USE(OPENGL_ES)
     friend class Extensions3DOpenGLES;
     friend class Extensions3DOpenGLCommon;
     std::unique_ptr<Extensions3DOpenGLES> m_extensions;
@@ -1464,9 +1467,6 @@ private:
     friend class Extensions3DOpenGL;
     friend class Extensions3DOpenGLCommon;
     std::unique_ptr<Extensions3DOpenGL> m_extensions;
-#elif USE(ANGLE)
-    friend class Extensions3DANGLE;
-    std::unique_ptr<Extensions3DANGLE> m_extensions;
 #endif
 
     GraphicsContext3DAttributes m_attrs;
@@ -1492,7 +1492,7 @@ private:
     bool m_layerComposited { false };
     GC3Duint m_internalColorFormat { 0 };
 
-#if USE(ANGLE)
+#if USE(ANGLE) && PLATFORM(COCOA)
     PlatformGraphicsContext3DSurface m_pbuffer;
 #endif
 
index d3cfd27..f7976e6 100644 (file)
@@ -162,6 +162,7 @@ bool initializeOpenGLShims()
     ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderInfoLog, success);
     ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderiv, success);
     ASSIGN_FUNCTION_TABLE_ENTRY(glGetShaderSource, success);
+    ASSIGN_FUNCTION_TABLE_ENTRY(glGetString, success);
     // glGetStringi is only available on OpenGL or GLES versions >= 3.0.
     // Add it with _EXT so it doesn't cause an initialization failure on lower versions.
     ASSIGN_FUNCTION_TABLE_ENTRY_EXT(glGetStringi);
index de3295d..4c357dd 100644 (file)
@@ -98,6 +98,7 @@ typedef void (GLAPIENTRY *glGetRenderbufferParameterivType) (GLenum, GLenum, GLi
 typedef void (GLAPIENTRY *glGetShaderInfoLogType) (GLuint, GLsizei, GLsizei*, char*);
 typedef void (GLAPIENTRY *glGetShaderivType) (GLuint, GLenum, GLint*);
 typedef void (GLAPIENTRY *glGetShaderSourceType) (GLuint, GLsizei, GLsizei*, char*);
+typedef const GLubyte* (GLAPIENTRY *glGetStringType) (GLenum);
 typedef const GLubyte* (GLAPIENTRY *glGetStringiType) (GLenum, GLuint);
 typedef GLint (GLAPIENTRY *glGetUniformLocationType) (GLuint, const char*);
 typedef void (GLAPIENTRY *glGetUniformfvType) (GLuint, GLint, GLfloat*);
@@ -205,6 +206,7 @@ typedef struct _OpenGLFunctionTable {
     FUNCTION_TABLE_ENTRY(glGetShaderInfoLog);
     FUNCTION_TABLE_ENTRY(glGetShaderiv);
     FUNCTION_TABLE_ENTRY(glGetShaderSource);
+    FUNCTION_TABLE_ENTRY(glGetString);
     FUNCTION_TABLE_ENTRY(glGetStringi);
     FUNCTION_TABLE_ENTRY(glGetUniformfv);
     FUNCTION_TABLE_ENTRY(glGetUniformiv);
@@ -333,6 +335,7 @@ typedef struct _OpenGLFunctionTable {
 #define glGetShaderInfoLog                     LOOKUP_GL_FUNCTION(glGetShaderInfoLog)
 #define glGetShaderiv                          LOOKUP_GL_FUNCTION(glGetShaderiv)
 #define glGetShaderSource                      LOOKUP_GL_FUNCTION(glGetShaderSource)
+#define glGetString                            LOOKUP_GL_FUNCTION(glGetString)
 #define glGetStringi                           LOOKUP_GL_FUNCTION(glGetStringi)
 #define glGetUniformfv                         LOOKUP_GL_FUNCTION(glGetUniformfv)
 #define glGetUniformiv                         LOOKUP_GL_FUNCTION(glGetUniformiv)
index f978dbe..156e5aa 100644 (file)
@@ -52,6 +52,9 @@
 
 #if PLATFORM(GTK) && PLATFORM(X11)
 #include <gdk/gdkx.h>
+#if defined(None)
+#undef None
+#endif
 #endif
 
 #if PLATFORM(GTK) && PLATFORM(WAYLAND)
index f161ea5..6b5be10 100644 (file)
@@ -69,6 +69,11 @@ typedef void* GLeglContext;
 // would need more work to be included from WebCore.
 #define GL_MAX_SAMPLES_EXT 0x8D57
 
+#if USE(COORDINATED_GRAPHICS) && USE(TEXTURE_MAPPER)
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#endif
+
 namespace WebCore {
 
 static const char* packedDepthStencilExtensionName = "GL_OES_packed_depth_stencil";
@@ -191,6 +196,18 @@ bool GraphicsContext3D::reshapeFBOs(const IntSize& size)
     allocateIOSurfaceBackingStore(IntSize(width, height));
     updateFramebufferTextureBackingStoreFromLayer();
     gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ANGLE, m_texture, 0);
+#elif PLATFORM(GTK)
+    gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_texture);
+    gl::TexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+    gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ANGLE, m_texture, 0);
+    if (m_compositorTexture) {
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_compositorTexture);
+        gl::TexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, 0);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_intermediateTexture);
+        gl::TexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, m_internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, 0);
+    }
 #else
 #error FIXME: Port to non-Cocoa platforms.
 #endif // PLATFORM(COCOA)
@@ -476,7 +493,20 @@ void GraphicsContext3D::prepareTexture()
     if (m_attrs.antialias)
         resolveMultisamplingIfNecessary();
 
+#if USE(COORDINATED_GRAPHICS)
+    std::swap(m_texture, m_compositorTexture);
+    std::swap(m_texture, m_intermediateTexture);
+    gl::BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+    gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ANGLE, m_texture, 0);
     gl::Flush();
+
+    if (m_state.boundFBO != m_fbo)
+        gl::BindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_state.boundFBO);
+    else
+        gl::BindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
+#else
+    gl::Flush();
+#endif
 }
 
 void GraphicsContext3D::readRenderingResults(unsigned char *pixels, int pixelsSize)
diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp
new file mode 100644 (file)
index 0000000..47cf5d1
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2018 Metrological Group B.V.
+ * Copyright (C) 2018, 2019 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NicosiaGC3DANGLELayer.h"
+
+#if USE(NICOSIA) && USE(TEXTURE_MAPPER)
+
+#include "Logging.h"
+
+#define EGL_EGL_PROTOTYPES 0
+// Skip the inclusion of ANGLE's explicit context entry points for now.
+#define GL_ANGLE_explicit_context
+#define GL_ANGLE_explicit_context_gles1
+typedef void* GLeglContext;
+#include <ANGLE/egl.h>
+#include <ANGLE/eglext.h>
+#include <ANGLE/eglext_angle.h>
+#include <ANGLE/entry_points_egl.h>
+#include <ANGLE/entry_points_gles_2_0_autogen.h>
+#include <ANGLE/entry_points_gles_ext_autogen.h>
+#include <ANGLE/gl2ext.h>
+#include <ANGLE/gl2ext_angle.h>
+
+namespace Nicosia {
+
+using namespace WebCore;
+
+const char* GC3DANGLELayer::ANGLEContext::errorString(int statusCode)
+{
+    static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int");
+    switch (statusCode) {
+#define CASE_RETURN_STRING(name) case name: return #name
+        // https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglGetError.xhtml
+        CASE_RETURN_STRING(EGL_SUCCESS);
+        CASE_RETURN_STRING(EGL_NOT_INITIALIZED);
+        CASE_RETURN_STRING(EGL_BAD_ACCESS);
+        CASE_RETURN_STRING(EGL_BAD_ALLOC);
+        CASE_RETURN_STRING(EGL_BAD_ATTRIBUTE);
+        CASE_RETURN_STRING(EGL_BAD_CONTEXT);
+        CASE_RETURN_STRING(EGL_BAD_CONFIG);
+        CASE_RETURN_STRING(EGL_BAD_CURRENT_SURFACE);
+        CASE_RETURN_STRING(EGL_BAD_DISPLAY);
+        CASE_RETURN_STRING(EGL_BAD_SURFACE);
+        CASE_RETURN_STRING(EGL_BAD_MATCH);
+        CASE_RETURN_STRING(EGL_BAD_PARAMETER);
+        CASE_RETURN_STRING(EGL_BAD_NATIVE_PIXMAP);
+        CASE_RETURN_STRING(EGL_BAD_NATIVE_WINDOW);
+        CASE_RETURN_STRING(EGL_CONTEXT_LOST);
+#undef CASE_RETURN_STRING
+    default: return "Unknown EGL error";
+    }
+}
+
+const char* GC3DANGLELayer::ANGLEContext::lastErrorString()
+{
+    return errorString(EGL_GetError());
+}
+
+std::unique_ptr<GC3DANGLELayer::ANGLEContext> GC3DANGLELayer::ANGLEContext::createContext()
+{
+    EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
+    if (display == EGL_NO_DISPLAY)
+        return nullptr;
+
+    EGLint majorVersion, minorVersion;
+    if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
+        LOG(WebGL, "EGLDisplay Initialization failed.");
+        return nullptr;
+    }
+    LOG(WebGL, "ANGLE initialised Major: %d Minor: %d", majorVersion, minorVersion);
+
+    const char* displayExtensions = EGL_QueryString(display, EGL_EXTENSIONS);
+    LOG(WebGL, "Extensions: %s", displayExtensions);
+
+    EGLConfig config;
+    EGLint configAttributes[] = {
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+        EGL_RED_SIZE, 8,
+        EGL_GREEN_SIZE, 8,
+        EGL_BLUE_SIZE, 8,
+        EGL_ALPHA_SIZE, 8,
+        EGL_NONE
+    };
+    EGLint numberConfigsReturned = 0;
+    EGL_ChooseConfig(display, configAttributes, &config, 1, &numberConfigsReturned);
+    if (numberConfigsReturned != 1) {
+        LOG(WebGL, "EGLConfig Initialization failed.");
+        return nullptr;
+    }
+    LOG(WebGL, "Got EGLConfig");
+
+    EGL_BindAPI(EGL_OPENGL_ES_API);
+    if (EGL_GetError() != EGL_SUCCESS) {
+        LOG(WebGL, "Unable to bind to OPENGL_ES_API");
+        return nullptr;
+    }
+
+    std::vector<EGLint> contextAttributes;
+    contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
+    contextAttributes.push_back(2);
+    contextAttributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
+    contextAttributes.push_back(EGL_TRUE);
+    contextAttributes.push_back(EGL_EXTENSIONS_ENABLED_ANGLE);
+    contextAttributes.push_back(EGL_TRUE);
+    if (strstr(displayExtensions, "EGL_ANGLE_power_preference")) {
+        contextAttributes.push_back(EGL_POWER_PREFERENCE_ANGLE);
+        // EGL_LOW_POWER_ANGLE is the default. Change to
+        // EGL_HIGH_POWER_ANGLE if desired.
+        contextAttributes.push_back(EGL_LOW_POWER_ANGLE);
+    }
+    contextAttributes.push_back(EGL_NONE);
+
+    EGLContext context = EGL_CreateContext(display, config, EGL_NO_CONTEXT, contextAttributes.data());
+    if (context == EGL_NO_CONTEXT) {
+        LOG(WebGL, "EGLContext Initialization failed.");
+        return nullptr;
+    }
+    LOG(WebGL, "Got EGLContext");
+
+    return std::unique_ptr<ANGLEContext>(new ANGLEContext(display, context, EGL_NO_SURFACE));
+}
+
+GC3DANGLELayer::ANGLEContext::ANGLEContext(EGLDisplay display, EGLContext context, EGLSurface surface)
+    : m_display(display)
+    , m_context(context)
+    , m_surface(surface)
+{
+}
+
+GC3DANGLELayer::ANGLEContext::~ANGLEContext()
+{
+    if (m_context) {
+        gl::BindFramebuffer(GL_FRAMEBUFFER, 0);
+        EGL_MakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+        EGL_DestroyContext(m_display, m_context);
+    }
+
+    if (m_surface)
+        EGL_DestroySurface(m_display, m_surface);
+}
+
+bool GC3DANGLELayer::ANGLEContext::makeContextCurrent()
+{
+    ASSERT(m_context);
+
+    if (EGL_GetCurrentContext() != m_context)
+        return EGL_MakeCurrent(m_display, m_surface, m_surface, m_context);
+    return true;
+}
+
+PlatformGraphicsContext3D GC3DANGLELayer::ANGLEContext::platformContext()
+{
+    return m_context;
+}
+
+GC3DANGLELayer::GC3DANGLELayer(GraphicsContext3D& context, GraphicsContext3D::RenderStyle renderStyle)
+    : GC3DLayer(context)
+{
+    switch (renderStyle) {
+    case GraphicsContext3D::RenderOffscreen:
+        m_angleContext = ANGLEContext::createContext();
+        break;
+    case GraphicsContext3D::RenderDirectlyToHostWindow:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+GC3DANGLELayer::~GC3DANGLELayer()
+{
+}
+
+bool GC3DANGLELayer::makeContextCurrent()
+{
+    ASSERT(m_angleContext);
+    return m_angleContext->makeContextCurrent();
+
+}
+
+PlatformGraphicsContext3D GC3DANGLELayer::platformContext()
+{
+    ASSERT(m_angleContext);
+    return m_angleContext->platformContext();
+}
+
+} // namespace Nicosia
+
+#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER)
diff --git a/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h b/Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h
new file mode 100644 (file)
index 0000000..bc2f6ef
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2018 Metrological Group B.V.
+ * Copyright (C) 2018, 2019 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(NICOSIA) && USE(TEXTURE_MAPPER)
+
+#include "GLContext.h"
+#include "GraphicsContext3D.h"
+#include "NicosiaGC3DLayer.h"
+#include <memory>
+
+typedef void *EGLConfig;
+typedef void *EGLContext;
+typedef void *EGLDisplay;
+typedef void *EGLSurface;
+
+namespace WebCore {
+class IntSize;
+class GLContext;
+class PlatformDisplay;
+}
+
+namespace Nicosia {
+
+class GC3DANGLELayer final : public GC3DLayer {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    class ANGLEContext {
+        WTF_MAKE_NONCOPYABLE(ANGLEContext);
+    public:
+        static const char* errorString(int statusCode);
+        static const char* lastErrorString();
+
+        static std::unique_ptr<ANGLEContext> createContext();
+        virtual ~ANGLEContext();
+
+        bool makeContextCurrent();
+#if ENABLE(GRAPHICS_CONTEXT_3D)
+        PlatformGraphicsContext3D platformContext();
+#endif
+
+    private:
+        ANGLEContext(EGLDisplay, EGLContext, EGLSurface);
+
+        EGLDisplay m_display { nullptr };
+        EGLContext m_context { nullptr };
+        EGLSurface m_surface { nullptr };
+    };
+
+    GC3DANGLELayer(WebCore::GraphicsContext3D&, WebCore::GraphicsContext3D::RenderStyle);
+    virtual ~GC3DANGLELayer();
+
+    bool makeContextCurrent() override;
+    PlatformGraphicsContext3D platformContext() override;
+
+private:
+    std::unique_ptr<ANGLEContext> m_angleContext;
+};
+
+} // namespace Nicosia
+
+#endif // USE(NICOSIA) && USE(TEXTURE_MAPPER)
index 9a9bd46..2dc916d 100644 (file)
 #include "TextureMapperPlatformLayerProxy.h"
 #endif
 
+#if USE(ANGLE)
+#include "ImageBuffer.h"
+#endif
+
 #include "GLContext.h"
 
 namespace Nicosia {
 
 using namespace WebCore;
 
+GC3DLayer::GC3DLayer(GraphicsContext3D& context)
+    : m_context(context)
+    , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
+{
+}
+
 GC3DLayer::GC3DLayer(GraphicsContext3D& context, GraphicsContext3D::RenderStyle renderStyle)
     : m_context(context)
     , m_contentLayer(Nicosia::ContentLayer::create(Nicosia::ContentLayerTextureMapperImpl::createFactory(*this)))
@@ -82,13 +92,38 @@ void GC3DLayer::swapBuffersIfNeeded()
 
     m_context.prepareTexture();
     IntSize textureSize(m_context.m_currentWidth, m_context.m_currentHeight);
-    TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context.m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
+    TextureMapperGL::Flags flags = m_context.m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0;
+#if USE(ANGLE)
+    std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::create(textureSize, Unaccelerated);
+    if (!imageBuffer)
+        return;
+
+    m_context.paintRenderingResultsToCanvas(imageBuffer.get());
+    RefPtr<Image> image = imageBuffer->copyImage(DontCopyBackingStore);
+    if (!image)
+        return;
+#else
+    flags |= TextureMapperGL::ShouldFlipTexture;
+#endif
 
     {
         auto& proxy = downcast<Nicosia::ContentLayerTextureMapperImpl>(m_contentLayer->impl()).proxy();
+#if USE(ANGLE)
+        std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer;
+        layerBuffer = proxy.getAvailableBuffer(textureSize, m_context.m_internalColorFormat);
+        if (!layerBuffer) {
+            auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), m_context.m_internalColorFormat);
+            static_cast<BitmapTextureGL&>(texture.get()).setPendingContents(WTFMove(image));
+            layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), flags);
+        } else
+            layerBuffer->textureGL().setPendingContents(WTFMove(image));
 
         LockHolder holder(proxy.lock());
+        proxy.pushNextBuffer(WTFMove(layerBuffer));
+#else
+        LockHolder holder(proxy.lock());
         proxy.pushNextBuffer(makeUnique<TextureMapperPlatformLayerBuffer>(m_context.m_compositorTexture, textureSize, flags, m_context.m_internalColorFormat));
+#endif
     }
 
     m_context.markLayerComposited();
index 9f5445b..326d6e5 100644 (file)
@@ -43,12 +43,14 @@ namespace Nicosia {
 class GC3DLayer : public ContentLayerTextureMapperImpl::Client {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    explicit GC3DLayer(WebCore::GraphicsContext3D&);
     GC3DLayer(WebCore::GraphicsContext3D&, WebCore::GraphicsContext3D::RenderStyle);
+
     virtual ~GC3DLayer();
 
     ContentLayer& contentLayer() const { return m_contentLayer; }
-    bool makeContextCurrent();
-    PlatformGraphicsContext3D platformContext();
+    virtual bool makeContextCurrent();
+    virtual PlatformGraphicsContext3D platformContext();
 
     void swapBuffersIfNeeded() override;
 
index 79b006e..0fb63d9 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "Extensions3D.h"
 #include "FilterOperations.h"
-#include "Image.h"
 #include "LengthFunctions.h"
 #include "NativeImage.h"
 #include "NotImplemented.h"
@@ -169,6 +168,25 @@ void BitmapTextureGL::updateContents(Image* image, const IntRect& targetRect, co
     updateContents(imageData, targetRect, offset, bytesPerLine);
 }
 
+#if USE(ANGLE)
+void BitmapTextureGL::setPendingContents(RefPtr<Image>&& image)
+{
+    m_pendingContents = image;
+}
+
+void BitmapTextureGL::updatePendingContents(const IntRect& targetRect, const IntPoint& offset)
+{
+    if (!m_pendingContents)
+        return;
+
+    if (!isValid()) {
+        IntSize textureSize(m_pendingContents->size());
+        reset(textureSize);
+    }
+    updateContents(m_pendingContents.get(), targetRect, offset);
+}
+#endif
+
 static unsigned getPassesRequiredForFilter(FilterOperation::OperationType type)
 {
     switch (type) {
index 8709a82..5b163f6 100644 (file)
@@ -26,6 +26,7 @@
 #include "BitmapTexture.h"
 #include "ClipStack.h"
 #include "FilterOperation.h"
+#include "Image.h"
 #include "IntSize.h"
 #include "TextureMapperContextAttributes.h"
 #include "TextureMapperGL.h"
@@ -77,6 +78,10 @@ public:
     GLint internalFormat() const { return m_internalFormat; }
 
     void copyFromExternalTexture(GLuint textureID);
+#if USE(ANGLE)
+    void setPendingContents(RefPtr<Image>&&);
+    void updatePendingContents(const IntRect& targetRect, const IntPoint& offset);
+#endif
 
     TextureMapperGL::Flags colorConvertFlags() const { return m_colorConvertFlags; }
 
@@ -94,6 +99,10 @@ private:
     TextureMapperContextAttributes m_contextAttributes;
     TextureMapperGL::Flags m_colorConvertFlags { TextureMapperGL::NoFlag };
 
+#if USE(ANGLE)
+    RefPtr<Image> m_pendingContents { nullptr };
+#endif
+
     void clearIfNeeded();
     void createFboIfNeeded();
 
index 8fd3ad4..fab807b 100644 (file)
 
 #include <ANGLE/ShaderLang.h>
 
-#if USE(LIBEPOXY)
+#if USE(ANGLE)
+#define EGL_EGL_PROTOTYPES 0
+// Skip the inclusion of ANGLE's explicit context entry points for now.
+#define GL_ANGLE_explicit_context
+#define GL_ANGLE_explicit_context_gles1
+typedef void* GLeglContext;
+#include <ANGLE/egl.h>
+#include <ANGLE/eglext.h>
+#include <ANGLE/eglext_angle.h>
+#include <ANGLE/entry_points_egl.h>
+#include <ANGLE/entry_points_gles_2_0_autogen.h>
+#include <ANGLE/entry_points_gles_ext_autogen.h>
+#include <ANGLE/gl2ext.h>
+#include <ANGLE/gl2ext_angle.h>
+#if defined(Above)
+#undef Above
+#endif
+#if defined(Below)
+#undef Below
+#endif
+#if defined(None)
+#undef None
+#endif
+#elif USE(LIBEPOXY)
 #include <epoxy/gl.h>
 #elif !USE(OPENGL_ES)
 #include "OpenGLShims.h"
 #endif
 
-#if USE(OPENGL_ES)
+#if USE(ANGLE)
+#include "Extensions3DANGLE.h"
+#elif USE(OPENGL_ES)
 #include "Extensions3DOpenGLES.h"
 #else
 #include "Extensions3DOpenGL.h"
 #endif
 
 #if USE(NICOSIA)
+#if USE(ANGLE)
+#include "NicosiaGC3DANGLELayer.h"
+#else
 #include "NicosiaGC3DLayer.h"
 #endif
+#endif
 
 namespace WebCore {
 
@@ -71,7 +100,7 @@ RefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3DAttributes
     static bool initialized = false;
     static bool success = true;
     if (!initialized) {
-#if !USE(OPENGL_ES) && !USE(LIBEPOXY)
+#if !USE(OPENGL_ES) && !USE(LIBEPOXY) && !USE(ANGLE)
         success = initializeOpenGLShims();
 #endif
         initialized = true;
@@ -101,6 +130,79 @@ RefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3DAttributes
     return context;
 }
 
+#if USE(ANGLE)
+GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle, GraphicsContext3D* sharedContext)
+    : m_attrs(attributes)
+{
+    ASSERT_UNUSED(sharedContext, !sharedContext);
+#if USE(NICOSIA)
+    m_nicosiaLayer = WTF::makeUnique<Nicosia::GC3DANGLELayer>(*this, renderStyle);
+#else
+    m_texmapLayer = WTF::makeUnique<TextureMapperGC3DPlatformLayer>(*this, renderStyle);
+#endif
+    makeContextCurrent();
+
+
+    validateAttributes();
+
+    if (renderStyle == RenderOffscreen) {
+        // Create a texture to render into.
+        gl::GenTextures(1, &m_texture);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_texture);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, 0);
+
+        // Create an FBO.
+        gl::GenFramebuffers(1, &m_fbo);
+        gl::BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+
+#if USE(COORDINATED_GRAPHICS)
+        gl::GenTextures(1, &m_compositorTexture);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_compositorTexture);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+        gl::GenTextures(1, &m_intermediateTexture);
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, m_intermediateTexture);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        gl::TexParameterf(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+        gl::TexParameteri(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+        gl::BindTexture(GL_TEXTURE_RECTANGLE_ANGLE, 0);
+#endif
+
+        // Create a multisample FBO.
+        if (m_attrs.antialias) {
+            gl::GenFramebuffers(1, &m_multisampleFBO);
+            gl::BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
+            m_state.boundFBO = m_multisampleFBO;
+            gl::GenRenderbuffers(1, &m_multisampleColorBuffer);
+            if (m_attrs.stencil || m_attrs.depth)
+                gl::GenRenderbuffers(1, &m_multisampleDepthStencilBuffer);
+        } else {
+            // Bind canvas FBO.
+            gl::BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+            m_state.boundFBO = m_fbo;
+#if USE(OPENGL_ES)
+            if (m_attrs.depth)
+                gl::GenRenderbuffers(1, &m_depthBuffer);
+            if (m_attrs.stencil)
+                gl::GenRenderbuffers(1, &m_stencilBuffer);
+#endif
+            if (m_attrs.stencil || m_attrs.depth)
+                gl::GenRenderbuffers(1, &m_depthStencilBuffer);
+        }
+    }
+
+    gl::ClearColor(0, 0, 0, 0);
+}
+#else
 GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle, GraphicsContext3D* sharedContext)
     : m_attrs(attributes)
 {
@@ -225,7 +327,51 @@ GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, Hos
 
     ::glClearColor(0, 0, 0, 0);
 }
+#endif
 
+#if USE(ANGLE)
+GraphicsContext3D::~GraphicsContext3D()
+{
+    makeContextCurrent();
+    if (m_texture)
+        gl::DeleteTextures(1, &m_texture);
+#if USE(COORDINATED_GRAPHICS)
+    if (m_compositorTexture)
+        gl::DeleteTextures(1, &m_compositorTexture);
+#endif
+
+    if (m_attrs.antialias) {
+        gl::DeleteRenderbuffers(1, &m_multisampleColorBuffer);
+        if (m_attrs.stencil || m_attrs.depth)
+            gl::DeleteRenderbuffers(1, &m_multisampleDepthStencilBuffer);
+        gl::DeleteFramebuffers(1, &m_multisampleFBO);
+    } else if (m_attrs.stencil || m_attrs.depth) {
+#if USE(OPENGL_ES)
+        if (m_depthBuffer)
+            glDeleteRenderbuffers(1, &m_depthBuffer);
+
+        if (m_stencilBuffer)
+            glDeleteRenderbuffers(1, &m_stencilBuffer);
+#endif
+        if (m_depthStencilBuffer)
+            gl::DeleteRenderbuffers(1, &m_depthStencilBuffer);
+    }
+    gl::DeleteFramebuffers(1, &m_fbo);
+#if USE(COORDINATED_GRAPHICS)
+    gl::DeleteTextures(1, &m_intermediateTexture);
+#endif
+
+#if USE(CAIRO)
+    if (m_vao)
+        deleteVertexArray(m_vao);
+#endif
+
+    auto* activeContext = activeContexts().takeLast([this](auto* it) {
+        return it == this;
+    });
+    ASSERT_UNUSED(activeContext, !!activeContext);
+}
+#else
 GraphicsContext3D::~GraphicsContext3D()
 {
     makeContextCurrent();
@@ -262,9 +408,12 @@ GraphicsContext3D::~GraphicsContext3D()
         deleteVertexArray(m_vao);
 #endif
 
-    auto* activeContext = activeContexts().takeLast([this](auto* it) { return it == this; });
+    auto* activeContext = activeContexts().takeLast([this](auto* it) {
+        return it == this;
+    });
     ASSERT_UNUSED(activeContext, !!activeContext);
 }
+#endif // USE(ANGLE)
 
 void GraphicsContext3D::setContextLostCallback(std::unique_ptr<ContextLostCallback>)
 {
@@ -319,7 +468,7 @@ PlatformLayer* GraphicsContext3D::platformLayer() const
 #endif
 }
 
-#if PLATFORM(GTK)
+#if PLATFORM(GTK) && !USE(ANGLE)
 Extensions3D& GraphicsContext3D::getExtensions()
 {
     if (!m_extensions) {
index 5efb190..2db8cfb 100644 (file)
@@ -97,6 +97,9 @@ void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper& textu
     if (m_hasManagedTexture) {
         ASSERT(m_texture);
         BitmapTextureGL* textureGL = static_cast<BitmapTextureGL*>(m_texture.get());
+#if USE(ANGLE)
+        textureGL->updatePendingContents(IntRect(IntPoint(), textureGL->contentSize()), IntPoint());
+#endif
         texmapGL.drawTexture(textureGL->id(), m_extraFlags | textureGL->colorConvertFlags(), textureGL->size(), targetRect, modelViewMatrix, opacity);
         return;
     }
index 3793675..3814f68 100644 (file)
@@ -113,6 +113,12 @@ bool TextureMapperPlatformLayerProxy::isActive()
 void TextureMapperPlatformLayerProxy::pushNextBuffer(std::unique_ptr<TextureMapperPlatformLayerBuffer> newBuffer)
 {
     ASSERT(m_lock.isHeld());
+#if USE(ANGLE)
+    // When the newBuffer overwrites m_pendingBuffer that is not swapped yet,
+    // the layer related to m_pendingBuffer is flickering since its texture is destroyed.
+    if (m_pendingBuffer && m_pendingBuffer->hasManagedTexture())
+        return;
+#endif
     m_pendingBuffer = WTFMove(newBuffer);
     m_wasBufferDropped = false;
 
index 5a6f64b..99fcc06 100644 (file)
@@ -1,3 +1,15 @@
+2019-11-20  ChangSeok Oh  <changseok@webkit.org>
+
+        [GTK] Add ANGLE backend to GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=199060
+
+        Reviewed by Žan Doberšek.
+
+        * UIProcess/API/glib/WebKitProtocolHandler.cpp: Extention3DANGLE is used instead
+          where ANGLE for WebGL is enabled.
+        * UIProcess/gtk/AcceleratedBackingStoreWayland.cpp: Append gl extensions for ANGLE.
+        (WebKit::AcceleratedBackingStoreWayland::checkRequirements):
+
 2019-11-20  Chris Dumez  <cdumez@apple.com>
 
         [iOS] Make sure WebContent process does not get suspended while it is holding a process assertion for the UIProcess
index 973b316..1a3264d 100644 (file)
 #include <WebCore/CairoUtilities.h>
 #include <WebCore/GLContext.h>
 
-#if USE(OPENGL_ES)
+#if USE(ANGLE)
+#include <WebCore/Extensions3DANGLE.h>
+#include <WebCore/OpenGLShims.h>
+#elif USE(OPENGL_ES)
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 #include <WebCore/Extensions3DOpenGLES.h>
@@ -78,7 +81,9 @@ bool AcceleratedBackingStoreWayland::checkRequirements()
         if (!eglContext->makeContextCurrent())
             return false;
 
-#if USE(OPENGL_ES)
+#if USE(ANGLE)
+        std::unique_ptr<Extensions3DANGLE> glExtensions = makeUnique<Extensions3DANGLE>(nullptr, GLContext::current()->version() >= 320);
+#elif USE(OPENGL_ES)
         std::unique_ptr<Extensions3DOpenGLES> glExtensions = makeUnique<Extensions3DOpenGLES>(nullptr,  false);
 #else
         std::unique_ptr<Extensions3DOpenGL> glExtensions = makeUnique<Extensions3DOpenGL>(nullptr, GLContext::current()->version() >= 320);
index 6ad0df0..cfeff6d 100644 (file)
@@ -90,6 +90,7 @@ WEBKIT_OPTION_DEFINE(USE_WPE_RENDERER "Whether to enable WPE rendering" PUBLIC O
 
 # Private options specific to the GTK port. Changing these options is
 # completely unsupported. They are intended for use only by WebKit developers.
+WEBKIT_OPTION_DEFINE(USE_ANGLE_WEBGL "Whether to use ANGLE as WebGL backend." PRIVATE OFF)
 WEBKIT_OPTION_DEFINE(USE_OPENVR "Whether to use OpenVR as WebVR backend." PRIVATE OFF)
 
 # FIXME: Can we use cairo-glesv2 to avoid this conflict?
@@ -100,6 +101,7 @@ WEBKIT_OPTION_DEPEND(ENABLE_ACCELERATED_2D_CANVAS ENABLE_OPENGL)
 WEBKIT_OPTION_DEPEND(ENABLE_ASYNC_SCROLLING ENABLE_OPENGL)
 WEBKIT_OPTION_DEPEND(ENABLE_GLES2 ENABLE_OPENGL)
 WEBKIT_OPTION_DEPEND(ENABLE_WEBGL ENABLE_OPENGL)
+WEBKIT_OPTION_DEPEND(USE_ANGLE_WEBGL ENABLE_WEBGL)
 WEBKIT_OPTION_DEPEND(USE_WPE_RENDERER ENABLE_OPENGL)
 WEBKIT_OPTION_DEPEND(USE_WPE_RENDERER ENABLE_WAYLAND_TARGET)
 
@@ -306,6 +308,11 @@ if (ENABLE_OPENGL)
     SET_AND_EXPOSE_TO_BUILD(USE_NICOSIA TRUE)
 endif ()
 
+if (USE_ANGLE_WEBGL)
+    SET_AND_EXPOSE_TO_BUILD(USE_ANGLE TRUE)
+    SET_AND_EXPOSE_TO_BUILD(USE_ANGLE_EGL TRUE)
+endif ()
+
 if (ENABLE_SPELLCHECK)
     find_package(Enchant)
     if (NOT PC_ENCHANT_FOUND)