[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 12:39:33 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit a127393c5299e9b3c74c3f728c6c2ebb09fcaffb
Author: senorblanco at chromium.org <senorblanco at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Aug 26 20:33:11 2010 +0000
2010-08-26 Stephen White <senorblanco at chromium.org>
Reviewed by Kenneth Russell.
[CHROMIUM] Give <canvas> 2D shaders their own class hierarchy.
https://bugs.webkit.org/show_bug.cgi?id=44682
Covered by fast/canvas layout tests.
* WebCore.gypi:
Add Shader.cpp, Shader.h to chromium build.
* platform/graphics/chromium/GLES2Canvas.cpp:
(WebCore::GLES2Canvas::GLES2Canvas):
(WebCore::GLES2Canvas::~GLES2Canvas):
(WebCore::GLES2Canvas::fillRect):
(WebCore::GLES2Canvas::drawTexturedRect):
(WebCore::GLES2Canvas::drawTexturedRectTile):
Rip out all shader initialization and compilation code.
Instantiate specialized shaders instead.
* platform/graphics/chromium/GLES2Canvas.h:
* platform/graphics/chromium/Shader.cpp: Added.
(WebCore::affineTo3x3):
(WebCore::Shader::Shader):
(WebCore::Shader::~Shader):
Implement Shader base class.
(WebCore::loadShader):
(WebCore::loadProgram):
Utility functions refactored from GLES2Canvas.
(WebCore::SolidFillShader::SolidFillShader):
(WebCore::TexShader::TexShader):
(WebCore::SolidFillShader::create):
(WebCore::SolidFillShader::use):
(WebCore::TexShader::create):
(WebCore::TexShader::use):
* platform/graphics/chromium/Shader.h: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66130 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 755ae2d..3cc9453 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,39 @@
+2010-08-26 Stephen White <senorblanco at chromium.org>
+
+ Reviewed by Kenneth Russell.
+
+ [CHROMIUM] Give <canvas> 2D shaders their own class hierarchy.
+ https://bugs.webkit.org/show_bug.cgi?id=44682
+
+ Covered by fast/canvas layout tests.
+
+ * WebCore.gypi:
+ Add Shader.cpp, Shader.h to chromium build.
+ * platform/graphics/chromium/GLES2Canvas.cpp:
+ (WebCore::GLES2Canvas::GLES2Canvas):
+ (WebCore::GLES2Canvas::~GLES2Canvas):
+ (WebCore::GLES2Canvas::fillRect):
+ (WebCore::GLES2Canvas::drawTexturedRect):
+ (WebCore::GLES2Canvas::drawTexturedRectTile):
+ Rip out all shader initialization and compilation code.
+ Instantiate specialized shaders instead.
+ * platform/graphics/chromium/GLES2Canvas.h:
+ * platform/graphics/chromium/Shader.cpp: Added.
+ (WebCore::affineTo3x3):
+ (WebCore::Shader::Shader):
+ (WebCore::Shader::~Shader):
+ Implement Shader base class.
+ (WebCore::loadShader):
+ (WebCore::loadProgram):
+ Utility functions refactored from GLES2Canvas.
+ (WebCore::SolidFillShader::SolidFillShader):
+ (WebCore::TexShader::TexShader):
+ (WebCore::SolidFillShader::create):
+ (WebCore::SolidFillShader::use):
+ (WebCore::TexShader::create):
+ (WebCore::TexShader::use):
+ * platform/graphics/chromium/Shader.h: Added.
+
2010-08-26 Brian Weinstein <bweinstein at apple.com>
Reviewed by Adam Roben.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 3f0c6de..f7fc01c 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2271,6 +2271,8 @@
'platform/graphics/chromium/LayerRendererChromium.h',
'platform/graphics/chromium/MediaPlayerPrivateChromium.h',
'platform/graphics/chromium/PlatformIcon.h',
+ 'platform/graphics/chromium/Shader.cpp',
+ 'platform/graphics/chromium/Shader.h',
'platform/graphics/chromium/SimpleFontDataChromiumWin.cpp',
'platform/graphics/chromium/SimpleFontDataLinux.cpp',
'platform/graphics/chromium/TilingData.h',
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
index c0cb87c..63bd53b 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -39,6 +39,7 @@
#include "GraphicsContext3D.h"
#include "IntRect.h"
#include "PlatformString.h"
+#include "Shader.h"
#define _USE_MATH_DEFINES
#include <math.h>
@@ -48,19 +49,6 @@
namespace WebCore {
-static inline void affineTo3x3(const AffineTransform& transform, float 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)
@@ -77,16 +65,8 @@ struct GLES2Canvas::State {
GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
: m_context(context)
, m_quadVertices(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_solidFillShader(SolidFillShader::create(context))
+ , m_texShader(TexShader::create(context))
, m_state(0)
{
m_flipMatrix.translate(-1.0f, 1.0f);
@@ -105,8 +85,6 @@ GLES2Canvas::GLES2Canvas(GraphicsContext3D* context, const IntSize& size)
GLES2Canvas::~GLES2Canvas()
{
- m_context->deleteProgram(m_simpleProgram);
- m_context->deleteProgram(m_texProgram);
m_context->deleteBuffer(m_quadVertices);
}
@@ -131,23 +109,11 @@ void GLES2Canvas::fillRect(const FloatRect& rect, const Color& color, ColorSpace
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
- m_context->useProgram(getSimpleProgram());
-
- float rgba[4];
- color.getRGBA(rgba[0], rgba[1], rgba[2], 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());
- float mat[9];
- affineTo3x3(matrix, mat);
- m_context->uniformMatrix3fv(m_simpleMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
-
- m_context->vertexAttribPointer(m_simplePositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
-
- m_context->enableVertexAttribArray(m_simplePositionLocation);
+ m_solidFillShader->use(matrix, color);
m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
}
@@ -212,37 +178,23 @@ void GLES2Canvas::drawTexturedRect(GLES2Texture* texture, const FloatRect& srcRe
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, getQuadVertices());
checkGLError("glBindBuffer");
- m_context->useProgram(getTexProgram());
- checkGLError("glUseProgram");
-
- m_context->activeTexture(GraphicsContext3D::TEXTURE0);
-
- m_context->uniform1i(m_texSamplerLocation, 0);
- checkGLError("glUniform1i");
-
- m_context->uniform1f(m_texAlphaLocation, alpha);
- checkGLError("glUniform1f for alpha");
-
- m_context->vertexAttribPointer(m_texPositionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
-
- m_context->enableVertexAttribArray(m_texPositionLocation);
-
const TilingData& tiles = texture->tiles();
IntRect tileIdxRect = tiles.overlappedTileIndices(srcRect);
for (int y = tileIdxRect.y(); y <= tileIdxRect.bottom(); y++) {
for (int x = tileIdxRect.x(); x <= tileIdxRect.right(); x++)
- drawTexturedRectTile(texture, tiles.tileIndex(x, y), srcRect, dstRect, transform);
+ drawTexturedRectTile(texture, tiles.tileIndex(x, y), srcRect, dstRect, transform, alpha);
}
}
-void GLES2Canvas::drawTexturedRectTile(GLES2Texture* texture, int tile, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform)
+void GLES2Canvas::drawTexturedRectTile(GLES2Texture* texture, int tile, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform& transform, float alpha)
{
if (dstRect.isEmpty())
return;
const TilingData& tiles = texture->tiles();
+ m_context->activeTexture(GraphicsContext3D::TEXTURE0);
texture->bindTile(tile);
FloatRect srcRectClippedInTileSpace;
@@ -255,19 +207,13 @@ void GLES2Canvas::drawTexturedRectTile(GLES2Texture* texture, int tile, const Fl
matrix.multLeft(transform);
matrix.translate(dstRectIntersected.x(), dstRectIntersected.y());
matrix.scale(dstRectIntersected.width(), dstRectIntersected.height());
- float mat[9];
- affineTo3x3(matrix, mat);
- m_context->uniformMatrix3fv(m_texMatrixLocation, false /*transpose*/, mat, 1 /*count*/);
- checkGLError("glUniformMatrix3fv");
AffineTransform texMatrix;
texMatrix.scale(1.0f / tileBoundsWithBorder.width(), 1.0f / tileBoundsWithBorder.height());
texMatrix.translate(srcRectClippedInTileSpace.x(), srcRectClippedInTileSpace.y());
texMatrix.scale(srcRectClippedInTileSpace.width(), srcRectClippedInTileSpace.height());
- float texMat[9];
- affineTo3x3(texMatrix, texMat);
- m_context->uniformMatrix3fv(m_texTexMatrixLocation, false /*transpose*/, texMat, 1 /*count*/);
- checkGLError("glUniformMatrix3fv");
+
+ m_texShader->use(matrix, texMatrix, 0, alpha);
m_context->drawArrays(GraphicsContext3D::TRIANGLE_STRIP, 0, 4);
checkGLError("glDrawArrays");
@@ -375,95 +321,6 @@ static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char
return shader;
}
-unsigned GLES2Canvas::getSimpleProgram()
-{
- if (!m_simpleProgram) {
- unsigned vertexShader = loadShader(m_context, GraphicsContext3D::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;
- unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::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 = m_context->createProgram();
- if (!m_simpleProgram)
- return 0;
- 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) {
- m_context->deleteProgram(m_simpleProgram);
- m_simpleProgram = 0;
- }
- 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;
-}
-
-unsigned GLES2Canvas::getTexProgram()
-{
- if (!m_texProgram) {
- unsigned vertexShader = loadShader(m_context, GraphicsContext3D::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;
- unsigned fragmentShader = loadShader(m_context, GraphicsContext3D::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 = m_context->createProgram();
- if (!m_texProgram)
- return 0;
- 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) {
- m_context->deleteProgram(m_texProgram);
- m_texProgram = 0;
- }
- 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;
-}
-
GLES2Texture* GLES2Canvas::createTexture(NativeImagePtr ptr, GLES2Texture::Format format, int width, int height)
{
PassRefPtr<GLES2Texture> texture = m_textures.get(ptr);
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.h b/WebCore/platform/graphics/chromium/GLES2Canvas.h
index d00510a..959825b 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.h
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.h
@@ -49,6 +49,8 @@ namespace WebCore {
class Color;
class FloatRect;
class GraphicsContext3D;
+class SolidFillShader;
+class TexShader;
typedef HashMap<NativeImagePtr, RefPtr<GLES2Texture> > TextureHashMap;
@@ -81,28 +83,18 @@ public:
GLES2Texture* getTexture(NativeImagePtr);
private:
- void drawTexturedRectTile(GLES2Texture* texture, int tile, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&);
+ void drawTexturedRectTile(GLES2Texture* texture, int tile, const FloatRect& srcRect, const FloatRect& dstRect, const AffineTransform&, float alpha);
void applyCompositeOperator(CompositeOperator);
void checkGLError(const char* header);
unsigned getQuadVertices();
- unsigned getSimpleProgram();
- unsigned getTexProgram();
GraphicsContext3D* m_context;
struct State;
WTF::Vector<State> m_stateStack;
State* m_state;
unsigned m_quadVertices;
- 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;
+ OwnPtr<SolidFillShader> m_solidFillShader;
+ OwnPtr<TexShader> m_texShader;
AffineTransform m_flipMatrix;
TextureHashMap m_textures;
CompositeOperator m_lastCompositeOp; // This is the one last set, not necessarily the one in the state stack.
diff --git a/WebCore/platform/graphics/chromium/Shader.cpp b/WebCore/platform/graphics/chromium/Shader.cpp
new file mode 100644
index 0000000..2ef7935
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/Shader.cpp
@@ -0,0 +1,209 @@
+/*
+ * 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"
+#include "Shader.h"
+
+#include "GraphicsContext3D.h"
+
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+static inline void affineTo3x3(const AffineTransform& transform, float 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;
+}
+
+Shader::Shader(GraphicsContext3D* context, unsigned program)
+ : m_context(context)
+ , m_program(program)
+{
+}
+
+Shader::~Shader()
+{
+ m_context->deleteProgram(m_program);
+}
+
+static unsigned loadShader(GraphicsContext3D* context, unsigned type, const char* shaderSource)
+{
+ unsigned shader = context->createShader(type);
+ if (!shader)
+ return 0;
+
+ String shaderSourceStr(shaderSource);
+ context->shaderSource(shader, shaderSourceStr);
+ context->compileShader(shader);
+ int compileStatus;
+ context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compileStatus);
+ if (!compileStatus) {
+ String infoLog = context->getShaderInfoLog(shader);
+ LOG_ERROR(infoLog.utf8().data());
+ context->deleteShader(shader);
+ return 0;
+ }
+ return shader;
+}
+
+static unsigned loadProgram(GraphicsContext3D* context, const char* vertexShaderSource, const char* fragmentShaderSource)
+{
+ unsigned vertexShader = loadShader(context, GraphicsContext3D::VERTEX_SHADER, vertexShaderSource);
+ if (!vertexShader)
+ return 0;
+ unsigned fragmentShader = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShaderSource);
+ if (!fragmentShader)
+ return 0;
+ unsigned program = context->createProgram();
+ if (!program)
+ return 0;
+ context->attachShader(program, vertexShader);
+ context->attachShader(program, fragmentShader);
+ context->linkProgram(program);
+ int linkStatus;
+ context->getProgramiv(program, GraphicsContext3D::LINK_STATUS, &linkStatus);
+ if (!linkStatus)
+ context->deleteProgram(program);
+ context->deleteShader(vertexShader);
+ context->deleteShader(fragmentShader);
+ return program;
+}
+
+SolidFillShader::SolidFillShader(GraphicsContext3D* context, unsigned program)
+ : Shader(context, program)
+{
+ m_matrixLocation = context->getUniformLocation(program, "matrix");
+ m_colorLocation = context->getUniformLocation(program, "color");
+ m_positionLocation = context->getAttribLocation(program, "position");
+}
+
+TexShader::TexShader(GraphicsContext3D* context, unsigned program)
+ : Shader(context, program)
+{
+ m_matrixLocation = context->getUniformLocation(program, "matrix");
+ m_texMatrixLocation = context->getUniformLocation(program, "texMatrix");
+ m_alphaLocation = context->getUniformLocation(program, "alpha");
+ m_positionLocation = context->getAttribLocation(program, "position");
+ m_samplerLocation = context->getUniformLocation(program, "sampler");
+}
+
+PassOwnPtr<SolidFillShader> SolidFillShader::create(GraphicsContext3D* context)
+{
+ const char* vertexShaderSource =
+ "uniform mat3 matrix;\n"
+ "uniform vec4 color;\n"
+ "attribute vec3 position;\n"
+ "void main() {\n"
+ " gl_Position = vec4(matrix * position, 1.0);\n"
+ "}\n";
+ const char* fragmentShaderSource =
+ "precision mediump float;\n"
+ "uniform mat3 matrix;\n"
+ "uniform vec4 color;\n"
+ "void main() {\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+ unsigned program = loadProgram(context, vertexShaderSource, fragmentShaderSource);
+ if (!program)
+ return 0;
+ return new SolidFillShader(context, program);
+}
+
+void SolidFillShader::use(const AffineTransform& transform, const Color& color)
+{
+ m_context->useProgram(m_program);
+
+ float rgba[4];
+ color.getRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
+ m_context->uniform4f(m_colorLocation, rgba[0] * rgba[3], rgba[1] * rgba[3], rgba[2] * rgba[3], rgba[3]);
+
+ float matrix[9];
+ affineTo3x3(transform, matrix);
+ m_context->uniformMatrix3fv(m_matrixLocation, false /*transpose*/, matrix, 1 /*count*/);
+
+ m_context->vertexAttribPointer(m_positionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
+
+ m_context->enableVertexAttribArray(m_positionLocation);
+}
+
+PassOwnPtr<TexShader> TexShader::create(GraphicsContext3D* context)
+{
+ const char* vertexShaderSource =
+ "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";
+ const char* fragmentShaderSource =
+ "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";
+ unsigned program = loadProgram(context, vertexShaderSource, fragmentShaderSource);
+ if (!program)
+ return 0;
+ return new TexShader(context, program);
+}
+
+void TexShader::use(const AffineTransform& transform, const AffineTransform& texTransform, int sampler, float alpha)
+{
+ m_context->useProgram(m_program);
+ float matrix[9];
+ affineTo3x3(transform, matrix);
+ m_context->uniformMatrix3fv(m_matrixLocation, false /*transpose*/, matrix, 1 /*count*/);
+
+ float texMatrix[9];
+ affineTo3x3(texTransform, texMatrix);
+ m_context->uniformMatrix3fv(m_texMatrixLocation, false /*transpose*/, texMatrix, 1 /*count*/);
+
+ m_context->uniform1i(m_samplerLocation, sampler);
+ m_context->uniform1f(m_alphaLocation, alpha);
+
+ m_context->vertexAttribPointer(m_positionLocation, 3, GraphicsContext3D::FLOAT, false, 0, 0);
+
+ m_context->enableVertexAttribArray(m_positionLocation);
+
+}
+
+}
diff --git a/WebCore/platform/graphics/chromium/Shader.h b/WebCore/platform/graphics/chromium/Shader.h
new file mode 100644
index 0000000..5e0c8c9
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/Shader.h
@@ -0,0 +1,82 @@
+/*
+ * 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 Shader_h
+#define Shader_h
+
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class AffineTransform;
+class GraphicsContext3D;
+class Color;
+
+class Shader : public Noncopyable {
+protected:
+ Shader(GraphicsContext3D*, unsigned program);
+ ~Shader();
+
+ GraphicsContext3D* m_context;
+ unsigned m_program;
+};
+
+class SolidFillShader : public Shader {
+public:
+ static PassOwnPtr<SolidFillShader> create(GraphicsContext3D* context);
+ void use(const AffineTransform& transform, const Color& color);
+
+private:
+ SolidFillShader(GraphicsContext3D* context, unsigned program);
+
+ int m_matrixLocation;
+ int m_colorLocation;
+ int m_positionLocation;
+};
+
+class TexShader : public Shader {
+public:
+ static PassOwnPtr<TexShader> create(GraphicsContext3D* context);
+ void use(const AffineTransform& transform, const AffineTransform& texTransform, int sampler, float alpha);
+
+private:
+ TexShader(GraphicsContext3D* context, unsigned program);
+
+ int m_matrixLocation;
+ int m_texMatrixLocation;
+ int m_samplerLocation;
+ int m_alphaLocation;
+ int m_positionLocation;
+};
+
+}
+
+#endif // Shader_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list