[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 12:43:33 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 52758b5af135ad20e452bcd8e29dc25e9365be7f
Author: jamesr at google.com <jamesr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Aug 27 21:18:23 2010 +0000
2010-08-27 James Robinson <jamesr at chromium.org>
Reviewed by Dimitri Glazkov.
Move Shader class from platform/graphics/chromium to platform/graphics/gpu
https://bugs.webkit.org/show_bug.cgi?id=44793
The Shader class and its subclasses are not chromium-specific. This moves
them to a common location so they can be re-used on all platforms. Also
moves the Shader subclasses into their own .h/.cpp files.
Refactor, no new tests.
* WebCore.gypi:
* platform/graphics/chromium/GLES2Canvas.cpp:
* platform/graphics/chromium/Shader.cpp: Removed.
* platform/graphics/chromium/Shader.h: Removed.
* platform/graphics/gpu/Shader.cpp: Added.
(WebCore::Shader::affineTo3x3):
(WebCore::Shader::loadShader):
(WebCore::Shader::loadProgram):
(WebCore::Shader::Shader):
(WebCore::Shader::~Shader):
* platform/graphics/gpu/Shader.h: Added.
* platform/graphics/gpu/SolidFillShader.cpp: Added.
(WebCore::SolidFillShader::SolidFillShader):
(WebCore::SolidFillShader::create):
(WebCore::SolidFillShader::use):
* platform/graphics/gpu/SolidFillShader.h: Added.
* platform/graphics/gpu/TexShader.cpp: Added.
(WebCore::TexShader::TexShader):
(WebCore::TexShader::create):
(WebCore::TexShader::use):
* platform/graphics/gpu/TexShader.h: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66256 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index bbd3e68..c04f37e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,38 @@
+2010-08-27 James Robinson <jamesr at chromium.org>
+
+ Reviewed by Dimitri Glazkov.
+
+ Move Shader class from platform/graphics/chromium to platform/graphics/gpu
+ https://bugs.webkit.org/show_bug.cgi?id=44793
+
+ The Shader class and its subclasses are not chromium-specific. This moves
+ them to a common location so they can be re-used on all platforms. Also
+ moves the Shader subclasses into their own .h/.cpp files.
+
+ Refactor, no new tests.
+
+ * WebCore.gypi:
+ * platform/graphics/chromium/GLES2Canvas.cpp:
+ * platform/graphics/chromium/Shader.cpp: Removed.
+ * platform/graphics/chromium/Shader.h: Removed.
+ * platform/graphics/gpu/Shader.cpp: Added.
+ (WebCore::Shader::affineTo3x3):
+ (WebCore::Shader::loadShader):
+ (WebCore::Shader::loadProgram):
+ (WebCore::Shader::Shader):
+ (WebCore::Shader::~Shader):
+ * platform/graphics/gpu/Shader.h: Added.
+ * platform/graphics/gpu/SolidFillShader.cpp: Added.
+ (WebCore::SolidFillShader::SolidFillShader):
+ (WebCore::SolidFillShader::create):
+ (WebCore::SolidFillShader::use):
+ * platform/graphics/gpu/SolidFillShader.h: Added.
+ * platform/graphics/gpu/TexShader.cpp: Added.
+ (WebCore::TexShader::TexShader):
+ (WebCore::TexShader::create):
+ (WebCore::TexShader::use):
+ * platform/graphics/gpu/TexShader.h: Added.
+
2010-08-27 Kinuko Yasuda <kinuko at chromium.org>
Reviewed by Darin Fisher.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index bdf8f50..6dfc8f5 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2269,8 +2269,6 @@
'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/TransparencyWin.cpp',
@@ -2300,6 +2298,12 @@
'platform/graphics/filters/SourceAlpha.h',
'platform/graphics/filters/SourceGraphic.cpp',
'platform/graphics/filters/SourceGraphic.h',
+ 'platform/graphics/gpu/Shader.cpp',
+ 'platform/graphics/gpu/Shader.h',
+ 'platform/graphics/gpu/SolidFillShader.cpp',
+ 'platform/graphics/gpu/SolidFillShader.h',
+ 'platform/graphics/gpu/TexShader.cpp',
+ 'platform/graphics/gpu/TexShader.h',
'platform/graphics/gpu/Texture.cpp',
'platform/graphics/gpu/Texture.h',
'platform/graphics/gpu/TilingData.h',
diff --git a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
index 6f594df..82d4c0b 100644
--- a/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
+++ b/WebCore/platform/graphics/chromium/GLES2Canvas.cpp
@@ -36,7 +36,8 @@
#include "GraphicsContext3D.h"
#include "IntRect.h"
#include "PlatformString.h"
-#include "Shader.h"
+#include "SolidFillShader.h"
+#include "TexShader.h"
#include "Texture.h"
#define _USE_MATH_DEFINES
diff --git a/WebCore/platform/graphics/chromium/Shader.cpp b/WebCore/platform/graphics/chromium/Shader.cpp
deleted file mode 100644
index 8b5f289..0000000
--- a/WebCore/platform/graphics/chromium/Shader.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * 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 "AffineTransform.h"
-#include "Color.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("%s", 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
deleted file mode 100644
index 5e0c8c9..0000000
--- a/WebCore/platform/graphics/chromium/Shader.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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
diff --git a/WebCore/platform/graphics/gpu/Shader.cpp b/WebCore/platform/graphics/gpu/Shader.cpp
new file mode 100644
index 0000000..59c50a7
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/Shader.cpp
@@ -0,0 +1,111 @@
+/*
+ * 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 "AffineTransform.h"
+#include "GraphicsContext3D.h"
+
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+// static
+void Shader::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;
+}
+
+// static
+unsigned Shader::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("%s", infoLog.utf8().data());
+ context->deleteShader(shader);
+ return 0;
+ }
+ return shader;
+}
+
+// static
+unsigned Shader::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;
+}
+
+Shader::Shader(GraphicsContext3D* context, unsigned program)
+ : m_context(context)
+ , m_program(program)
+{
+}
+
+Shader::~Shader()
+{
+ m_context->deleteProgram(m_program);
+}
+
+}
diff --git a/WebCore/platform/graphics/gpu/Shader.h b/WebCore/platform/graphics/gpu/Shader.h
new file mode 100644
index 0000000..e5bd8de
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/Shader.h
@@ -0,0 +1,58 @@
+/*
+ * 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();
+
+ static void affineTo3x3(const AffineTransform&, float mat[9]);
+ static unsigned loadShader(GraphicsContext3D*, unsigned type, const char* shaderSource);
+ static unsigned loadProgram(GraphicsContext3D*, const char* vertexShaderSource, const char* fragmentShaderSource);
+
+ GraphicsContext3D* m_context;
+ unsigned m_program;
+};
+
+}
+
+#endif // Shader_h
diff --git a/WebCore/platform/graphics/gpu/SolidFillShader.cpp b/WebCore/platform/graphics/gpu/SolidFillShader.cpp
new file mode 100644
index 0000000..bbc4792
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/SolidFillShader.cpp
@@ -0,0 +1,86 @@
+/*
+ * 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 "SolidFillShader.h"
+
+#include "Color.h"
+#include "GraphicsContext3D.h"
+
+namespace WebCore {
+
+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");
+}
+
+PassOwnPtr<SolidFillShader> SolidFillShader::create(GraphicsContext3D* context)
+{
+ static 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";
+ static 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);
+}
+
+}
diff --git a/WebCore/platform/graphics/gpu/SolidFillShader.h b/WebCore/platform/graphics/gpu/SolidFillShader.h
new file mode 100644
index 0000000..1071e73
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/SolidFillShader.h
@@ -0,0 +1,53 @@
+/*
+ * 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 SolidFillShader_h
+#define SolidFillShader_h
+
+#include "Shader.h"
+
+namespace WebCore {
+
+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;
+};
+
+}
+
+#endif // SolidFillShader_h
diff --git a/WebCore/platform/graphics/gpu/TexShader.cpp b/WebCore/platform/graphics/gpu/TexShader.cpp
new file mode 100644
index 0000000..ba3ecdd
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/TexShader.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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 "TexShader.h"
+
+#include "GraphicsContext3D.h"
+
+namespace WebCore {
+
+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<TexShader> TexShader::create(GraphicsContext3D* context)
+{
+ static 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";
+ static 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/gpu/TexShader.h b/WebCore/platform/graphics/gpu/TexShader.h
new file mode 100644
index 0000000..535997d
--- /dev/null
+++ b/WebCore/platform/graphics/gpu/TexShader.h
@@ -0,0 +1,55 @@
+/*
+ * 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 TexShader_h
+#define TexShader_h
+
+#include "Shader.h"
+
+namespace WebCore {
+
+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 // TexShader_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list