[Texmap][CSS Shaders] Make the CustomFilterValidatedProgram maintain the platform...
authorachicu@adobe.com <achicu@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 15:39:12 +0000 (15:39 +0000)
committerachicu@adobe.com <achicu@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Nov 2012 15:39:12 +0000 (15:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102414

Reviewed by Noam Rosenthal.

Source/WebCore:

Added WebCore classes needed for the WebKit2 implementation of Texture Mapper to keep a reference to the
platform compiled custom filter. It is just used to maintain the life-time of the objects. WebKit2 injects a
client in TextureMapperPlatformCompiledProgram and receives a callback when the custom filter program is not
used to render any layer on the page.

Note that CustomFilterValidatedProgram are reused across multiple elements of the same page. Also, the instances
are reused across frames, so animations should reuse the same pre-validated program. In this case, the mechanism is
extended and reused in the platform compositor.

No new tests, existing tests for CSS Custom Filters already cover this path.

* CMakeLists.txt:
* GNUmakefile.am:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.pri:
* platform/graphics/filters/CustomFilterValidatedProgram.cpp:
(WebCore):
* platform/graphics/filters/CustomFilterValidatedProgram.h:
(WebCore):
(CustomFilterValidatedProgram):
* platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp: Added.
(WebCore):
(WebCore::CustomFilterValidatedProgram::platformCompiledProgram): Platform implementation for creating and deleting the reference.
(WebCore::CustomFilterValidatedProgram::platformInit):
(WebCore::CustomFilterValidatedProgram::platformDestroy):
* platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h: Added.
(WebCore):
(TextureMapperPlatformCompiledProgramClient):
(WebCore::TextureMapperPlatformCompiledProgramClient::ref):
(WebCore::TextureMapperPlatformCompiledProgramClient::deref):
(TextureMapperPlatformCompiledProgram):
Stores a link to a TextureMapperPlatformCompiledProgramClient. It's main purpose is to call unref on the client when
the shader is not needed anymore. WebKit2 can use that to delete the corresponding shader from the compositor side.
(WebCore::TextureMapperPlatformCompiledProgram::create):
(WebCore::TextureMapperPlatformCompiledProgram::setClient): Used by WebKit2 to inject the platform client.
(WebCore::TextureMapperPlatformCompiledProgram::client):
(WebCore::TextureMapperPlatformCompiledProgram::TextureMapperPlatformCompiledProgram):

Source/WebKit2:

This is the first part of shader caching implementation for the Custom Filters in WK2 LayerTreeCoordinator.
In this patch it will just make the LayerTreeCoordinator knowledgeable about the life-time
of the custom filter programs. It can allocate IDs for the filters and it also gets a callback when the
filters are not needed anymore.

The UI process is still recreating the shader every time, but https://bugs.webkit.org/show_bug.cgi?id=101801
will fix that and try to reuse existing custom filters.

* CMakeLists.txt:
* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
(CoreIPC::::encode):
* Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp: Added.
(WebKit):
(WebKit::WebCustomFilterProgramProxy::~WebCustomFilterProgramProxy):
* Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h: Added.
(WebKit):
(WebCustomFilterProgramProxyClient):
(WebCustomFilterProgramProxy):
(WebKit::WebCustomFilterProgramProxy::create):
(WebKit::WebCustomFilterProgramProxy::id):
(WebKit::WebCustomFilterProgramProxy::refFromValidatedProgram):
(WebKit::WebCustomFilterProgramProxy::derefFromValidatedProgram):
(WebKit::WebCustomFilterProgramProxy::setClient):
(WebKit::WebCustomFilterProgramProxy::client):
(WebKit::WebCustomFilterProgramProxy::WebCustomFilterProgramProxy):
* Target.pri:
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:
(WebKit::LayerTreeCoordinator::~LayerTreeCoordinator):
(WebKit::LayerTreeCoordinator::syncLayerFilters):
(WebKit):
(WebKit::LayerTreeCoordinator::checkCustomFilterProgramProxies):
(WebKit::LayerTreeCoordinator::removeCustomFilterProgramProxy):
(WebKit::LayerTreeCoordinator::disconnectCustomFilterPrograms):
* WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h:
(LayerTreeCoordinator):

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

18 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.pri
Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp
Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h
Source/WebCore/platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h [new file with mode: 0644]
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp
Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp [new file with mode: 0644]
Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h [new file with mode: 0644]
Source/WebKit2/Target.pri
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h

index 1cc03a6..3506423 100644 (file)
@@ -51,6 +51,7 @@ SET(WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/cpu/arm"
     "${WEBCORE_DIR}/platform/graphics/cpu/arm/filters"
     "${WEBCORE_DIR}/platform/graphics/filters"
+    "${WEBCORE_DIR}/platform/graphics/filters/texmap"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz"
     "${WEBCORE_DIR}/platform/graphics/harfbuzz/ng"
     "${WEBCORE_DIR}/platform/graphics/opentype"
@@ -1908,6 +1909,7 @@ SET(WebCore_SOURCES
 
     platform/graphics/cpu/arm/filters/FELightingNEON.cpp
 
+    platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp
     platform/graphics/filters/CustomFilterCompiledProgram.cpp
     platform/graphics/filters/CustomFilterGlobalContext.cpp
     platform/graphics/filters/CustomFilterMesh.cpp
index 1c10e1a..13de463 100644 (file)
@@ -1,3 +1,49 @@
+2012-11-16  Alexandru Chiculita  <achicu@adobe.com>
+
+        [Texmap][CSS Shaders] Make the CustomFilterValidatedProgram maintain the platform compiled program
+        https://bugs.webkit.org/show_bug.cgi?id=102414
+
+        Reviewed by Noam Rosenthal.
+
+        Added WebCore classes needed for the WebKit2 implementation of Texture Mapper to keep a reference to the 
+        platform compiled custom filter. It is just used to maintain the life-time of the objects. WebKit2 injects a
+        client in TextureMapperPlatformCompiledProgram and receives a callback when the custom filter program is not
+        used to render any layer on the page. 
+
+        Note that CustomFilterValidatedProgram are reused across multiple elements of the same page. Also, the instances
+        are reused across frames, so animations should reuse the same pre-validated program. In this case, the mechanism is
+        extended and reused in the platform compositor.
+        
+        No new tests, existing tests for CSS Custom Filters already cover this path.
+
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.pri:
+        * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
+        (WebCore):
+        * platform/graphics/filters/CustomFilterValidatedProgram.h:
+        (WebCore):
+        (CustomFilterValidatedProgram):
+        * platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp: Added.
+        (WebCore):
+        (WebCore::CustomFilterValidatedProgram::platformCompiledProgram): Platform implementation for creating and deleting the reference.
+        (WebCore::CustomFilterValidatedProgram::platformInit):
+        (WebCore::CustomFilterValidatedProgram::platformDestroy):
+        * platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h: Added.
+        (WebCore):
+        (TextureMapperPlatformCompiledProgramClient):
+        (WebCore::TextureMapperPlatformCompiledProgramClient::ref):
+        (WebCore::TextureMapperPlatformCompiledProgramClient::deref):
+        (TextureMapperPlatformCompiledProgram):
+        Stores a link to a TextureMapperPlatformCompiledProgramClient. It's main purpose is to call unref on the client when
+        the shader is not needed anymore. WebKit2 can use that to delete the corresponding shader from the compositor side.
+        (WebCore::TextureMapperPlatformCompiledProgram::create):
+        (WebCore::TextureMapperPlatformCompiledProgram::setClient): Used by WebKit2 to inject the platform client.
+        (WebCore::TextureMapperPlatformCompiledProgram::client):
+        (WebCore::TextureMapperPlatformCompiledProgram::TextureMapperPlatformCompiledProgram):
+
 2012-11-16  Andreas Kling  <akling@apple.com>
 
         Short-circuit Element::hasEquivalentAttributes() if elements share attribute data.
index 5efb13e..c310b7d 100644 (file)
@@ -57,6 +57,7 @@ webcore_cppflags += \
        -I$(srcdir)/Source/WebCore/platform/graphics/cpu/arm \
        -I$(srcdir)/Source/WebCore/platform/graphics/cpu/arm/filters/ \
        -I$(srcdir)/Source/WebCore/platform/graphics/filters \
+       -I$(srcdir)/Source/WebCore/platform/graphics/filters/texmap \
        -I$(srcdir)/Source/WebCore/platform/graphics/gpu \
        -I$(srcdir)/Source/WebCore/platform/graphics/opengl \
        -I$(srcdir)/Source/WebCore/platform/graphics/opentype \
index ff66208..4d8cb8b 100644 (file)
@@ -6339,6 +6339,8 @@ endif  # END USE_CLUTTER
 
 if USE_TEXTURE_MAPPER_CAIRO
 webcore_sources += \
+       Source/WebCore//platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp \
+       Source/WebCore//platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h \
        Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp \
        Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h \
        Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp \
@@ -6360,6 +6362,8 @@ endif  # END USE_TEXTURE_MAPPER_CAIRO
 
 if USE_TEXTURE_MAPPER_GL
 webcore_sources += \
+       Source/WebCore//platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp \
+       Source/WebCore//platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h \
        Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp \
        Source/WebCore/platform/graphics/texmap/TextureMapperGL.h \
        Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp \
index ac4473a..e4ed2e9 100644 (file)
@@ -2087,6 +2087,7 @@ HEADERS += \
     platform/graphics/cpu/arm/filters/FEGaussianBlurNEON.h \
     platform/graphics/cpu/arm/filters/FELightingNEON.h \
     platform/graphics/CrossfadeGeneratedImage.h \
+    platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h \
     platform/graphics/filters/CustomFilterArrayParameter.h \
     platform/graphics/filters/CustomFilterConstants.h \
     platform/graphics/filters/CustomFilterGlobalContext.h \
@@ -3509,6 +3510,7 @@ enable?(XSLT) {
 enable?(FILTERS) {
     SOURCES += \
         platform/graphics/cpu/arm/filters/FELightingNEON.cpp \
+        platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp \
         platform/graphics/filters/CustomFilterGlobalContext.cpp \
         platform/graphics/filters/CustomFilterOperation.cpp \
         platform/graphics/filters/CustomFilterParameterList.cpp \
index 029c7ae..3504870 100644 (file)
@@ -56,6 +56,7 @@ INCLUDEPATH += \
     $$SOURCE_DIR/platform/graphics/cpu/arm \
     $$SOURCE_DIR/platform/graphics/cpu/arm/filters \
     $$SOURCE_DIR/platform/graphics/filters \
+    $$SOURCE_DIR/platform/graphics/filters/texmap \
     $$SOURCE_DIR/platform/graphics/opengl \
     $$SOURCE_DIR/platform/graphics/opentype \
     $$SOURCE_DIR/platform/graphics/qt \
index f5ef6cf..ef5ee4e 100644 (file)
@@ -512,7 +512,7 @@ CustomFilterValidatedProgram::~CustomFilterValidatedProgram()
         m_globalContext->removeValidatedProgram(this);
 }
 
-#if !PLATFORM(BLACKBERRY)
+#if !PLATFORM(BLACKBERRY) && !USE(TEXTURE_MAPPER)
 void CustomFilterValidatedProgram::platformInit()
 {
 }
index 12fefcc..8afc9ec 100644 (file)
@@ -53,6 +53,11 @@ struct ANGLEShaderSymbol;
 class CustomFilterCompiledProgram;
 class CustomFilterGlobalContext;
 
+#if USE(TEXTURE_MAPPER)
+class TextureMapperPlatformCompiledProgram;
+typedef TextureMapperPlatformCompiledProgram PlatformCompiledProgram;
+#endif
+
 //
 // A unique combination of vertex shader and fragment shader is only validated and compiled once.
 // All shaders are validated through ANGLE in CustomFilterValidatedProgram before being compiled by the GraphicsContext3D in CustomFilterCompiledProgram.
@@ -91,7 +96,7 @@ public:
         return m_validatedFragmentShader; 
     }
 
-#if PLATFORM(BLACKBERRY)
+#if PLATFORM(BLACKBERRY) || USE(TEXTURE_MAPPER)
     PlatformCompiledProgram* platformCompiledProgram();
 #endif
 
@@ -124,7 +129,7 @@ private:
     String m_validatedFragmentShader;
 
     RefPtr<CustomFilterCompiledProgram> m_compiledProgram;
-#if PLATFORM(BLACKBERRY)
+#if PLATFORM(BLACKBERRY) || USE(TEXTURE_MAPPER)
     PlatformCompiledProgram* m_platformCompiledProgram;
 #endif
 
diff --git a/Source/WebCore/platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp b/Source/WebCore/platform/graphics/filters/texmap/CustomFilterValidatedProgramTextureMapper.cpp
new file mode 100644 (file)
index 0000000..bed0e6e
--- /dev/null
@@ -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.
+ */
+
+#include "config.h"
+
+#if ENABLE(CSS_SHADERS) && USE(TEXTURE_MAPPER)
+#include "CustomFilterValidatedProgram.h"
+
+#include "TextureMapperPlatformCompiledProgram.h"
+
+namespace WebCore {
+
+PlatformCompiledProgram* CustomFilterValidatedProgram::platformCompiledProgram()
+{
+    if (!m_platformCompiledProgram)
+        m_platformCompiledProgram = TextureMapperPlatformCompiledProgram::create().leakRef();
+    return m_platformCompiledProgram;
+}
+
+void CustomFilterValidatedProgram::platformInit()
+{
+    m_platformCompiledProgram = 0;
+}
+
+void CustomFilterValidatedProgram::platformDestroy()
+{
+    derefIfNotNull(m_platformCompiledProgram);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(CSS_SHADERS) && USE(TEXTURE_MAPPER)
diff --git a/Source/WebCore/platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h b/Source/WebCore/platform/graphics/filters/texmap/TextureMapperPlatformCompiledProgram.h
new file mode 100644 (file)
index 0000000..afa6ca5
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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 TextureMapperPlatformCompiledProgram_h
+#define TextureMapperPlatformCompiledProgram_h
+
+#if ENABLE(CSS_SHADERS)
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class TextureMapperPlatformCompiledProgramClient {
+public:
+    void ref() { refFromValidatedProgram(); }
+    void deref() { derefFromValidatedProgram(); }
+
+    virtual void refFromValidatedProgram() = 0;
+    virtual void derefFromValidatedProgram() = 0;
+};
+
+class TextureMapperPlatformCompiledProgram : public RefCounted<TextureMapperPlatformCompiledProgram> {
+public:
+    static PassRefPtr<TextureMapperPlatformCompiledProgram> create()
+    {
+        return adoptRef(new TextureMapperPlatformCompiledProgram());
+    }
+    
+    void setClient(PassRefPtr<TextureMapperPlatformCompiledProgramClient> client) { m_client = client; }
+    TextureMapperPlatformCompiledProgramClient* client() const { return m_client.get(); }
+
+private:
+    TextureMapperPlatformCompiledProgram()
+    {
+    }
+
+    RefPtr<TextureMapperPlatformCompiledProgramClient> m_client;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(CSS_SHADERS)
+
+#endif // TextureMapperPlatformCompiledProgram_h
index 05d7c6d..003396a 100644 (file)
@@ -218,6 +218,7 @@ SET(WebKit2_SOURCES
     Shared/API/c/WKUserContentURLPattern.cpp
 
     Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp
+    Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp
 
     Shared/Plugins/NPIdentifierData.cpp
     Shared/Plugins/NPObjectMessageReceiver.cpp
index 9af0b43..a3cfbad 100644 (file)
@@ -1,3 +1,46 @@
+2012-11-16  Alexandru Chiculita  <achicu@adobe.com>
+
+        [Texmap][CSS Shaders] Make the CustomFilterValidatedProgram maintain the platform compiled program
+        https://bugs.webkit.org/show_bug.cgi?id=102414
+
+        Reviewed by Noam Rosenthal.
+
+        This is the first part of shader caching implementation for the Custom Filters in WK2 LayerTreeCoordinator.
+        In this patch it will just make the LayerTreeCoordinator knowledgeable about the life-time
+        of the custom filter programs. It can allocate IDs for the filters and it also gets a callback when the
+        filters are not needed anymore.
+
+        The UI process is still recreating the shader every time, but https://bugs.webkit.org/show_bug.cgi?id=101801
+        will fix that and try to reuse existing custom filters.
+
+        * CMakeLists.txt:
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
+        (CoreIPC::::encode):
+        * Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp: Added.
+        (WebKit):
+        (WebKit::WebCustomFilterProgramProxy::~WebCustomFilterProgramProxy):
+        * Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h: Added.
+        (WebKit):
+        (WebCustomFilterProgramProxyClient):
+        (WebCustomFilterProgramProxy):
+        (WebKit::WebCustomFilterProgramProxy::create):
+        (WebKit::WebCustomFilterProgramProxy::id):
+        (WebKit::WebCustomFilterProgramProxy::refFromValidatedProgram):
+        (WebKit::WebCustomFilterProgramProxy::derefFromValidatedProgram):
+        (WebKit::WebCustomFilterProgramProxy::setClient):
+        (WebKit::WebCustomFilterProgramProxy::client):
+        (WebKit::WebCustomFilterProgramProxy::WebCustomFilterProgramProxy):
+        * Target.pri:
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:
+        (WebKit::LayerTreeCoordinator::~LayerTreeCoordinator):
+        (WebKit::LayerTreeCoordinator::syncLayerFilters):
+        (WebKit):
+        (WebKit::LayerTreeCoordinator::checkCustomFilterProgramProxies):
+        (WebKit::LayerTreeCoordinator::removeCustomFilterProgramProxy):
+        (WebKit::LayerTreeCoordinator::disconnectCustomFilterPrograms):
+        * WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.h:
+        (LayerTreeCoordinator):
+
 2012-11-16  Peter Gal  <galpeter@inf.u-szeged.hu>
 
         [Qt][Mac] Fix the build after r124873
index bdb9065..d985707 100644 (file)
@@ -146,6 +146,10 @@ void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder& encoder,
             ASSERT(customOperation->validatedProgram());
             RefPtr<CustomFilterValidatedProgram> program = customOperation->validatedProgram();
             ASSERT(program->isInitialized());
+            ASSERT(program->platformCompiledProgram());
+            // FIXME: We should only serialize the object if it was not serialized before,
+            // otherwise only the ID of the program should be written to the stream.
+            // https://bugs.webkit.org/show_bug.cgi?id=101801
             encoder << program->validatedVertexShader();
             encoder << program->validatedFragmentShader();
             const CustomFilterProgramInfo& programInfo = program->programInfo();
diff --git a/Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp b/Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp
new file mode 100644 (file)
index 0000000..56f7076
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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)
+#include "WebCustomFilterProgramProxy.h"
+
+namespace WebKit {
+
+int WebCustomFilterProgramProxy::s_nextId = 1;
+
+WebCustomFilterProgramProxy::~WebCustomFilterProgramProxy()
+{
+    if (m_client) {
+        m_client->removeCustomFilterProgramProxy(this);
+        m_client = 0;
+    }
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(CSS_SHADERS)
diff --git a/Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h b/Source/WebKit2/Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.h
new file mode 100644 (file)
index 0000000..bb6f0bb
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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 WebCustomFilterProgramProxy_h
+#define WebCustomFilterProgramProxy_h
+
+#if USE(COORDINATED_GRAPHICS) && ENABLE(CSS_SHADERS)
+
+#include "TextureMapperPlatformCompiledProgram.h"
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class WebCustomFilterProgramProxy;
+
+class WebCustomFilterProgramProxyClient {
+public:
+    virtual void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*) = 0;
+};
+
+// This is a proxy class used to store the ID of the custom filter program serialized to the other process.
+// It lives in the WebProcess and is referenced from the CustomFilterValidatedProgram meaning that it will be kept alive as
+// long as a layer on the page will render with this program. It will call removeCustomFilterProgramProxy on the m_client
+// when the program is no longer needed to render the filter. The client can then send a message to the UI process
+// to destroy the associated reference. Note that more layers can share the same program and there's
+// no need to implement a caching mechanism in the compositor side.
+
+class WebCustomFilterProgramProxy : public RefCounted<WebCustomFilterProgramProxy>, public WebCore::TextureMapperPlatformCompiledProgramClient {
+public:
+    using RefCounted<WebCustomFilterProgramProxy>::ref;
+    using RefCounted<WebCustomFilterProgramProxy>::deref;
+
+    static PassRefPtr<WebCustomFilterProgramProxy> create(WebCustomFilterProgramProxyClient* client)
+    {
+        return adoptRef(new WebCustomFilterProgramProxy(client));
+    }
+
+    int id() const { return m_id; }
+
+    // Needed to make TextureMapperPlatformCompiledProgramClient look like a RefCounted object.
+    virtual void refFromValidatedProgram() { ref(); }
+    virtual void derefFromValidatedProgram() { deref(); }
+
+    ~WebCustomFilterProgramProxy();
+    
+    void setClient(WebCustomFilterProgramProxyClient* client) { m_client = client; }
+    WebCustomFilterProgramProxyClient* client() const { return m_client; }
+
+private:
+    WebCustomFilterProgramProxy(WebCustomFilterProgramProxyClient* client)
+        : m_client(client)
+        , m_id(s_nextId++)
+    {
+    }
+    
+    WebCustomFilterProgramProxyClient* m_client;
+    int m_id;
+    
+    static int s_nextId;
+};
+
+} // namespace WebKit
+
+#endif // USE(COORDINATED_GRAPHICS) && ENABLE(CSS_SHADERS)
+
+#endif // WebCustomFilterProgramProxy_h
+
index 7cd016e..098b5b9 100644 (file)
@@ -503,6 +503,7 @@ SOURCES += \
     Shared/WebURLResponse.cpp \
     Shared/WebWheelEvent.cpp \
     Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp \
+    Shared/CoordinatedGraphics/WebCustomFilterProgramProxy.cpp \
     Shared/qt/ArgumentCodersQt.cpp \
     Shared/qt/LayerTreeContextQt.cpp \
     Shared/qt/ShareableBitmapQt.cpp \
index 59a94dd..8e1767c 100644 (file)
 #include <WebCore/Settings.h>
 #include <wtf/TemporaryChange.h>
 
+#if ENABLE(CSS_SHADERS)
+#include "CustomFilterValidatedProgram.h"
+#include "ValidatedCustomFilterOperation.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -60,6 +65,10 @@ PassRefPtr<LayerTreeCoordinator> LayerTreeCoordinator::create(WebPage* webPage)
 
 LayerTreeCoordinator::~LayerTreeCoordinator()
 {
+#if ENABLE(CSS_SHADERS)
+    disconnectCustomFilterPrograms();
+#endif
+
     // Prevent setCoordinatedGraphicsLayerClient(0) -> detachLayer() from modifying the set while we iterate it.
     HashSet<WebCore::CoordinatedGraphicsLayer*> registeredLayers;
     registeredLayers.swap(m_registeredLayers);
@@ -323,10 +332,62 @@ void LayerTreeCoordinator::syncCanvas(WebLayerID id, const IntSize& canvasSize,
 void LayerTreeCoordinator::syncLayerFilters(WebLayerID id, const FilterOperations& filters)
 {
     m_shouldSyncFrame = true;
+#if ENABLE(CSS_SHADERS)
+    checkCustomFilterProgramProxies(filters);
+#endif
     m_webPage->send(Messages::LayerTreeCoordinatorProxy::SetCompositingLayerFilters(id, filters));
 }
 #endif
 
+#if ENABLE(CSS_SHADERS)
+void LayerTreeCoordinator::checkCustomFilterProgramProxies(const FilterOperations& filters)
+{
+    // We need to create the WebCustomFilterProgramProxy objects before we get to serialize the
+    // custom filters to the other process. That's because WebCustomFilterProgramProxy needs
+    // to link back to the coordinator, so that we can send a message to the UI process when 
+    // the program is not needed anymore.
+    // Note that the serialization will only happen at a later time in ArgumentCoder<WebCore::FilterOperations>::encode.
+    // At that point the program will only be serialized once. All the other times it will only use the ID of the program.
+    for (size_t i = 0; i < filters.size(); ++i) {
+        const FilterOperation* operation = filters.at(i);
+        if (operation->getOperationType() != FilterOperation::VALIDATED_CUSTOM)
+            continue;
+        const ValidatedCustomFilterOperation* customOperation = static_cast<const ValidatedCustomFilterOperation*>(operation);
+        ASSERT(customOperation->validatedProgram()->isInitialized());
+        TextureMapperPlatformCompiledProgram* program = customOperation->validatedProgram()->platformCompiledProgram();
+        if (!program->client())
+            program->setClient(WebCustomFilterProgramProxy::create(this));
+        else {
+            WebCustomFilterProgramProxy* customFilterProgramProxy = static_cast<WebCustomFilterProgramProxy*>(program->client());
+            if (!customFilterProgramProxy->client()) {
+                // Just in case the LayerTreeCoordinator was destroyed and recreated.
+                customFilterProgramProxy->setClient(this);
+            } else {
+                // If the client was not disconnected then this coordinator must be the client for it.
+                ASSERT(customFilterProgramProxy->client() == this);
+            }
+        }
+    }
+}
+
+void LayerTreeCoordinator::removeCustomFilterProgramProxy(WebCustomFilterProgramProxy* customFilterProgramProxy)
+{
+    // At this time the shader is not needed anymore, so we remove it from our set and 
+    // send a message to the other process to delete it.
+    m_customFilterPrograms.remove(customFilterProgramProxy);
+    // FIXME: Send a message to delete the object on the UI process.
+    // https://bugs.webkit.org/show_bug.cgi?id=101801
+}
+
+void LayerTreeCoordinator::disconnectCustomFilterPrograms()
+{
+    // Make sure that WebCore will not call into this coordinator anymore.
+    HashSet<WebCustomFilterProgramProxy*>::iterator iter = m_customFilterPrograms.begin();
+    for (; iter != m_customFilterPrograms.end(); ++iter)
+        (*iter)->setClient(0);
+}
+#endif
+
 void LayerTreeCoordinator::detachLayer(CoordinatedGraphicsLayer* layer)
 {
     m_registeredLayers.remove(layer);
index 198e3c1..b4f1226 100644 (file)
 #include <WebCore/GraphicsSurface.h>
 #include <wtf/OwnPtr.h>
 
+#if ENABLE(CSS_SHADERS)
+#include "WebCustomFilterProgramProxy.h"
+#endif
+
 namespace WebKit {
 
 class UpdateInfo;
@@ -42,7 +46,11 @@ class LayerTreeCoordinator : public LayerTreeHost, WebCore::GraphicsLayerClient
     , public CoordinatedGraphicsLayerClient
     , public CoordinatedImageBacking::Coordinator
     , public UpdateAtlasClient
-    , public WebCore::GraphicsLayerFactory {
+    , public WebCore::GraphicsLayerFactory
+#if ENABLE(CSS_SHADERS)
+    , WebCustomFilterProgramProxyClient
+#endif
+{
 public:
     static PassRefPtr<LayerTreeCoordinator> create(WebPage*);
     virtual ~LayerTreeCoordinator();
@@ -143,6 +151,14 @@ private:
 
     void releaseInactiveAtlasesTimerFired(WebCore::Timer<LayerTreeCoordinator>*);
 
+#if ENABLE(CSS_SHADERS)
+    // WebCustomFilterProgramProxyClient
+    void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
+
+    void checkCustomFilterProgramProxies(const WebCore::FilterOperations&);
+    void disconnectCustomFilterPrograms();
+#endif
+
     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
 
     // The layer which contains all non-composited content.
@@ -157,6 +173,10 @@ private:
     ImageBackingMap m_imageBackings;
     Vector<OwnPtr<UpdateAtlas> > m_updateAtlases;
 
+#if ENABLE(CSS_SHADERS)
+    HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
+#endif
+
     bool m_notifyAfterScheduledLayerFlush;
     bool m_isValid;
     // We don't send the messages related to releasing resources to UI Process during purging, because UI Process already had removed all resources.