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

senorblanco at chromium.org senorblanco at chromium.org
Wed Dec 22 11:27:53 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 5c3b2ee8039edac4485bf639e60374b5fdab8bf4
Author: senorblanco at chromium.org <senorblanco at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Jul 26 15:43:55 2010 +0000

    2010-07-23  Stephen White  <senorblanco at chromium.org>
    
            Reviewed by Darin Fisher.
    
            Implement OpenGLES2 helper classes.
            https://bugs.webkit.org/show_bug.cgi?id=42905
    
            GLES2Canvas and GLES2Texture are some simple OpenGLES2 helper classes
            for managing state, samplers and textures.
    
            When this is hooked up, it will be covered by many layout tests.
    
            * WebCore.gypi:
            Add new files to chromium build (contents are protected by #if's for now).
            * platform/graphics/chromium/GLES2Canvas.cpp: Added.
            (WebCore::affineTo3x3):
            (WebCore::GLES2Canvas::State::State):
            (WebCore::GLES2Canvas::GLES2Canvas):
            (WebCore::GLES2Canvas::~GLES2Canvas):
            (WebCore::GLES2Canvas::clearRect):
            (WebCore::GLES2Canvas::fillRect):
            (WebCore::GLES2Canvas::setFillColor):
            (WebCore::GLES2Canvas::setAlpha):
            (WebCore::GLES2Canvas::translate):
            (WebCore::GLES2Canvas::rotate):
            (WebCore::GLES2Canvas::scale):
            (WebCore::GLES2Canvas::concatCTM):
            (WebCore::GLES2Canvas::save):
            (WebCore::GLES2Canvas::restore):
            (WebCore::GLES2Canvas::drawTexturedRect):
            (WebCore::GLES2Canvas::setCompositeOperation):
            (WebCore::GLES2Canvas::applyCompositeOperator):
            (WebCore::GLES2Canvas::getQuadVertices):
            (WebCore::GLES2Canvas::getQuadIndices):
            (WebCore::loadShader):
            (WebCore::GLES2Canvas::getSimpleProgram):
            (WebCore::GLES2Canvas::getTexProgram):
            (WebCore::GLES2Canvas::createTexture):
            (WebCore::GLES2Canvas::getTexture):
            (WebCore::GLES2Canvas::checkGLError):
            * platform/graphics/chromium/GLES2Canvas.h: Added.
            (WebCore::GLES2Canvas::gles2Context):
            * platform/graphics/chromium/GLES2Texture.cpp: Added.
            (WebCore::GLES2Texture::GLES2Texture):
            (WebCore::GLES2Texture::~GLES2Texture):
            (WebCore::GLES2Texture::create):
            (WebCore::convertFormat):
            (WebCore::GLES2Texture::load):
            (WebCore::GLES2Texture::bind):
            * platform/graphics/chromium/GLES2Texture.h: Added.
            (WebCore::GLES2Texture::):
            (WebCore::GLES2Texture::format):
            (WebCore::GLES2Texture::width):
            (WebCore::GLES2Texture::height):
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64046 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 8e9c525..9ba9840 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,59 @@
+2010-07-23  Stephen White  <senorblanco at chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Implement OpenGLES2 helper classes.
+        https://bugs.webkit.org/show_bug.cgi?id=42905
+
+        GLES2Canvas and GLES2Texture are some simple OpenGLES2 helper classes
+        for managing state, samplers and textures.
+
+        When this is hooked up, it will be covered by many layout tests.
+
+        * WebCore.gypi:
+        Add new files to chromium build (contents are protected by #if's for now).
+        * platform/graphics/chromium/GLES2Canvas.cpp: Added.
+        (WebCore::affineTo3x3):
+        (WebCore::GLES2Canvas::State::State):
+        (WebCore::GLES2Canvas::GLES2Canvas):
+        (WebCore::GLES2Canvas::~GLES2Canvas):
+        (WebCore::GLES2Canvas::clearRect):
+        (WebCore::GLES2Canvas::fillRect):
+        (WebCore::GLES2Canvas::setFillColor):
+        (WebCore::GLES2Canvas::setAlpha):
+        (WebCore::GLES2Canvas::translate):
+        (WebCore::GLES2Canvas::rotate):
+        (WebCore::GLES2Canvas::scale):
+        (WebCore::GLES2Canvas::concatCTM):
+        (WebCore::GLES2Canvas::save):
+        (WebCore::GLES2Canvas::restore):
+        (WebCore::GLES2Canvas::drawTexturedRect):
+        (WebCore::GLES2Canvas::setCompositeOperation):
+        (WebCore::GLES2Canvas::applyCompositeOperator):
+        (WebCore::GLES2Canvas::getQuadVertices):
+        (WebCore::GLES2Canvas::getQuadIndices):
+        (WebCore::loadShader):
+        (WebCore::GLES2Canvas::getSimpleProgram):
+        (WebCore::GLES2Canvas::getTexProgram):
+        (WebCore::GLES2Canvas::createTexture):
+        (WebCore::GLES2Canvas::getTexture):
+        (WebCore::GLES2Canvas::checkGLError):
+        * platform/graphics/chromium/GLES2Canvas.h: Added.
+        (WebCore::GLES2Canvas::gles2Context):
+        * platform/graphics/chromium/GLES2Texture.cpp: Added.
+        (WebCore::GLES2Texture::GLES2Texture):
+        (WebCore::GLES2Texture::~GLES2Texture):
+        (WebCore::GLES2Texture::create):
+        (WebCore::convertFormat):
+        (WebCore::GLES2Texture::load):
+        (WebCore::GLES2Texture::bind):
+        * platform/graphics/chromium/GLES2Texture.h: Added.
+        (WebCore::GLES2Texture::):
+        (WebCore::GLES2Texture::format):
+        (WebCore::GLES2Texture::width):
+        (WebCore::GLES2Texture::height):
+
+
 2010-07-26  Jeremy Orlow  <jorlow at chromium.org>
 
         Reviewed by Steve Block.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index f53f456..9e24641 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2182,6 +2182,10 @@
             'platform/graphics/chromium/FontPlatformDataLinux.h',
             'platform/graphics/chromium/FontUtilsChromiumWin.cpp',
             'platform/graphics/chromium/FontUtilsChromiumWin.h',
+            'platform/graphics/chromium/GLES2Canvas.cpp',
+            'platform/graphics/chromium/GLES2Canvas.h',
+            'platform/graphics/chromium/GLES2Texture.cpp',
+            'platform/graphics/chromium/GLES2Texture.h',
             'platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp',
             'platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp',
             'platform/graphics/chromium/GraphicsLayerChromium.cpp',
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
new file mode 100644
index 0000000..5b15e62
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -0,0 +1,525 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * OWNER OR CONTRIBUTORS 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 USE(GLES2_RENDERING)
+
+#include "GLES2Canvas.h"
+
+#include "FloatRect.h"
+#include "GLES2Context.h"
+#include "GLES2Texture.h"
+
+#include <GLES2/gl2.h>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+#include <wtf/OwnArrayPtr.h>
+
+namespace WebCore {
+
+static inline void affineTo3x3(const AffineTransform& transform, GLfloat mat[9])
+{
+    mat[0] = transform.a();
+    mat[1] = transform.b();
+    mat[2] = 0.0f;
+    mat[3] = transform.c();
+    mat[4] = transform.d();
+    mat[5] = 0.0f;
+    mat[6] = transform.e();
+    mat[7] = transform.f();
+    mat[8] = 1.0f;
+}
+
+struct GLES2Canvas::State {
+    State()
+        : m_fillColor(0, 0, 0, 255)
+        , m_alpha(1.0f)
+        , m_compositeOp(CompositeSourceOver)
+    {
+    }
+    Color m_fillColor;
+    float m_alpha;
+    CompositeOperator m_compositeOp;
+    AffineTransform m_ctm;
+};
+
+GLES2Canvas::GLES2Canvas(GLES2Context* context, int width, int height)
+    : m_gles2Context(context)
+    , m_quadVertices(0)
+    , m_quadIndices(0)
+    , m_simpleProgram(0)
+    , m_texProgram(0)
+    , m_simpleMatrixLocation(-1)
+    , m_simpleColorLocation(-1)
+    , m_simplePositionLocation(-1)
+    , m_texMatrixLocation(-1)
+    , m_texTexMatrixLocation(-1)
+    , m_texSamplerLocation(-1)
+    , m_texAlphaLocation(-1)
+    , m_texPositionLocation(-1)
+    , m_width(width)
+    , m_height(height)
+    , m_state(0)
+{
+    m_flipMatrix.translate(-1.0f, 1.0f);
+    m_flipMatrix.scale(2.0f / width, -2.0f / height);
+
+    m_gles2Context->makeCurrent();
+    m_gles2Context->resizeOffscreenContent(IntSize(width, height));
+    m_gles2Context->swapBuffers();
+    glViewport(0, 0, width, height);
+
+    m_stateStack.append(State());
+    m_state = &m_stateStack.last();
+}
+
+GLES2Canvas::~GLES2Canvas()
+{
+    m_gles2Context->makeCurrent();
+    if (m_simpleProgram)
+        glDeleteProgram(m_simpleProgram);
+    if (m_texProgram)
+        glDeleteProgram(m_texProgram);
+    if (m_quadVertices)
+        glDeleteBuffers(1, &m_quadVertices);
+    if (m_quadIndices)
+        glDeleteBuffers(1, &m_quadVertices);
+}
+
+void GLES2Canvas::clearRect(const FloatRect& rect)
+{
+    m_gles2Context->makeCurrent();
+
+    glScissor(rect.x(), rect.y(), rect.width(), rect.height());
+    glEnable(GL_SCISSOR_TEST);
+    glClear(GL_COLOR_BUFFER_BIT);
+    glDisable(GL_SCISSOR_TEST);
+}
+
+void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
+{
+    m_gles2Context->makeCurrent();
+
+    glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
+
+    float rgba[4];
+    color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
+    glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
+
+    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+}
+
+void GLES2Canvas::fillRect(const FloatRect& rect)
+{
+    m_gles2Context->makeCurrent();
+
+    applyCompositeOperator(m_state->m_compositeOp);
+
+    glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
+
+    glUseProgram(getSimpleProgram());
+
+    float rgba[4];
+    m_state->m_fillColor.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
+    glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
+
+    AffineTransform matrix(m_flipMatrix);
+    matrix.multLeft(m_state->m_ctm);
+    matrix.translate(rect.x(), rect.y());
+    matrix.scale(rect.width(), rect.height());
+    GLfloat mat[9];
+    affineTo3x3(matrix, mat);
+    glUniformMatrix3fv(m_simpleMatrixLocation, 1, GL_FALSE, mat);
+
+    glVertexAttribPointer(m_simplePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
+
+    glEnableVertexAttribArray(m_simplePositionLocation);
+
+    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+}
+
+void GLES2Canvas::setFillColor(const Color& color, ColorSpace colorSpace)
+{
+    m_state->m_fillColor = color;
+}
+
+void GLES2Canvas::setAlpha(float alpha)
+{
+    m_state->m_alpha = alpha;
+}
+
+void GLES2Canvas::translate(float x, float y)
+{
+    m_state->m_ctm.translate(x, y);
+}
+
+void GLES2Canvas::rotate(float angleInRadians)
+{
+    m_state->m_ctm.rotate(angleInRadians * (180.0f / M_PI));
+}
+
+void GLES2Canvas::scale(const FloatSize& size)
+{
+    m_state->m_ctm.scale(size.width(), size.height());
+}
+
+void GLES2Canvas::concatCTM(const AffineTransform& affine)
+{
+    m_state->m_ctm.multLeft(affine);
+}
+
+void GLES2Canvas::save()
+{
+    m_stateStack.append(State(m_stateStack.last()));
+    m_state = &m_stateStack.last();
+}
+
+void GLES2Canvas::restore()
+{
+    ASSERT(!m_stateStack.isEmpty());
+    m_stateStack.removeLast();
+    m_state = &m_stateStack.last();
+}
+
+void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace colorSpace, CompositeOperator compositeOp)
+{
+    drawTexturedRect(texture, srcRect, dstRect, m_state->m_ctm, m_state->m_alpha, colorSpace, compositeOp);
+}
+
+void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha, ColorSpace colorSpace, CompositeOperator compositeOp)
+{
+    m_gles2Context->makeCurrent();
+
+    applyCompositeOperator(compositeOp);
+
+    glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
+    checkGLError("glBindBuffer");
+
+    glUseProgram(getTexProgram());
+    checkGLError("glUseProgram");
+
+    glActiveTexture(GL_TEXTURE0);
+    texture->bind();
+
+    glUniform1i(m_texSamplerLocation, 0);
+    checkGLError("glUniform1i");
+
+    glUniform1f(m_texAlphaLocation, alpha);
+    checkGLError("glUniform1f for alpha");
+
+    AffineTransform matrix(m_flipMatrix);
+    matrix.multLeft(transform);
+    matrix.translate(dstRect.x(), dstRect.y());
+    matrix.scale(dstRect.width(), dstRect.height());
+    GLfloat mat[9];
+    affineTo3x3(matrix, mat);
+    glUniformMatrix3fv(m_texMatrixLocation, 1, GL_FALSE, mat);
+    checkGLError("glUniformMatrix3fv");
+
+    AffineTransform texMatrix;
+    texMatrix.scale(1.0f / texture->width(), 1.0f / texture->height());
+    texMatrix.translate(srcRect.x(), srcRect.y());
+    texMatrix.scale(srcRect.width(), srcRect.height());
+    GLfloat texMat[9];
+    affineTo3x3(texMatrix, texMat);
+    glUniformMatrix3fv(m_texTexMatrixLocation, 1, GL_FALSE, texMat);
+    checkGLError("glUniformMatrix3fv");
+
+    glVertexAttribPointer(m_texPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
+
+    glEnableVertexAttribArray(m_texPositionLocation);
+
+    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+    checkGLError("glDrawElements");
+}
+
+void GLES2Canvas::setCompositeOperation(CompositeOperator op)
+{
+    m_state->m_compositeOp = op;
+}
+
+void GLES2Canvas::applyCompositeOperator(CompositeOperator op)
+{
+    if (op == m_lastCompositeOp)
+        return;
+
+    switch (op) {
+    case CompositeClear:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ZERO, GL_ZERO);
+        break;
+    case CompositeCopy:
+        glDisable(GL_BLEND);
+        break;
+    case CompositeSourceOver:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeSourceIn:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_DST_ALPHA, GL_ZERO);
+        break;
+    case CompositeSourceOut:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);
+        break;
+    case CompositeSourceAtop:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeDestinationOver:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
+        break;
+    case CompositeDestinationIn:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
+        break;
+    case CompositeDestinationOut:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositeDestinationAtop:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);
+        break;
+    case CompositeXOR:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+        break;
+    case CompositePlusDarker:
+    case CompositeHighlight:
+        // unsupported
+        glDisable(GL_BLEND);
+        break;
+    case CompositePlusLighter:
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE, GL_ONE);
+        break;
+    }
+    m_lastCompositeOp = op;
+}
+
+unsigned GLES2Canvas::getQuadVertices()
+{
+    if (!m_quadVertices) {
+        GLfloat vertices[] = { 0.0f, 0.0f, 1.0f,
+                               1.0f, 0.0f, 1.0f,
+                               1.0f, 1.0f, 1.0f,
+                               0.0f, 1.0f, 1.0f };
+        glGenBuffers(1, &m_quadVertices);
+        glBindBuffer(GL_ARRAY_BUFFER, m_quadVertices);
+        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+    }
+    return m_quadVertices;
+}
+
+
+unsigned GLES2Canvas::getQuadIndices()
+{
+    if (!m_quadIndices) {
+        GLushort indices[] = { 0, 1, 2, 0, 2, 3};
+
+        glGenBuffers(1, &m_quadIndices);
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadIndices);
+        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
+    }
+    return m_quadIndices;
+}
+
+static GLuint loadShader(GLenum type, const char* shaderSource)
+{
+    GLuint shader = glCreateShader(type);
+    if (!shader)
+        return 0;
+
+    glShaderSource(shader, 1, &shaderSource, 0);
+    glCompileShader(shader);
+    GLint compileStatus;
+    glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
+    if (!compileStatus) {
+        int length;
+        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
+        OwnArrayPtr<char> log(new char[length]);
+        glGetShaderInfoLog(shader, length, 0, log.get());
+        LOG_ERROR(log.get());
+        glDeleteShader(shader);
+        return 0;
+    }
+    return shader;
+}
+
+unsigned GLES2Canvas::getSimpleProgram()
+{
+    if (!m_simpleProgram) {
+        GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
+            "uniform mat3 matrix;\n"
+            "uniform vec4 color;\n"
+            "attribute vec3 position;\n"
+            "void main() {\n"
+            "    gl_Position = vec4(matrix * position, 1.0);\n"
+            "}\n");
+        if (!vertexShader)
+            return 0;
+        GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
+            "precision mediump float;\n"
+            "uniform mat3 matrix;\n"
+            "uniform vec4 color;\n"
+            "void main() {\n"
+            "    gl_FragColor = color;\n"
+            "}\n");
+        if (!fragmentShader)
+            return 0;
+        m_simpleProgram = glCreateProgram();
+        if (!m_simpleProgram)
+            return 0;
+        glAttachShader(m_simpleProgram, vertexShader);
+        glAttachShader(m_simpleProgram, fragmentShader);
+        glLinkProgram(m_simpleProgram);
+        GLint linkStatus;
+        glGetProgramiv(m_simpleProgram, GL_LINK_STATUS, &linkStatus);
+        if (!linkStatus) {
+            glDeleteProgram(m_simpleProgram);
+            m_simpleProgram = 0;
+        }
+        glDeleteShader(vertexShader);
+        glDeleteShader(fragmentShader);
+        m_simplePositionLocation = glGetAttribLocation(m_simpleProgram, "position");
+        m_simpleMatrixLocation = glGetUniformLocation(m_simpleProgram, "matrix");
+        m_simpleColorLocation = glGetUniformLocation(m_simpleProgram, "color");
+    }
+    return m_simpleProgram;
+}
+
+unsigned GLES2Canvas::getTexProgram()
+{
+    if (!m_texProgram) {
+        GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
+            "uniform mat3 matrix;\n"
+            "uniform mat3 texMatrix;\n"
+            "attribute vec3 position;\n"
+            "varying vec3 texCoord;\n"
+            "void main() {\n"
+            "    texCoord = texMatrix * position;\n"
+            "    gl_Position = vec4(matrix * position, 1.0);\n"
+            "}\n");
+        if (!vertexShader)
+            return 0;
+        GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
+            "precision mediump float;\n"
+            "uniform sampler2D sampler;\n"
+            "uniform float alpha;\n"
+            "varying vec3 texCoord;\n"
+            "void main() {\n"
+            "    gl_FragColor = texture2D(sampler, texCoord.xy)* vec4(alpha);\n"
+            "}\n");
+        if (!fragmentShader)
+            return 0;
+        m_texProgram = glCreateProgram();
+        if (!m_texProgram)
+            return 0;
+        glAttachShader(m_texProgram, vertexShader);
+        glAttachShader(m_texProgram, fragmentShader);
+        glLinkProgram(m_texProgram);
+        GLint linkStatus;
+        glGetProgramiv(m_texProgram, GL_LINK_STATUS, &linkStatus);
+        if (!linkStatus) {
+            glDeleteProgram(m_texProgram);
+            m_texProgram = 0;
+        }
+        glDeleteShader(vertexShader);
+        glDeleteShader(fragmentShader);
+        m_texMatrixLocation = glGetUniformLocation(m_texProgram, "matrix");
+        m_texSamplerLocation = glGetUniformLocation(m_texProgram, "sampler");
+        m_texTexMatrixLocation = glGetUniformLocation(m_texProgram, "texMatrix");
+        m_texPositionLocation = glGetAttribLocation(m_texProgram, "position");
+        m_texAlphaLocation = glGetUniformLocation(m_texProgram, "alpha");
+    }
+    return m_texProgram;
+}
+
+GLES2Texture* GLES2Canvas::createTexture(NativeImagePtr ptr, GLES2Texture::Format format, int width, int height)
+{
+    PassRefPtr<GLES2Texture> texture = m_textures.get(ptr);
+    if (texture)
+        return texture.get();
+
+    texture = GLES2Texture::create(format, width, height);
+    GLES2Texture* t = texture.get();
+    m_textures.set(ptr, texture);
+    return t;
+}
+
+GLES2Texture* GLES2Canvas::getTexture(NativeImagePtr ptr)
+{
+    PassRefPtr<GLES2Texture> texture = m_textures.get(ptr);
+    return texture ? texture.get() : 0;
+}
+
+void GLES2Canvas::checkGLError(const char* header)
+{
+#ifndef NDEBUG
+    GLenum err;
+    while ((err = glGetError()) != GL_NO_ERROR) {
+        const char* errorStr = "*** UNKNOWN ERROR ***";
+        switch (err) {
+        case GL_INVALID_ENUM:
+            errorStr = "GL_INVALID_ENUM";
+            break;
+        case GL_INVALID_VALUE:
+            errorStr = "GL_INVALID_VALUE";
+            break;
+        case GL_INVALID_OPERATION:
+            errorStr = "GL_INVALID_OPERATION";
+            break;
+        case GL_INVALID_FRAMEBUFFER_OPERATION:
+            errorStr = "GL_INVALID_FRAMEBUFFER_OPERATION";
+            break;
+        case GL_OUT_OF_MEMORY:
+            errorStr = "GL_OUT_OF_MEMORY";
+            break;
+        }
+        if (header)
+            LOG_ERROR("%s:  %s", header, errorStr);
+        else
+            LOG_ERROR("%s", errorStr);
+    }
+#endif
+}
+
+}
+
+#endif
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.h b/WebCore/platform/graphics/chromium/GLES2Canvas.h
new file mode 100644
index 0000000..802b200
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * OWNER OR CONTRIBUTORS 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 GLES2Canvas_h
+#define GLES2Canvas_h
+
+#if USE(GLES2_RENDERING)
+
+#include "AffineTransform.h"
+#include "Color.h"
+#include "ColorSpace.h"
+#include "GLES2Texture.h"
+#include "GraphicsTypes.h"
+#include "ImageSource.h"
+
+#include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class FloatRect;
+class Color;
+class GLES2Context;
+
+typedef HashMap<NativeImagePtr, RefPtr<GLES2Texture> > TextureHashMap;
+
+class GLES2Canvas : public Noncopyable {
+public:
+    GLES2Canvas(GLES2Context* context, int width, int height);
+    ~GLES2Canvas();
+
+    void fillRect(const FloatRect&, const Color&, ColorSpace);
+    void fillRect(const FloatRect&);
+    void clearRect(const FloatRect&);
+    void setFillColor(const Color&, ColorSpace);
+    void setAlpha(float alpha);
+    void setCompositeOperation(CompositeOperator);
+    void translate(float x, float y);
+    void rotate(float angleInRadians);
+    void scale(const FloatSize&);
+    void concatCTM(const AffineTransform&);
+
+    void save();
+    void restore();
+
+    // non-standard functions
+    // These are not standard GraphicsContext functions, and should be pushed
+    // down into a PlatformContextGLES2 at some point.
+    void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha, ColorSpace, CompositeOperator);
+    void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace, CompositeOperator);
+    GLES2Context* gles2Context() { return m_gles2Context; }
+    GLES2Texture* createTexture(NativeImagePtr, GLES2Texture::Format, int width, int height);
+    GLES2Texture* getTexture(NativeImagePtr);
+
+private:
+    void applyCompositeOperator(CompositeOperator);
+    void checkGLError(const char* header);
+    unsigned getQuadVertices();
+    unsigned getQuadIndices();
+    unsigned getSimpleProgram();
+    unsigned getTexProgram();
+
+    GLES2Context* m_gles2Context;
+    struct State;
+    WTF::Vector<State> m_stateStack;
+    State* m_state;
+    unsigned m_quadVertices;
+    unsigned m_quadIndices;
+    unsigned m_simpleProgram;
+    unsigned m_texProgram;
+    int m_simpleMatrixLocation;
+    int m_simpleColorLocation;
+    int m_simplePositionLocation;
+    int m_texMatrixLocation;
+    int m_texTexMatrixLocation;
+    int m_texSamplerLocation;
+    int m_texAlphaLocation;
+    int m_texPositionLocation;
+    int m_width;
+    int m_height;
+    AffineTransform m_flipMatrix;
+    TextureHashMap m_textures;
+    CompositeOperator m_lastCompositeOp; // This is the one last set, not necessarily the one in the state stack.
+};
+
+}
+
+#endif
+
+#endif // GLES2Canvas_h
diff --git a/WebCore/platform/graphics/chromium/GLES2Texture.cpp b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
new file mode 100644
index 0000000..26c8bf7
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * OWNER OR CONTRIBUTORS 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 USE(GLES2_RENDERING)
+
+#include "GLES2Texture.h"
+
+#include <GLES2/gl2.h>
+
+#include <wtf/OwnArrayPtr.h>
+
+namespace WebCore {
+
+GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int height)
+    : m_textureId(textureId)
+    , m_format(format)
+    , m_width(width)
+    , m_height(height)
+{
+}
+
+GLES2Texture::~GLES2Texture()
+{
+    glDeleteTextures(1, &m_textureId);
+}
+
+PassRefPtr<GLES2Texture> GLES2Texture::create(Format format, int width, int height)
+{
+    GLuint textureId;
+    glGenTextures(1, &textureId);
+    if (!textureId)
+        return 0;
+
+    glBindTexture(GL_TEXTURE_2D, textureId);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+
+    int max;
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
+    if (width > max || height > max)
+        ASSERT(!"texture too big");
+
+    return adoptRef(new GLES2Texture(textureId, format, width, height));
+}
+
+static void convertFormat(GLES2Texture::Format format, unsigned int* glFormat, unsigned int* glType, bool* swizzle)
+{
+    *swizzle = false;
+    switch (format) {
+    case GLES2Texture::RGBA8:
+        *glFormat = GL_RGBA;
+        *glType = GL_UNSIGNED_BYTE;
+        break;
+    case GLES2Texture::BGRA8:
+// FIXME:  Once we have support for extensions, we should check for EXT_texture_format_BGRA8888,
+// and use that if present.
+        *glFormat = GL_RGBA;
+        *glType = GL_UNSIGNED_BYTE;
+        *swizzle = true;
+        break;
+    default:
+        ASSERT(!"bad format");
+        break;
+    }
+}
+
+void GLES2Texture::load(void* pixels)
+{
+    unsigned int glFormat, glType;
+    bool swizzle;
+    convertFormat(m_format, &glFormat, &glType, &swizzle);
+    glBindTexture(GL_TEXTURE_2D, m_textureId);
+    if (swizzle) {
+        ASSERT(glFormat == GL_RGBA && glType == GL_UNSIGNED_BYTE);
+        // FIXME:  This could use PBO's to save doing an extra copy here.
+        int size = m_width * m_height;
+        unsigned* pixels32 = static_cast<unsigned*>(pixels);
+        OwnArrayPtr<unsigned> buf(new unsigned[size]);
+        unsigned* bufptr = buf.get();
+        for (int i = 0; i < size; ++i) {
+            unsigned pixel = pixels32[i];
+            bufptr[i] = pixel & 0xFF00FF00 | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16);
+        }
+        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());
+    } else
+        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);
+}
+
+void GLES2Texture::bind()
+{
+    glBindTexture(GL_TEXTURE_2D, m_textureId);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+}
+
+}
+
+#endif
diff --git a/WebCore/platform/graphics/chromium/GLES2Texture.h b/WebCore/platform/graphics/chromium/GLES2Texture.h
new file mode 100644
index 0000000..346365a
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/GLES2Texture.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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
+ * OWNER OR CONTRIBUTORS 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 GLES2Texture_h
+#define GLES2Texture_h
+
+#if USE(GLES2_RENDERING)
+
+#include "RefCounted.h"
+#include "RefPtr.h"
+
+namespace WebCore {
+
+class GLES2Texture : public RefCounted<GLES2Texture> {
+public:
+    ~GLES2Texture();
+    enum Format { RGBA8, BGRA8 };
+    static PassRefPtr<GLES2Texture> create(Format, int width, int height);
+    void bind();
+    void load(void* pixels);
+    Format format() const { return m_format; }
+    int width() const { return m_width; }
+    int height() const { return m_height; }
+private:
+    GLES2Texture(unsigned int textureId, Format format, int width, int height);
+    unsigned int m_textureId;
+    Format m_format;
+    int m_width;
+    int m_height;
+};
+
+}
+
+#endif
+
+#endif // GLES2Texture_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list