Changeset 64872 in webkit


Ignore:
Timestamp:
Aug 6, 2010 2:58:55 PM (14 years ago)
Author:
jamesr@google.com
Message:

2010-08-06 James Robinson <jamesr@chromium.org>

Reviewed by Dimitri Glazkov.

[chromium] Implement GLES2Canvas/Texture in terms of GraphicsContext3D instead of direct OpenGL calls
https://bugs.webkit.org/show_bug.cgi?id=43608

This converts all OpenGL calls in GLES2(Canvas|Texture) to calls on the corresponding GraphicsContext3D
API, due to feedback on https://bugs.webkit.org/show_bug.cgi?id=43362. Nearly all the changes are
applying the regex s/gl([A-Z])/m_context->%1</ and removing unnecessary makeCurrent() calls.
Other changes hilighted below.

  • platform/graphics/chromium/GLES2Canvas.cpp: (WebCore::affineTo3x3): (WebCore::GLES2Canvas::GLES2Canvas): (WebCore::GLES2Canvas::~GLES2Canvas): (WebCore::GLES2Canvas::clearRect): (WebCore::GLES2Canvas::fillRect): (WebCore::GLES2Canvas::drawTexturedRect): (WebCore::GLES2Canvas::applyCompositeOperator): (WebCore::GLES2Canvas::getQuadVertices): (WebCore::GLES2Canvas::getQuadIndices):
    • use new typed XXArray classes for buffer uploads

(WebCore::loadShader):
(WebCore::GLES2Canvas::getSimpleProgram):
(WebCore::GLES2Canvas::getTexProgram):
(WebCore::GLES2Canvas::createTexture):
(WebCore::GLES2Canvas::checkGLError):

  • platform/graphics/chromium/GLES2Canvas.h: (WebCore::GLES2Canvas::context):
  • platform/graphics/chromium/GLES2Texture.cpp: (WebCore::GLES2Texture::GLES2Texture): (WebCore::GLES2Texture::~GLES2Texture): (WebCore::GLES2Texture::create): (WebCore::convertFormat): (WebCore::GLES2Texture::load): (WebCore::GLES2Texture::bind):
  • platform/graphics/chromium/GLES2Texture.h:
  • platform/graphics/skia/GraphicsContextSkia.cpp: (WebCore::GraphicsContext::fillRect):
    • add a missing restore() call to the H/W path
  • platform/graphics/skia/ImageSkia.cpp: (WebCore::drawBitmapGLES2):
  • platform/graphics/skia/PlatformContextSkia.cpp: (WebCore::PlatformContextSkia::setGraphicsContext3D): (WebCore::PlatformContextSkia::uploadSoftwareToHardware):
    • avoid applying CTM to uploads

