Title: [271065] trunk/Source
Revision
271065
Author
[email protected]
Date
2020-12-22 14:37:46 -0800 (Tue, 22 Dec 2020)

Log Message

Use an enum class to identify WebGL versions
https://bugs.webkit.org/show_bug.cgi?id=220099
<rdar://problem/72596828>

Reviewed by Ken Russell.

Source/WebCore:

Rather than doing string comparisons multiple times, against
values that have been deprecated, use an enum class to
identify the version of WebGL that we are creating.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
(WebCore::HTMLCanvasElement::toWebGLVersion):
(WebCore::HTMLCanvasElement::createContextWebGL):
(WebCore::HTMLCanvasElement::getContextWebGL):
* html/HTMLCanvasElement.h:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* html/canvas/WebGLRenderingContextBase.h:
* platform/graphics/GraphicsContextGLAttributes.h: New enum class.
* platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
(WebCore::RemoteGraphicsContextGLProxyBase::isGLES2Compliant const):
* platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
(WebCore::InitializeEGLDisplay): Add a logging statement as a drive-by.
(WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):

Source/WebKit:

Encode the WebGL version.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<WebCore::GraphicsContextGLAttributes>::encode):
(IPC::ArgumentCoder<WebCore::GraphicsContextGLAttributes>::decode):
* Shared/WebCoreArgumentCoders.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271064 => 271065)


--- trunk/Source/WebCore/ChangeLog	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/ChangeLog	2020-12-22 22:37:46 UTC (rev 271065)
@@ -1,3 +1,31 @@
+2020-12-22  Dean Jackson  <[email protected]>
+
+        Use an enum class to identify WebGL versions
+        https://bugs.webkit.org/show_bug.cgi?id=220099
+        <rdar://problem/72596828>
+
+        Reviewed by Ken Russell.
+
+        Rather than doing string comparisons multiple times, against
+        values that have been deprecated, use an enum class to
+        identify the version of WebGL that we are creating.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::getContext):
+        (WebCore::HTMLCanvasElement::toWebGLVersion):
+        (WebCore::HTMLCanvasElement::createContextWebGL):
+        (WebCore::HTMLCanvasElement::getContextWebGL):
+        * html/HTMLCanvasElement.h:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * html/canvas/WebGLRenderingContextBase.h:
+        * platform/graphics/GraphicsContextGLAttributes.h: New enum class.
+        * platform/graphics/RemoteGraphicsContextGLProxyBase.cpp:
+        (WebCore::RemoteGraphicsContextGLProxyBase::isGLES2Compliant const):
+        * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+        (WebCore::InitializeEGLDisplay): Add a logging statement as a drive-by.
+        (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+
 2020-12-22  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Use reserveInitialCapacity when applicable

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (271064 => 271065)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -300,7 +300,7 @@
         auto attributes = convert<IDLDictionary<WebGLContextAttributes>>(state, !arguments.isEmpty() ? arguments[0].get() : JSC::jsUndefined());
         RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
 
-        auto context = createContextWebGL(contextId, WTFMove(attributes));
+        auto context = createContextWebGL(toWebGLVersion(contextId), WTFMove(attributes));
         if (!context)
             return Optional<RenderingContext> { WTF::nullopt };
 
@@ -335,7 +335,7 @@
 
 #if ENABLE(WEBGL)
     if (HTMLCanvasElement::isWebGLType(type))
-        return getContextWebGL(type);
+        return getContextWebGL(HTMLCanvasElement::toWebGLVersion(type));
 #endif
 
 #if ENABLE(WEBGPU)
@@ -421,9 +421,20 @@
         || type == "webkit-3d";
 }
 
-WebGLRenderingContextBase* HTMLCanvasElement::createContextWebGL(const String& type, WebGLContextAttributes&& attrs)
+GraphicsContextGLWebGLVersion HTMLCanvasElement::toWebGLVersion(const String& type)
 {
-    ASSERT(HTMLCanvasElement::isWebGLType(type));
+    ASSERT(isWebGLType(type));
+#if ENABLE(WEBGL2)
+    if (type == "webgl2")
+        return WebGLVersion::WebGL2;
+#else
+    UNUSED_PARAM(type);
+#endif
+    return WebGLVersion::WebGL1;
+}
+
+WebGLRenderingContextBase* HTMLCanvasElement::createContextWebGL(WebGLVersion type, WebGLContextAttributes&& attrs)
+{
     ASSERT(!m_context);
 
     if (!shouldEnableWebGL(document().settings()))
@@ -457,10 +468,8 @@
     return downcast<WebGLRenderingContextBase>(m_context.get());
 }
 
