WebGPU layers don't show up sometimes
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Aug 2019 00:37:55 +0000 (00:37 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Aug 2019 00:37:55 +0000 (00:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200752

Reviewed by Dean Jackson.

Ensure HTML canvas is properly notified of WebGPU updates. Fixes alpha WebGPU MotionMark benchmark no-show issue.

Normal WebGPU behavior unaffected and covered by existing tests.

* Modules/webgpu/GPUCanvasContext.cpp:
(WebCore::GPUCanvasContext::configureSwapChain):
(WebCore::GPUCanvasContext::reshape):
* Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
(WebCore::WHLSL::Metal::inlineNativeFunction):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* html/canvas/GPUBasedCanvasRenderingContext.cpp: Added.
(WebCore::GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext):
(WebCore::GPUBasedCanvasRenderingContext::htmlCanvas const):
(WebCore::GPUBasedCanvasRenderingContext::notifyCanvasContentChanged):
* html/canvas/GPUBasedCanvasRenderingContext.h:
(WebCore::GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext): Deleted.
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::reshape):
(WebCore::WebGLRenderingContextBase::htmlCanvas): Deleted.
* html/canvas/WebGLRenderingContextBase.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::contentChanged):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/GPUCanvasContext.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.cpp [new file with mode: 0644]
Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.h
Source/WebCore/rendering/RenderLayerBacking.cpp

index e60588d..ac9292a 100644 (file)
@@ -1,3 +1,34 @@
+2019-08-19  Justin Fan  <justin_fan@apple.com>
+
+        WebGPU layers don't show up sometimes
+        https://bugs.webkit.org/show_bug.cgi?id=200752
+
+        Reviewed by Dean Jackson.
+
+        Ensure HTML canvas is properly notified of WebGPU updates. Fixes alpha WebGPU MotionMark benchmark no-show issue.
+
+        Normal WebGPU behavior unaffected and covered by existing tests.
+
+        * Modules/webgpu/GPUCanvasContext.cpp:
+        (WebCore::GPUCanvasContext::configureSwapChain):
+        (WebCore::GPUCanvasContext::reshape):
+        * Modules/webgpu/WHLSL/Metal/WHLSLNativeFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::inlineNativeFunction):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/canvas/GPUBasedCanvasRenderingContext.cpp: Added.
+        (WebCore::GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext):
+        (WebCore::GPUBasedCanvasRenderingContext::htmlCanvas const):
+        (WebCore::GPUBasedCanvasRenderingContext::notifyCanvasContentChanged):
+        * html/canvas/GPUBasedCanvasRenderingContext.h:
+        (WebCore::GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext): Deleted.
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::reshape):
+        (WebCore::WebGLRenderingContextBase::htmlCanvas): Deleted.
+        * html/canvas/WebGLRenderingContextBase.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::contentChanged):
+
 2019-08-19  Sihui Liu  <sihui_liu@apple.com>
 
         Remove IDB-specific quota
index c6c3bfd..bd20979 100644 (file)
@@ -69,6 +69,7 @@ Ref<WebGPUSwapChain> GPUCanvasContext::configureSwapChain(const WebGPUSwapChainD
             m_swapChain->destroy();
         
         m_swapChain = newSwapChain.copyRef();
+        notifyCanvasContentChanged();
     }
     
     return newSwapChain;
@@ -85,6 +86,8 @@ void GPUCanvasContext::reshape(int width, int height)
 {
     if (m_swapChain && m_swapChain->swapChain())
         m_swapChain->swapChain()->reshape(width, height);
+
+    notifyCanvasContentChanged();
 }
 
 void GPUCanvasContext::markLayerComposited()
index 23e0d3f..0a38dd4 100644 (file)
@@ -1241,6 +1241,7 @@ html/canvas/EXTFragDepth.cpp
 html/canvas/EXTShaderTextureLOD.cpp
 html/canvas/EXTsRGB.cpp
 html/canvas/EXTTextureFilterAnisotropic.cpp
+html/canvas/GPUBasedCanvasRenderingContext.cpp
 html/canvas/ImageBitmapRenderingContext.cpp
 html/canvas/OESElementIndexUint.cpp
 html/canvas/OESStandardDerivatives.cpp
