[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
jamesr at google.com
jamesr at google.com
Wed Dec 22 11:47:34 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit eb9636799ca467dd913da7a453daedff73dae9c1
Author: jamesr at google.com <jamesr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Aug 6 21:58:55 2010 +0000
2010-08-06 James Robinson <jamesr at 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:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64872 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 54c5e1f..aef1c3c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,5 +1,55 @@
2010-08-06 James Robinson <jamesr at 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:
+
+2010-08-06 James Robinson <jamesr at chromium.org>
+
Reviewed by Simon Fraser.
Composited canvas should be treated the same by the compositor and not be WebGL specific
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
index 9fc8917..8a9bde1 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -34,20 +34,22 @@
#include "GLES2Canvas.h"
+#include "Float32Array.h"
#include "FloatRect.h"
-#include "GLES2Context.h"
#include "GLES2Texture.h"
-
-#include <GLES2/gl2.h>
+#include "GraphicsContext3D.h"
+#include "PlatformString.h"
+#include "Uint16Array.h"
#define _USE_MATH_DEFINES
#include <math.h>
+#include <wtf/text/CString.h>
#include <wtf/OwnArrayPtr.h>
namespace WebCore {
-static inline void affineTo3x3(const AffineTransform& transform, GLfloat mat[9])
+static inline void affineTo3x3(const AffineTransform& transform, float mat[9])
{
mat[0] = transform.a();
mat[1] = transform.b();
@@ -73,8 +75,8 @@ struct GLES2Canvas::State {
AffineTransform m_ctm;
};
-GLES2Canvas::GLES2Canvas(GLES2Context* context, const IntSize& size)
- : m_gles2Context(context)
+GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
+ : m_context(context)
, m_quadVertices(0)
, m_quadIndices(0)
, m_simpleProgram(0)
@@ -92,10 +94,8 @@ GLES2Canvas::GLES2Canvas(GLES2Context* context, const IntSize& size)
m_flipMatrix.translate(-1.0f, 1.0f);
m_flipMatrix.scale(2.0f / size.width(), -2.0f / size.height());
- m_gles2Context->makeCurrent();
- m_gles2Context->resizeOffscreenContent(size);
- m_gles2Context->swapBuffers();
- glViewport(0, 0, size.width(), size.height());
+ m_context->reshape(size.width(), size.height());
+ m_context->viewport(0, 0, size.width(), size.height());
m_stateStack.append(State());
m_state = &m_stateStack.last();
@@ -107,69 +107,58 @@ GLES2Canvas::GLES2Canvas(GLES2Context* context, const IntSize& size)
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);
+ m_context->deleteProgram(m_simpleProgram);
+ m_context->deleteProgram(m_texProgram);
+ m_context->deleteBuffer(m_quadVertices);
+ m_context->deleteBuffer(m_quadIndices);
}
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);
+ m_context->scissor(rect.x(), rect.y(), rect.width(), rect.height());
+ m_context->enable(GraphicsContext3D::SCISSOR_TEST);
+ m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
+ m_context->disable(GraphicsContext3D::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());
+ m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
+ m_context->bindBuffer(GraphicsContext3D::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]);
+ m_context->uniform4f(m_simpleColorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+ m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::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());
+ m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
+ m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
- glUseProgram(getSimpleProgram());
+ m_context->useProgram(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]);
+ m_context->uniform4f(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];
+ float mat[9];
affineTo3x3(matrix, mat);
- glUniformMatrix3fv(m_simpleMatrixLocation, 1, GL_FALSE, mat);
+ m_context->uniformMatrix3fv(m_simpleMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
- glVertexAttribPointer(m_simplePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
+ m_context->vertexAttribPointer(m_simplePositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
- glEnableVertexAttribArray(m_simplePositionLocation);
+ m_context->enableVertexAttribArray(m_simplePositionLocation);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+ m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
}
void GLES2Canvas::setFillColor(const Color& color, ColorSpace colorSpace)
@@ -222,49 +211,47 @@ void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRe
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());
+ m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
+ m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, getQuadIndices());
checkGLError("glBindBuffer");
- glUseProgram(getTexProgram());
+ m_context->useProgram(getTexProgram());
checkGLError("glUseProgram");
- glActiveTexture(GL_TEXTURE0);
+ m_context->activeTexture(GraphicsContext3D::TEXTURE0);
texture->bind();
- glUniform1i(m_texSamplerLocation, 0);
+ m_context->uniform1i(m_texSamplerLocation, 0);
checkGLError("glUniform1i");
- glUniform1f(m_texAlphaLocation, alpha);
+ m_context->uniform1f(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];
+ float mat[9];
affineTo3x3(matrix, mat);
- glUniformMatrix3fv(m_texMatrixLocation, 1, GL_FALSE, mat);
+ m_context->uniformMatrix3fv(m_texMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
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];
+ float texMat[9];
affineTo3x3(texMatrix, texMat);
- glUniformMatrix3fv(m_texTexMatrixLocation, 1, GL_FALSE, texMat);
+ m_context->uniformMatrix3fv(m_texTexMatrixLocation, false /*transpose*/, texMat, 1 /*count*/);
checkGLError("glUniformMatrix3fv");
- glVertexAttribPointer(m_texPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0));
+ m_context->vertexAttribPointer(m_texPositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
- glEnableVertexAttribArray(m_texPositionLocation);
+ m_context->enableVertexAttribArray(m_texPositionLocation);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
+ m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, GraphicsContext3D::UNSIGNED_SHORT, 0);
checkGLError("glDrawElements");
}
@@ -280,56 +267,56 @@ void GLES2Canvas::applyCompositeOperator(CompositeOperator op)
switch (op) {
case CompositeClear:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ZERO, GL_ZERO);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ZERO);
break;
case CompositeCopy:
- glDisable(GL_BLEND);
+ m_context->disable(GraphicsContext3D::BLEND);
break;
case CompositeSourceOver:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeSourceIn:
- glEnable(GL_BLEND);
- glBlendFunc(GL_DST_ALPHA, GL_ZERO);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ZERO);
break;
case CompositeSourceOut:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ZERO);
break;
case CompositeSourceAtop:
- glEnable(GL_BLEND);
- glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeDestinationOver:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE);
break;
case CompositeDestinationIn:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::SRC_ALPHA);
break;
case CompositeDestinationOut:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ZERO, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositeDestinationAtop:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::SRC_ALPHA);
break;
case CompositeXOR:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE_MINUS_DST_ALPHA, GraphicsContext3D::ONE_MINUS_SRC_ALPHA);
break;
case CompositePlusDarker:
case CompositeHighlight:
// unsupported
- glDisable(GL_BLEND);
+ m_context->disable(GraphicsContext3D::BLEND);
break;
case CompositePlusLighter:
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
+ m_context->enable(GraphicsContext3D::BLEND);
+ m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE);
break;
}
m_lastCompositeOp = op;
@@ -338,13 +325,14 @@ void GLES2Canvas::applyCompositeOperator(CompositeOperator 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);
+ float 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 };
+ m_quadVertices = m_context->createBuffer();
+ RefPtr<Float32Array> vertexArray = Float32Array::create(vertices, sizeof(vertices) / sizeof(float));
+ m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_quadVertices);
+ m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, vertexArray.get(), GraphicsContext3D::STATIC_DRAW);
}
return m_quadVertices;
}
@@ -353,32 +341,31 @@ unsigned GLES2Canvas::getQuadVertices()
unsigned GLES2Canvas::getQuadIndices()
{
if (!m_quadIndices) {
- GLushort indices[] = { 0, 1, 2, 0, 2, 3};
+ unsigned short 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);
+ m_quadIndices = m_context->createBuffer();
+ RefPtr<Uint16Array> indexArray = Uint16Array::create(indices, sizeof(indices) / sizeof(unsigned short));
+ m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_quadIndices);
+ m_context->bufferData(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, indexArray.get(), GraphicsContext3D::STATIC_DRAW);
}
return m_quadIndices;
}
-static GLuint loadShader(GLenum type, const char* shaderSource)
+static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource)
{
- GLuint shader = glCreateShader(type);
+ unsigned shader = context->createShader(type);
if (!shader)
return 0;
- glShaderSource(shader, 1, &shaderSource, 0);
- glCompileShader(shader);
- GLint compileStatus;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compileStatus);
+ String shaderSourceStr(shaderSource);
+ context->shaderSource(shader, shaderSourceStr);
+ context->compileShader(shader);
+ int compileStatus;
+ context->getShaderiv(shader, GraphicsContext3D::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);
+ String infoLog = context->getShaderInfoLog(shader);
+ LOG_ERROR(infoLog.utf8().data());
+ context->deleteShader(shader);
return 0;
}
return shader;
@@ -387,7 +374,7 @@ static GLuint loadShader(GLenum type, const char* shaderSource)
unsigned GLES2Canvas::getSimpleProgram()
{
if (!m_simpleProgram) {
- GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
+ unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER,
"uniform mat3 matrix;\n"
"uniform vec4 color;\n"
"attribute vec3 position;\n"
@@ -396,7 +383,7 @@ unsigned GLES2Canvas::getSimpleProgram()
"}\n");
if (!vertexShader)
return 0;
- GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
+ unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER,
"precision mediump float;\n"
"uniform mat3 matrix;\n"
"uniform vec4 color;\n"
@@ -405,23 +392,23 @@ unsigned GLES2Canvas::getSimpleProgram()
"}\n");
if (!fragmentShader)
return 0;
- m_simpleProgram = glCreateProgram();
+ m_simpleProgram = m_context->createProgram();
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);
+ m_context->attachShader(m_simpleProgram, vertexShader);
+ m_context->attachShader(m_simpleProgram, fragmentShader);
+ m_context->linkProgram(m_simpleProgram);
+ int linkStatus;
+ m_context->getProgramiv(m_simpleProgram, GraphicsContext3D::LINK_STATUS, &linkStatus);
if (!linkStatus) {
- glDeleteProgram(m_simpleProgram);
+ m_context->deleteProgram(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");
+ m_context->deleteShader(vertexShader);
+ m_context->deleteShader(fragmentShader);
+ m_simplePositionLocation = m_context->getAttribLocation(m_simpleProgram, "position");
+ m_simpleMatrixLocation = m_context->getUniformLocation(m_simpleProgram, "matrix");
+ m_simpleColorLocation = m_context->getUniformLocation(m_simpleProgram, "color");
}
return m_simpleProgram;
}
@@ -429,7 +416,7 @@ unsigned GLES2Canvas::getSimpleProgram()
unsigned GLES2Canvas::getTexProgram()
{
if (!m_texProgram) {
- GLuint vertexShader = loadShader(GL_VERTEX_SHADER,
+ unsigned vertexShader = loadShader(m_context, GraphicsContext3D::VERTEX_SHADER,
"uniform mat3 matrix;\n"
"uniform mat3 texMatrix;\n"
"attribute vec3 position;\n"
@@ -440,7 +427,7 @@ unsigned GLES2Canvas::getTexProgram()
"}\n");
if (!vertexShader)
return 0;
- GLuint fragmentShader = loadShader(GL_FRAGMENT_SHADER,
+ unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::FRAGMENT_SHADER,
"precision mediump float;\n"
"uniform sampler2D sampler;\n"
"uniform float alpha;\n"
@@ -450,25 +437,25 @@ unsigned GLES2Canvas::getTexProgram()
"}\n");
if (!fragmentShader)
return 0;
- m_texProgram = glCreateProgram();
+ m_texProgram = m_context->createProgram();
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);
+ m_context->attachShader(m_texProgram, vertexShader);
+ m_context->attachShader(m_texProgram, fragmentShader);
+ m_context->linkProgram(m_texProgram);
+ int linkStatus;
+ m_context->getProgramiv(m_texProgram, GraphicsContext3D::LINK_STATUS, &linkStatus);
if (!linkStatus) {
- glDeleteProgram(m_texProgram);
+ m_context->deleteProgram(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");
+ m_context->deleteShader(vertexShader);
+ m_context->deleteShader(fragmentShader);
+ m_texMatrixLocation = m_context->getUniformLocation(m_texProgram, "matrix");
+ m_texSamplerLocation = m_context->getUniformLocation(m_texProgram, "sampler");
+ m_texTexMatrixLocation = m_context->getUniformLocation(m_texProgram, "texMatrix");
+ m_texPositionLocation = m_context->getAttribLocation(m_texProgram, "position");
+ m_texAlphaLocation = m_context->getUniformLocation(m_texProgram, "alpha");
}
return m_texProgram;
}
@@ -479,7 +466,7 @@ GLES2Texture* GLES2Canvas::createTexture(NativeImagePtr ptr, GLES2Texture::Forma
if (texture)
return texture.get();
- texture = GLES2Texture::create(format, width, height);
+ texture = GLES2Texture::create(m_context, format, width, height);
GLES2Texture* t = texture.get();
m_textures.set(ptr, texture);
return t;
@@ -494,24 +481,24 @@ GLES2Texture* GLES2Canvas::getTexture(NativeImagePtr ptr)
void GLES2Canvas::checkGLError(const char* header)
{
#ifndef NDEBUG
- GLenum err;
- while ((err = glGetError()) != GL_NO_ERROR) {
+ unsigned err;
+ while ((err = m_context->getError()) != GraphicsContext3D::NO_ERROR) {
const char* errorStr = "*** UNKNOWN ERROR ***";
switch (err) {
- case GL_INVALID_ENUM:
- errorStr = "GL_INVALID_ENUM";
+ case GraphicsContext3D::INVALID_ENUM:
+ errorStr = "GraphicsContext3D::INVALID_ENUM";
break;
- case GL_INVALID_VALUE:
- errorStr = "GL_INVALID_VALUE";
+ case GraphicsContext3D::INVALID_VALUE:
+ errorStr = "GraphicsContext3D::INVALID_VALUE";
break;
- case GL_INVALID_OPERATION:
- errorStr = "GL_INVALID_OPERATION";
+ case GraphicsContext3D::INVALID_OPERATION:
+ errorStr = "GraphicsContext3D::INVALID_OPERATION";
break;
- case GL_INVALID_FRAMEBUFFER_OPERATION:
- errorStr = "GL_INVALID_FRAMEBUFFER_OPERATION";
+ case GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION:
+ errorStr = "GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION";
break;
- case GL_OUT_OF_MEMORY:
- errorStr = "GL_OUT_OF_MEMORY";
+ case GraphicsContext3D::OUT_OF_MEMORY:
+ errorStr = "GraphicsContext3D::OUT_OF_MEMORY";
break;
}
if (header)
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.h b/WebCore/platform/graphics/chromium/GLES2Canvas.h
index 4e500be..cea90ae 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.h
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.h
@@ -46,15 +46,15 @@
namespace WebCore {
-class FloatRect;
class Color;
-class GLES2Context;
+class FloatRect;
+class GraphicsContext3D;
typedef HashMap<NativeImagePtr, RefPtr<GLES2Texture> > TextureHashMap;
class GLES2Canvas : public Noncopyable {
public:
- GLES2Canvas(GLES2Context*, const IntSize&);
+ GLES2Canvas(GraphicsContext3D*, const IntSize&);
~GLES2Canvas();
void fillRect(const FloatRect&, const Color&, ColorSpace);
@@ -76,7 +76,7 @@ public:
// 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; }
+ GraphicsContext3D* context() { return m_context; }
GLES2Texture* createTexture(NativeImagePtr, GLES2Texture::Format, int width, int height);
GLES2Texture* getTexture(NativeImagePtr);
@@ -88,7 +88,7 @@ private:
unsigned getSimpleProgram();
unsigned getTexProgram();
- GLES2Context* m_gles2Context;
+ GraphicsContext3D* m_context;
struct State;
WTF::Vector<State> m_stateStack;
State* m_state;
diff --git a/WebCore/platform/graphics/chromium/GLES2Texture.cpp b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
index 26c8bf7..5e8a141 100644
--- a/WebCore/platform/graphics/chromium/GLES2Texture.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Texture.cpp
@@ -34,14 +34,15 @@
#include "GLES2Texture.h"
-#include <GLES2/gl2.h>
+#include "GraphicsContext3D.h"
#include <wtf/OwnArrayPtr.h>
namespace WebCore {
-GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int height)
- : m_textureId(textureId)
+GLES2Texture::GLES2Texture(GraphicsContext3D* context, unsigned textureId, Format format, int width, int height)
+ : m_context(context)
+ , m_textureId(textureId)
, m_format(format)
, m_width(width)
, m_height(height)
@@ -50,25 +51,26 @@ GLES2Texture::GLES2Texture(unsigned int textureId, Format format, int width, int
GLES2Texture::~GLES2Texture()
{
- glDeleteTextures(1, &m_textureId);
+ m_context->deleteTexture(m_textureId);
}
-PassRefPtr<GLES2Texture> GLES2Texture::create(Format format, int width, int height)
+PassRefPtr<GLES2Texture> GLES2Texture::create(GraphicsContext3D* context, Format format, int width, int height)
{
- GLuint textureId;
- glGenTextures(1, &textureId);
- if (!textureId)
+ int max;
+ context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &max);
+ if (width > max || height > max) {
+ ASSERT(!"texture too big");
return 0;
+ }
- glBindTexture(GL_TEXTURE_2D, textureId);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+ unsigned textureId = context->createTexture();
+ if (!textureId)
+ return 0;
- int max;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
- if (width > max || height > max)
- ASSERT(!"texture too big");
+ context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId);
+ context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, width, height, 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, 0);
- return adoptRef(new GLES2Texture(textureId, format, width, height));
+ return adoptRef(new GLES2Texture(context, textureId, format, width, height));
}
static void convertFormat(GLES2Texture::Format format, unsigned int* glFormat, unsigned int* glType, bool* swizzle)
@@ -76,14 +78,14 @@ static void convertFormat(GLES2Texture::Format format, unsigned int* glFormat, u
*swizzle = false;
switch (format) {
case GLES2Texture::RGBA8:
- *glFormat = GL_RGBA;
- *glType = GL_UNSIGNED_BYTE;
+ *glFormat = GraphicsContext3D::RGBA;
+ *glType = GraphicsContext3D::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;
+ *glFormat = GraphicsContext3D::RGBA;
+ *glType = GraphicsContext3D::UNSIGNED_BYTE;
*swizzle = true;
break;
default:
@@ -97,9 +99,9 @@ void GLES2Texture::load(void* pixels)
unsigned int glFormat, glType;
bool swizzle;
convertFormat(m_format, &glFormat, &glType, &swizzle);
- glBindTexture(GL_TEXTURE_2D, m_textureId);
+ m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
if (swizzle) {
- ASSERT(glFormat == GL_RGBA && glType == GL_UNSIGNED_BYTE);
+ ASSERT(glFormat == GraphicsContext3D::RGBA && glType == GraphicsContext3D::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);
@@ -109,18 +111,18 @@ void GLES2Texture::load(void* pixels)
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());
+ m_context->texSubImage2D(GraphicsContext3D::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);
+ m_context->texSubImage2D(GraphicsContext3D::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);
+ m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
+ m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
}
}
diff --git a/WebCore/platform/graphics/chromium/GLES2Texture.h b/WebCore/platform/graphics/chromium/GLES2Texture.h
index 346365a..4d351cd 100644
--- a/WebCore/platform/graphics/chromium/GLES2Texture.h
+++ b/WebCore/platform/graphics/chromium/GLES2Texture.h
@@ -37,20 +37,22 @@
#include "RefPtr.h"
namespace WebCore {
+class GraphicsContext3D;
class GLES2Texture : public RefCounted<GLES2Texture> {
public:
~GLES2Texture();
enum Format { RGBA8, BGRA8 };
- static PassRefPtr<GLES2Texture> create(Format, int width, int height);
+ static PassRefPtr<GLES2Texture> create(GraphicsContext3D*, 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;
+ GLES2Texture(GraphicsContext3D*, unsigned textureId, Format, int width, int height);
+ GraphicsContext3D* m_context;
+ unsigned m_textureId;
Format m_format;
int m_width;
int m_height;
diff --git a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
index 7994244..ae088b6 100644
--- a/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp
@@ -786,8 +786,6 @@ void GraphicsContext::fillRect(const FloatRect& rect)
if (paintingDisabled())
return;
- platformContext()->save();
-
SkRect r = rect;
if (!isRectSkiaSafe(getCTM(), r)) {
// See the other version of fillRect below.
@@ -802,6 +800,8 @@ void GraphicsContext::fillRect(const FloatRect& rect)
}
#endif
+ platformContext()->save();
+
platformContext()->prepareForSoftwareDraw();
SkPaint paint;
diff --git a/WebCore/platform/graphics/skia/ImageSkia.cpp b/WebCore/platform/graphics/skia/ImageSkia.cpp
index a2485e6..024bf50 100644
--- a/WebCore/platform/graphics/skia/ImageSkia.cpp
+++ b/WebCore/platform/graphics/skia/ImageSkia.cpp
@@ -414,7 +414,6 @@ static void drawBitmapGLES2(GraphicsContext* ctxt, NativeImageSkia* bitmap, cons
{
ctxt->platformContext()->prepareForHardwareDraw();
GLES2Canvas* gpuCanvas = ctxt->platformContext()->gpuCanvas();
- gpuCanvas->gles2Context()->makeCurrent();
GLES2Texture* texture = gpuCanvas->getTexture(bitmap);
if (!texture) {
ASSERT(bitmap->config() == SkBitmap::kARGB_8888_Config);
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
index 5ec9a5c..b14c6cd 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
@@ -30,6 +30,9 @@
#include "config.h"
+#include "PlatformContextSkia.h"
+
+#include "AffineTransform.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "NativeImageSkia.h"
@@ -45,10 +48,9 @@
#include "SkDashPathEffect.h"
#if USE(GLES2_RENDERING)
+#include "GraphicsContext3D.h"
#include "GLES2Canvas.h"
-#include "GLES2Context.h"
#include "GLES2Texture.h"
-#include <GLES2/gl2.h>
#endif
#include <wtf/MathExtras.h>
@@ -675,7 +677,8 @@ void PlatformContextSkia::applyAntiAliasedClipPaths(WTF::Vector<SkPath>& paths)
}
#if USE(GLES2_RENDERING)
-void PlatformContextSkia::setGLES2Context(GLES2Context* context, const IntSize& size)
+
+void PlatformContextSkia::setGraphicsContext3D(GraphicsContext3D* context, const WebCore::IntSize& size)
{
m_useGPU = true;
m_gpuCanvas = new GLES2Canvas(context, size);
@@ -760,25 +763,26 @@ void PlatformContextSkia::uploadSoftwareToHardware(CompositeOperator op) const
{
const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false);
SkAutoLockPixels lock(bitmap);
- m_gpuCanvas->gles2Context()->makeCurrent();
// FIXME: Keep a texture around for this rather than constantly creating/destroying one.
- RefPtr<GLES2Texture> texture = GLES2Texture::create(GLES2Texture::BGRA8, bitmap.width(), bitmap.height());
+ GraphicsContext3D* context = m_gpuCanvas->context();
+ RefPtr<GLES2Texture> texture = GLES2Texture::create(context, GLES2Texture::BGRA8, bitmap.width(), bitmap.height());
texture->load(bitmap.getPixels());
IntRect rect(0, 0, bitmap.width(), bitmap.height());
- gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, DeviceColorSpace, op);
+ AffineTransform identity;
+ gpuCanvas()->drawTexturedRect(texture.get(), rect, rect, identity, 1.0, DeviceColorSpace, op);
}
void PlatformContextSkia::readbackHardwareToSoftware() const
{
const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true);
SkAutoLockPixels lock(bitmap);
- m_gpuCanvas->gles2Context()->makeCurrent();
int width = bitmap.width(), height = bitmap.height();
OwnArrayPtr<uint32_t> buf(new uint32_t[width]);
+ GraphicsContext3D* context = m_gpuCanvas->context();
// Flips the image vertically.
for (int y = 0; y < height; ++y) {
uint32_t* pixels = bitmap.getAddr32(0, y);
- glReadPixels(0, height - 1 - y, width, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ context->readPixels(0, height - 1 - y, width, 1, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels);
for (int i = 0; i < width; ++i) {
uint32_t pixel = pixels[i];
// Swizzles from RGBA -> BGRA.
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h
index 5da5141..ff80d1b 100644
--- a/WebCore/platform/graphics/skia/PlatformContextSkia.h
+++ b/WebCore/platform/graphics/skia/PlatformContextSkia.h
@@ -48,7 +48,7 @@ namespace WebCore {
#if USE(GLES2_RENDERING)
enum CompositeOperator;
class GLES2Canvas;
-class GLES2Context;
+class GraphicsContext3D;
#endif
// This class holds the platform-specific state for GraphicsContext. We put
@@ -183,7 +183,7 @@ public:
bool hasImageResamplingHint() const;
#if USE(GLES2_RENDERING)
bool useGPU() { return m_useGPU; }
- void setGLES2Context(GLES2Context*, const IntSize&);
+ void setGraphicsContext3D(GraphicsContext3D*, const IntSize&);
GLES2Canvas* gpuCanvas() const { return m_gpuCanvas.get(); }
#endif
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list