Diff
Modified: trunk/Source/WebCore/ChangeLog (214016 => 214017)
--- trunk/Source/WebCore/ChangeLog 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/ChangeLog 2017-03-15 22:56:21 UTC (rev 214017)
@@ -1,3 +1,46 @@
+2017-03-15 Dean Jackson <d...@apple.com>
+
+ Make a base class for WebGL and WebGPU contexts
+ https://bugs.webkit.org/show_bug.cgi?id=169651
+ <rdar://problem/31053489>
+
+ Reviewed by Simon Fraser.
+
+ Add a new pure virtual base class, GPUBasedCanvasRenderingContext, that
+ will be used by WebGL and WebGPU rendering contexts. This allows us
+ to avoid some code duplication, since many places treat the two
+ as the same.
+
+ Also rename is3d() -> isWebGL() and isGPU() -> isWebGPU().
+
+ * WebCore.xcodeproj/project.pbxproj: New file.
+ * html/HTMLCanvasElement.cpp:
+ (WebCore::HTMLCanvasElement::getContextWebGL):
+ (WebCore::HTMLCanvasElement::getContextWebGPU):
+ (WebCore::HTMLCanvasElement::reset):
+ (WebCore::HTMLCanvasElement::paint):
+ (WebCore::HTMLCanvasElement::isGPUBased):
+ (WebCore::HTMLCanvasElement::getImageData):
+ (WebCore::HTMLCanvasElement::isGPU): Deleted.
+ (WebCore::HTMLCanvasElement::is3D): Deleted.
+ * html/HTMLCanvasElement.h:
+ * html/canvas/CanvasRenderingContext.h:
+ (WebCore::CanvasRenderingContext::isWebGL):
+ (WebCore::CanvasRenderingContext::isWebGPU):
+ (WebCore::CanvasRenderingContext::isGPUBased):
+ (WebCore::CanvasRenderingContext::is3d): Deleted.
+ (WebCore::CanvasRenderingContext::isGPU): Deleted.
+ * html/canvas/GPUBasedCanvasRenderingContext.h: Added.
+ (WebCore::GPUBasedCanvasRenderingContext::GPUBasedCanvasRenderingContext):
+ * html/canvas/WebGLRenderingContextBase.cpp:
+ (WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
+ * html/canvas/WebGLRenderingContextBase.h:
+ * html/canvas/WebGPURenderingContext.cpp:
+ (WebCore::WebGPURenderingContext::WebGPURenderingContext):
+ * html/canvas/WebGPURenderingContext.h:
+ * rendering/RenderLayerBacking.cpp:
+ (WebCore::canvasCompositingStrategy):
+
2017-03-15 Daniel Bates <daba...@apple.com>
Iteratively dispatch DOM events after restoring a cached page
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (214016 => 214017)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-03-15 22:56:21 UTC (rev 214017)
@@ -1334,6 +1334,7 @@
31078CCA1880AACE008099DC /* JSOESTextureHalfFloatLinear.h in Headers */ = {isa = PBXBuildFile; fileRef = 31078CC61880AAAA008099DC /* JSOESTextureHalfFloatLinear.h */; };
310D71951B335C9D009C7B73 /* ThemeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 310D71931B335C9D009C7B73 /* ThemeCocoa.mm */; };
310D71961B335C9E009C7B73 /* ThemeCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 310D71941B335C9D009C7B73 /* ThemeCocoa.h */; };
+ 311518FC1E78C15F00EC514A /* GPUBasedCanvasRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 311518FB1E78C15F00EC514A /* GPUBasedCanvasRenderingContext.h */; };
311C08BD18EB7CAF00B65615 /* mediaControlsApple.css in Resources */ = {isa = PBXBuildFile; fileRef = CDC1DD4117CC2C48008CB55D /* mediaControlsApple.css */; };
311C08BE18EB7CAF00B65615 /* mediaControlsApple.js in Resources */ = {isa = PBXBuildFile; fileRef = CDE6560E17CA6E7600526BA7 /* mediaControlsApple.js */; };
311C08BF18EB7CAF00B65615 /* mediaControlsiOS.css in Resources */ = {isa = PBXBuildFile; fileRef = CDAAF45D1869094E003C1717 /* mediaControlsiOS.css */; };
@@ -8817,6 +8818,7 @@
31078CC61880AAAA008099DC /* JSOESTextureHalfFloatLinear.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSOESTextureHalfFloatLinear.h; sourceTree = "<group>"; };
310D71931B335C9D009C7B73 /* ThemeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ThemeCocoa.mm; sourceTree = "<group>"; };
310D71941B335C9D009C7B73 /* ThemeCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThemeCocoa.h; sourceTree = "<group>"; };
+ 311518FB1E78C15F00EC514A /* GPUBasedCanvasRenderingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUBasedCanvasRenderingContext.h; sourceTree = "<group>"; };
311C08BC18E35D6800B65615 /* ControlStates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlStates.h; sourceTree = "<group>"; };
31288E6E0E3005D6003619AE /* CSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSKeyframeRule.cpp; sourceTree = "<group>"; };
31288E6F0E3005D6003619AE /* CSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSKeyframeRule.h; sourceTree = "<group>"; };
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (214016 => 214017)
--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2017-03-15 22:56:21 UTC (rev 214017)
@@ -37,6 +37,7 @@
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoaderClient.h"
+#include "GPUBasedCanvasRenderingContext.h"
#include "GeometryUtilities.h"
#include "GraphicsContext.h"
#include "HTMLNames.h"
@@ -293,7 +294,7 @@
if (!shouldEnableWebGL(document().settings()))
return nullptr;
- if (m_context && !m_context->is3d())
+ if (m_context && !m_context->isWebGL())
return nullptr;
if (!m_context) {
@@ -321,7 +322,7 @@
if (!RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled())
return nullptr;
- if (m_context && !m_context->isGPU())
+ if (m_context && !m_context->isWebGPU())
return nullptr;
if (!m_context) {
@@ -393,17 +394,9 @@
setSurfaceSize(newSize);
-#if ENABLE(WEBGPU)
- // FIXME: WebGPU needs something here too.
- if (isGPU() && oldSize != size())
- static_cast<WebGPURenderingContext*>(m_context.get())->reshape(width(), height());
-#endif
+ if (isGPUBased() && oldSize != size())
+ downcast<GPUBasedCanvasRenderingContext>(*m_context).reshape(width(), height());
-#if ENABLE(WEBGL)
- if (is3D() && oldSize != size())
- static_cast<WebGLRenderingContextBase*>(m_context.get())->reshape(width(), height());
-#endif
-
auto renderer = this->renderer();
if (is<RenderHTMLCanvas>(renderer)) {
auto& canvasRenderer = downcast<RenderHTMLCanvas>(*renderer);
@@ -467,31 +460,15 @@
}
}
-#if ENABLE(WEBGPU)
- if (isGPU())
- static_cast<WebGPURenderingContext*>(m_context.get())->markLayerComposited();
-#endif
-
-#if ENABLE(WEBGL)
- if (is3D())
- static_cast<WebGLRenderingContextBase*>(m_context.get())->markLayerComposited();
-#endif
+ if (isGPUBased())
+ downcast<GPUBasedCanvasRenderingContext>(*m_context).markLayerComposited();
}
-#if ENABLE(WEBGPU)
-bool HTMLCanvasElement::isGPU() const
+bool HTMLCanvasElement::isGPUBased() const
{
- return m_context && m_context->isGPU();
+ return m_context && m_context->isGPUBased();
}
-#endif
-#if ENABLE(WEBGL)
-bool HTMLCanvasElement::is3D() const
-{
- return m_context && m_context->is3d();
-}
-#endif
-
void HTMLCanvasElement::makeRenderingResultsAvailable()
{
if (m_context)
@@ -592,7 +569,7 @@
RefPtr<ImageData> HTMLCanvasElement::getImageData()
{
#if ENABLE(WEBGL)
- if (!is3D())
+ if (!m_context || !m_context->isWebGL())
return nullptr;
WebGLRenderingContextBase* ctx = static_cast<WebGLRenderingContextBase*>(m_context.get());
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (214016 => 214017)
--- trunk/Source/WebCore/html/HTMLCanvasElement.h 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h 2017-03-15 22:56:21 UTC (rev 214017)
@@ -177,12 +177,7 @@
bool paintsIntoCanvasBuffer() const;
-#if ENABLE(WEBGL)
- bool is3D() const;
-#endif
-#if ENABLE(WEBGPU)
- bool isGPU() const;
-#endif
+ bool isGPUBased() const;
HashSet<CanvasObserver*> m_observers;
std::unique_ptr<CanvasRenderingContext> m_context;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h (214016 => 214017)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2017-03-15 22:56:21 UTC (rev 214017)
@@ -53,8 +53,11 @@
virtual bool is2d() const { return false; }
virtual bool isWebGL1() const { return false; }
virtual bool isWebGL2() const { return false; }
- bool is3d() const { return isWebGL1() || isWebGL2(); }
- virtual bool isGPU() const { return false; }
+ bool isWebGL() const { return isWebGL1() || isWebGL2(); }
+#if ENABLE(WEBGPU)
+ virtual bool isWebGPU() const { return false; }
+#endif
+ virtual bool isGPUBased() const { return false; }
virtual bool isAccelerated() const { return false; }
virtual void paintRenderingResultsToCanvas() {}
Added: trunk/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h (0 => 214017)
--- trunk/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h (rev 0)
+++ trunk/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h 2017-03-15 22:56:21 UTC (rev 214017)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#include "ActiveDOMObject.h"
+#include "CanvasRenderingContext.h"
+
+namespace WebCore {
+
+class GPUBasedCanvasRenderingContext : public CanvasRenderingContext, public ActiveDOMObject {
+public:
+
+ bool isGPUBased() const override { return true; }
+
+ bool isAccelerated() const override
+ {
+#if PLATFORM(WIN)
+ // FIXME: Implement accelerated canvas on Windows.
+ return false;
+#else
+ return true;
+#endif
+ }
+
+ virtual void reshape(int width, int height) = 0;
+ virtual void markLayerComposited() = 0;
+
+protected:
+ GPUBasedCanvasRenderingContext(HTMLCanvasElement& passedCanvas)
+ : CanvasRenderingContext(passedCanvas)
+ , ActiveDOMObject(&passedCanvas.document())
+ {
+ }
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::GPUBasedCanvasRenderingContext, isGPUBased())
Property changes on: trunk/Source/WebCore/html/canvas/GPUBasedCanvasRenderingContext.h
___________________________________________________________________
Added: svn:eol-style
+native
\ No newline at end of property
Added: svn:keywords
+Date Author Id Revision HeadURL
\ No newline at end of property
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (214016 => 214017)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2017-03-15 22:56:21 UTC (rev 214017)
@@ -460,8 +460,7 @@
}
WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement& passedCanvas, WebGLContextAttributes attributes)
- : CanvasRenderingContext(passedCanvas)
- , ActiveDOMObject(&passedCanvas.document())
+ : GPUBasedCanvasRenderingContext(passedCanvas)
, m_dispatchContextLostEventTimer(*this, &WebGLRenderingContextBase::dispatchContextLostEvent)
, m_restoreTimer(*this, &WebGLRenderingContextBase::maybeRestoreContext)
, m_attributes(attributes)
@@ -474,8 +473,7 @@
}
WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement& passedCanvas, Ref<GraphicsContext3D>&& context, WebGLContextAttributes attributes)
- : CanvasRenderingContext(passedCanvas)
- , ActiveDOMObject(&passedCanvas.document())
+ : GPUBasedCanvasRenderingContext(passedCanvas)
, m_context(WTFMove(context))
, m_dispatchContextLostEventTimer(*this, &WebGLRenderingContextBase::dispatchContextLostEvent)
, m_restoreTimer(*this, &WebGLRenderingContextBase::maybeRestoreContext)
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (214016 => 214017)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h 2017-03-15 22:56:21 UTC (rev 214017)
@@ -27,9 +27,8 @@
#if ENABLE(WEBGL)
-#include "ActiveDOMObject.h"
#include "ActivityStateChangeObserver.h"
-#include "CanvasRenderingContext.h"
+#include "GPUBasedCanvasRenderingContext.h"
#include "GraphicsContext3D.h"
#include "ImageBuffer.h"
#include "Timer.h"
@@ -110,18 +109,11 @@
return (*clippedX != x || *clippedY != y || *clippedWidth != width || *clippedHeight != height);
}
-class WebGLRenderingContextBase : public CanvasRenderingContext, private ActivityStateChangeObserver, public ActiveDOMObject {
+class WebGLRenderingContextBase : public GPUBasedCanvasRenderingContext, private ActivityStateChangeObserver {
public:
static std::unique_ptr<WebGLRenderingContextBase> create(HTMLCanvasElement&, WebGLContextAttributes&, const String&);
virtual ~WebGLRenderingContextBase();
-#if PLATFORM(WIN)
- // FIXME: Implement accelerated 3d canvas on Windows.
- bool isAccelerated() const override { return false; }
-#else
- bool isAccelerated() const override { return true; }
-#endif
-
int drawingBufferWidth() const;
int drawingBufferHeight() const;
@@ -347,9 +339,9 @@
WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); }
PlatformLayer* platformLayer() const override;
- void reshape(int width, int height);
+ void reshape(int width, int height) override;
- void markLayerComposited();
+ void markLayerComposited() final;
void paintRenderingResultsToCanvas() override;
RefPtr<ImageData> paintRenderingResultsToImageData();
@@ -846,6 +838,6 @@
} // namespace WebCore
-SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGLRenderingContextBase, is3d())
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGLRenderingContextBase, isWebGL())
#endif
Modified: trunk/Source/WebCore/html/canvas/WebGPURenderingContext.cpp (214016 => 214017)
--- trunk/Source/WebCore/html/canvas/WebGPURenderingContext.cpp 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/canvas/WebGPURenderingContext.cpp 2017-03-15 22:56:21 UTC (rev 214017)
@@ -86,8 +86,7 @@
}
WebGPURenderingContext::WebGPURenderingContext(HTMLCanvasElement& canvas, PassRefPtr<GPUDevice> device)
- : CanvasRenderingContext(canvas)
- , ActiveDOMObject(&canvas.document())
+ : GPUBasedCanvasRenderingContext(canvas)
, m_device(device)
{
initializeNewContext();
Modified: trunk/Source/WebCore/html/canvas/WebGPURenderingContext.h (214016 => 214017)
--- trunk/Source/WebCore/html/canvas/WebGPURenderingContext.h 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/html/canvas/WebGPURenderingContext.h 2017-03-15 22:56:21 UTC (rev 214017)
@@ -27,8 +27,7 @@
#if ENABLE(WEBGPU)
-#include "ActiveDOMObject.h"
-#include "CanvasRenderingContext.h"
+#include "GPUBasedCanvasRenderingContext.h"
#include "GPUDevice.h"
#include <runtime/ArrayBuffer.h>
@@ -46,19 +45,16 @@
class WebGPUTexture;
class WebGPUTextureDescriptor;
-class WebGPURenderingContext : public CanvasRenderingContext, public ActiveDOMObject {
+class WebGPURenderingContext : public GPUBasedCanvasRenderingContext {
public:
static std::unique_ptr<WebGPURenderingContext> create(HTMLCanvasElement&);
-// virtual ~WebGPURenderingContext();
- bool isGPU() const override { return true; }
+ bool isWebGPU() const final { return true; }
- bool isAccelerated() const override { return true; }
+ void reshape(int width, int height) final;
- void reshape(int width, int height);
+ void markLayerComposited() final;
- void markLayerComposited();
-
PlatformLayer* platformLayer() const override;
RefPtr<GPUDevice> device() { return m_device; }
@@ -90,7 +86,6 @@
void initializeNewContext();
private:
-// WebGPURenderingContext(HTMLCanvasElement*);//, GraphicsContext3D::Attributes);
WebGPURenderingContext(HTMLCanvasElement&, PassRefPtr<GPUDevice>);
RefPtr<GPUDevice> m_device;
@@ -98,6 +93,6 @@
} // namespace WebCore
-SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGPURenderingContext, isGPU())
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::WebGPURenderingContext, isWebGPU())
#endif
Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (214016 => 214017)
--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp 2017-03-15 22:49:36 UTC (rev 214016)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp 2017-03-15 22:56:21 UTC (rev 214017)
@@ -81,14 +81,9 @@
if (!context || !context->isAccelerated())
return UnacceleratedCanvas;
- if (context->is3d())
+ if (context->isGPUBased())
return CanvasAsLayerContents;
-#if ENABLE(WEBGPU)
- if (context->isGPU())
- return CanvasAsLayerContents;
-#endif
-
#if ENABLE(ACCELERATED_2D_CANVAS)
return CanvasAsLayerContents;
#else