[Qt][WK2] Make TextureMapperShaderManager::getShaderProgram() not be a template.
authorzeno.albisser@nokia.com <zeno.albisser@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Mar 2012 08:37:51 +0000 (08:37 +0000)
committerzeno.albisser@nokia.com <zeno.albisser@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Mar 2012 08:37:51 +0000 (08:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82049

Change the getShaderProgram() function to not be a template.
This is a workaround for a compiler bug that leads to an assert
when compiling in debug mode on mac.

Reviewed by Noam Rosenthal.

* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawTexture):
(WebCore::TextureMapperGL::beginClip):
* platform/graphics/texmap/TextureMapperShaderManager.h:
(TextureMapperShaderProgram):
(WebCore::TextureMapperShaderManager::getShaderProgram):
(TextureMapperShaderManager):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h

index aa6ce604515c11f7264a4cb670e8d05cb478a2f7..fd27f7febcdebd3a4be8ecf26c0b3de70a74fc13 100644 (file)
@@ -1,3 +1,22 @@
+2012-03-24  Zeno Albisser  <zeno@webkit.org>
+
+        [Qt][WK2] Make TextureMapperShaderManager::getShaderProgram() not be a template.
+        https://bugs.webkit.org/show_bug.cgi?id=82049
+
+        Change the getShaderProgram() function to not be a template.
+        This is a workaround for a compiler bug that leads to an assert
+        when compiling in debug mode on mac.
+
+        Reviewed by Noam Rosenthal.
+
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGL::drawTexture):
+        (WebCore::TextureMapperGL::beginClip):
+        * platform/graphics/texmap/TextureMapperShaderManager.h:
+        (TextureMapperShaderProgram):
+        (WebCore::TextureMapperShaderManager::getShaderProgram):
+        (TextureMapperShaderManager):
+
 2012-03-23  Shawn Singh  <shawnsingh@chromium.org>
 
         [chromium] Incorrect replica originTransform used in CCDamageTracker
index 633ec1fbfa1e966b3a2f7167bfd7a7f6eae1085c..5a36088092dc7c92a5d0705ca9afff030e7d23f5 100644 (file)
@@ -319,9 +319,9 @@ void TextureMapperGL::drawTexture(uint32_t texture, Flags flags, const IntSize&
 {
     RefPtr<TextureMapperShaderProgram> shaderInfo;
     if (maskTexture)
-        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram<TextureMapperShaderProgramOpacityAndMask>();
+        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::OpacityAndMask);
     else
-        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram<TextureMapperShaderProgramSimple>();
+        shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple);
 
     GL_CMD(glUseProgram(shaderInfo->id()))
     GL_CMD(glEnableVertexAttribArray(shaderInfo->vertexAttrib()))
@@ -624,7 +624,7 @@ void TextureMapperGL::beginClip(const TransformationMatrix& modelViewMatrix, con
 
     data().initializeStencil();
 
-    RefPtr<TextureMapperShaderProgramSimple> shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram<TextureMapperShaderProgramSimple>();
+    RefPtr<TextureMapperShaderProgram> shaderInfo = data().sharedGLData().textureMapperShaderManager.getShaderProgram(TextureMapperShaderManager::Simple);
 
     GL_CMD(glUseProgram(shaderInfo->id()))
     GL_CMD(glEnableVertexAttribArray(shaderInfo->vertexAttrib()))
index 426b903d82e42b1402089017f6ec9784f0cbb73f..94a86084bd2f8d05e13a24097cd39ace82443311 100644 (file)
@@ -33,8 +33,6 @@
 
 namespace WebCore {
 
-typedef void* ShaderType;
-
 class BitmapTexture;
 class TextureMapperShaderManager;
 
@@ -45,13 +43,6 @@ public:
 
     virtual ~TextureMapperShaderProgram();
 
-    template<class T>
-    static ShaderType shaderType()
-    {
-        static int type = 0;
-        return &type;
-    }
-
     virtual void prepare(float opacity, const BitmapTexture*) { }
     GLint matrixVariable() const { return m_matrixVariable; }
     GLint sourceMatrixVariable() const { return m_sourceMatrixVariable; }
@@ -101,24 +92,36 @@ private:
 
 class TextureMapperShaderManager {
 public:
+    enum ShaderType {
+        Invalid = 0, // HashMaps do not like 0 as a key.
+        Simple,
+        OpacityAndMask
+    };
+
     TextureMapperShaderManager();
     virtual ~TextureMapperShaderManager();
 
-    template<class T>
-    PassRefPtr<T> getShaderProgram()
+    PassRefPtr<TextureMapperShaderProgram> getShaderProgram(ShaderType shaderType)
     {
-        ShaderType shaderType = TextureMapperShaderProgram::shaderType<T>();
-        TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
-        if (it != m_textureMapperShaderProgramMap.end())
-            return static_cast<T*>(it->second.get());
+        RefPtr<TextureMapperShaderProgram> program;
+        if (shaderType == Invalid)
+            return program;
 
-        RefPtr<T> t = T::create();
-        m_textureMapperShaderProgramMap.add(shaderType, t);
-        return t;
+        TextureMapperShaderProgramMap::iterator it = m_textureMapperShaderProgramMap.find(shaderType);
+        switch (shaderType) {
+        case Simple:
+            program = TextureMapperShaderProgramSimple::create();
+            break;
+        case OpacityAndMask:
+            program = TextureMapperShaderProgramOpacityAndMask::create();
+            break;
+        }
+        m_textureMapperShaderProgramMap.add(shaderType, program);
+        return program;
     }
 
 private:
-    typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram> > TextureMapperShaderProgramMap;
+    typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap;
     TextureMapperShaderProgramMap m_textureMapperShaderProgramMap;
 };