[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

crogers at google.com crogers at google.com
Wed Dec 22 15:25:40 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 34c20523e2d185c18977ead75a6478f62ecfc64d
Author: crogers at google.com <crogers at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 3 04:41:32 2010 +0000

    2010-11-02  Chris Rogers  <crogers at google.com>
    
            Reviewed by James Robinson.
    
            Add AudioProcessingEvent files
            https://bugs.webkit.org/show_bug.cgi?id=48884
    
            No new tests since audio API is not yet implemented.
    
            * webaudio/AudioProcessingEvent.cpp: Added.
            (WebCore::AudioProcessingEvent::create):
            (WebCore::AudioProcessingEvent::AudioProcessingEvent):
            (WebCore::AudioProcessingEvent::~AudioProcessingEvent):
            (WebCore::AudioProcessingEvent::isAudioProcessingEvent):
            * webaudio/AudioProcessingEvent.h: Added.
            (WebCore::AudioProcessingEvent::inputBuffer):
            (WebCore::AudioProcessingEvent::outputBuffer):
            * webaudio/AudioProcessingEvent.idl: Added.
    2010-11-02  Noam Rosenthal  <noam.rosenthal at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            Some refactor for texmap to enable WebKit2: remove globals, and allow TextureMapper to exist without a GraphicsContext.
            This will allow rendering the TextureMapperNode tree without an active QPainter, into the current GL context.
            Most of the changes simply move the globas in TextureMapperGL into members of that class.
    
            [Texmap] [Qt] Texture mapper initial implementation
            https://bugs.webkit.org/show_bug.cgi?id=47070
    
            * Api/qwebframe.cpp:
            (QWebFramePrivate::renderFromTiledBackingStore):
            (QWebFramePrivate::renderCompositedLayers):
            (QWebFramePrivate::renderRelativeCoords):
            * Api/qwebframe_p.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71213 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 4b4f31f..d47a4d1 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -782,7 +782,57 @@
         (WebInspector.ImageView.prototype.contentTabSelected):
         (WebInspector.ImageView.prototype.contentTabSelected.onImageLoad):
 
-2010-11-02  Adele Peterson  <adele at apple.com>
+ 2010-10-31  Noam Rosenthal  <noam.rosenthal at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Texmap] [Qt] Texture mapper initial implementation
+        https://bugs.webkit.org/show_bug.cgi?id=47070
+
+        Some refactor for texmap to enable WebKit2: remove globals, and allow TextureMapper to exist without a GraphicsContext.
+        This will allow rendering the TextureMapperNode tree without an active QPainter, into the current GL context.
+        Most of the changes simply move the globas in TextureMapperGL into members of that class.
+
+        No new tests. Old tests in LayoutTests/compositing cover this.
+
+        * platform/graphics/opengl/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGLData::ShaderInfo::getUniformLocation):
+        (WebCore::TextureMapperGLData::ShaderInfo::createShaderProgram):
+        (WebCore::TextureMapperGLData::DirectlyCompositedImageRepository::findOrCreate):
+        (WebCore::TextureMapperGLData::DirectlyCompositedImageRepository::deref):
+        (WebCore::TextureMapperGLData::DirectlyCompositedImageRepository::DirectlyCompositedImageRepository):
+        (WebCore::TextureMapperGLData::DirectlyCompositedImageRepository::~DirectlyCompositedImageRepository):
+        (WebCore::TextureMapperGLData::TextureMapperGLData):
+        (WebCore::TextureMapperGL::TextureMapperGL):
+        (WebCore::TextureMapperGL::drawTexture):
+        (WebCore::BitmapTextureGL::setContentsToImage):
+        (WebCore::BitmapTextureGL::destroy):
+        (WebCore::TextureMapperGL::~TextureMapperGL):
+        (WebCore::TextureMapperGL::makeContextCurrent):
+        (WebCore::TextureMapperGL::obtainCurrentContext):
+        (WebCore::TextureMapperGL::bindSurface):
+        (WebCore::TextureMapperGL::paintToTarget):
+        (WebCore::TextureMapperGL::createTexture):
+        * platform/graphics/opengl/TextureMapperGL.h:
+        (WebCore::TextureMapperGL::data):
+        * platform/graphics/qt/TextureMapperQt.cpp:
+        (WebCore::TextureMapperQt::TextureMapperQt):
+        (WebCore::TextureMapperQt::setGraphicsContext):
+        (WebCore::TextureMapper::create):
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
+        (WebCore::TextureMapperNode::paint):
+        (WebCore::TextureMapperNode::uploadTextureFromContent):
+        * platform/graphics/texmap/TextureMapper.h:
+        (WebCore::TextureMapper::setGraphicsContext):
+        (WebCore::TextureMapper::setImageInterpolationQuality):
+        (WebCore::TextureMapper::setTextDrawingMode):
+        (WebCore::TextureMapper::imageInterpolationQuality):
+        (WebCore::TextureMapper::textDrawingMode):
+        (WebCore::TextureMapper::TextureMapper):
+        * platform/graphics/texmap/TextureMapperPlatformLayer.h:
+        (WebCore::TextureMapperContentLayer::paint):
+
+ 2010-11-02  Adele Peterson  <adele at apple.com>
 
         Reviewed by Kent Tamura.
 
@@ -83083,7 +83133,7 @@
 
         Reviewed by Gustavo Noronha Silva.
 
-        Bug 41340 - [GStreamer] Subtle race condition during seeks
+        Bug 41340 - [GStreamer] Subtle race condition during seeks
         https://bugs.webkit.org/show_bug.cgi?id=41340
 
         * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
