[CSS Shaders] Add blend mode and composite op to compiled program cache key
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Aug 2012 22:15:52 +0000 (22:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Aug 2012 22:15:52 +0000 (22:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93623

Patch by Max Vujovic <mvujovic@adobe.com> on 2012-08-10
Reviewed by Dirk Schulze.

Right now, only the vertex shader string and the fragment shader string are hashed
to create a key for the compiled program. However, in a future patch, WebKit will
rewrite the fragment shader based on the blend mode and composite op specified by
the author. This means that the unique key for a compiled program is (original
vertex shader string, original fragment shader string, blend mode, composite
operator). This patch adds blend mode and composite operator in the hash for the
key.

No new tests. The state of the compiled program cache is not exposed to a web
page. Existing tests should ensure this change doesn't break current
functionality. Additional tests will be added in a future patch that implements
shader rewriting based on blend mode and composite op.

* platform/graphics/filters/CustomFilterProgram.cpp:
(WebCore::CustomFilterProgram::programInfo):
* platform/graphics/filters/CustomFilterProgram.h:
(WebCore):
* platform/graphics/filters/CustomFilterProgramInfo.cpp:
(WebCore::CustomFilterProgramInfo::CustomFilterProgramInfo):
(WebCore::CustomFilterProgramInfo::hash):
(WebCore::CustomFilterProgramInfo::operator==):
* platform/graphics/filters/CustomFilterProgramInfo.h:
(WebCore::CustomFilterProgramMixSettings::CustomFilterProgramMixSettings):
(CustomFilterProgramMixSettings):
(WebCore::CustomFilterProgramMixSettings::operator==):
(WebCore):
(CustomFilterProgramInfo):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/filters/CustomFilterProgram.cpp
Source/WebCore/platform/graphics/filters/CustomFilterProgram.h
Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.cpp
Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h

index 90c7dcc..8b8cdfd 100644 (file)
@@ -1,3 +1,38 @@
+2012-08-10  Max Vujovic  <mvujovic@adobe.com>
+
+        [CSS Shaders] Add blend mode and composite op to compiled program cache key
+        https://bugs.webkit.org/show_bug.cgi?id=93623
+
+        Reviewed by Dirk Schulze.
+
+        Right now, only the vertex shader string and the fragment shader string are hashed
+        to create a key for the compiled program. However, in a future patch, WebKit will
+        rewrite the fragment shader based on the blend mode and composite op specified by
+        the author. This means that the unique key for a compiled program is (original
+        vertex shader string, original fragment shader string, blend mode, composite
+        operator). This patch adds blend mode and composite operator in the hash for the
+        key.
+
+        No new tests. The state of the compiled program cache is not exposed to a web
+        page. Existing tests should ensure this change doesn't break current
+        functionality. Additional tests will be added in a future patch that implements
+        shader rewriting based on blend mode and composite op.
+
+        * platform/graphics/filters/CustomFilterProgram.cpp:
+        (WebCore::CustomFilterProgram::programInfo):
+        * platform/graphics/filters/CustomFilterProgram.h:
+        (WebCore):
+        * platform/graphics/filters/CustomFilterProgramInfo.cpp:
+        (WebCore::CustomFilterProgramInfo::CustomFilterProgramInfo):
+        (WebCore::CustomFilterProgramInfo::hash):
+        (WebCore::CustomFilterProgramInfo::operator==):
+        * platform/graphics/filters/CustomFilterProgramInfo.h:
+        (WebCore::CustomFilterProgramMixSettings::CustomFilterProgramMixSettings):
+        (CustomFilterProgramMixSettings):
+        (WebCore::CustomFilterProgramMixSettings::operator==):
+        (WebCore):
+        (CustomFilterProgramInfo):
+
 2012-08-10  Alice Cheng  <alice_cheng@apple.com>
 
         Part 1 of: Extend -webkit-user-select with a new value "all"
index 853e513..d1cf613 100644 (file)
@@ -81,7 +81,7 @@ void CustomFilterProgram::notifyClients()
 CustomFilterProgramInfo CustomFilterProgram::programInfo() const
 {
     ASSERT(isLoaded());
-    return CustomFilterProgramInfo(vertexShaderString(), fragmentShaderString());
+    return CustomFilterProgramInfo(vertexShaderString(), fragmentShaderString(), m_mixSettings);
 }
 
 } // namespace WebCore
index f7da188..ef19dfb 100644 (file)
@@ -32,7 +32,7 @@
 
 #if ENABLE(CSS_SHADERS)
 
-#include "GraphicsTypes.h"
+#include "CustomFilterProgramInfo.h"
 
 #include <wtf/HashCountedSet.h>
 #include <wtf/RefCounted.h>
@@ -43,20 +43,6 @@ namespace WebCore {
 class GraphicsContext3D;
 class CustomFilterCompiledProgram;
 class CustomFilterProgramClient;
-class CustomFilterProgramInfo;
-
-typedef struct CustomFilterProgramMixSettings {
-    CustomFilterProgramMixSettings()
-        : enabled(false)
-        , blendMode(BlendModeNormal)
-        , compositeOperator(CompositeSourceOver)
-    {
-    }
-    
-    bool enabled;
-    BlendMode blendMode;
-    CompositeOperator compositeOperator;
-} CustomFilterProgramMixSettings;
 
 // This is the base class for the StyleCustomFilterProgram class which knows how to keep
 // references to the cached shaders.
index bc7c9e9..1bf6a91 100644 (file)
@@ -64,19 +64,27 @@ bool CustomFilterProgramInfo::isHashTableDeletedValue() const
         && m_fragmentShaderString.isHashTableDeletedValue();
 }
 
-CustomFilterProgramInfo::CustomFilterProgramInfo(const String& vertexShader, const String& fragmentShader)
+CustomFilterProgramInfo::CustomFilterProgramInfo(const String& vertexShader, const String& fragmentShader, const CustomFilterProgramMixSettings& mixSettings)
     : m_vertexShaderString(vertexShader)
     , m_fragmentShaderString(fragmentShader)
+    , m_mixSettings(mixSettings)
 {
     // At least one of the shaders needs to be non-null.
     ASSERT(!m_vertexShaderString.isNull() || !m_fragmentShaderString.isNull());
 }
 
-unsigned CustomFilterProgramInfo::hash() const 
+unsigned CustomFilterProgramInfo::hash() const
 {
     // At least one of the shaders needs to be non-null.
     ASSERT(!m_vertexShaderString.isNull() || !m_fragmentShaderString.isNull());
-    return WTF::intHash((static_cast<uint64_t>(hashPossiblyNullString(m_vertexShaderString)) << 32 | hashPossiblyNullString(m_fragmentShaderString)));
+    uintptr_t hashCodes[5] = {
+        hashPossiblyNullString(m_vertexShaderString),
+        hashPossiblyNullString(m_fragmentShaderString),
+        m_mixSettings.enabled,
+        m_mixSettings.enabled ? m_mixSettings.blendMode : 0,
+        m_mixSettings.enabled ? m_mixSettings.compositeOperator : 0
+    };
+    return StringHasher::hashMemory<sizeof(hashCodes)>(&hashCodes);
 }
 
 bool CustomFilterProgramInfo::operator==(const CustomFilterProgramInfo& o) const 
@@ -84,7 +92,8 @@ bool CustomFilterProgramInfo::operator==(const CustomFilterProgramInfo& o) const
     ASSERT(!isHashTableDeletedValue());
     ASSERT(!o.isHashTableDeletedValue());
     return m_vertexShaderString == o.m_vertexShaderString
-        && m_fragmentShaderString == o.m_fragmentShaderString;
+        && m_fragmentShaderString == o.m_fragmentShaderString
+        && m_mixSettings == o.m_mixSettings;
 }
 
 } // namespace WebCore
