[WebGL] Remove software rendering and simplify context creation on macOS
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Jul 2019 22:27:45 +0000 (22:27 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Jul 2019 22:27:45 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199789

Reviewed by Sam Weinig.

Source/WebCore:

We don't ever want to fall-back to the software renderer. We'd be better
off failing to create the context completely.

Also, the number of fall-back attempts we were making before hitting
the software renderer was overkill. All hardware we support should
handle a 32bpp buffer.

Lastly, we don't want to support supersampling - multisampling only.

I lied… there is one more thing - failing to create the context
was causing an ASSERT trying to remove the GC3D from the global list.

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* page/Settings.yaml: Remove forceSoftwareWebGL setting.
* platform/graphics/GraphicsContext3DAttributes.h:
* platform/graphics/GraphicsContext3DManager.cpp:
(WebCore::GraphicsContext3DManager::addContext):
(WebCore::GraphicsContext3DManager::removeContext):
(WebCore::GraphicsContext3DManager::removeContextRequiringHighPerformance):
* platform/graphics/cocoa/GraphicsContext3DCocoa.mm:
(WebCore::GraphicsContext3D::GraphicsContext3D):
(WebCore::setPixelFormat): Deleted.

Source/WebKit:

Remove force software WebGL setting.

* Shared/WebPreferences.yaml:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetForceSoftwareWebGLRendering): Deleted.
(WKPreferencesGetForceSoftwareWebGLRendering): Deleted.
* UIProcess/API/C/WKPreferencesRefPrivate.h:

Source/WebKitLegacy/mac:

Remove force software WebGL setting.

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences forceSoftwareWebGLRendering]): Deleted.
(-[WebPreferences setForceSoftwareWebGLRendering:]): Deleted.
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/page/Settings.yaml
Source/WebCore/platform/graphics/GraphicsContext3DAttributes.h
Source/WebCore/platform/graphics/GraphicsContext3DManager.cpp
Source/WebCore/platform/graphics/cocoa/GraphicsContext3DCocoa.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/UIProcess/API/C/WKPreferences.cpp
Source/WebKit/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h
Source/WebKitLegacy/mac/WebView/WebView.mm

index f13bf21..736cf73 100644 (file)
@@ -1,3 +1,34 @@
+2019-07-15  Dean Jackson  <dino@apple.com>
+
+        [WebGL] Remove software rendering and simplify context creation on macOS
+        https://bugs.webkit.org/show_bug.cgi?id=199789
+
+        Reviewed by Sam Weinig.
+
+        We don't ever want to fall-back to the software renderer. We'd be better
+        off failing to create the context completely.
+
+        Also, the number of fall-back attempts we were making before hitting
+        the software renderer was overkill. All hardware we support should
+        handle a 32bpp buffer.
+
+        Lastly, we don't want to support supersampling - multisampling only.
+
+        I lied… there is one more thing - failing to create the context
+        was causing an ASSERT trying to remove the GC3D from the global list.
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * page/Settings.yaml: Remove forceSoftwareWebGL setting.
+        * platform/graphics/GraphicsContext3DAttributes.h:
+        * platform/graphics/GraphicsContext3DManager.cpp:
+        (WebCore::GraphicsContext3DManager::addContext):
+        (WebCore::GraphicsContext3DManager::removeContext):
+        (WebCore::GraphicsContext3DManager::removeContextRequiringHighPerformance):
+        * platform/graphics/cocoa/GraphicsContext3DCocoa.mm:
+        (WebCore::GraphicsContext3D::GraphicsContext3D):
+        (WebCore::setPixelFormat): Deleted.
+
 2019-07-14  Dean Jackson  <dino@apple.com>
 
         Move more WebGL things into unified builds
index c85a8f4..3ece7ee 100644 (file)
@@ -562,9 +562,6 @@ std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(Can
             }
         }
 