-WebGLRenderingContextBase* HTMLCanvasElement::getContextWebGL(const String& type, WebGLContextAttributes&& attrs)
+WebGLRenderingContextBase* HTMLCanvasElement::getContextWebGL(WebGLVersion type, WebGLContextAttributes&& attrs)
 {
-    ASSERT(HTMLCanvasElement::isWebGLType(type));
-
     if (!shouldEnableWebGL(document().settings()))
         return nullptr;
 

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (271064 => 271065)


--- trunk/Source/WebCore/html/HTMLCanvasElement.h	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h	2020-12-22 22:37:46 UTC (rev 271065)
@@ -81,10 +81,13 @@
     CanvasRenderingContext2D* getContext2d(const String&);
 
 #if ENABLE(WEBGL)
+    using WebGLVersion = GraphicsContextGLWebGLVersion;
     static bool isWebGLType(const String&);
-    WebGLRenderingContextBase* createContextWebGL(const String&, WebGLContextAttributes&& = { });
-    WebGLRenderingContextBase* getContextWebGL(const String&, WebGLContextAttributes&& = { });
+    static WebGLVersion toWebGLVersion(const String&);
+    WebGLRenderingContextBase* createContextWebGL(WebGLVersion type, WebGLContextAttributes&& = { });
+    WebGLRenderingContextBase* getContextWebGL(WebGLVersion type, WebGLContextAttributes&& = { });
 #endif
+
 #if ENABLE(WEBGPU)
     static bool isWebGPUType(const String&);
     GPUCanvasContext* createContextWebGPU(const String&);

Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (271064 => 271065)


--- trunk/Source/WebCore/html/OffscreenCanvas.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -190,8 +190,13 @@
             return;
     } else
         return;
-
-    m_context = WebGLRenderingContextBase::create(*this, attrs, (contextType == RenderingContextType::Webgl) ? "webgl" : "webgl2");
+    GraphicsContextGLWebGLVersion webGLVersion = GraphicsContextGLWebGLVersion::WebGL1;
+#if ENABLE(WEBGL2)
+    webGLVersion = (contextType == RenderingContextType::Webgl) ? GraphicsContextGLWebGLVersion::WebGL1 : GraphicsContextGLWebGLVersion::WebGL2;
+#else
+    UNUSED_PARAM(contextType);
+#endif
+    m_context = WebGLRenderingContextBase::create(*this, attrs, webGLVersion);
 }
 
 #endif // ENABLE(WEBGL)

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (271064 => 271065)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -645,11 +645,11 @@
     return context->powerPreferenceUsedForCreation() == WebGLPowerPreference::HighPerformance;
 }
 
