• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef DrawQuadData_h
27 #define DrawQuadData_h
28 
29 #if USE(ACCELERATED_COMPOSITING)
30 
31 #include "Color.h"
32 #include "FloatRect.h"
33 #include "SkRect.h"
34 #include <GLES2/gl2.h>
35 
36 namespace WebCore {
37 
38 class TransformationMatrix;
39 
40 enum DrawQuadType {
41     BaseQuad,
42     LayerQuad,
43     Blit        // 1:1 straight pixel blit
44 };
45 
46 // Both PureColorQuadData and TextureQuadData share the data from DrawQuadData.
47 class DrawQuadData {
48 public:
49     DrawQuadData(DrawQuadType type = BaseQuad,
50                  const TransformationMatrix* drawMatrix = 0,
51                  const SkRect* geometry = 0,
52                  float opacity = 1.0f,
53                  bool forceBlending = true,
54                  FloatRect fillPortion = FloatRect(0.0f, 0.0f, 1.0f, 1.0f))
m_type(type)55         : m_type(type)
56         , m_drawMatrix(drawMatrix)
57         , m_geometry(geometry)
58         , m_opacity(opacity)
59         , m_forceBlending(forceBlending)
60         , m_fillPortion(fillPortion.x(), fillPortion.y(),
61                         fillPortion.width(), fillPortion.height())
62     {
63     }
64 
DrawQuadData(const DrawQuadData & data)65     DrawQuadData(const DrawQuadData& data)
66         : m_type(data.m_type)
67         , m_drawMatrix(data.m_drawMatrix)
68         , m_geometry(data.m_geometry)
69         , m_opacity(data.m_opacity)
70         , m_forceBlending(data.m_forceBlending)
71         , m_fillPortion(data.m_fillPortion.x(), data.m_fillPortion.y(),
72                         data.m_fillPortion.width(), data.m_fillPortion.height())
73     {
74     }
75 
~DrawQuadData()76     virtual ~DrawQuadData() {};
77 
type()78     DrawQuadType type() const { return m_type; }
drawMatrix()79     const TransformationMatrix* drawMatrix() const { return m_drawMatrix; }
geometry()80     const SkRect* geometry() const { return m_geometry; }
opacity()81     float opacity() const { return m_opacity; }
forceBlending()82     bool forceBlending() const { return m_forceBlending; }
83 
updateDrawMatrix(TransformationMatrix * matrix)84     void updateDrawMatrix(TransformationMatrix* matrix) { m_drawMatrix = matrix; }
updateGeometry(SkRect * rect)85     void updateGeometry(SkRect* rect) { m_geometry = rect; }
updateOpacity(float opacity)86     void updateOpacity(float opacity) { m_opacity = opacity; }
87 
pureColor()88     virtual bool pureColor() const { return false; }
89 
quadColor()90     virtual Color quadColor() const { return Color(); }
91 
textureId()92     virtual int textureId() const { return 0; }
textureFilter()93     virtual GLint textureFilter() const { return 0; }
textureTarget()94     virtual GLenum textureTarget() const { return 0; }
fillPortion()95     virtual FloatRect fillPortion() const { return m_fillPortion; }
hasRepeatScale()96     virtual bool hasRepeatScale() const { return false; }
repeatScale()97     virtual FloatSize repeatScale() const { return FloatSize(); }
98 
99 private:
100     DrawQuadType m_type;
101     const TransformationMatrix* m_drawMatrix;
102     const SkRect* m_geometry;
103     float m_opacity;
104     bool m_forceBlending;
105     FloatRect m_fillPortion;
106 };
107 
108 class PureColorQuadData : public DrawQuadData {
109 public:
110     PureColorQuadData(Color color,
111                       DrawQuadType type = BaseQuad,
112                       const TransformationMatrix* drawMatrix = 0,
113                       const SkRect* geometry = 0,
114                       float opacity = 1.0f,
115                       bool forceBlending = true)
DrawQuadData(type,drawMatrix,geometry,opacity,forceBlending)116         : DrawQuadData(type, drawMatrix, geometry, opacity, forceBlending)
117     {
118         m_quadColor = color;
119     }
120 
PureColorQuadData(const DrawQuadData & data,Color color)121     PureColorQuadData(const DrawQuadData& data, Color color)
122         : DrawQuadData(data)
123     {
124         m_quadColor = color;
125     }
126 
~PureColorQuadData()127     virtual ~PureColorQuadData() {};
pureColor()128     virtual bool pureColor() const { return true; }
quadColor()129     virtual Color quadColor() const { return m_quadColor; }
updateColor(const Color & color)130     void updateColor(const Color& color) { m_quadColor = color; }
131 
132 private:
133     Color m_quadColor;
134 };
135 
136 class TextureQuadData : public DrawQuadData {
137 public:
138     TextureQuadData(int textureId,
139                     GLenum textureTarget = GL_TEXTURE_2D,
140                     GLint textureFilter = GL_LINEAR,
141                     DrawQuadType type = BaseQuad,
142                     const TransformationMatrix* drawMatrix = 0,
143                     const SkRect* geometry = 0,
144                     float opacity = 1.0f,
145                     bool forceBlending = true,
146                     FloatRect fillPortion = FloatRect(0.0f, 0.0f, 1.0f, 1.0f),
147                     FloatSize repeatScale = FloatSize())
DrawQuadData(type,drawMatrix,geometry,opacity,forceBlending,fillPortion)148         : DrawQuadData(type, drawMatrix, geometry, opacity, forceBlending, fillPortion)
149     {
150         m_textureId = textureId;
151         m_textureTarget = textureTarget;
152         m_textureFilter = textureFilter;
153         m_repeatScale = repeatScale;
154     }
155 
156     TextureQuadData(const DrawQuadData& data,
157                     int textureId,
158                     GLenum textureTarget = GL_TEXTURE_2D,
159                     GLint textureFilter = GL_LINEAR)
DrawQuadData(data)160         : DrawQuadData(data)
161     {
162         m_textureId = textureId;
163         m_textureTarget = textureTarget;
164         m_textureFilter = textureFilter;
165     }
166 
~TextureQuadData()167     virtual ~TextureQuadData() {};
pureColor()168     virtual bool pureColor() const { return false; }
169 
textureId()170     virtual int textureId() const { return m_textureId; }
textureFilter()171     virtual GLint textureFilter() const { return m_textureFilter; }
textureTarget()172     virtual GLenum textureTarget() const { return m_textureTarget; }
173 
updateTextureId(int newId)174     void updateTextureId(int newId) { m_textureId = newId; }
hasRepeatScale()175     virtual bool hasRepeatScale() const { return !m_repeatScale.isEmpty(); }
repeatScale()176     virtual FloatSize repeatScale() const { return m_repeatScale; }
177 private:
178     int m_textureId;
179     GLint m_textureFilter;
180     GLenum m_textureTarget;
181     FloatSize m_repeatScale;
182 };
183 
184 } // namespace WebCore
185 
186 #endif // USE(ACCELERATED_COMPOSITING)
187 #endif // DrawQuadData_h
188