-        if (frame->settings().forceSoftwareWebGLRendering())
-            attributes.forceSoftwareRenderer = true;
-
         if (frame->settings().forceWebGLUsesLowPower()) {
             if (attributes.powerPreference == GraphicsContext3DPowerPreference::HighPerformance)
                 LOG(WebGL, "Overriding powerPreference from high-performance to low-power.");
index 7e7d01a..45625e1 100644 (file)
@@ -237,8 +237,6 @@ webGLErrorsToConsoleEnabled:
   initial: true
 unhandledPromiseRejectionToConsoleEnabled:
   initial: true
-forceSoftwareWebGLRendering:
-  initial: false
 forceWebGLUsesLowPower:
   initial: false
 accelerated2dCanvasEnabled:
index 32a7bbb..97ff17c 100644 (file)
@@ -46,7 +46,6 @@ struct GraphicsContext3DAttributes {
     PowerPreference powerPreference { PowerPreference::Default };
 
     // Additional attributes.
-    bool forceSoftwareRenderer { false };
     bool shareResources { true };
     bool isWebGL2 { false };
     bool noExtensions { false };
index 0880008..89e3e59 100644 (file)
@@ -160,7 +160,7 @@ void GraphicsContext3DManager::addContext(GraphicsContext3D* context, HostWindow
     ASSERT(context);
     if (!context)
         return;
-    
+
 #if PLATFORM(MAC) && !ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
     if (!m_contexts.size())
         CGDisplayRegisterReconfigurationCallback(displayWasReconfigured, nullptr);
@@ -173,7 +173,8 @@ void GraphicsContext3DManager::addContext(GraphicsContext3D* context, HostWindow
 
 void GraphicsContext3DManager::removeContext(GraphicsContext3D* context)
 {
-    ASSERT(m_contexts.contains(context));
+    if (!m_contexts.contains(context))
+        return;
     m_contexts.removeFirst(context);
     m_contextWindowMap.remove(context);
     removeContextRequiringHighPerformance(context);
@@ -207,6 +208,9 @@ void GraphicsContext3DManager::addContextRequiringHighPerformance(GraphicsContex
 
 void GraphicsContext3DManager::removeContextRequiringHighPerformance(GraphicsContext3D* context)
 {
+    if (!context)
+        return;
+
     if (!m_contextsRequiringHighPerformance.contains(context))
         return;
     
index 0757fa6..892b4a9 100644 (file)
@@ -98,57 +98,6 @@ public:
     ~GraphicsContext3DPrivate() { }
 };
 
-#if USE(OPENGL)
-
-static void setPixelFormat(Vector<CGLPixelFormatAttribute>& attribs, int colorBits, int depthBits, bool accelerated, bool supersample, bool closest, bool antialias, bool isWebGL2, bool allowOfflineRenderers)
-{
-    attribs.clear();
-    
-    attribs.append(kCGLPFAColorSize);
-    attribs.append(static_cast<CGLPixelFormatAttribute>(colorBits));
-    attribs.append(kCGLPFADepthSize);
-    attribs.append(static_cast<CGLPixelFormatAttribute>(depthBits));
-
-    // This attribute, while mentioning offline renderers, is actually
-    // allowing us to request the integrated graphics on a dual GPU
-    // system, and not force the discrete GPU.
-    // See https://developer.apple.com/library/mac/technotes/tn2229/_index.html
-    if (allowOfflineRenderers)
-        attribs.append(kCGLPFAAllowOfflineRenderers);
-
-    if (accelerated)
-        attribs.append(kCGLPFAAccelerated);
-    else {
-        attribs.append(kCGLPFARendererID);
-        attribs.append(static_cast<CGLPixelFormatAttribute>(kCGLRendererGenericFloatID));
-    }
-        
-    if (supersample && !antialias)
-        attribs.append(kCGLPFASupersample);
-
-    if (closest)
-        attribs.append(kCGLPFAClosestPolicy);
-
-    if (antialias) {
-        attribs.append(kCGLPFAMultisample);
-        attribs.append(kCGLPFASampleBuffers);
-        attribs.append(static_cast<CGLPixelFormatAttribute>(1));
-        attribs.append(kCGLPFASamples);
-        attribs.append(static_cast<CGLPixelFormatAttribute>(4));
-    }
-
-    if (isWebGL2) {
-        // FIXME: Instead of backing a WebGL2 GraphicsContext3D with a OpenGL 4 context, we should instead back it with ANGLE.
-        // Use an OpenGL 4 context for now until the ANGLE backend is ready.
-        attribs.append(kCGLPFAOpenGLProfile);
-        attribs.append(static_cast<CGLPixelFormatAttribute>(kCGLOGLPVersion_GL4_Core));
-    }
-        
-    attribs.append(static_cast<CGLPixelFormatAttribute>(0));
-}
-
-#endif // USE(OPENGL)
-
 RefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3DAttributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
 {
     // This implementation doesn't currently support rendering directly to the HostWindow.
@@ -289,56 +238,51 @@ GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attrs, HostWind
     if (m_attrs.isWebGL2)
         ::glEnable(GraphicsContext3D::PRIMITIVE_RESTART_FIXED_INDEX);
 #elif USE(OPENGL)
-    Vector<CGLPixelFormatAttribute> attribs;
-    CGLPixelFormatObj pixelFormatObj = 0;
-    GLint numPixelFormats = 0;
-    
+
 #if HAVE(APPLE_GRAPHICS_CONTROL)
     m_powerPreferenceUsedForCreation = (hasLowAndHighPowerGPUs() && attrs.powerPreference == GraphicsContext3DPowerPreference::HighPerformance) ? GraphicsContext3DPowerPreference::HighPerformance : GraphicsContext3DPowerPreference::Default;
 #else
     m_powerPreferenceUsedForCreation = GraphicsContext3DPowerPreference::Default;
 #endif
 
-    // If we're configured to demand the software renderer, we'll
-    // do so. We attempt to create contexts in this order:
-    //
-    // 1) 32 bit RGBA/32 bit depth/supersampled
-    // 2) 32 bit RGBA/32 bit depth
-    // 3) 32 bit RGBA/16 bit depth
-    //
-    // If we were not forced into software mode already, our final attempt is
-    // to try that:
-    //
-    // 4) closest to 32 bit RGBA/16 bit depth/software renderer
-    //
-    // If none of that works, we fail and leave m_contextObj as nullptr.
-
     bool useMultisampling = m_attrs.antialias;
 
-    setPixelFormat(attribs, 32, 32, !attrs.forceSoftwareRenderer, true, false, useMultisampling, attrs.isWebGL2, allowOfflineRenderers());
-    CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
+    Vector<CGLPixelFormatAttribute> attribs;
+    CGLPixelFormatObj pixelFormatObj = 0;
+    GLint numPixelFormats = 0;
 
-    if (!numPixelFormats) {
-        setPixelFormat(attribs, 32, 32, !attrs.forceSoftwareRenderer, true, false, useMultisampling, attrs.isWebGL2, allowOfflineRenderers());
-        CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
+    attribs.append(kCGLPFAAccelerated);
+    attribs.append(kCGLPFAColorSize);
+    attribs.append(static_cast<CGLPixelFormatAttribute>(32));
+    attribs.append(kCGLPFADepthSize);
+    attribs.append(static_cast<CGLPixelFormatAttribute>(32));
 
-        if (!numPixelFormats) {
-            setPixelFormat(attribs, 32, 32, !attrs.forceSoftwareRenderer, false, false, useMultisampling, attrs.isWebGL2, allowOfflineRenderers());
-            CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
+    // This attribute, while mentioning offline renderers, is actually
+    // allowing us to request the integrated graphics on a dual GPU
+    // system, and not force the discrete GPU.
+    // See https://developer.apple.com/library/mac/technotes/tn2229/_index.html
+    if (allowOfflineRenderers())
+        attribs.append(kCGLPFAAllowOfflineRenderers);
 
-            if (!numPixelFormats) {
-                setPixelFormat(attribs, 32, 16, !attrs.forceSoftwareRenderer, false, false, useMultisampling, attrs.isWebGL2, allowOfflineRenderers());
-                CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
+    if (useMultisampling) {
+        attribs.append(kCGLPFAMultisample);
+        attribs.append(kCGLPFASampleBuffers);
+        attribs.append(static_cast<CGLPixelFormatAttribute>(1));
+        attribs.append(kCGLPFASamples);
+        attribs.append(static_cast<CGLPixelFormatAttribute>(4));
+    }
 
-                if (!attrs.forceSoftwareRenderer && !numPixelFormats) {
-                    setPixelFormat(attribs, 32, 16, false, false, true, false, attrs.isWebGL2, allowOfflineRenderers());
-                    CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
-                    useMultisampling = false;
-                }
-            }
-        }
+    if (attrs.isWebGL2) {
+        // FIXME: Instead of backing a WebGL2 GraphicsContext3D with a OpenGL 4 context, we should instead back it with ANGLE.
+        // Use an OpenGL 4 context for now until the ANGLE backend is ready.
+        attribs.append(kCGLPFAOpenGLProfile);
+        attribs.append(static_cast<CGLPixelFormatAttribute>(kCGLOGLPVersion_GL4_Core));
     }
 
+    attribs.append(static_cast<CGLPixelFormatAttribute>(0));
+
+    CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
+
     if (!numPixelFormats)
         return;
 
index d1e1188..770d317 100644 (file)
@@ -1,3 +1,18 @@
+2019-07-15  Dean Jackson  <dino@apple.com>
+
+        [WebGL] Remove software rendering and simplify context creation on macOS
+        https://bugs.webkit.org/show_bug.cgi?id=199789
+
+        Reviewed by Sam Weinig.
+
+        Remove force software WebGL setting.
+
+        * Shared/WebPreferences.yaml:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetForceSoftwareWebGLRendering): Deleted.
+        (WKPreferencesGetForceSoftwareWebGLRendering): Deleted.
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+
 2019-07-15  Daniel Bates  <dabates@apple.com>
 
         Typing into a cell in a Google Sheet lags behind by one character
index 6fe8530..1d3412b 100644 (file)
@@ -130,10 +130,6 @@ WebGLEnabled:
   type: bool
   defaultValue: true
 
-ForceSoftwareWebGLRendering:
-  type: bool
-  defaultValue: false
-
 Accelerated2dCanvasEnabled:
   type: bool
   defaultValue: false
index a031798..2326050 100644 (file)
@@ -469,16 +469,6 @@ bool WKPreferencesGetWebGLEnabled(WKPreferencesRef preferencesRef)
     return toImpl(preferencesRef)->webGLEnabled();
 }
 
-void WKPreferencesSetForceSoftwareWebGLRendering(WKPreferencesRef preferencesRef, bool flag)
-{
-    toImpl(preferencesRef)->setForceSoftwareWebGLRendering(flag);
-}
-
-bool WKPreferencesGetForceSoftwareWebGLRendering(WKPreferencesRef preferencesRef)
-{
-    return toImpl(preferencesRef)->forceSoftwareWebGLRendering();
-}
-
 void WKPreferencesSetAccelerated2DCanvasEnabled(WKPreferencesRef preferencesRef, bool flag)
 {
     toImpl(preferencesRef)->setAccelerated2dCanvasEnabled(flag);
index 5c3398c..b47a0ad 100644 (file)
@@ -91,10 +91,6 @@ WK_EXPORT void WKPreferencesSetWebGLEnabled(WKPreferencesRef, bool);
 WK_EXPORT bool WKPreferencesGetWebGLEnabled(WKPreferencesRef);
 
 // Defaults to false.
-WK_EXPORT void WKPreferencesSetForceSoftwareWebGLRendering(WKPreferencesRef, bool);
-WK_EXPORT bool WKPreferencesGetForceSoftwareWebGLRendering(WKPreferencesRef);
-
-// Defaults to false.
 WK_EXPORT void WKPreferencesSetAccelerated2DCanvasEnabled(WKPreferencesRef, bool);
 WK_EXPORT bool WKPreferencesGetAccelerated2DCanvasEnabled(WKPreferencesRef);
 
index f2653b2..412f0e8 100644 (file)
@@ -1,3 +1,21 @@
+2019-07-15  Dean Jackson  <dino@apple.com>
+
+        [WebGL] Remove software rendering and simplify context creation on macOS
+        https://bugs.webkit.org/show_bug.cgi?id=199789
+
+        Reviewed by Sam Weinig.
+
+        Remove force software WebGL setting.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        (-[WebPreferences forceSoftwareWebGLRendering]): Deleted.
+        (-[WebPreferences setForceSoftwareWebGLRendering:]): Deleted.
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2019-07-13  Zalan Bujtas  <zalan@apple.com>
 
         Cannot bring up custom media controls at all on v.youku.com
index 86addf6..f22f1ff 100644 (file)
 #define WebKitWebGLEnabledPreferenceKey @"WebKitWebGLEnabled"
 #define WebKitWebGL2EnabledPreferenceKey @"WebKitWebGL2Enabled"
 #define WebKitWebGPUEnabledPreferenceKey @"WebKitWebGPUEnabled"
-#define WebKitForceSoftwareWebGLRenderingPreferenceKey @"WebKitForceSoftwareWebGLRendering"
 #define WebKitForceWebGLUsesLowPowerPreferenceKey @"WebKitForceWebGLUsesLowPower"
 #define WebKitAccelerated2dCanvasEnabledPreferenceKey @"WebKitAccelerated2dCanvasEnabled"
 #define WebKitFrameFlatteningPreferenceKey @"WebKitFrameFlattening"
index ec91327..014adde 100644 (file)
@@ -506,7 +506,6 @@ public:
         [NSNumber numberWithBool:NO],   WebKitSimpleLineLayoutDebugBordersEnabledPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitShowRepaintCounterPreferenceKey,
         [NSNumber numberWithBool:YES],  WebKitWebGLEnabledPreferenceKey,
-        [NSNumber numberWithBool:NO],  WebKitForceSoftwareWebGLRenderingPreferenceKey,
         [NSNumber numberWithBool:YES],   WebKitForceWebGLUsesLowPowerPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitAccelerated2dCanvasEnabledPreferenceKey,
         [NSNumber numberWithBool:NO],  WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey,
@@ -2144,16 +2143,6 @@ static NSString *classIBCreatorID = nil;
     [self _setBoolValue:enabled forKey:WebKitWebGL2EnabledPreferenceKey];
 }
 
-- (BOOL)forceSoftwareWebGLRendering
-{
-    return [self _boolValueForKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
-}
-
-- (void)setForceSoftwareWebGLRendering:(BOOL)forced
-{
-    [self _setBoolValue:forced forKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
-}
-
 - (BOOL)forceLowPowerGPUForWebGL
 {
     return [self _boolValueForKey:WebKitForceWebGLUsesLowPowerPreferenceKey];
index a8b9ac7..09a83b2 100644 (file)
@@ -275,9 +275,6 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR
 - (BOOL)webGL2Enabled;
 - (void)setWebGL2Enabled:(BOOL)enabled;
 
-- (BOOL)forceSoftwareWebGLRendering;
-- (void)setForceSoftwareWebGLRendering:(BOOL)forced;
-
 - (BOOL)forceLowPowerGPUForWebGL;
 - (void)setForceWebGLUsesLowPower:(BOOL)forceLowPower;
 
index cdcc0fc..525c725 100644 (file)
@@ -2939,7 +2939,6 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setSubpixelCSSOMElementMetricsEnabled([preferences subpixelCSSOMElementMetricsEnabled]);
     settings.setSubpixelAntialiasedLayerTextEnabled([preferences subpixelAntialiasedLayerTextEnabled]);
 
-    settings.setForceSoftwareWebGLRendering([preferences forceSoftwareWebGLRendering]);
     settings.setForceWebGLUsesLowPower([preferences forceLowPowerGPUForWebGL]);
     settings.setAccelerated2dCanvasEnabled([preferences accelerated2dCanvasEnabled]);
     settings.setLoadDeferringEnabled(shouldEnableLoadDeferring());