Title: [120757] trunk/Source/WebCore
Revision
120757
Author
[email protected]
Date
2012-06-19 14:44:48 -0700 (Tue, 19 Jun 2012)

Log Message

[CSS Shaders] Create a shared object between FECustomFilter objects to store the shared resources
https://bugs.webkit.org/show_bug.cgi?id=87878

Reviewed by Dean Jackson.

An object called CustomFilterGlobalContext is created the first time a new FECustomFilter is needed in a document.
It is used to store the GraphicsContext3D needed to render the CSS Shaders. The context is shared by all the elements
in a document (no cross-domain).

More resources will be shared in following patches, including precompiled shaders and vertices/indices data.
https://bugs.webkit.org/show_bug.cgi?id=88427
https://bugs.webkit.org/show_bug.cgi?id=88429

The plan is to make CustomFilterGlobalContext and FECustomFilter (or a base class extracted out of it) usable from platform
code in the hardware accelerated compositing layer. The only dependency of the code is on the GraphicsContext3D.

No new tests. No functionality is changed yet, just added the new objects.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/filters/CustomFilterGlobalContext.cpp: Added.
(WebCore):
(WebCore::CustomFilterGlobalContext::CustomFilterGlobalContext):
(WebCore::CustomFilterGlobalContext::~CustomFilterGlobalContext):
(WebCore::CustomFilterGlobalContext::prepareContextIfNeeded):
* platform/graphics/filters/CustomFilterGlobalContext.h: Added.
(WebCore):
(CustomFilterGlobalContext):
(WebCore::CustomFilterGlobalContext::context):
* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::FECustomFilter): Changed to use the global context instead of the host window.
(WebCore::FECustomFilter::create):
(WebCore::FECustomFilter::initializeContext):
* platform/graphics/filters/FECustomFilter.h:
(WebCore):
(FECustomFilter):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::build): Changed to initialize the global context if needed and pass it to the FECustomFilter.
* rendering/RenderView.cpp:
(WebCore):
(WebCore::RenderView::customFilterGlobalContext):
* rendering/RenderView.h:
(WebCore):
(RenderView):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (120756 => 120757)


--- trunk/Source/WebCore/CMakeLists.txt	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-06-19 21:44:48 UTC (rev 120757)
@@ -1199,6 +1199,7 @@
     platform/graphics/TextRun.cpp
     platform/graphics/WidthIterator.cpp
 
+    platform/graphics/filters/CustomFilterGlobalContext.cpp
     platform/graphics/filters/CustomFilterMesh.cpp
     platform/graphics/filters/CustomFilterProgram.cpp
     platform/graphics/filters/CustomFilterShader.cpp

Modified: trunk/Source/WebCore/ChangeLog (120756 => 120757)


--- trunk/Source/WebCore/ChangeLog	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/ChangeLog	2012-06-19 21:44:48 UTC (rev 120757)
@@ -1,3 +1,54 @@
+2012-06-19  Alexandru Chiculita  <[email protected]>
+
+        [CSS Shaders] Create a shared object between FECustomFilter objects to store the shared resources
+        https://bugs.webkit.org/show_bug.cgi?id=87878
+
+        Reviewed by Dean Jackson.
+
+        An object called CustomFilterGlobalContext is created the first time a new FECustomFilter is needed in a document.
+        It is used to store the GraphicsContext3D needed to render the CSS Shaders. The context is shared by all the elements
+        in a document (no cross-domain).
+
+        More resources will be shared in following patches, including precompiled shaders and vertices/indices data.
+        https://bugs.webkit.org/show_bug.cgi?id=88427
+        https://bugs.webkit.org/show_bug.cgi?id=88429
+
+        The plan is to make CustomFilterGlobalContext and FECustomFilter (or a base class extracted out of it) usable from platform
+        code in the hardware accelerated compositing layer. The only dependency of the code is on the GraphicsContext3D.
+
+        No new tests. No functionality is changed yet, just added the new objects.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/filters/CustomFilterGlobalContext.cpp: Added.
+        (WebCore):
+        (WebCore::CustomFilterGlobalContext::CustomFilterGlobalContext):
+        (WebCore::CustomFilterGlobalContext::~CustomFilterGlobalContext):
+        (WebCore::CustomFilterGlobalContext::prepareContextIfNeeded):
+        * platform/graphics/filters/CustomFilterGlobalContext.h: Added.
+        (WebCore):
+        (CustomFilterGlobalContext):
+        (WebCore::CustomFilterGlobalContext::context):
+        * platform/graphics/filters/FECustomFilter.cpp:
+        (WebCore::FECustomFilter::FECustomFilter): Changed to use the global context instead of the host window.
+        (WebCore::FECustomFilter::create):
+        (WebCore::FECustomFilter::initializeContext):
+        * platform/graphics/filters/FECustomFilter.h:
+        (WebCore):
+        (FECustomFilter):
+        * rendering/FilterEffectRenderer.cpp:
+        (WebCore::FilterEffectRenderer::build): Changed to initialize the global context if needed and pass it to the FECustomFilter.
+        * rendering/RenderView.cpp:
+        (WebCore):
+        (WebCore::RenderView::customFilterGlobalContext):
+        * rendering/RenderView.h:
+        (WebCore):
+        (RenderView):
+
 2012-06-19  Dominik Röttsches  <[email protected]>
 
         [cairo] Fix LayoutTests/fast/canvas/patternfill-repeat.html