index 34b982b..b4ab509 100644 (file)
                0F15DA890F3AAEE70000CE47 /* CSSAnimationControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSAnimationControllerPrivate.h; sourceTree = "<group>"; };
                0F15ED591B7EC7C500EDDFEB /* WillChangeData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillChangeData.cpp; sourceTree = "<group>"; };
                0F15ED5A1B7EC7C500EDDFEB /* WillChangeData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WillChangeData.h; sourceTree = "<group>"; };
+               0F16BED92304F05300B4A167 /* GPUBasedCanvasRenderingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUBasedCanvasRenderingContext.cpp; sourceTree = "<group>"; };
                0F17747E1378B771009DA76A /* ScrollAnimatorIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollAnimatorIOS.h; sourceTree = "<group>"; };
                0F17747F1378B772009DA76A /* ScrollAnimatorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollAnimatorIOS.mm; sourceTree = "<group>"; };
                0F1A0C36229A481800D37ADB /* VelocityData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VelocityData.h; sourceTree = "<group>"; };
                                7728694B14F8882500F484DC /* EXTTextureFilterAnisotropic.cpp */,
                                7728694C14F8882500F484DC /* EXTTextureFilterAnisotropic.h */,
                                7728694D14F8882500F484DC /* EXTTextureFilterAnisotropic.idl */,