index e89e9f5..e1f4559 100644 (file)
 #define CustomFilterProgramInfo_h
 
 #if ENABLE(CSS_SHADERS)
+#include "GraphicsTypes.h"
+
 #include <wtf/HashTraits.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
+struct CustomFilterProgramMixSettings {
+    CustomFilterProgramMixSettings()
+        : enabled(false)
+        , blendMode(BlendModeNormal)
+        , compositeOperator(CompositeSourceOver)
+    {
+    }
+    
+    bool operator==(const CustomFilterProgramMixSettings& o) const
+    {
+        return (!enabled && !o.enabled)
+            || (blendMode == o.blendMode && compositeOperator == o.compositeOperator);
+    }
+    
+    bool enabled;
+    BlendMode blendMode;
+    CompositeOperator compositeOperator;
+};
+
 // CustomFilterProgramInfo is the key used to link CustomFilterProgram with CustomFilterCompiledProgram.
 // It can be used as a key in a HashMap, with the note that at least one of Strings needs to be non-null. 
 // Null strings are placeholders for the default shader.
 class CustomFilterProgramInfo {
 public:
-    CustomFilterProgramInfo(const String&, const String&);
+    CustomFilterProgramInfo(const String&, const String&, const CustomFilterProgramMixSettings&);
 
     CustomFilterProgramInfo();
     bool isEmptyValue() const;
@@ -57,9 +78,7 @@ public:
 private:
     String m_vertexShaderString;
     String m_fragmentShaderString;
-
-    // FIXME: Alpha compositing and blending will come here after mix() function parsing will land.
-    // https://bugs.webkit.org/show_bug.cgi?id=90101
+    CustomFilterProgramMixSettings m_mixSettings;
 };
 
 struct CustomFilterProgramInfoHash {