diff --git a/WebCore/platform/graphics/opengl/TextureMapperGL.cpp b/WebCore/platform/graphics/opengl/TextureMapperGL.cpp
index 6527ce4..41bcfc4 100644
--- a/WebCore/platform/graphics/opengl/TextureMapperGL.cpp
+++ b/WebCore/platform/graphics/opengl/TextureMapperGL.cpp
@@ -30,8 +30,12 @@
 #if defined(TEXMAP_OPENGL_ES_2)
 #include <GLES2/gl2.h>
 #elif OS(MAC_OS_X)
+#include <AGL/agl.h>
 #include <gl.h>
 #else
+#if OS(UNIX)
+#include <GL/glx.h>
+#endif
 #include <GL/gl.h>
 #endif
 
@@ -90,6 +94,132 @@ inline static void debugGLCommand(const char* command, int line)
 #define GL_CMD(x) x
 #endif
 
+static const GLuint gInVertexAttributeIndex = 0;
+
+struct TextureMapperGLData {
+    static struct ShaderInfo {
+        enum ShaderProgramIndex {
+            SimpleProgram,
+            OpacityAndMaskProgram,
+            TargetProgram,
+
+            ProgramCount
+        };
+
+        enum ShaderVariableIndex {
+            InMatrixVariable,
+            InSourceMatrixVariable,
+            InMaskMatrixVariable,
+            OpacityVariable,
+            SourceTextureVariable,
+            MaskTextureVariable,
+
+            VariableCount
+        };
+
+        struct ProgramInfo {
+            GLuint id;
+            GLint vars[VariableCount];
+        };
+
+        GLint getUniformLocation(ShaderProgramIndex prog, ShaderVariableIndex var, const char* name)
+        {
+            return programs[prog].vars[var] = glGetUniformLocation(programs[prog].id, name);
+        }
+
+        void createShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource, ShaderProgramIndex index)
+        {
+            GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
+            GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
+            GL_CMD(glShaderSource(vertexShader, 1, &vertexShaderSource, 0))
+            GL_CMD(glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0))
+            GLuint programID = glCreateProgram();
+            GL_CMD(glCompileShader(vertexShader))
+            GL_CMD(glCompileShader(fragmentShader))
+            GL_CMD(glAttachShader(programID, vertexShader))
+            GL_CMD(glAttachShader(programID, fragmentShader))
+            GL_CMD(glBindAttribLocation(programID, gInVertexAttributeIndex, "InVertex"))
+            GL_CMD(glLinkProgram(programID))
+            programs[index].id = programID;
+#ifdef PRINT_PROGRAM_INFO_LOG
+            char infoLog[1024];
+            int len;
+            GL_CMD(glGetProgramInfoLog(programID, 1024, &len, infoLog));
+            LOG(Graphics, "Compiled program for texture mapper. Log: %s\n", infoLog);
+#endif
+        }
+
+        ProgramInfo programs[ProgramCount];
+
+    } shaderInfo;
+
+    struct DirectlyCompositedImageRepository {
+        struct Entry {
+            GLuint texture;
+            int refCount;
+        };
+        HashMap<NativeImagePtr, Entry> imageToTexture;
+
+        GLuint findOrCreate(NativeImagePtr image, bool& found)
+        {
+            HashMap<NativeImagePtr, Entry>::iterator it = imageToTexture.find(image);
+            found = false;
+            if (it != imageToTexture.end()) {
+                it->second.refCount++;
+                found = true;
+                return it->second.texture;
+            }
+            Entry entry;
+            GL_CMD(glGenTextures(1, &entry.texture));
+            entry.refCount = 1;
+            imageToTexture.add(image, entry);
+            return entry.texture;
+        }
+
+        bool deref(NativeImagePtr image)
+        {
+            HashMap<NativeImagePtr, Entry>::iterator it = imageToTexture.find(image);
+            if (it != imageToTexture.end()) {
+                if (it->second.refCount < 2) {
+                    imageToTexture.remove(it);
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        DirectlyCompositedImageRepository()
+        {
+        }
+
+        ~DirectlyCompositedImageRepository()
+        {
+            for (HashMap<NativeImagePtr, Entry>::iterator it = imageToTexture.begin(); it != imageToTexture.end(); ++it) {
+                GLuint texture = it->second.texture;
+                if (texture)
+                    GL_CMD(glDeleteTextures(1, &texture));
+            }
+
+        }
+    } directlyCompositedImages;
+
+    TextureMapperGLData()
+        : currentProgram(TextureMapperGLData::ShaderInfo::TargetProgram)
+    { }
+
+    TransformationMatrix projectionMatrix;
+    int currentProgram;
+
+#if OS(MAC_OS_X)
+    AGLContext aglContext;
+#elif OS(UNIX)
+    Drawable glxDrawable;
+    GLXContext glxContext;
+#endif
+};
+
+TextureMapperGLData::ShaderInfo TextureMapperGLData::shaderInfo;
+
 class BitmapTextureGL : public BitmapTexture {
 public:
     virtual void destroy();
@@ -111,6 +241,7 @@ private:
     GLuint m_fbo;
     IntSize m_actualSize;
     bool m_surfaceNeedsReset;
+    RefPtr<TextureMapperGL> m_textureMapper;
     BitmapTextureGL()
         : m_id(0)
         , m_image(0)
@@ -123,64 +254,15 @@ private:
     friend class TextureMapperGL;
 };
 
-static struct TexmapShaderInfo {
-    enum ShaderProgramIndex {
-        SimpleProgram,
-        OpacityAndMaskProgram,
-        TargetProgram,
-        NumPrograms
-    };
-
-    enum ShaderVariableIndex {
-        InMatrixVariable,
-        InSourceMatrixVariable,
-        InMaskMatrixVariable,
-        InVertexVariable,
-
-        OpacityVariable,
-        SourceTextureVariable,
-        MaskTextureVariable,
-        NumVariables
-    };
-
-    struct ProgramInfo {
-        GLuint id;
-        GLint vars[NumVariables];
-    };
-
-    GLint getUniformLocation(ShaderProgramIndex prog, ShaderVariableIndex var, const char* name)
-    {
-        return programs[prog].vars[var] = glGetUniformLocation(programs[prog].id, name);
-    }
-
-    void createShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource, ShaderProgramIndex index)
-    {
-        GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
-        GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-        GL_CMD(glShaderSource(vertexShader, 1, &vertexShaderSource, 0))
-        GL_CMD(glShaderSource(fragmentShader, 1, &fragmentShaderSource, 0))
-        GLuint programID = glCreateProgram();
-        GL_CMD(glCompileShader(vertexShader))
-        GL_CMD(glCompileShader(fragmentShader))
-        GL_CMD(glAttachShader(programID, vertexShader))
-        GL_CMD(glAttachShader(programID, fragmentShader))
-        GL_CMD(glBindAttribLocation(programID, 0, "InVertex"))
-        GL_CMD(glLinkProgram(programID))
-        programs[index].id = programID;
-    }
-
-    ProgramInfo programs[NumPrograms];
-
-} gShaderInfo;
-
 #define TEXMAP_GET_SHADER_VAR_LOCATION(prog, var) \
-            if (gShaderInfo.getUniformLocation(TexmapShaderInfo::prog##Program, TexmapShaderInfo::var##Variable, #var) < 0) \
-                    LOG_ERROR("Couldn't find variable "#var" in program "#prog"\n");
-#define TEXMAP_BUILD_SHADER(program) gShaderInfo.createShaderProgram(vertexShaderSource##program, fragmentShaderSource##program, TexmapShaderInfo::program##Program);
+    if (TextureMapperGLData::shaderInfo.getUniformLocation(TextureMapperGLData::shaderInfo.prog##Program, TextureMapperGLData::shaderInfo.var##Variable, #var) < 0) \
+            LOG_ERROR("Couldn't find variable "#var" in program "#prog"\n");
 
-TextureMapperGL::TextureMapperGL(GraphicsContext* context)
-    : TextureMapper(context)
-    , m_currentProgram(TexmapShaderInfo::TargetProgram)
+#define TEXMAP_BUILD_SHADER(program) \
+    TextureMapperGLData::shaderInfo.createShaderProgram(vertexShaderSource##program, fragmentShaderSource##program, TextureMapperGLData::shaderInfo.program##Program);
+
+TextureMapperGL::TextureMapperGL()
+    : m_data(new TextureMapperGLData)
 {
     static bool shadersCompiled = false;
     if (shadersCompiled)
@@ -282,18 +364,18 @@ void TextureMapperGL::drawTexture(const BitmapTexture& texture, const IntRect& t
 
     const BitmapTextureGL& textureGL = static_cast<const BitmapTextureGL&>(texture);
 
-    TexmapShaderInfo::ShaderProgramIndex program;
+    TextureMapperGLData::ShaderInfo::ShaderProgramIndex program;
     if (maskTexture)
-        program = TexmapShaderInfo::OpacityAndMaskProgram;
+        program = TextureMapperGLData::ShaderInfo::OpacityAndMaskProgram;
     else
-        program = TexmapShaderInfo::SimpleProgram;
+        program = TextureMapperGLData::ShaderInfo::SimpleProgram;
 
-    const TexmapShaderInfo::ProgramInfo& programInfo = gShaderInfo.programs[program];
-    if (m_currentProgram != program) {
+    const TextureMapperGLData::ShaderInfo::ProgramInfo& programInfo = data().shaderInfo.programs[program];
+    if (data().currentProgram != program) {
         GL_CMD(glUseProgram(programInfo.id))
-        GL_CMD(glDisableVertexAttribArray(gShaderInfo.programs[m_currentProgram].vars[TexmapShaderInfo::InVertexVariable]))
-        m_currentProgram = program;
-        GL_CMD(glEnableVertexAttribArray(programInfo.vars[TexmapShaderInfo::InVertexVariable]))
+        GL_CMD(glDisableVertexAttribArray(gInVertexAttributeIndex))
+        data().currentProgram = program;
+        GL_CMD(glEnableVertexAttribArray(gInVertexAttributeIndex))
     }
 
     GL_CMD(glDisable(GL_DEPTH_TEST))
@@ -305,7 +387,7 @@ void TextureMapperGL::drawTexture(const BitmapTexture& texture, const IntRect& t
     const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
     GL_CMD(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, unitRect))
 
-    TransformationMatrix matrix = TransformationMatrix(m_projectionMatrix).multLeft(modelViewMatrix).multLeft(TransformationMatrix(
+    TransformationMatrix matrix = TransformationMatrix(data().projectionMatrix).multLeft(modelViewMatrix).multLeft(TransformationMatrix(
             targetRect.width(), 0, 0, 0,
             0, targetRect.height(), 0, 0,
             0, 0, 1, 0,
@@ -321,10 +403,10 @@ void TextureMapperGL::drawTexture(const BitmapTexture& texture, const IntRect& t
                                      0, textureGL.m_relativeSize.height(), 0, 0,
                                      0, 0, 1, 0,
                                      0, 0, 0, 1};
-    GL_CMD(glUniformMatrix4fv(programInfo.vars[TexmapShaderInfo::InMatrixVariable], 1, GL_FALSE, m4))
-    GL_CMD(glUniformMatrix4fv(programInfo.vars[TexmapShaderInfo::InSourceMatrixVariable], 1, GL_FALSE, m4src))
-    GL_CMD(glUniform1i(programInfo.vars[TexmapShaderInfo::SourceTextureVariable], 0))
-    GL_CMD(glUniform1f(programInfo.vars[TexmapShaderInfo::OpacityVariable], opacity))
+    GL_CMD(glUniformMatrix4fv(programInfo.vars[TextureMapperGLData::ShaderInfo::InMatrixVariable], 1, GL_FALSE, m4))
+    GL_CMD(glUniformMatrix4fv(programInfo.vars[TextureMapperGLData::ShaderInfo::InSourceMatrixVariable], 1, GL_FALSE, m4src))
+    GL_CMD(glUniform1i(programInfo.vars[TextureMapperGLData::ShaderInfo::SourceTextureVariable], 0))
+    GL_CMD(glUniform1f(programInfo.vars[TextureMapperGLData::ShaderInfo::OpacityVariable], opacity))
 
     if (maskTexture && maskTexture->isValid()) {
         const BitmapTextureGL* maskTextureGL = static_cast<const BitmapTextureGL*>(maskTexture);
@@ -334,8 +416,8 @@ void TextureMapperGL::drawTexture(const BitmapTexture& texture, const IntRect& t
                                          0, maskTextureGL->m_relativeSize.height(), 0, 0,
                                          0, 0, 1, 0,
                                          0, 0, 0, 1};
-        glUniformMatrix4fv(programInfo.vars[TexmapShaderInfo::InMaskMatrixVariable], 1, GL_FALSE, m4mask);
-        GL_CMD(glUniform1i(programInfo.vars[TexmapShaderInfo::MaskTextureVariable], 1))
+        glUniformMatrix4fv(programInfo.vars[TextureMapperGLData::ShaderInfo::InMaskMatrixVariable], 1, GL_FALSE, m4mask);
+        GL_CMD(glUniform1i(programInfo.vars[TextureMapperGLData::ShaderInfo::MaskTextureVariable], 1))
         GL_CMD(glActiveTexture(GL_TEXTURE0))
     }
 
@@ -399,43 +481,6 @@ void BitmapTextureGL::endPaint()
     m_buffer.clear();
 }
 
-struct TexmapGLShaderTextures {
-    struct Entry {
-        GLuint texture;
-        int refCount;
-    };
-    HashMap<NativeImagePtr, Entry> imageToTexture;
-    GLuint findOrCreate(NativeImagePtr image, bool& found)
-    {
-        HashMap<NativeImagePtr, Entry>::iterator it = imageToTexture.find(image);
-        found = false;
-        if (it != imageToTexture.end()) {
-            it->second.refCount++;
-            found = true;
-            return it->second.texture;
-        }
-        Entry entry;
-        GL_CMD(glGenTextures(1, &entry.texture));
-        entry.refCount = 1;
-        imageToTexture.add(image, entry);
-        return entry.texture;
-    }
-
-    bool deref(NativeImagePtr image)
-    {
-        HashMap<NativeImagePtr, Entry>::iterator it = imageToTexture.find(image);
-        if (it != imageToTexture.end()) {
-            if (it->second.refCount < 2) {
-                imageToTexture.remove(it);
-                return false;
-            }
-        }
-        return true;
-    }
-};
-
-static TexmapGLShaderTextures gTextureRepository;
-
 void BitmapTextureGL::setContentsToImage(Image* image)
 {
     NativeImagePtr nativeImage = image ? image->nativeImageForCurrentFrame() : 0;
@@ -448,7 +493,7 @@ void BitmapTextureGL::setContentsToImage(Image* image)
     if (nativeImage == m_image)
         return;
     bool found = false;
-    GLuint newTextureID = gTextureRepository.findOrCreate(nativeImage, found);
+    GLuint newTextureID = m_textureMapper->data().directlyCompositedImages.findOrCreate(nativeImage, found);
     if (newTextureID != m_id) {
         destroy();
         m_id = newTextureID;
@@ -464,7 +509,7 @@ void BitmapTextureGL::setContentsToImage(Image* image)
 
 void BitmapTextureGL::destroy()
 {
-    if (m_id && (!m_image || !gTextureRepository.deref(m_image)))
+    if (m_id && (!m_image || !m_textureMapper->data().directlyCompositedImages.deref(m_image)))
         GL_CMD(glDeleteTextures(1, &m_id))
     if (m_fbo)
         GL_CMD(glDeleteFramebuffers(1, &m_fbo))
@@ -493,8 +538,32 @@ static inline TransformationMatrix createProjectionMatrix(const IntSize& size, b
                                 -1, flip ? 1 : -1, 0, 1);
 }
 
-void TextureMapperGL::cleanup()
+TextureMapperGL::~TextureMapperGL()
 {
+    makeContextCurrent();
+    delete m_data;
+}
+
+bool TextureMapperGL::makeContextCurrent()
+{
+#if OS(MAC_OS_X)
+    return aglSetCurrentContext(data().aglContext);
+#elif OS(UNIX)
+    Display* display = XOpenDisplay(0);
+    if (!display)
+        return false;
+    return glXMakeCurrent(display, data().glxDrawable, data().glxContext);
+#endif
+}
+
+void TextureMapperGL::obtainCurrentContext()
+{
+#if OS(MAC_OS_X)
+    data().aglContext = aglGetCurrentContext();
+#elif OS(UNIX)
+    data().glxDrawable = glXGetCurrentDrawable();
+    data().glxContext = glXGetCurrentContext();
+#endif
 }
 
 void TextureMapperGL::bindSurface(BitmapTexture *surfacePointer)
@@ -503,6 +572,7 @@ void TextureMapperGL::bindSurface(BitmapTexture *surfacePointer)
 
     if (!surface)
         return;
+
     TransformationMatrix matrix = createProjectionMatrix(surface->size(), false);
     matrix.translate(-surface->offset().x(), -surface->offset().y());
 
@@ -520,7 +590,7 @@ void TextureMapperGL::bindSurface(BitmapTexture *surfacePointer)
     }
 
     GL_CMD(glViewport(0, 0, surface->size().width(), surface->size().height()))
-    m_projectionMatrix = matrix;
+    data().projectionMatrix = matrix;
 }
 
 void TextureMapperGL::setClip(const IntRect& rect)
@@ -540,8 +610,7 @@ void TextureMapperGL::paintToTarget(const BitmapTexture& aSurface, const IntSize
                         surface.m_actualSize.width(), 0, 0, 0,
                         0, surface.m_actualSize.height(), 0, 0,
                         0, 0, 1, 0,
-                        surface.offset().x(), surface.offset().y(), 0, 1
-                )
+                        surface.offset().x(), surface.offset().y(), 0, 1)
             );
 
     const GLfloat m4[] = {
@@ -557,18 +626,18 @@ void TextureMapperGL::paintToTarget(const BitmapTexture& aSurface, const IntSize
                                      0, 0, 0, 1};
 
     // We already blended the alpha in; the result is premultiplied.
-    GL_CMD(glUseProgram(gShaderInfo.programs[TexmapShaderInfo::TargetProgram].id))
+    GL_CMD(glUseProgram(data().shaderInfo.programs[TextureMapperGLData::ShaderInfo::TargetProgram].id))
     GL_CMD(glBindFramebuffer(GL_FRAMEBUFFER, 0))
     GL_CMD(glViewport(0, 0, surfaceSize.width(), surfaceSize.height()))
     GL_CMD(glDisable(GL_STENCIL_TEST))
-    const TexmapShaderInfo::ProgramInfo& programInfo = gShaderInfo.programs[TexmapShaderInfo::TargetProgram];
-    GL_CMD(glUniform1f(programInfo.vars[TexmapShaderInfo::OpacityVariable], opacity))
+    const TextureMapperGLData::ShaderInfo::ProgramInfo& programInfo = data().shaderInfo.programs[TextureMapperGLData::ShaderInfo::TargetProgram];
+    GL_CMD(glUniform1f(programInfo.vars[TextureMapperGLData::ShaderInfo::OpacityVariable], opacity))
     GL_CMD(glActiveTexture(GL_TEXTURE0))
     GL_CMD(glBindTexture(GL_TEXTURE_2D, surface.m_id))
-    GL_CMD(glUniform1i(programInfo.vars[TexmapShaderInfo::SourceTextureVariable], 0))
-    GL_CMD(glEnableVertexAttribArray(programInfo.vars[TexmapShaderInfo::InVertexVariable]))
-    GL_CMD(glUniformMatrix4fv(programInfo.vars[TexmapShaderInfo::InMatrixVariable], 1, GL_FALSE, m4))
-    GL_CMD(glUniformMatrix4fv(programInfo.vars[TexmapShaderInfo::InSourceMatrixVariable], 1, GL_FALSE, m4src))
+    GL_CMD(glUniform1i(programInfo.vars[TextureMapperGLData::ShaderInfo::SourceTextureVariable], 0))
+    GL_CMD(glEnableVertexAttribArray(gInVertexAttributeIndex))
+    GL_CMD(glUniformMatrix4fv(programInfo.vars[TextureMapperGLData::ShaderInfo::InMatrixVariable], 1, GL_FALSE, m4))
+    GL_CMD(glUniformMatrix4fv(programInfo.vars[TextureMapperGLData::ShaderInfo::InSourceMatrixVariable], 1, GL_FALSE, m4src))
     GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0))
     const GLfloat unitRect[] = {0, 0, 1, 0, 1, 1, 0, 1};
     GL_CMD(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, unitRect))
@@ -577,15 +646,17 @@ void TextureMapperGL::paintToTarget(const BitmapTexture& aSurface, const IntSize
     setClip(visibleRect);
 
     GL_CMD(glDrawArrays(GL_TRIANGLE_FAN, 0, 4))
-    GL_CMD(glDisableVertexAttribArray(programInfo.vars[TexmapShaderInfo::InVertexVariable]))
+    GL_CMD(glDisableVertexAttribArray(0))
     GL_CMD(glUseProgram(0))
     GL_CMD(glBindBuffer(GL_ARRAY_BUFFER, 0))
-    m_currentProgram = TexmapShaderInfo::TargetProgram;
+    data().currentProgram = TextureMapperGLData::ShaderInfo::TargetProgram;
 }
 
 PassRefPtr<BitmapTexture> TextureMapperGL::createTexture()
 {
-    return adoptRef(new BitmapTextureGL());
+    BitmapTextureGL* texture = new BitmapTextureGL();
+    texture->m_textureMapper = this;
+    return adoptRef(texture);
 }
 
 };
diff --git a/WebCore/platform/graphics/opengl/TextureMapperGL.h b/WebCore/platform/graphics/opengl/TextureMapperGL.h
index 7a12c72..d05601d 100644
--- a/WebCore/platform/graphics/opengl/TextureMapperGL.h
+++ b/WebCore/platform/graphics/opengl/TextureMapperGL.h
@@ -29,11 +29,13 @@
 
 namespace WebCore {
 
+class TextureMapperGLData;
+
 // An OpenGL-ES2 implementation of TextureMapper.
 class TextureMapperGL : public TextureMapper {
 public:
-    TextureMapperGL(GraphicsContext* gc);
-    virtual ~TextureMapperGL() {}
+    TextureMapperGL();
+    virtual ~TextureMapperGL();
 
     // reimps from TextureMapper
     virtual void drawTexture(const BitmapTexture& texture, const IntRect&, const TransformationMatrix& transform, float opacity, const BitmapTexture* maskTexture);
@@ -43,11 +45,13 @@ public:
     virtual bool allowSurfaceForRoot() const { return true; }
     virtual PassRefPtr<BitmapTexture> createTexture();
     virtual const char* type() const;
-    virtual void cleanup();
+    void obtainCurrentContext();
+    bool makeContextCurrent();
 
 private:
-    TransformationMatrix m_projectionMatrix;
-    int m_currentProgram;
+    inline TextureMapperGLData& data() { return *m_data; }
+    TextureMapperGLData* m_data;
+    friend class BitmapTextureGL;
 };
 
 // An offscreen buffer to be rendered by software.
diff --git a/WebCore/platform/graphics/qt/TextureMapperQt.cpp b/WebCore/platform/graphics/qt/TextureMapperQt.cpp
index 9236dae..1c3a1c7 100644
--- a/WebCore/platform/graphics/qt/TextureMapperQt.cpp
+++ b/WebCore/platform/graphics/qt/TextureMapperQt.cpp
@@ -54,8 +54,9 @@ public:
     virtual void drawTexture(const BitmapTexture& texture, const IntRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* maskTexture);
     virtual void bindSurface(BitmapTexture* surface);
     virtual void setClip(const IntRect&);
+    virtual void setGraphicsContext(GraphicsContext*);
     virtual bool allowSurfaceForRoot() const { return false; }
-    TextureMapperQt(GraphicsContext* context);
+    TextureMapperQt();
     virtual const char* type() const { return "TextureMapperQt"; }
     virtual PassRefPtr<BitmapTexture> createTexture();
 
@@ -123,12 +124,15 @@ void TextureMapperQt::setClip(const IntRect& rect)
      painter->setClipRect(rect);
 }
 
-TextureMapperQt::TextureMapperQt(GraphicsContext* context)
-    : TextureMapper(context)
-    , m_painter(context->platformContext())
-    , m_currentSurface(0)
+TextureMapperQt::TextureMapperQt()
+    : m_currentSurface(0)
 {
-    TextureMapperQt::initialize(m_painter);
+}
+
+void TextureMapperQt::setGraphicsContext(GraphicsContext* context)
+{
+    m_painter = context->platformContext();
+    initialize(m_painter);
 }
 
 void TextureMapperQt::bindSurface(BitmapTexture* surface)
@@ -181,10 +185,12 @@ void TextureMapperQt::drawTexture(const BitmapTexture& texture, const IntRect& t
 PassRefPtr<TextureMapper> TextureMapper::create(GraphicsContext* context)
 {
 #ifdef QT_OPENGL_LIB
-    if (context->platformContext()->paintEngine()->type() == QPaintEngine::OpenGL2)
-        return adoptRef(new TextureMapperGL(context));
+    if (context->platformContext()->paintEngine()->type() == QPaintEngine::OpenGL2) {
+        TextureMapperGL* texmapGL = new TextureMapperGL;
+        return adoptRef(texmapGL);
+    }
 #endif
-    return adoptRef(new TextureMapperQt(context));
+    return adoptRef(new TextureMapperQt);
 }
 
 
diff --git a/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp b/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
index 057bcfc..54e6c7a 100644
--- a/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
+++ b/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
@@ -40,7 +40,6 @@ namespace WebCore {
 struct TexmapPaintOptions {
     BitmapTexture* surface;
     TextureMapper* textureMapper;
-    GraphicsContext* context;
     TextureMapperNode* rootLayer;
     float opacity;
     IntRect scissorRect;
@@ -214,7 +213,7 @@ public:
     IntSize size() const { return m_size; }
 
     virtual void setPlatformLayerClient(TextureMapperLayerClient*);
-    virtual void paint(GraphicsContext*, const IntSize&, const IntRect& targetRect, const IntRect& exposedRect, const TransformationMatrix& transform, float opacity);
+    virtual void paint(TextureMapper*, const TextureMapperContentLayer::PaintOptions&);
 
     static TextureMapperNode* toTextureMapperNode(GraphicsLayer*);
 public:
@@ -398,7 +397,7 @@ bool TextureMapperNode::hasSurfaceDescendants() const
 
 }
 
-void TextureMapperNode::paint(GraphicsContext* context, const IntSize& size, const IntRect& targetRect, const IntRect& exposedRect, const TransformationMatrix& transform, float opacity)
+void TextureMapperNode::paint(TextureMapper* textureMapper, const TextureMapperContentLayer::PaintOptions& options)
 {
     ASSERT(m_layerType == RootLayer);
     if (m_size.isEmpty())
@@ -409,8 +408,6 @@ void TextureMapperNode::paint(GraphicsContext* context, const IntSize& size, con
     ("[TextureMapper] RootPaint!!\n");
 #endif
 
-    RefPtr<TextureMapper> textureMapper = TextureMapper::create(context);
-
     if (textureMapper->type() != m_lastTextureMapperType)
         gTextureMapperCache.m_data.clear();
 
@@ -418,16 +415,15 @@ void TextureMapperNode::paint(GraphicsContext* context, const IntSize& size, con
     TexmapPaintOptions opt;
     opt.opacity = 1;
     opt.rootLayer = this;
-    opt.scissorRect = targetRect;
-    opt.visibleRect = exposedRect;
-    opt.textureMapper = textureMapper.get();
-    opt.context = textureMapper->graphicsContext();
+    opt.scissorRect = options.targetRect;
+    opt.visibleRect = options.visibleRect;
+    opt.textureMapper = textureMapper;
     opt.surface = 0;
     paintRecursive(opt);
 
     if (textureMapper->allowSurfaceForRoot() || m_state.hasSurfaceDescendants) {
         textureMapper->bindSurface(0);
-        textureMapper->paintToTarget(*m_surface.get(), size, transform, opacity * m_state.opacity, targetRect);
+        textureMapper->paintToTarget(*m_surface.get(), options.viewportSize, options.transform, options.opacity * m_state.opacity, options.targetRect);
     }
     gTextureMapperCache.purge();
 }
@@ -692,10 +688,9 @@ void TextureMapperNode::uploadTextureFromContent(TextureMapper* textureMapper, c
 
     {
         GraphicsContext context(m_texture->beginPaint(dirtyRect));
-        if (textureMapper && textureMapper->graphicsContext()) {
-            GraphicsContext* originalContext = textureMapper->graphicsContext();
-            context.setImageInterpolationQuality(originalContext->imageInterpolationQuality());
-            context.setTextDrawingMode(originalContext->textDrawingMode());
+        if (textureMapper) {
+            context.setImageInterpolationQuality(textureMapper->imageInterpolationQuality());
+            context.setTextDrawingMode(textureMapper->textDrawingMode());
         }
         m_layer->paintGraphicsLayerContents(context, dirtyRect);
     }
diff --git a/WebCore/platform/graphics/texmap/TextureMapper.h b/WebCore/platform/graphics/texmap/TextureMapper.h
index 03c1c6d..89899c0 100644
--- a/WebCore/platform/graphics/texmap/TextureMapper.h
+++ b/WebCore/platform/graphics/texmap/TextureMapper.h
@@ -97,20 +97,30 @@ public:
         drawTexture(texture, IntRect(0, 0, texture.contentSize().width(), texture.contentSize().height()), matrix, opacity, 0);
     }
 
+    virtual void setGraphicsContext(GraphicsContext*) { }
     virtual void setClip(const IntRect&) = 0;
     virtual bool allowSurfaceForRoot() const = 0;
     virtual PassRefPtr<BitmapTexture> createTexture() = 0;
     virtual const char* type() const = 0;
     virtual void cleanup() {}
 
-    GraphicsContext* graphicsContext() const
-    {
-        return m_gc;
-    }
+    void setImageInterpolationQuality(InterpolationQuality quality) { m_interpolationQuality = quality; }
+    void setTextDrawingMode(int mode) { m_textDrawingMode = mode; }
+
+    InterpolationQuality imageInterpolationQuality() const { return m_interpolationQuality; }
+    int textDrawingMode() const { return m_textDrawingMode; }
+
+    void setViewportSize(const IntSize&);
 
 protected:
-    TextureMapper(GraphicsContext* gc) : m_gc(gc) {}
-    GraphicsContext* m_gc;
+    TextureMapper()
+        : m_interpolationQuality(InterpolationDefault)
+        , m_textDrawingMode(cTextFill)
+    {}
+
+private:
+    InterpolationQuality m_interpolationQuality;
+    int m_textDrawingMode;
 };
 
 };
diff --git a/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h b/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
index 23e9fc9..a15681c 100644
--- a/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
+++ b/WebCore/platform/graphics/texmap/TextureMapperPlatformLayer.h
@@ -25,6 +25,7 @@ namespace WebCore {
 class GraphicsContext;
 class IntRect;
 class IntSize;
+class TextureMapper;
 class TransformationMatrix;
 
 
@@ -50,10 +51,17 @@ public:
 
 class TextureMapperContentLayer : public TextureMapperPlatformLayer {
 public:
+    struct PaintOptions {
+        IntRect visibleRect;
+        IntRect targetRect;
+        IntSize viewportSize;
+        TransformationMatrix transform;
+        float opacity;
+    };
+
     virtual void setPlatformLayerClient(TextureMapperLayerClient*) = 0;
-    virtual void paint(GraphicsContext*, const IntSize&, const IntRect& targetRect, const IntRect& exposedRect, const TransformationMatrix& transform, float opacity) {}
+    virtual void paint(TextureMapper*, const PaintOptions&) {}
     virtual IntSize size() const = 0;
-    virtual void cleanupTextureMapper() {}
     virtual Type layerType() const { return ContentLayer; }
 };
 
diff --git a/WebKit/qt/Api/qwebframe.cpp b/WebKit/qt/Api/qwebframe.cpp
index 39e74d9..fe65be6 100644
--- a/WebKit/qt/Api/qwebframe.cpp
+++ b/WebKit/qt/Api/qwebframe.cpp
@@ -97,6 +97,7 @@
 #include "runtime_root.h"
 #endif
 #if USE(TEXTURE_MAPPER)
+#include "texmap/TextureMapper.h"
 #include "texmap/TextureMapperPlatformLayer.h"
 #endif
 #include "wtf/HashMap.h"
@@ -294,19 +295,41 @@ void QWebFramePrivate::renderFromTiledBackingStore(GraphicsContext* context, con
 
         painter->restore();
     }
-#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
-    // TextureMapper might use raw OpenGL or some other backend that requires native painting. On raster this doesn't have any effect.
-    if (rootGraphicsLayer) {
-        painter->beginNativePainting();
-        rootGraphicsLayer->paint(context, view->size(), view->frameRect(), IntRect(clip.boundingRect()), TransformationMatrix(), painter->opacity());
-        painter->endNativePainting();
-    }
 
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+    renderCompositedLayers(context, IntRect(clip.boundingRect()));
     renderRelativeCoords(context, (QWebFrame::RenderLayer)(QWebFrame::ScrollBarLayer | QWebFrame::PanIconLayer), clip);
 #endif
 }
 #endif
 
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+void QWebFramePrivate::renderCompositedLayers(GraphicsContext* context, const IntRect& clip)
+{
+    if (!rootGraphicsLayer)
+        return;
+
+    if (!textureMapper)
+        textureMapper = TextureMapper::create(context);
+
+    textureMapper->setGraphicsContext(context);
+    textureMapper->setImageInterpolationQuality(context->imageInterpolationQuality());
+    textureMapper->setTextDrawingMode(context->textDrawingMode());
+    QPainter* painter = context->platformContext();
+    FrameView* view = frame->view();
+    painter->save();
+    painter->beginNativePainting();
+    TextureMapperContentLayer::PaintOptions options;
+    options.visibleRect = clip;
+    options.targetRect = view->frameRect();
+    options.viewportSize = view->size();
+    options.opacity = painter->opacity();
+    rootGraphicsLayer->paint(textureMapper.get(), options);
+    painter->endNativePainting();
+    painter->restore();
+}
+#endif
+
 void QWebFramePrivate::renderRelativeCoords(GraphicsContext* context, QWebFrame::RenderLayer layer, const QRegion& clip)
 {
     if (!frame->view() || !frame->contentRenderer())
@@ -349,16 +372,8 @@ void QWebFramePrivate::renderRelativeCoords(GraphicsContext* context, QWebFrame:
             context->restore();
         }
         painter->restore();
-
 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
-        if (rootGraphicsLayer) {
-            painter->save();
-            painter->beginNativePainting();
-            rootGraphicsLayer->paint(context, view->size(), view->frameRect(), IntRect(clip.boundingRect()),
-                                     TransformationMatrix(), context->platformContext()->opacity());
-            painter->endNativePainting();
-            painter->restore();
-        }
+        renderCompositedLayers(context, IntRect(clip.boundingRect()));
 #endif
     }
     if (layer & (QWebFrame::PanIconLayer | QWebFrame::ScrollBarLayer)) {
diff --git a/WebKit/qt/Api/qwebframe_p.h b/WebKit/qt/Api/qwebframe_p.h
index 5660bd1..634e21b 100644
--- a/WebKit/qt/Api/qwebframe_p.h
+++ b/WebKit/qt/Api/qwebframe_p.h
@@ -33,6 +33,10 @@
 #include "Frame.h"
 #include "ViewportArguments.h"
 
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+#include "texmap/TextureMapper.h"
+#endif
+
 namespace WebCore {
     class FrameLoaderClientQt;
     class FrameView;
@@ -94,6 +98,9 @@ public:
     void renderFromTiledBackingStore(WebCore::GraphicsContext*, const QRegion& clip);
 #endif
 
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+    void renderCompositedLayers(WebCore::GraphicsContext* context, const WebCore::IntRect& clip);
+#endif
     QWebFrame *q;
     Qt::ScrollBarPolicy horizontalScrollBarPolicy;
     Qt::ScrollBarPolicy verticalScrollBarPolicy;
@@ -106,6 +113,7 @@ public:
     int marginHeight;
 #if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
     WebCore::TextureMapperContentLayer* rootGraphicsLayer;
+    RefPtr<WebCore::TextureMapper> textureMapper;
 #endif
     bool zoomTextOnly;
 };
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index 320fc88..eb8e3ce 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,20 @@
+2010-11-02  Noam Rosenthal  <noam.rosenthal at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Some refactor for texmap to enable WebKit2: remove globals, and allow TextureMapper to exist without a GraphicsContext.
+        This will allow rendering the TextureMapperNode tree without an active QPainter, into the current GL context.
+        Most of the changes simply move the globas in TextureMapperGL into members of that class.
+
+        [Texmap] [Qt] Texture mapper initial implementation
+        https://bugs.webkit.org/show_bug.cgi?id=47070
+
+        * Api/qwebframe.cpp:
+        (QWebFramePrivate::renderFromTiledBackingStore):
+        (QWebFramePrivate::renderCompositedLayers):
+        (QWebFramePrivate::renderRelativeCoords):
+        * Api/qwebframe_p.h:
+
 2010-11-01  Brady Eidson  <beidson at apple.com>
 
         Reviewed by Anders Carlsson.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list