(WebCore::PlatformContextSkia::readbackHardwareToSoftware):

  • platform/graphics/skia/PlatformContextSkia.h:
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64870 r64872  
     12010-08-06  James Robinson  <jamesr@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        [chromium] Implement GLES2Canvas/Texture in terms of GraphicsContext3D instead of direct OpenGL calls
     6        https://bugs.webkit.org/show_bug.cgi?id=43608
     7
     8        This converts all OpenGL calls in GLES2(Canvas|Texture) to calls on the corresponding GraphicsContext3D
     9        API, due to feedback on https://bugs.webkit.org/show_bug.cgi?id=43362.  Nearly all the changes are
     10        applying the regex s/gl([A-Z])/m_context->%1</ and removing unnecessary makeCurrent() calls.
     11        Other changes hilighted below.
     12
     13        * platform/graphics/chromium/GLES2Canvas.cpp:
     14        (WebCore::affineTo3x3):
     15        (WebCore::GLES2Canvas::GLES2Canvas):
     16        (WebCore::GLES2Canvas::~GLES2Canvas):
     17        (WebCore::GLES2Canvas::clearRect):
     18        (WebCore::GLES2Canvas::fillRect):
     19        (WebCore::GLES2Canvas::drawTexturedRect):
     20        (WebCore::GLES2Canvas::applyCompositeOperator):
     21        (WebCore::GLES2Canvas::getQuadVertices):
     22        (WebCore::GLES2Canvas::getQuadIndices):
     23            - use new typed XXArray classes for buffer uploads
     24        (WebCore::loadShader):
     25        (WebCore::GLES2Canvas::getSimpleProgram):
     26        (WebCore::GLES2Canvas::getTexProgram):
     27        (WebCore::GLES2Canvas::createTexture):
     28        (WebCore::GLES2Canvas::checkGLError):
     29        * platform/graphics/chromium/GLES2Canvas.h:
     30        (WebCore::GLES2Canvas::context):
     31        * platform/graphics/chromium/GLES2Texture.cpp:
     32        (WebCore::GLES2Texture::GLES2Texture):
     33        (WebCore::GLES2Texture::~GLES2Texture):
     34        (WebCore::GLES2Texture::create):
     35        (WebCore::convertFormat):
     36        (WebCore::GLES2Texture::load):
     37        (WebCore::GLES2Texture::bind):
     38        * platform/graphics/chromium/GLES2Texture.h:
     39        * platform/graphics/skia/GraphicsContextSkia.cpp:
     40        (WebCore::GraphicsContext::fillRect):
     41            - add a missing restore() call to the H/W path
     42        * platform/graphics/skia/ImageSkia.cpp:
     43        (WebCore::drawBitmapGLES2):
     44        * platform/graphics/skia/PlatformContextSkia.cpp:
     45        (WebCore::PlatformContextSkia::setGraphicsContext3D):
     46        (WebCore::PlatformContextSkia::uploadSoftwareToHardware):
     47            - avoid applying CTM to uploads
     48        (WebCore::PlatformContextSkia::readbackHardwareToSoftware):
     49        * platform/graphics/skia/PlatformContextSkia.h:
     50
    1512010-08-06  James Robinson  <jamesr@chromium.org>
    252
  • trunk/WebCore/platform/graphics/chromium/GLES2Canvas.cpp

    r64374 r64872  
    3535#include "GLES2Canvas.h"
    3636
     37#include "Float32Array.h"
    3738#include "FloatRect.h"
    38 #include "GLES2Context.h"
    3939#include "GLES2Texture.h"
    40 
    41 #include <GLES2/gl2.h>
     40#include "GraphicsContext3D.h"
     41#include "PlatformString.h"
     42#include "Uint16Array.h"
    4243
    4344#define _USE_MATH_DEFINES
    4445#include <math.h>
    4546
     47#include <wtf/text/CString.h>
    4648#include <wtf/OwnArrayPtr.h>
    4749
    4850namespace WebCore {
    4951
    50 static inline void affineTo3x3(const AffineTransform& transform, GLfloat mat[9])
     52static inline void affineTo3x3(const AffineTransform& transform, float mat[9])
    5153{
    5254    mat[0] = transform.a();
     
    7476};
    7577
    76 GLES2Canvas::GLES2Canvas(GLES2Context* context, const IntSize& size)
    77     : m_gles2Context(context)
     78GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
     79    : m_context(context)
    7880    , m_quadVertices(0)
    7981    , m_quadIndices(0)
     
    9395    m_flipMatrix.scale(2.0f / size.width(), -2.0f / size.height());
    9496
    95     m_gles2Context->makeCurrent();
    96     m_gles2Context->resizeOffscreenContent(size);
    97     m_gles2Context->swapBuffers();
    98     glViewport(0, 0, size.width(), size.height());
     97    m_context->reshape(size.width(), size.height());
     98    m_context->viewport(0, 0, size.width(), size.height());
    9999
    100100    m_stateStack.append(State());
     
    108108GLES2Canvas::~GLES2Canvas()
    109109{
    110     m_gles2Context->makeCurrent();
    111     if (m_simpleProgram)
    112         glDeleteProgram(m_simpleProgram);
    113     if (m_texProgram)
    114         glDeleteProgram(m_texProgram);
    115     if (m_quadVertices)
    116         glDeleteBuffers(1, &m_quadVertices);
    117     if (m_quadIndices)
    118         glDeleteBuffers(1, &m_quadVertices);
     110    m_context->deleteProgram(m_simpleProgram);
     111    m_context->deleteProgram(m_texProgram);
     112    m_context->deleteBuffer(m_quadVertices);
     113    m_context->deleteBuffer(m_quadIndices);
    119114}
    120115
    121116void GLES2Canvas::clearRect(const FloatRect& rect)
    122117{
    123     m_gles2Context->makeCurrent();
    124 
    125     glScissor(rect.x(), rect.y(), rect.width(), rect.height());
    126     glEnable(GL_SCISSOR_TEST);
    127     glClear(GL_COLOR_BUFFER_BIT);
    128     glDisable(GL_SCISSOR_TEST);
     118    m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
     119    m_context->enable(GraphicsContext3D::SCISSOR_TEST);
     120    m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
     121    m_context->disable(GraphicsContext3D::SCISSOR_TEST);
    129122}
    130123
    131124void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
    132125{
    133     m_gles2Context->makeCurrent();
    134 
    135     glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
    136     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
     126    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
     127    m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
    137128
    138129    float rgba[4];
    139130    color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
    140     glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
    141 
    142     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
     131    m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
     132
     133    m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
    143134}
    144135
    145136void GLES2Canvas::fillRect(const FloatRect& rect)
    146137{
    147     m_gles2Context->makeCurrent();
    148 
    149138    applyCompositeOperator(m_state->m_compositeOp);
    150139
    151     glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
    152     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
    153 
    154     glUseProgram(getSimpleProgram());
     140    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
     141    m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
     142
     143    m_context->useProgram(getSimpleProgram());
    155144
    156145    float rgba[4];
    157146    m_state->m_fillColor.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
    158     glUniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
     147    m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
    159148
    160149    AffineTransform matrix(m_flipMatrix);
     
    162151    matrix.translate(rect.x(), rect.y());
    163152    matrix.scale(rect.width(), rect.height());
    164     GLfloat mat[9];
     153    float mat[9];
    165154    affineTo3x3(matrix, mat);
    166     glUniformMatrix3fv(m_simpleMatrixLocation, 1, GL_FALSE, mat);
    167 
    168     glVertexAttribPointer(m_simplePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
    169 
    170     glEnableVertexAttribArray(m_simplePositionLocation);
    171 
    172     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
     155    m_context->uniformMatrix3fv(m_simpleMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
     156
     157    m_context->vertexAttribPointer(m_simplePositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
     158
     159    m_context->enableVertexAttribArray(m_simplePositionLocation);
     160
     161    m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
    173162}
    174163
     
    223212void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha, ColorSpace colorSpace, CompositeOperator compositeOp)
    224213{
    225     m_gles2Context->makeCurrent();
    226 
    227214    applyCompositeOperator(compositeOp);
    228215
    229     glBindBuffer(GL_ARRAY_BUFFER, getQuadVertices());
    230     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getQuadIndices());
     216    m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
     217    m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
    231218    checkGLError("glBindBuffer");
    232219
    233     glUseProgram(getTexProgram());
     220    m_context->useProgram(getTexProgram());
    234221    checkGLError("glUseProgram");
    235222
    236     glActiveTexture(GL_TEXTURE0);
     223    m_context->activeTexture(GraphicsContext3D::TEXTURE0);
    237224    texture->bind();
    238225
    239     glUniform1i(m_texSamplerLocation, 0);
     226    m_context->uniform1i(m_texSamplerLocation, 0);
    240227    checkGLError("glUniform1i");
    241228
    242     glUniform1f(m_texAlphaLocation, alpha);
     229    m_context->uniform1f(m_texAlphaLocation, alpha);
    243230    checkGLError("glUniform1f for alpha");
    244231
     
    247234    matrix.translate(dstRect.x(), dstRect.y());
    248235    matrix.scale(dstRect.width(), dstRect.height());
    249     GLfloat mat[9];
     236    float mat[9];
    250237    affineTo3x3(matrix, mat);
    251     glUniformMatrix3fv(m_texMatrixLocation, 1, GL_FALSE, mat);
     238    m_context->uniformMatrix3fv(m_texMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
    252239    checkGLError("glUniformMatrix3fv");
    253240
     
    256243    texMatrix.translate(srcRect.x(), srcRect.y());
    257244    texMatrix.scale(srcRect.width(), srcRect.height());
    258     GLfloat texMat[9];
     245    float texMat[9];
    259246    affineTo3x3(texMatrix, texMat);
    260     glUniformMatrix3fv(m_texTexMatrixLocation, 1, GL_FALSE, texMat);
     247    m_context->uniformMatrix3fv(m_texTexMatrixLocation, false /*transpose*/, texMat, 1 /*count*/);
    261248    checkGLError("glUniformMatrix3fv");
    262249
    263     glVertexAttribPointer(m_texPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
    264 
    265     glEnableVertexAttribArray(m_texPositionLocation);
    266 
    267     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
     250    m_context->vertexAttribPointer(m_texPositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
     251
     252    m_context->enableVertexAttribArray(m_texPositionLocation);
     253
     254    m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
    268255    checkGLError("glDrawElements");
    269256}
     
    281268    switch (op) {
    282269    case CompositeClear:
    283         glEnable(GL_BLEND);
    284         glBlendFunc(GL_ZERO, GL_ZERO);
     270        m_context->enable(GraphicsContext3D::BLEND);
     271        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO);
    285272        break;
    286273    case CompositeCopy:
    287         glDisable(GL_BLEND);
     274        m_context->disable(GraphicsContext3D::BLEND);
    288275        break;
    289276    case CompositeSourceOver:
    290         glEnable(GL_BLEND);
    291         glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     277        m_context->enable(GraphicsContext3D::BLEND);
     278        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
    292279        break;
    293280    case CompositeSourceIn:
    294         glEnable(GL_BLEND);
    295         glBlendFunc(GL_DST_ALPHA, GL_ZERO);
     281        m_context->enable(GraphicsContext3D::BLEND);
     282        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO);
    296283        break;
    297284    case CompositeSourceOut:
    298         glEnable(GL_BLEND);
    299         glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);
     285        m_context->enable(GraphicsContext3D::BLEND);
     286        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO);
    300287        break;
    301288    case CompositeSourceAtop:
    302         glEnable(GL_BLEND);
    303         glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     289        m_context->enable(GraphicsContext3D::BLEND);
     290        m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
    304291        break;
    305292    case CompositeDestinationOver:
    306         glEnable(GL_BLEND);
    307         glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
     293        m_context->enable(GraphicsContext3D::BLEND);
     294        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE);
    308295        break;
    309296    case CompositeDestinationIn:
    310         glEnable(GL_BLEND);
    311         glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
     297        m_context->enable(GraphicsContext3D::BLEND);
     298        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA);
    312299        break;
    313300    case CompositeDestinationOut:
    314         glEnable(GL_BLEND);
    315         glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
     301        m_context->enable(GraphicsContext3D::BLEND);
     302        m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
    316303        break;
    317304    case CompositeDestinationAtop:
    318         glEnable(GL_BLEND);
    319         glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);
     305        m_context->enable(GraphicsContext3D::BLEND);
     306        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA);
    320307        break;
    321308    case CompositeXOR:
    322         glEnable(GL_BLEND);
    323         glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     309        m_context->enable(GraphicsContext3D::BLEND);
     310        m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
    324311        break;
    325312    case CompositePlusDarker:
    326313    case CompositeHighlight:
    327314        // unsupported
    328         glDisable(GL_BLEND);
     315        m_context->disable(GraphicsContext3D::BLEND);
    329316        break;
    330317    case CompositePlusLighter:
    331         glEnable(GL_BLEND);
    332         glBlendFunc(GL_ONE, GL_ONE);
     318        m_context->enable(GraphicsContext3D::BLEND);
     319        m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE);
    333320        break;
    334321    }
     
    339326{
    340327    if (!m_quadVertices) {
    341         GLfloat vertices[] = { 0.0f, 0.0f, 1.0f,
    342                                1.0f, 0.0f, 1.0f,
    343                                1.0f, 1.0f, 1.0f,
    344                                0.0f, 1.0f, 1.0f };
    345         glGenBuffers(1, &m_quadVertices);
    346         glBindBuffer(GL_ARRAY_BUFFER, m_quadVertices);
    347         glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
     328        float vertices[] = { 0.0f, 0.0f, 1.0f,
     329                             1.0f, 0.0f, 1.0f,
     330                             1.0f, 1.0f, 1.0f,
     331                             0.0f, 1.0f, 1.0f };
     332        m_quadVertices = m_context->createBuffer();
     333        RefPtr<Float32Array> vertexArray = Float32Array::create(vertices, sizeof(vertices) / sizeof(float));
     334        m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
     335        m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, vertexArray.get(), GraphicsContext3D::STATIC_DRAW);
    348336    }
    349337    return m_quadVertices;
     
    354342{
    355343    if (!m_quadIndices) {
    356         GLushort indices[] = { 0, 1, 2, 0, 2, 3};
    357 
    358         glGenBuffers(1, &m_quadIndices);
    359         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_quadIndices);
    360         glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
     344        unsigned short indices[] = { 0, 1, 2, 0, 2, 3};
     345
     346        m_quadIndices = m_context->createBuffer();
     347        RefPtr<Uint16Array> indexArray = Uint16Array::create(indices, sizeof(indices) / sizeof(unsigned short));
     348        m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_quadIndices);
     349        m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, indexArray.get(), GraphicsContext3D::STATIC_DRAW);
    361350    }
    362351    return m_quadIndices;
    363352}
    364353
    365 static GLuint loadShader(GLenum type, const char* shaderSource)
    366 {
    367     GLuint shader = glCreateShader(type);
     354static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource)
     355{
     356    unsigned shader = context->createShader(type);
    368357    if (!shader)
    369358        return 0;
    370359
    371     glShaderSource(shader, 1, &shaderSource, 0);
    372     glCompileShader(shader);
    373     GLint compileStatus;
    374     glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
     360    String shaderSourceStr(shaderSource);
     361    context->shaderSource(shader, shaderSourceStr);
     362    context->compileShader(shader);
     363    int compileStatus;
     364    context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compileStatus);
    375365    if (!compileStatus) {
    376         int length;
    377         glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
    378         OwnArrayPtr<char> log(new char[length]);
    379         glGetShaderInfoLog(shader, length, 0, log.get());
    380         LOG_ERROR(log.get());
    381         glDeleteShader(shader);
     366        String infoLog = context->getShaderInfoLog(shader);
     367        LOG_ERROR(infoLog.utf8().data());
     368        context->deleteShader(shader);
    382369        return 0;
    383370    }
     
    388375{
    389376    if (!m_simpleProgram) {
    390         GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
     377        unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER,
    391378            "uniform mat3 matrix;\n"
    392379            "uniform vec4 color;\n"
     
    397384        if (!vertexShader)
    398385            return 0;
    399         GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
     386        unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER,
    400387            "precision mediump float;\n"
    401388            "uniform mat3 matrix;\n"
     
    406393        if (!fragmentShader)
    407394            return 0;
    408         m_simpleProgram = glCreateProgram();
     395        m_simpleProgram = m_context->createProgram();
    409396        if (!m_simpleProgram)
    410397            return 0;
    411         glAttachShader(m_simpleProgram, vertexShader);
    412         glAttachShader(m_simpleProgram, fragmentShader);
    413         glLinkProgram(m_simpleProgram);
    414         GLint linkStatus;
    415         glGetProgramiv(m_simpleProgram, GL_LINK_STATUS, &linkStatus);
     398        m_context->attachShader(m_simpleProgram, vertexShader);
     399        m_context->attachShader(m_simpleProgram, fragmentShader);
     400        m_context->linkProgram(m_simpleProgram);
     401        int linkStatus;
     402        m_context->getProgramiv(m_simpleProgram, GraphicsContext3D::LINK_STATUS, &linkStatus);
    416403        if (!linkStatus) {
    417             glDeleteProgram(m_simpleProgram);
     404            m_context->deleteProgram(m_simpleProgram);
    418405            m_simpleProgram = 0;
    419406        }
    420         glDeleteShader(vertexShader);
    421         glDeleteShader(fragmentShader);
    422         m_simplePositionLocation = glGetAttribLocation(m_simpleProgram, "position");
    423         m_simpleMatrixLocation = glGetUniformLocation(m_simpleProgram, "matrix");
    424         m_simpleColorLocation = glGetUniformLocation(m_simpleProgram, "color");
     407        m_context->deleteShader(vertexShader);
     408        m_context->deleteShader(fragmentShader);
     409        m_simplePositionLocation = m_context->getAttribLocation(m_simpleProgram, "position");
     410        m_simpleMatrixLocation = m_context->getUniformLocation(m_simpleProgram, "matrix");
     411        m_simpleColorLocation = m_context->getUniformLocation(m_simpleProgram, "color");
    425412    }
    426413    return m_simpleProgram;
     
    430417{
    431418    if (!m_texProgram) {
    432         GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
     419        unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER,
    433420            "uniform mat3 matrix;\n"
    434421            "uniform mat3 texMatrix;\n"
     
    441428        if (!vertexShader)
    442429            return 0;
    443         GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
     430        unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER,
    444431            "precision mediump float;\n"
    445432            "uniform sampler2D sampler;\n"
     
    451438        if (!fragmentShader)
    452439            return 0;
    453         m_texProgram = glCreateProgram();
     440        m_texProgram = m_context->createProgram();
    454441        if (!m_texProgram)
    455442            return 0;
    456         glAttachShader(m_texProgram, vertexShader);
    457         glAttachShader(m_texProgram, fragmentShader);
    458         glLinkProgram(m_texProgram);
    459         GLint linkStatus;
    460         glGetProgramiv(m_texProgram, GL_LINK_STATUS, &linkStatus);
     443        m_context->attachShader(m_texProgram, vertexShader);
     444        m_context->attachShader(m_texProgram, fragmentShader);
     445        m_context->linkProgram(m_texProgram);
     446        int linkStatus;
     447        m_context->getProgramiv(m_texProgram, GraphicsContext3D::LINK_STATUS, &linkStatus);
    461448        if (!linkStatus) {
    462             glDeleteProgram(m_texProgram);
     449            m_context->deleteProgram(m_texProgram);
    463450            m_texProgram = 0;
    464451        }
    465         glDeleteShader(vertexShader);
    466         glDeleteShader(fragmentShader);
    467         m_texMatrixLocation = glGetUniformLocation(m_texProgram, "matrix");
    468         m_texSamplerLocation = glGetUniformLocation(m_texProgram, "sampler");
    469         m_texTexMatrixLocation = glGetUniformLocation(m_texProgram, "texMatrix");
    470         m_texPositionLocation = glGetAttribLocation(m_texProgram, "position");
    471         m_texAlphaLocation = glGetUniformLocation(m_texProgram, "alpha");
     452        m_context->deleteShader(vertexShader);
     453        m_context->deleteShader(fragmentShader);
     454        m_texMatrixLocation = m_context->getUniformLocation(m_texProgram, "matrix");
     455        m_texSamplerLocation = m_context->getUniformLocation(m_texProgram, "sampler");
     456        m_texTexMatrixLocation = m_context->getUniformLocation(m_texProgram, "texMatrix");
     457        m_texPositionLocation = m_context->getAttribLocation(m_texProgram, "position");
     458        m_texAlphaLocation = m_context->getUniformLocation(m_texProgram, "alpha");
    472459    }
    473460    return m_texProgram;
     
    480467        return texture.get();
    481468
    482     texture = GLES2Texture::create(format, width, height);
     469    texture = GLES2Texture::create(m_context, format, width, height);
    483470    GLES2Texture* t = texture.get();
    484471    m_textures.set(ptr, texture);
     
    495482{
    496483#ifndef NDEBUG
    497     GLenum err;
    498     while ((err = glGetError()) != GL_NO_ERROR) {
     484    unsigned err;
     485    while ((err = m_context->getError()) != GraphicsContext3D::NO_ERROR) {
    499486        const char* errorStr = "*** UNKNOWN ERROR ***";
    500487        switch (err) {
    501         case GL_INVALID_ENUM:
    502             errorStr = "GL_INVALID_ENUM";
     488        case GraphicsContext3D::INVALID_ENUM:
     489            errorStr = "GraphicsContext3D::INVALID_ENUM";
    503490            break;
    504         case GL_INVALID_VALUE:
    505             errorStr = "GL_INVALID_VALUE";
     491        case GraphicsContext3D::INVALID_VALUE:
     492            errorStr = "GraphicsContext3D::INVALID_VALUE";
    506493            break;
    507         case GL_INVALID_OPERATION:
    508             errorStr = "GL_INVALID_OPERATION";
     494        case GraphicsContext3D::INVALID_OPERATION:
     495            errorStr = "GraphicsContext3D::INVALID_OPERATION";
    509496            break;
    510         case GL_INVALID_FRAMEBUFFER_OPERATION:
    511             errorStr = "GL_INVALID_FRAMEBUFFER_OPERATION";
     497        case GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION:
     498            errorStr = "GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION";
    512499            break;
    513         case GL_OUT_OF_MEMORY:
    514             errorStr = "GL_OUT_OF_MEMORY";
     500        case GraphicsContext3D::OUT_OF_MEMORY:
     501            errorStr = "GraphicsContext3D::OUT_OF_MEMORY";
    515502            break;
    516503        }
  • trunk/WebCore/platform/graphics/chromium/GLES2Canvas.h

    r64374 r64872  
    4747namespace WebCore {
    4848
     49class Color;
    4950class FloatRect;
    50 class Color;
    51 class GLES2Context;
     51class GraphicsContext3D;
    5252
    5353typedef HashMap<NativeImagePtr, RefPtr<GLES2Texture> > TextureHashMap;
     
    5555class GLES2Canvas : public Noncopyable {
    5656public:
    57     GLES2Canvas(GLES2Context*, const IntSize&);
     57    GLES2Canvas(GraphicsContext3D*, const IntSize&);
    5858    ~GLES2Canvas();
    5959
     
    7777    void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha, ColorSpace, CompositeOperator);
    7878    void drawTexturedRect(GLES2Texture*, const FloatRect& srcRect, const FloatRect& dstRect, ColorSpace, CompositeOperator);
    79     GLES2Context* gles2Context() { return m_gles2Context; }
     79    GraphicsContext3D* context() { return m_context; }
    8080    GLES2Texture* createTexture(NativeImagePtr, GLES2Texture::Format, int width, int height);
    8181    GLES2Texture* getTexture(NativeImagePtr);
     
    8989    unsigned getTexProgram();
    9090
    91     GLES2Context* m_gles2Context;
     91    GraphicsContext3D* m_context;
    9292    struct State;
    9393    WTF::Vector<State> m_stateStack;
  • trunk/WebCore/platform/graphics/chromium/GLES2Texture.cpp

    r64046 r64872  
    3535#include "GLES2Texture.h"
    3636
    37 #include <GLES2/gl2.h>
     37#include "GraphicsContext3D.h"
    3838
    3939#include <wtf/OwnArrayPtr.h>
     
    4141namespace WebCore {
    4242
    43 GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int height)
    44     : m_textureId(textureId)
     43GLES2Texture::GLES2Texture(GraphicsContext3D* context, unsigned textureId, Format format, int width, int height)
     44    : m_context(context)
     45    , m_textureId(textureId)
    4546    , m_format(format)
    4647    , m_width(width)
     
    5152GLES2Texture::~GLES2Texture()
    5253{
    53     glDeleteTextures(1, &m_textureId);
     54    m_context->deleteTexture(m_textureId);
    5455}
    5556
    56 PassRefPtr<GLES2Texture> GLES2Texture::create(Format format, int width, int height)
     57PassRefPtr<GLES2Texture> GLES2Texture::create(GraphicsContext3D* context, Format format, int width, int height)
    5758{
    58     GLuint textureId;
    59     glGenTextures(1, &textureId);
     59    int max;
     60    context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &max);
     61    if (width > max || height > max) {
     62        ASSERT(!"texture too big");
     63        return 0;
     64    }
     65
     66    unsigned textureId = context->createTexture();
    6067    if (!textureId)
    6168        return 0;
    6269
    63     glBindTexture(GL_TEXTURE_2D, textureId);
    64     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
     70    context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
     71    context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, width, height, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0);
    6572
    66     int max;
    67     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
    68     if (width > max || height > max)
    69         ASSERT(!"texture too big");
    70 
    71     return adoptRef(new GLES2Texture(textureId, format, width, height));
     73    return adoptRef(new GLES2Texture(context, textureId, format, width, height));
    7274}
    7375
     
    7779    switch (format) {
    7880    case GLES2Texture::RGBA8:
    79         *glFormat = GL_RGBA;
    80         *glType = GL_UNSIGNED_BYTE;
     81        *glFormat = GraphicsContext3D::RGBA;
     82        *glType = GraphicsContext3D::UNSIGNED_BYTE;
    8183        break;
    8284    case GLES2Texture::BGRA8:
    8385// FIXME:  Once we have support for extensions, we should check for EXT_texture_format_BGRA8888,
    8486// and use that if present.
    85         *glFormat = GL_RGBA;
    86         *glType = GL_UNSIGNED_BYTE;
     87        *glFormat = GraphicsContext3D::RGBA;
     88        *glType = GraphicsContext3D::UNSIGNED_BYTE;
    8789        *swizzle = true;
    8890        break;
     
    98100    bool swizzle;
    99101    convertFormat(m_format, &glFormat, &glType, &swizzle);
    100     glBindTexture(GL_TEXTURE_2D, m_textureId);
     102    m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
    101103    if (swizzle) {
    102         ASSERT(glFormat == GL_RGBA && glType == GL_UNSIGNED_BYTE);
     104        ASSERT(glFormat == GraphicsContext3D::RGBA && glType == GraphicsContext3D::UNSIGNED_BYTE);
    103105        // FIXME:  This could use PBO's to save doing an extra copy here.
    104106        int size = m_width * m_height;
     
    110112            bufptr[i] = pixel & 0xFF00FF00 | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16);
    111113        }
    112         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());
     114        m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, buf.get());
    113115    } else
    114         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);
     116        m_context->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, m_width, m_height, glFormat, glType, pixels);
    115117}
    116118
    117119void GLES2Texture::bind()
    118120{
    119     glBindTexture(GL_TEXTURE_2D, m_textureId);
    120     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    121     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    122     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    123     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     121    m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
     122    m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
     123    m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
     124    m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
     125    m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
    124126}
    125127
  • trunk/WebCore/platform/graphics/chromium/GLES2Texture.h

    r64046 r64872  
    3838
    3939namespace WebCore {
     40class GraphicsContext3D;
    4041
    4142class GLES2Texture : public RefCounted<GLES2Texture> {
     
    4344    ~GLES2Texture();
    4445    enum Format { RGBA8, BGRA8 };
    45     static PassRefPtr<GLES2Texture> create(Format, int width, int height);
     46    static PassRefPtr<GLES2Texture> create(GraphicsContext3D*, Format, int width, int height);
    4647    void bind();
    4748    void load(void* pixels);
     
    5051    int height() const { return m_height; }
    5152private:
    52     GLES2Texture(unsigned int textureId, Format format, int width, int height);
    53     unsigned int m_textureId;
     53    GLES2Texture(GraphicsContext3D*, unsigned textureId, Format, int width, int height);
     54    GraphicsContext3D* m_context;
     55    unsigned m_textureId;
    5456    Format m_format;
    5557    int m_width;
  • trunk/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp

    r64227 r64872  
    787787        return;
    788788
    789     platformContext()->save();
    790 
    791789    SkRect r = rect;
    792790    if (!isRectSkiaSafe(getCTM(), r)) {
     
    802800    }
    803801#endif
     802
     803    platformContext()->save();
    804804
    805805    platformContext()->prepareForSoftwareDraw();
  • trunk/WebCore/platform/graphics/skia/ImageSkia.cpp

    r64374 r64872  
    415415    ctxt->platformContext()->prepareForHardwareDraw();
    416416    GLES2Canvas* gpuCanvas = ctxt->platformContext()->gpuCanvas();
    417     gpuCanvas->gles2Context()->makeCurrent();
    418417    GLES2Texture* texture = gpuCanvas->getTexture(bitmap);
    419418    if (!texture) {
  • trunk/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

    r64584 r64872  
    3131#include "config.h"
    3232
     33#include "PlatformContextSkia.h"
     34
     35#include "AffineTransform.h"
    3336#include "GraphicsContext.h"
    3437#include "ImageBuffer.h"
     
    4649
    4750#if USE(GLES2_RENDERING)
     51#include "GraphicsContext3D.h"
    4852#include "GLES2Canvas.h"
    49 #include "GLES2Context.h"
    5053#include "GLES2Texture.h"
    51 #include <GLES2/gl2.h>
    5254#endif
    5355
     
    676678
    677679#if USE(GLES2_RENDERING)
    678 void PlatformContextSkia::setGLES2Context(GLES2Context* context, const IntSize& size)
     680
     681void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, const WebCore::IntSize& size)
    679682{
    680683    m_useGPU = true;
     
    761764    const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false);
    762765    SkAutoLockPixels lock(bitmap);
    763     m_gpuCanvas->gles2Context()->makeCurrent();
    764766    // FIXME: Keep a texture around for this rather than constantly creating/destroying one.
    765     RefPtr<GLES2Texture> texture = GLES2Texture::create(GLES2Texture::BGRA8, bitmap.width(), bitmap.height());
     767    GraphicsContext3D* context = m_gpuCanvas->context();
     768    RefPtr<GLES2Texture> texture = GLES2Texture::create(context, GLES2Texture::BGRA8, bitmap.width(), bitmap.height());
    766769    texture->load(bitmap.getPixels());
    767770    IntRect rect(0, 0, bitmap.width(), bitmap.height());
    768     gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, DeviceColorSpace, op);
     771    AffineTransform identity;
     772    gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, identity, 1.0, DeviceColorSpace, op);
    769773}
    770774
     
    773777    const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true);
    774778    SkAutoLockPixels lock(bitmap);
    775     m_gpuCanvas->gles2Context()->makeCurrent();
    776779    int width = bitmap.width(), height = bitmap.height();
    777780    OwnArrayPtr<uint32_t> buf(new uint32_t[width]);
     781    GraphicsContext3D* context = m_gpuCanvas->context();
    778782    // Flips the image vertically.
    779783    for (int y = 0; y < height; ++y) {
    780784        uint32_t* pixels = bitmap.getAddr32(0, y);
    781         glReadPixels(0, height - 1 - y, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
     785        context->readPixels(0, height - 1 - y, width, 1, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels);
    782786        for (int i = 0; i < width; ++i) {
    783787            uint32_t pixel = pixels[i];
  • trunk/WebCore/platform/graphics/skia/PlatformContextSkia.h

    r64584 r64872  
    4949enum CompositeOperator;
    5050class GLES2Canvas;
    51 class GLES2Context;
     51class GraphicsContext3D;
    5252#endif
    5353
     
    184184#if USE(GLES2_RENDERING)
    185185    bool useGPU() { return m_useGPU; }
    186     void setGLES2Context(GLES2Context*, const IntSize&);
     186    void setGraphicsContext3D(GraphicsContext3D*, const IntSize&);
    187187    GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); }
    188188#endif
Note: See TracChangeset for help on using the changeset viewer.