Modified: trunk/Source/WebCore/GNUmakefile.list.am (120756 => 120757)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-06-19 21:44:48 UTC (rev 120757)
@@ -3183,6 +3183,8 @@
 	Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp \
 	Source/WebCore/platform/graphics/cairo/RefPtrCairo.h \
 	Source/WebCore/platform/graphics/cairo/TransformationMatrixCairo.cpp \
+	Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.cpp \
+	Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.h \
 	Source/WebCore/platform/graphics/filters/CustomFilterMesh.cpp \
 	Source/WebCore/platform/graphics/filters/CustomFilterMesh.h \
 	Source/WebCore/platform/graphics/filters/CustomFilterNumberParameter.h \

Modified: trunk/Source/WebCore/Target.pri (120756 => 120757)


--- trunk/Source/WebCore/Target.pri	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/Target.pri	2012-06-19 21:44:48 UTC (rev 120757)
@@ -2225,6 +2225,7 @@
     platform/graphics/BitmapImage.h \
     platform/graphics/Color.h \
     platform/graphics/CrossfadeGeneratedImage.h \
+    platform/graphics/filters/CustomFilterGlobalContext.h \
     platform/graphics/filters/CustomFilterMesh.h \
     platform/graphics/filters/CustomFilterNumberParameter.h \
     platform/graphics/filters/CustomFilterShader.h \
@@ -3405,6 +3406,7 @@
 
 contains(DEFINES, ENABLE_FILTERS=1) {
     SOURCES += \
+        platform/graphics/filters/CustomFilterGlobalContext.cpp \
         platform/graphics/filters/CustomFilterOperation.cpp \
         platform/graphics/filters/CustomFilterProgram.cpp \
         platform/graphics/filters/CustomFilterShader.cpp \

Modified: trunk/Source/WebCore/WebCore.gypi (120756 => 120757)


--- trunk/Source/WebCore/WebCore.gypi	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/WebCore.gypi	2012-06-19 21:44:48 UTC (rev 120757)
@@ -3796,6 +3796,8 @@
             'platform/graphics/efl/ImageEfl.cpp',
             'platform/graphics/efl/IntPointEfl.cpp',
             'platform/graphics/efl/IntRectEfl.cpp',
+            'platform/graphics/filters/CustomFilterGlobalContext.cpp',
+            'platform/graphics/filters/CustomFilterGlobalContext.h',
             'platform/graphics/filters/CustomFilterMesh.h',
             'platform/graphics/filters/CustomFilterNumberParameter.h',
             'platform/graphics/filters/CustomFilterOperation.cpp',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (120756 => 120757)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-06-19 21:44:48 UTC (rev 120757)
@@ -31425,6 +31425,14 @@
 					Name="filters"
 					>
 					<File
+						RelativePath="..\platform\graphics\filters\CustomFilterGlobalContext.cpp"
+						>
+					</File>
+					<File
+						RelativePath="..\platform\graphics\filters\CustomFilterGlobalContext.h"
+						>
+					</File>
+					<File
 						RelativePath="..\platform\graphics\filters\CustomFilterMesh.cpp"
 						>
 					</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (120756 => 120757)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-06-19 21:44:48 UTC (rev 120757)
@@ -1453,6 +1453,8 @@
 		503D0CAE14B5B0BA00F32F57 /* StyleCustomFilterProgram.h in Headers */ = {isa = PBXBuildFile; fileRef = 503D0CAD14B5B0BA00F32F57 /* StyleCustomFilterProgram.h */; settings = {ATTRIBUTES = (); }; };
 		508CCA4F13CF106B003151F3 /* RenderFlowThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 508CCA4D13CF106B003151F3 /* RenderFlowThread.h */; };
 		508CCA5013CF106B003151F3 /* RenderFlowThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 508CCA4E13CF106B003151F3 /* RenderFlowThread.cpp */; };
