43a6534becf62bf9a1cbc2a0d650ee9a9693cdbf
[WebKit-https.git] / Source / WebCore / platform / graphics / texmap / TextureMapperShaderProgram.h
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)
25 #include "GraphicsContext3D.h"
26 #include "TransformationMatrix.h"
27 #include <wtf/HashMap.h>
28 #include <wtf/PassRefPtr.h>
29 #include <wtf/RefPtr.h>
30 #include <wtf/text/AtomicStringHash.h>
31
32 namespace WebCore {
33 #define TEXMAP_DECLARE_VARIABLE(Accessor, Name, Type) GC3Duint Accessor##Location() { static const AtomicString name(Name); return getLocation(name, Type); }
34 #define TEXMAP_DECLARE_UNIFORM(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "u_"#Accessor, UniformVariable)
35 #define TEXMAP_DECLARE_ATTRIBUTE(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "a_"#Accessor, AttribVariable)
36 #define TEXMAP_DECLARE_SAMPLER(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "s_"#Accessor, UniformVariable)
37
38 class TextureMapperShaderProgram : public RefCounted<TextureMapperShaderProgram> {
39 public:
40     enum Option {
41         Texture          = 1L << 0,
42         Rect             = 1L << 1,
43         SolidColor       = 1L << 2,
44         Opacity          = 1L << 3,
45         Antialiasing     = 1L << 5,
46         GrayscaleFilter  = 1L << 6,
47         SepiaFilter      = 1L << 7,
48         SaturateFilter   = 1L << 8,
49         HueRotateFilter  = 1L << 9,
50         BrightnessFilter = 1L << 10,
51         ContrastFilter   = 1L << 11,
52         InvertFilter     = 1L << 12,
53         OpacityFilter    = 1L << 13,
54         BlurFilter       = 1L << 14,
55         AlphaBlur        = 1L << 15,
56         ContentTexture   = 1L << 16
57     };
58
59     typedef unsigned Options;
60
61     static PassRefPtr<TextureMapperShaderProgram> create(PassRefPtr<GraphicsContext3D>, Options);
62     virtual ~TextureMapperShaderProgram();
63     Platform3DObject programID() const { return m_id; }
64     GraphicsContext3D* context() { return m_context.get(); }
65
66     TEXMAP_DECLARE_ATTRIBUTE(vertex)
67
68     TEXMAP_DECLARE_UNIFORM(modelViewMatrix)
69     TEXMAP_DECLARE_UNIFORM(projectionMatrix)
70     TEXMAP_DECLARE_UNIFORM(textureSpaceMatrix)
71     TEXMAP_DECLARE_UNIFORM(opacity)
72     TEXMAP_DECLARE_UNIFORM(color)
73     TEXMAP_DECLARE_UNIFORM(expandedQuadEdgesInScreenSpace)
74     TEXMAP_DECLARE_SAMPLER(sampler)
75     TEXMAP_DECLARE_SAMPLER(mask)
76
77     TEXMAP_DECLARE_UNIFORM(filterAmount)
78     TEXMAP_DECLARE_UNIFORM(gaussianKernel)
79     TEXMAP_DECLARE_UNIFORM(blurRadius)
80     TEXMAP_DECLARE_UNIFORM(shadowOffset)
81     TEXMAP_DECLARE_SAMPLER(contentTexture)
82
83     void setMatrix(GC3Duint, const TransformationMatrix&);
84
85 private:
86     TextureMapperShaderProgram(PassRefPtr<GraphicsContext3D>, const String& vertexShaderSource, const String& fragmentShaderSource);
87     Platform3DObject m_vertexShader;
88     Platform3DObject m_fragmentShader;
89
90     enum VariableType { UniformVariable, AttribVariable };
91     GC3Duint getLocation(const AtomicString&, VariableType);
92
93     RefPtr<GraphicsContext3D> m_context;
94     Platform3DObject m_id;
95     HashMap<AtomicString, GC3Duint> m_variables;
96 };
97
98 }
99 #endif
100
101 #endif // TextureMapperShaderProgram_h