+                               0F16BED92304F05300B4A167 /* GPUBasedCanvasRenderingContext.cpp */,
                                311518FB1E78C15F00EC514A /* GPUBasedCanvasRenderingContext.h */,
                                7C7903B11F86F95C00463A70 /* ImageBitmapRenderingContext.cpp */,
                                7C7903B01F86F95C00463A70 /* ImageBitmapRenderingContext.h */,
                510A58EE1BAB71E000C19282 /* server */ = {
                        isa = PBXGroup;
                        children = (
-                               9323B06D23061E9B00901C8B /* IDBSerializationContext.cpp */,
-                               9323B06F23061E9C00901C8B /* IDBSerializationContext.h */,
                                51BA4AC71BBC5AD600DF3D6D /* IDBBackingStore.h */,
                                516D7D6D1BB5F06500AF7C77 /* IDBConnectionToClient.cpp */,
                                510A58FE1BB07AA500C19282 /* IDBConnectionToClient.h */,
                                516D7D6E1BB5F06500AF7C77 /* IDBConnectionToClientDelegate.h */,
                                511EC1251C50AA570032F983 /* IDBSerialization.cpp */,
                                511EC1261C50AA570032F983 /* IDBSerialization.h */,
+                               9323B06D23061E9B00901C8B /* IDBSerializationContext.cpp */,
+                               9323B06F23061E9C00901C8B /* IDBSerializationContext.h */,
                                510A58EF1BAB720F00C19282 /* IDBServer.cpp */,
                                510A58F01BAB720F00C19282 /* IDBServer.h */,
                                51EEAA711BEFFA7900218008 /* IndexValueEntry.cpp */,
                                5145B10A1BC48E2E00E86219 /* IDBResourceIdentifier.h in Headers */,
                                51D7236D1BB6174900478CA3 /* IDBResultData.h in Headers */,
                                511EC1281C50AACA0032F983 /* IDBSerialization.h in Headers */,
+                               9323B07023061F9700901C8B /* IDBSerializationContext.h in Headers */,
                                5185FCBB1BB4CBF80012898F /* IDBServer.h in Headers */,
                                5185FCAD1BB4C4E80012898F /* IDBTransaction.h in Headers */,
                                5198F7AD1BBDD3EB00E2CC5F /* IDBTransactionInfo.h in Headers */,
                                BC4918C90BFEA050009D6316 /* JSHTMLIFrameElement.h in Headers */,
                                1AE2AA980A1CDD2D00B42B25 /* JSHTMLImageElement.h in Headers */,
                                A80E7E970A1A83E3007FB8C5 /* JSHTMLInputElement.h in Headers */,
-                               9323B07023061F9700901C8B /* IDBSerializationContext.h in Headers */,
                                836B09561F5F34D9003C3702 /* JSHTMLInputElementEntriesAPI.h in Headers */,
                                A6148A7912E41E3B0044A784 /* JSHTMLKeygenElement.h in Headers */,
                                1AE2AB220A1CE63B00B42B25 /* JSHTMLLabelElement.h in Headers */,
diff --git a/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.cpp b/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.cpp
new file mode 100644 (file)
index 0000000..85446f6
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * 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 APPLE INC. ``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 APPLE INC. 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 "GPUBasedCanvasRenderingContext.h"
+
+#include "HTMLCanvasElement.h"
+#include "RenderBox.h"
+
+namespace WebCore {
+
+GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext(CanvasBase& canvas)
+    : CanvasRenderingContext(canvas)
+    , ActiveDOMObject(canvas.scriptExecutionContext())
+{
+}
+
+HTMLCanvasElement* GPUBasedCanvasRenderingContext::htmlCanvas() const
+{
+    auto& base = canvasBase();
+    if (!is<HTMLCanvasElement>(base))
+        return nullptr;
+    return &downcast<HTMLCanvasElement>(base);
+}
+
+void GPUBasedCanvasRenderingContext::notifyCanvasContentChanged()
+{
+    if (auto* canvas = htmlCanvas()) {
+        RenderBox* renderBox = htmlCanvas()->renderBox();
+        if (renderBox && renderBox->hasAcceleratedCompositing())
+            renderBox->contentChanged(CanvasChanged);
+    }
+}
+
+} // namespace WebCore
index 7fce092..0ed7fb3 100644 (file)
@@ -31,6 +31,8 @@
 
 namespace WebCore {
 
+class HTMLCanvasElement;
+
 class GPUBasedCanvasRenderingContext : public CanvasRenderingContext, public ActiveDOMObject {
     WTF_MAKE_ISO_NONALLOCATABLE(GPUBasedCanvasRenderingContext);
 public:
@@ -51,11 +53,10 @@ public:
     virtual void markLayerComposited() = 0;
 
 protected:
-    GPUBasedCanvasRenderingContext(CanvasBase& canvas)
-        : CanvasRenderingContext(canvas)
-        , ActiveDOMObject(canvas.scriptExecutionContext())
-    {
-    }
+    GPUBasedCanvasRenderingContext(CanvasBase&);
+
+    HTMLCanvasElement* htmlCanvas() const;
+    void notifyCanvasContentChanged();
 };
     
 } // namespace WebCore
index d166fb2..561fdd0 100644 (file)
@@ -676,14 +676,6 @@ WebGLCanvas WebGLRenderingContextBase::canvas()
     return &downcast<HTMLCanvasElement>(base);
 }
 
-HTMLCanvasElement* WebGLRenderingContextBase::htmlCanvas()
-{
-    auto& base = canvasBase();
-    if (!is<HTMLCanvasElement>(base))
-        return nullptr;
-    return &downcast<HTMLCanvasElement>(base);
-}
-
 OffscreenCanvas* WebGLRenderingContextBase::offscreenCanvas()
 {
     auto& base = canvasBase();
@@ -1089,12 +1081,7 @@ void WebGLRenderingContextBase::reshape(int width, int height)
     height = clamp(height, 1, maxHeight);
 
     if (m_needsUpdate) {
-        auto* canvas = htmlCanvas();
-        if (canvas) {
-            RenderBox* renderBox = htmlCanvas()->renderBox();
-            if (renderBox && renderBox->hasAcceleratedCompositing())
-                renderBox->contentChanged(CanvasChanged);
-        }
+        notifyCanvasContentChanged();
         m_needsUpdate = false;
     }
 
index d2d0db4..79fd4e7 100644 (file)
@@ -836,7 +836,6 @@ protected:
     // Check if EXT_draw_buffers extension is supported and if it satisfies the WebGL requirements.
     bool supportsDrawBuffers();
 
-    HTMLCanvasElement* htmlCanvas();
     OffscreenCanvas* offscreenCanvas();
 
     template <typename T> inline Optional<T> checkedAddAndMultiply(T value, T add, T multiply);
index 121d12f..e617259 100644 (file)
@@ -926,7 +926,7 @@ bool RenderLayerBacking::updateConfiguration()
         resetContentsRect();
     }
 #endif
-#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
+#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(WEBGPU)
     else if (renderer().isCanvas() && canvasCompositingStrategy(renderer()) == CanvasAsLayerContents) {
         const HTMLCanvasElement* canvas = downcast<HTMLCanvasElement>(renderer().element());
         if (auto* context = canvas->renderingContext())
@@ -2512,8 +2512,11 @@ void RenderLayerBacking::contentChanged(ContentChangeType changeType)
     if ((changeType == MaskImageChanged) && m_maskLayer)
         m_owningLayer.setNeedsCompositingConfigurationUpdate();
 
-#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS)
+#if ENABLE(WEBGL) || ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(WEBGPU)
     if ((changeType == CanvasChanged || changeType == CanvasPixelsChanged) && renderer().isCanvas() && canvasCompositingStrategy(renderer()) == CanvasAsLayerContents) {
+        if (changeType == CanvasChanged)
+            compositor().scheduleCompositingLayerUpdate();
+
         m_graphicsLayer->setContentsNeedsDisplay();
         return;
     }