-std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(CanvasBase& canvas, WebGLContextAttributes& attributes, const String& type)
+std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(CanvasBase& canvas, WebGLContextAttributes& attributes, WebGLVersion type)
 {
 #if ENABLE(WEBGL2)
     // Note: WebGL 2.0 is only supported with the ANGLE backend.
-    if (type == "webgl2" && !RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled())
+    if (type == GraphicsContextGLWebGLVersion::WebGL2 && !RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled())
         return nullptr;
 #else
     UNUSED_PARAM(type);
@@ -706,14 +706,9 @@
 
     attributes.noExtensions = true;
     attributes.shareResources = false;
-
     attributes.initialPowerPreference = attributes.powerPreference;
+    attributes.webGLVersion = type;
 
-#if ENABLE(WEBGL2)
-    if (type == "webgl2")
-        attributes.isWebGL2 = true;
-#endif
-
 #if PLATFORM(COCOA)
     if (RuntimeEnabledFeatures::sharedFeatures().webGLUsingMetal())
         attributes.useMetal = true;
@@ -723,7 +718,7 @@
         LOG(WebGL, "Create a WebGL context that looks real, but will require a policy resolution if used.");
         std::unique_ptr<WebGLRenderingContextBase> renderingContext = nullptr;
 #if ENABLE(WEBGL2)
-        if (type == "webgl2")
+        if (type == WebGLVersion::WebGL2)
             renderingContext = WebGL2RenderingContext::create(canvas, attributes);
         else
 #endif
@@ -746,7 +741,7 @@
 
     std::unique_ptr<WebGLRenderingContextBase> renderingContext;
 #if ENABLE(WEBGL2)
-    if (type == "webgl2")
+    if (type == WebGLVersion::WebGL2)
         renderingContext = WebGL2RenderingContext::create(canvas, context.releaseNonNull(), attributes);
     else
 #endif

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (271064 => 271065)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2020-12-22 22:37:46 UTC (rev 271065)
@@ -128,7 +128,8 @@
 class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBasedCanvasRenderingContext, private ActivityStateChangeObserver {
     WTF_MAKE_ISO_ALLOCATED(WebGLRenderingContextBase);
 public:
-    static std::unique_ptr<WebGLRenderingContextBase> create(CanvasBase&, WebGLContextAttributes&, const String&);
+    using WebGLVersion = GraphicsContextGLWebGLVersion;
+    static std::unique_ptr<WebGLRenderingContextBase> create(CanvasBase&, WebGLContextAttributes&, WebGLVersion);
     virtual ~WebGLRenderingContextBase();
 
     WebGLCanvas canvas();

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h (271064 => 271065)


--- trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h	2020-12-22 22:37:46 UTC (rev 271065)
@@ -35,6 +35,13 @@
     HighPerformance
 };
 
+enum class GraphicsContextGLWebGLVersion {
+    WebGL1,
+#if ENABLE(WEBGL2)
+    WebGL2
+#endif
+};
+
 struct GraphicsContextGLAttributes {
     // WebGLContextAttributes
     bool alpha { true };
@@ -49,10 +56,11 @@
 
     // Additional attributes.
     bool shareResources { true };
-    bool isWebGL2 { false };
     bool noExtensions { false };
     float devicePixelRatio { 1 };
     PowerPreference initialPowerPreference { PowerPreference::Default };
+    using WebGLVersion = GraphicsContextGLWebGLVersion;
+    WebGLVersion webGLVersion { WebGLVersion::WebGL1 };
 #if PLATFORM(COCOA)
     bool useMetal { false };
 #endif

Modified: trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp (271064 => 271065)


--- trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/platform/graphics/RemoteGraphicsContextGLProxyBase.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -57,7 +57,11 @@
 
 bool RemoteGraphicsContextGLProxyBase::isGLES2Compliant() const
 {
-    return contextAttributes().isWebGL2;
+#if ENABLE(WEBGL2)
+    return contextAttributes().webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
+#else
+    return false;
+#endif
 }
 
 void RemoteGraphicsContextGLProxyBase::markContextChanged()

Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (271064 => 271065)


--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm	2020-12-22 22:37:46 UTC (rev 271065)
@@ -102,6 +102,8 @@
         displayAttributes.append(EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE);
     }
 
+    LOG(WebGL, "Attempting to use ANGLE's %s backend.", attrs.useMetal ? "Metal" : "OpenGL");
+
     displayAttributes.append(EGL_NONE);
     display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
 
@@ -222,7 +224,7 @@
 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow* hostWindow, GraphicsContextGLOpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain)
     : GraphicsContextGL(attrs, Destination::Offscreen, sharedContext)
 {
-    m_isForWebGL2 = attrs.isWebGL2;
+    m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
 
 #if HAVE(APPLE_GRAPHICS_CONTROL)
     m_powerPreferenceUsedForCreation = (hasLowAndHighPowerGPUs() && attrs.powerPreference == GraphicsContextGLPowerPreference::HighPerformance) ? GraphicsContextGLPowerPreference::HighPerformance : GraphicsContextGLPowerPreference::Default;

Modified: trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp (271064 => 271065)


--- trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -99,9 +99,9 @@
     // Create the GraphicsContextGLOpenGL object first in order to establist a current context on this thread.
     auto context = adoptRef(new GraphicsContextGLOpenGL(attributes, hostWindow, destination));
 
-#if USE(LIBEPOXY) && USE(OPENGL_ES)
+#if USE(LIBEPOXY) && USE(OPENGL_ES) && ENABLE(WEBGL2)
     // Bail if GLES3 was requested but cannot be provided.
-    if (attributes.isWebGL2 && !epoxy_is_desktop_gl() && epoxy_gl_version() < 30)
+    if (attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2 && !epoxy_is_desktop_gl() && epoxy_gl_version() < 30)
         return nullptr;
 #endif
 
@@ -114,7 +114,9 @@
     : GraphicsContextGL(attributes, destination, sharedContext)
 {
     ASSERT_UNUSED(sharedContext, !sharedContext);
-    m_isForWebGL2 = attributes.isWebGL2;
+#if ENABLE(WEBGL2)
+    m_isForWebGL2 = attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2;
+#endif
 #if USE(NICOSIA)
     m_nicosiaLayer = WTF::makeUnique<Nicosia::GCGLANGLELayer>(*this, destination);
 #else
@@ -279,8 +281,12 @@
     }
 #else
     // Adjust the shader specification depending on whether GLES3 (i.e. WebGL2 support) was requested.
-    m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT, attributes.isWebGL2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC);
+#if ENABLE(WEBGL2)
+    m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT, (attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2) ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC);
+#else
+    m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT, SH_WEBGL_SPEC);
 #endif
