| 1 | /* |
| 2 | Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | Copyright (C) 2012 Igalia S.L. |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public License |
| 16 | along with this library; see the file COPYING.LIB. If not, write to |
| 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #ifndef TextureMapperShaderProgram_h |
| 22 | #define TextureMapperShaderProgram_h |
| 23 | |
| 24 | #if USE(TEXTURE_MAPPER_GL) |
| 25 | |
| 26 | #include "TextureMapperGLHeaders.h" |
| 27 | #include "TransformationMatrix.h" |
| 28 | #include <wtf/HashMap.h> |
| 29 | #include <wtf/NeverDestroyed.h> |
| 30 | #include <wtf/Ref.h> |
| 31 | #include <wtf/text/AtomicStringHash.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | #define TEXMAP_DECLARE_VARIABLE(Accessor, Name, Type) \ |
| 36 | GLuint Accessor##Location() { \ |
| 37 | static NeverDestroyed<const AtomicString> name(Name, AtomicString::ConstructFromLiteral); \ |
| 38 | return getLocation(name.get(), Type); \ |
| 39 | } |
| 40 | |
| 41 | #define TEXMAP_DECLARE_UNIFORM(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "u_"#Accessor, UniformVariable) |
| 42 | #define TEXMAP_DECLARE_ATTRIBUTE(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "a_"#Accessor, AttribVariable) |
| 43 | #define TEXMAP_DECLARE_SAMPLER(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "s_"#Accessor, UniformVariable) |
| 44 | |
| 45 | class TextureMapperShaderProgram : public RefCounted<TextureMapperShaderProgram> { |
| 46 | public: |
| 47 | enum Option { |
| 48 | Texture = 1L << 0, |
| 49 | Rect = 1L << 1, |
| 50 | SolidColor = 1L << 2, |
| 51 | Opacity = 1L << 3, |
| 52 | Antialiasing = 1L << 5, |
| 53 | GrayscaleFilter = 1L << 6, |
| 54 | SepiaFilter = 1L << 7, |
| 55 | SaturateFilter = 1L << 8, |
| 56 | HueRotateFilter = 1L << 9, |
| 57 | BrightnessFilter = 1L << 10, |
| 58 | ContrastFilter = 1L << 11, |
| 59 | InvertFilter = 1L << 12, |
| 60 | OpacityFilter = 1L << 13, |
| 61 | BlurFilter = 1L << 14, |
| 62 | AlphaBlur = 1L << 15, |
| 63 | ContentTexture = 1L << 16, |
| 64 | ManualRepeat = 1L << 17 |
| 65 | }; |
| 66 | |
| 67 | typedef unsigned Options; |
| 68 | |
| 69 | static Ref<TextureMapperShaderProgram> create(Options); |
| 70 | virtual ~TextureMapperShaderProgram(); |
| 71 | |
| 72 | GLuint programID() const { return m_id; } |
| 73 | |
| 74 | TEXMAP_DECLARE_ATTRIBUTE(vertex) |
| 75 | |
| 76 | TEXMAP_DECLARE_UNIFORM(modelViewMatrix) |
| 77 | TEXMAP_DECLARE_UNIFORM(projectionMatrix) |
| 78 | TEXMAP_DECLARE_UNIFORM(textureSpaceMatrix) |
| 79 | TEXMAP_DECLARE_UNIFORM(textureColorSpaceMatrix) |
| 80 | TEXMAP_DECLARE_UNIFORM(opacity) |
| 81 | TEXMAP_DECLARE_UNIFORM(color) |
| 82 | TEXMAP_DECLARE_UNIFORM(expandedQuadEdgesInScreenSpace) |
| 83 | TEXMAP_DECLARE_SAMPLER(sampler) |
| 84 | TEXMAP_DECLARE_SAMPLER(mask) |
| 85 | |
| 86 | TEXMAP_DECLARE_UNIFORM(filterAmount) |
| 87 | TEXMAP_DECLARE_UNIFORM(gaussianKernel) |
| 88 | TEXMAP_DECLARE_UNIFORM(blurRadius) |
| 89 | TEXMAP_DECLARE_UNIFORM(shadowOffset) |
| 90 | TEXMAP_DECLARE_SAMPLER(contentTexture) |
| 91 | |
| 92 | void setMatrix(GLuint, const TransformationMatrix&); |
| 93 | |
| 94 | private: |
| 95 | TextureMapperShaderProgram(const String& vertexShaderSource, const String& fragmentShaderSource); |
| 96 | |
| 97 | GLuint m_vertexShader; |
| 98 | GLuint m_fragmentShader; |
| 99 | |
| 100 | enum VariableType { UniformVariable, AttribVariable }; |
| 101 | GLuint getLocation(const AtomicString&, VariableType); |
| 102 | |
| 103 | GLuint m_id; |
| 104 | HashMap<AtomicString, GLuint> m_variables; |
| 105 | }; |
| 106 | |
| 107 | } |
| 108 | #endif // USE(TEXTURE_MAPPER_GL) |
| 109 | |
| 110 | #endif // TextureMapperShaderProgram_h |
| 111 | |