+		50987C26157D676D00BDA835 /* CustomFilterGlobalContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50987C24157D676D00BDA835 /* CustomFilterGlobalContext.cpp */; };
+		50987C27157D676D00BDA835 /* CustomFilterGlobalContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 50987C25157D676D00BDA835 /* CustomFilterGlobalContext.h */; };
 		509CC9FB14C069ED00BBECBD /* CustomFilterParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 509CC9FA14C069ED00BBECBD /* CustomFilterParameter.h */; };
 		50ACE2CB14B5D79300446666 /* CustomFilterOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ACE2CA14B5D79300446666 /* CustomFilterOperation.h */; };
 		50CC089A14C6E99C0017AB51 /* CustomFilterNumberParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 50CC089914C6E99C0017AB51 /* CustomFilterNumberParameter.h */; };
@@ -8516,6 +8518,8 @@
 		503D0CAD14B5B0BA00F32F57 /* StyleCustomFilterProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleCustomFilterProgram.h; path = style/StyleCustomFilterProgram.h; sourceTree = "<group>"; };
 		508CCA4D13CF106B003151F3 /* RenderFlowThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderFlowThread.h; sourceTree = "<group>"; };
 		508CCA4E13CF106B003151F3 /* RenderFlowThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFlowThread.cpp; sourceTree = "<group>"; };
+		50987C24157D676D00BDA835 /* CustomFilterGlobalContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomFilterGlobalContext.cpp; path = filters/CustomFilterGlobalContext.cpp; sourceTree = "<group>"; };
+		50987C25157D676D00BDA835 /* CustomFilterGlobalContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterGlobalContext.h; path = filters/CustomFilterGlobalContext.h; sourceTree = "<group>"; };
 		509CC9FA14C069ED00BBECBD /* CustomFilterParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterParameter.h; path = filters/CustomFilterParameter.h; sourceTree = "<group>"; };
 		50ACE2CA14B5D79300446666 /* CustomFilterOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterOperation.h; path = filters/CustomFilterOperation.h; sourceTree = "<group>"; };
 		50B42157146976960087E604 /* WebKitCSSShaderValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSShaderValue.h; sourceTree = "<group>"; };
@@ -17882,6 +17886,8 @@
 		A75E8B7F0E1DE2B0007F2481 /* filters */ = {
 			isa = PBXGroup;
 			children = (
+				50987C24157D676D00BDA835 /* CustomFilterGlobalContext.cpp */,
+				50987C25157D676D00BDA835 /* CustomFilterGlobalContext.h */,
 				49ECEB5C1499790D00CDD3A4 /* arm */,
 				50D405F7147D31F300D30BB5 /* CustomFilterMesh.cpp */,
 				50D405F8147D31F300D30BB5 /* CustomFilterMesh.h */,
@@ -25098,6 +25104,7 @@
 				FD537353137B651800008DCE /* ZeroPole.h in Headers */,
 				CE7B2DB31586ABAD0098B3FA /* AlternativeTextUIController.h in Headers */,
 				CE7B2DB51586ABAD0098B3FA /* TextAlternativeWithRange.h in Headers */,
+				50987C27157D676D00BDA835 /* CustomFilterGlobalContext.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -28144,6 +28151,7 @@
 				9A1B6F97158869C80011A8C4 /* JSDOMStringListCustom.cpp in Sources */,
 				CE7B2DB41586ABAD0098B3FA /* AlternativeTextUIController.mm in Sources */,
 				CE7B2DB61586ABAD0098B3FA /* TextAlternativeWithRange.mm in Sources */,
+				50987C26157D676D00BDA835 /* CustomFilterGlobalContext.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.cpp (0 => 120757)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.cpp	2012-06-19 21:44:48 UTC (rev 120757)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 Adobe Systems Incorporated. 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 THE COPYRIGHT HOLDER “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 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"
+
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+#include "CustomFilterGlobalContext.h"
+
+#include "GraphicsContext3D.h"
+
+namespace WebCore {
+
+CustomFilterGlobalContext::CustomFilterGlobalContext()
+{
+}
+
+CustomFilterGlobalContext::~CustomFilterGlobalContext()
+{
+}
+
+void CustomFilterGlobalContext::prepareContextIfNeeded(HostWindow* hostWindow)
+{
+    if (m_context.get())
+        return;
+
+    GraphicsContext3D::Attributes attributes;
+    attributes.preserveDrawingBuffer = true;
+    attributes.premultipliedAlpha = false;
+    m_context = GraphicsContext3D::create(attributes, hostWindow, GraphicsContext3D::RenderOffscreen);
+
+    m_context->enable(GraphicsContext3D::DEPTH_TEST);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(CSS_SHADERS) && ENABLE(WEBGL)

Added: trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.h (0 => 120757)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterGlobalContext.h	2012-06-19 21:44:48 UTC (rev 120757)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Adobe Systems Incorporated. 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 THE COPYRIGHT HOLDER “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 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.
+ */
+
+#ifndef CustomFilterGlobalContext_h
+#define CustomFilterGlobalContext_h
+
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class HostWindow;
+class GraphicsContext3D;
+
+class CustomFilterGlobalContext {
+public:
+    CustomFilterGlobalContext();
+    ~CustomFilterGlobalContext();
+    
+    GraphicsContext3D* context() const { return m_context.get(); }
+    
+    void prepareContextIfNeeded(HostWindow*);
+
+private:
+    RefPtr<GraphicsContext3D> m_context;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+
+#endif // CustomFilterGlobalContext_h

Modified: trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp (120756 => 120757)


--- trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp	2012-06-19 21:44:48 UTC (rev 120757)
@@ -32,6 +32,7 @@
 #if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
 #include "FECustomFilter.h"
 
+#include "CustomFilterGlobalContext.h"
 #include "CustomFilterMesh.h"
 #include "CustomFilterNumberParameter.h"
 #include "CustomFilterParameter.h"
@@ -72,11 +73,11 @@
     matrix.setM44(1.0f);
 }
 
-FECustomFilter::FECustomFilter(Filter* filter, HostWindow* hostWindow, PassRefPtr<CustomFilterProgram> program, const CustomFilterParameterList& parameters,
+FECustomFilter::FECustomFilter(Filter* filter, CustomFilterGlobalContext* customFilterGlobalContext, PassRefPtr<CustomFilterProgram> program, const CustomFilterParameterList& parameters,
                                unsigned meshRows, unsigned meshColumns, CustomFilterOperation::MeshBoxType meshBoxType,
                                CustomFilterOperation::MeshType meshType)
     : FilterEffect(filter)
-    , m_hostWindow(hostWindow)
+    , m_globalContext(customFilterGlobalContext)
     , m_frameBuffer(0)
     , m_depthBuffer(0)
     , m_destTexture(0)
@@ -84,15 +85,16 @@
     , m_parameters(parameters)
     , m_meshRows(meshRows)
     , m_meshColumns(meshColumns)
+    , m_meshBoxType(meshBoxType)
     , m_meshType(meshType)
 {
 }
 
-PassRefPtr<FECustomFilter> FECustomFilter::create(Filter* filter, HostWindow* hostWindow, PassRefPtr<CustomFilterProgram> program, const CustomFilterParameterList& parameters,
+PassRefPtr<FECustomFilter> FECustomFilter::create(Filter* filter, CustomFilterGlobalContext* customFilterGlobalContext, PassRefPtr<CustomFilterProgram> program, const CustomFilterParameterList& parameters,
                                            unsigned meshRows, unsigned meshColumns, CustomFilterOperation::MeshBoxType meshBoxType,
                                            CustomFilterOperation::MeshType meshType)
 {
-    return adoptRef(new FECustomFilter(filter, hostWindow, program, parameters, meshRows, meshColumns, meshBoxType, meshType));
+    return adoptRef(new FECustomFilter(filter, customFilterGlobalContext, program, parameters, meshRows, meshColumns, meshBoxType, meshType));
 }
 
 FECustomFilter::~FECustomFilter()
@@ -158,15 +160,18 @@
 
 void FECustomFilter::initializeContext()
 {
-    GraphicsContext3D::Attributes attributes;
-    attributes.preserveDrawingBuffer = true;
-    attributes.premultipliedAlpha = false;
-    
     ASSERT(!m_context.get());
-    m_context = GraphicsContext3D::create(attributes, m_hostWindow, GraphicsContext3D::RenderOffscreen);
-    m_context->enable(GraphicsContext3D::DEPTH_TEST);
+    ASSERT(m_globalContext->context());
+    m_context = m_globalContext->context();
     
+    // FIXME: The shader and the mesh can be shared across multiple elements when possible.
+    // Sharing the shader means it's no need to analyze / compile and upload to GPU again.
+    // https://bugs.webkit.org/show_bug.cgi?id=88427
     m_shader = m_program->createShaderWithContext(m_context.get());
+
+    // FIXME: Sharing the mesh would just save the time needed to upload it to the GPU, so I assume we could
+    // benchmark that for performance.
+    // https://bugs.webkit.org/show_bug.cgi?id=88429
     m_mesh = CustomFilterMesh::create(m_context.get(), m_meshColumns, m_meshRows, 
                                       FloatRect(0, 0, 1, 1),
                                       m_meshType);

Modified: trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h (120756 => 120757)


--- trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h	2012-06-19 21:44:48 UTC (rev 120757)
@@ -45,19 +45,19 @@
 namespace WebCore {
 
 class CachedShader;
+class CustomFilterGlobalContext;
 class CustomFilterMesh;
 class CustomFilterNumberParameter;
 class CustomFilterProgram;
 class CustomFilterShader;
 class DrawingBuffer;
 class GraphicsContext3D;
-class HostWindow;
 class IntSize;
 class Texture;
 
 class FECustomFilter : public FilterEffect {
 public:
-    static PassRefPtr<FECustomFilter> create(Filter*, HostWindow*, PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&,
+    static PassRefPtr<FECustomFilter> create(Filter*, CustomFilterGlobalContext*, PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&,
                    unsigned meshRows, unsigned meshColumns, CustomFilterOperation::MeshBoxType, 
                    CustomFilterOperation::MeshType);
 
@@ -67,7 +67,7 @@
     virtual TextStream& externalRepresentation(TextStream&, int indention) const;
 
 private:
-    FECustomFilter(Filter*, HostWindow*, PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&,
+    FECustomFilter(Filter*, CustomFilterGlobalContext*, PassRefPtr<CustomFilterProgram>, const CustomFilterParameterList&,
                    unsigned meshRows, unsigned meshColumns, CustomFilterOperation::MeshBoxType, 
                    CustomFilterOperation::MeshType);
     ~FECustomFilter();
@@ -80,7 +80,8 @@
     void bindProgramParameters();
     void bindProgramAndBuffers(Uint8ClampedArray* srcPixelArray);
     
-    HostWindow* m_hostWindow;
+    // No need to keep a reference here. It is owned by the RenderView.
+    CustomFilterGlobalContext* m_globalContext;
     
     RefPtr<GraphicsContext3D> m_context;
     RefPtr<Texture> m_inputTexture;
@@ -97,6 +98,7 @@
 
     unsigned m_meshRows;
     unsigned m_meshColumns;
+    CustomFilterOperation::MeshBoxType m_meshBoxType;
     CustomFilterOperation::MeshType m_meshType;
 };
 

Modified: trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp (120756 => 120757)


--- trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp	2012-06-19 21:44:48 UTC (rev 120757)
@@ -42,10 +42,11 @@
 #include <wtf/MathExtras.h>
 
 #if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+#include "CustomFilterGlobalContext.h"
 #include "CustomFilterProgram.h"
 #include "CustomFilterOperation.h"
 #include "FECustomFilter.h"
-#include "FrameView.h"
+#include "RenderView.h"
 #include "Settings.h"
 #endif
 
@@ -271,7 +272,9 @@
             CustomFilterOperation* customFilterOperation = static_cast<CustomFilterOperation*>(filterOperation);
             RefPtr<CustomFilterProgram> program = customFilterOperation->program();
             if (program->isLoaded()) {
-                effect = FECustomFilter::create(this, document->view()->root()->hostWindow(), program, customFilterOperation->parameters(),
+                CustomFilterGlobalContext* globalContext = document->renderView()->customFilterGlobalContext();
+                globalContext->prepareContextIfNeeded(document->view()->hostWindow());
+                effect = FECustomFilter::create(this, globalContext, program, customFilterOperation->parameters(),
                                                 customFilterOperation->meshRows(), customFilterOperation->meshColumns(),
                                                 customFilterOperation->meshBoxType(), customFilterOperation->meshType());
                 m_hasCustomShaderFilter = true;

Modified: trunk/Source/WebCore/rendering/RenderView.cpp (120756 => 120757)


--- trunk/Source/WebCore/rendering/RenderView.cpp	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/rendering/RenderView.cpp	2012-06-19 21:44:48 UTC (rev 120757)
@@ -44,6 +44,10 @@
 #include "RenderLayerCompositor.h"
 #endif
 
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+#include "CustomFilterGlobalContext.h"
+#endif
+
 namespace WebCore {
 
 RenderView::RenderView(Node* node, FrameView* view)
@@ -898,6 +902,15 @@
 #endif
 }
 
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+CustomFilterGlobalContext* RenderView::customFilterGlobalContext()
+{
+    if (!m_customFilterGlobalContext)
+        m_customFilterGlobalContext = adoptPtr(new CustomFilterGlobalContext());
+    return m_customFilterGlobalContext.get();
+}
+#endif
+
 void RenderView::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
 {
     RenderBlock::styleDidChange(diff, oldStyle);

Modified: trunk/Source/WebCore/rendering/RenderView.h (120756 => 120757)


--- trunk/Source/WebCore/rendering/RenderView.h	2012-06-19 21:43:52 UTC (rev 120756)
+++ trunk/Source/WebCore/rendering/RenderView.h	2012-06-19 21:44:48 UTC (rev 120757)
@@ -37,6 +37,10 @@
 class RenderLayerCompositor;
 #endif
 
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+class CustomFilterGlobalContext;
+#endif
+
 class RenderView : public RenderBlock {
 public:
     RenderView(Node*, FrameView*);
@@ -168,6 +172,10 @@
     bool usesCompositing() const;
 #endif
 
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+    CustomFilterGlobalContext* customFilterGlobalContext();
+#endif
+
     IntRect unscaledDocumentRect() const;
     LayoutRect backgroundRect(RenderBox* backgroundRenderer) const;
 
@@ -274,6 +282,9 @@
 #if USE(ACCELERATED_COMPOSITING)
     OwnPtr<RenderLayerCompositor> m_compositor;
 #endif
+#if ENABLE(CSS_SHADERS) && ENABLE(WEBGL)
+    OwnPtr<CustomFilterGlobalContext> m_customFilterGlobalContext;
+#endif
     OwnPtr<FlowThreadController> m_flowThreadController;
     RefPtr<IntervalArena> m_intervalArena;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to