+#endif
 
     // ANGLE initialization.
     ShBuiltInResources ANGLEResources;

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp (271064 => 271065)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -39,7 +39,11 @@
     switch (destination) {
     case GraphicsContextGLOpenGL::Destination::Offscreen: {
         auto sharingContext = PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->platformContext();
-        m_glContext = ANGLEContext::createContext(sharingContext, context.contextAttributes().isWebGL2);
+#if ENABLE(WEBGL2)
+        m_glContext = ANGLEContext::createContext(sharingContext, context.contextAttributes().webGLVersion == GraphicsContextGLWebGLVersion::WebGL2);
+#else
+        m_glContext = ANGLEContext::createContext(sharingContext, false);
+#endif
         break;
     }
     case GraphicsContextGLOpenGL::Destination::DirectlyToHostWindow:

Modified: trunk/Source/WebKit/ChangeLog (271064 => 271065)


--- trunk/Source/WebKit/ChangeLog	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebKit/ChangeLog	2020-12-22 22:37:46 UTC (rev 271065)
@@ -1,3 +1,18 @@
+2020-12-22  Dean Jackson  <[email protected]>
+
+        Use an enum class to identify WebGL versions
+        https://bugs.webkit.org/show_bug.cgi?id=220099
+        <rdar://problem/72596828>
+
+        Reviewed by Ken Russell.
+
+        Encode the WebGL version.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<WebCore::GraphicsContextGLAttributes>::encode):
+        (IPC::ArgumentCoder<WebCore::GraphicsContextGLAttributes>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+
 2020-12-22  Kate Cheney  <[email protected]>
 
         Cannot see 'Add to my stations' button in BBC World service Radio

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (271064 => 271065)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-12-22 22:37:46 UTC (rev 271065)
@@ -3185,7 +3185,7 @@
     encoder << attributes.failIfMajorPerformanceCaveat;
     encoder << attributes.powerPreference;
     encoder << attributes.shareResources;
-    encoder << attributes.isWebGL2;
+    encoder << attributes.webGLVersion;
     encoder << attributes.noExtensions;
     encoder << attributes.devicePixelRatio;
     encoder << attributes.initialPowerPreference;
@@ -3215,7 +3215,7 @@
         return WTF::nullopt;
     if (!decoder.decode(attributes.shareResources))
         return WTF::nullopt;
-    if (!decoder.decode(attributes.isWebGL2))
+    if (!decoder.decode(attributes.webGLVersion))
         return WTF::nullopt;
     if (!decoder.decode(attributes.noExtensions))
         return WTF::nullopt;

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (271064 => 271065)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2020-12-22 22:19:30 UTC (rev 271064)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2020-12-22 22:37:46 UTC (rev 271065)
@@ -1070,6 +1070,16 @@
     WebCore::GraphicsContextGLPowerPreference::HighPerformance
     >;
 };
+
+template <> struct EnumTraits<WebCore::GraphicsContextGLWebGLVersion> {
+    using values = EnumValues <
+    WebCore::GraphicsContextGLWebGLVersion,
+    WebCore::GraphicsContextGLWebGLVersion::WebGL1
+#if ENABLE(WEBGL2)
+    , WebCore::GraphicsContextGLWebGLVersion::WebGL2
 #endif
+    >;
+};
+#endif
 
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to