DrawQuadData.h revision 485445e9a624fe92ca04a1d0e92c1f71aaf8cd8f
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 36namespace WebCore { 37 38class TransformationMatrix; 39 40enum DrawQuadType { 41 BaseQuad, 42 LayerQuad, 43 Blit // 1:1 straight pixel blit 44}; 45 46// Both PureColorQuadData and TextureQuadData share the data from DrawQuadData. 47class DrawQuadData { 48public: 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)) 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 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 76 virtual ~DrawQuadData() {}; 77 78 DrawQuadType type() const { return m_type; } 79 const TransformationMatrix* drawMatrix() const { return m_drawMatrix; } 80 const SkRect* geometry() const { return m_geometry; } 81 float opacity() const { return m_opacity; } 82 bool forceBlending() const { return m_forceBlending; } 83 84 void updateDrawMatrix(TransformationMatrix* matrix) { m_drawMatrix = matrix; } 85 void updateGeometry(SkRect* rect) { m_geometry = rect; } 86 void updateOpacity(float opacity) { m_opacity = opacity; } 87 88 virtual bool pureColor() const { return false; } 89 90 virtual Color quadColor() const { return Color(); } 91 92 virtual int textureId() const { return 0; } 93 virtual GLint textureFilter() const { return 0; } 94 virtual GLenum textureTarget() const { return 0; } 95 virtual FloatRect fillPortion() const { return m_fillPortion; } 96 97private: 98 DrawQuadType m_type; 99 const TransformationMatrix* m_drawMatrix; 100 const SkRect* m_geometry; 101 float m_opacity; 102 bool m_forceBlending; 103 FloatRect m_fillPortion; 104}; 105 106class PureColorQuadData : public DrawQuadData { 107public: 108 PureColorQuadData(Color color, 109 DrawQuadType type = BaseQuad, 110 const TransformationMatrix* drawMatrix = 0, 111 const SkRect* geometry = 0, 112 float opacity = 1.0f, 113 bool forceBlending = true) 114 : DrawQuadData(type, drawMatrix, geometry, opacity, forceBlending) 115 { 116 m_quadColor = color; 117 } 118 119 PureColorQuadData(const DrawQuadData& data, Color color) 120 : DrawQuadData(data) 121 { 122 m_quadColor = color; 123 } 124 125 virtual ~PureColorQuadData() {}; 126 virtual bool pureColor() const { return true; } 127 virtual Color quadColor() const { return m_quadColor; } 128 void updateColor(const Color& color) { m_quadColor = color; } 129 130private: 131 Color m_quadColor; 132}; 133 134class TextureQuadData : public DrawQuadData { 135public: 136 TextureQuadData(int textureId, 137 GLenum textureTarget = GL_TEXTURE_2D, 138 GLint textureFilter = GL_LINEAR, 139 DrawQuadType type = BaseQuad, 140 const TransformationMatrix* drawMatrix = 0, 141 const SkRect* geometry = 0, 142 float opacity = 1.0f, 143 bool forceBlending = true) 144 : DrawQuadData(type, drawMatrix, geometry, opacity, forceBlending) 145 { 146 m_textureId = textureId; 147 m_textureTarget = textureTarget; 148 m_textureFilter = textureFilter; 149 } 150 151 TextureQuadData(const DrawQuadData& data, 152 int textureId, 153 GLenum textureTarget = GL_TEXTURE_2D, 154 GLint textureFilter = GL_LINEAR) 155 : DrawQuadData(data) 156 { 157 m_textureId = textureId; 158 m_textureTarget = textureTarget; 159 m_textureFilter = textureFilter; 160 } 161 162 virtual ~TextureQuadData() {}; 163 virtual bool pureColor() const { return false; } 164 165 virtual int textureId() const { return m_textureId; } 166 virtual GLint textureFilter() const { return m_textureFilter; } 167 virtual GLenum textureTarget() const { return m_textureTarget; } 168 169 void updateTextureId(int newId) { m_textureId = newId; } 170 171private: 172 int m_textureId; 173 GLint m_textureFilter; 174 GLenum m_textureTarget; 175}; 176 177} // namespace WebCore 178 179#endif // USE(ACCELERATED_COMPOSITING) 180#endif // DrawQuadData_h 181