2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef ShaderProgram_h
18 #define ShaderProgram_h
20 #if USE(ACCELERATED_COMPOSITING)
22 #include "FloatRect.h"
25 #include "TransformationMatrix.h"
26 #include <GLES2/gl2.h>
28 #define MAX_CONTRAST 5
36 int projectionMatrix() { return m_hProjectionMatrix; }
37 int alpha() { return m_hAlpha; }
38 int textureSampler() { return m_hTexSampler; }
39 int program() { return m_program; }
42 void setViewport(SkRect& viewport);
43 float zValue(const TransformationMatrix& drawMatrix, float w, float h);
45 // For drawQuad and drawLayerQuad, they can handle 3 cases for now:
46 // 1) textureTarget == GL_TEXTURE_2D
47 // Normal texture in GL_TEXTURE_2D target.
48 // 2) textureTarget == GL_TEXTURE_EXTERNAL_OES
49 // Surface texture in GL_TEXTURE_EXTERNAL_OES target.
50 // 3) textureTarget == 0 (Will be deprecated soon)
51 // Surface texture in GL_TEXTURE_2D target.
53 // TODO: Shrink the support modes into 2 (1 and 2) after media framework
54 // support Surface texture in GL_TEXTURE_EXTERNAL_OES target on all
56 void drawQuad(SkRect& geometry, int textureId, float opacity,
57 GLenum textureTarget = GL_TEXTURE_2D);
58 void drawLayerQuad(const TransformationMatrix& drawMatrix,
59 SkRect& geometry, int textureId, float opacity,
60 bool forceBlending = false,
61 GLenum textureTarget = GL_TEXTURE_2D);
62 void drawVideoLayerQuad(const TransformationMatrix& drawMatrix,
63 float* textureMatrix, SkRect& geometry, int textureId);
64 void setViewRect(const IntRect& viewRect);
65 FloatRect rectInScreenCoord(const TransformationMatrix& drawMatrix,
67 FloatRect rectInInvScreenCoord(const TransformationMatrix& drawMatrix,
70 FloatRect rectInInvScreenCoord(const FloatRect& rect);
71 FloatRect rectInScreenCoord(const FloatRect& rect);
72 FloatRect convertInvScreenCoordToScreenCoord(const FloatRect& rect);
73 FloatRect convertScreenCoordToInvScreenCoord(const FloatRect& rect);
75 void setTitleBarHeight(int height) { m_titleBarHeight = height; }
76 void setWebViewRect(const IntRect& rect) { m_webViewRect = rect; }
77 void setScreenClip(const IntRect& clip);
78 void clip(const FloatRect& rect);
79 IntRect clippedRectWithViewport(const IntRect& rect, int margin = 0);
82 float contrast() { return m_contrast; }
83 void setContrast(float c) {
87 if (contrast > MAX_CONTRAST)
88 contrast = MAX_CONTRAST;
89 m_contrast = contrast;
93 GLuint loadShader(GLenum shaderType, const char* pSource);
94 GLuint createProgram(const char* vertexSource, const char* fragmentSource);
95 void setProjectionMatrix(SkRect& geometry, GLint projectionMatrixHandle);
97 void setBlendingState(bool enableBlending);
99 void drawQuadInternal(SkRect& geometry, GLint textureId, float opacity,
100 GLint program, GLint projectionMatrixHandle,
101 GLint texSampler, GLenum textureTarget,
102 GLint position, GLint alpha, GLint contrast = -1);
104 void drawLayerQuadInternal(const GLfloat* projectionMatrix, int textureId,
105 float opacity, GLenum textureTarget, GLint program,
106 GLint matrix, GLint texSample,
107 GLint position, GLint alpha, GLint contrast = -1);
109 bool m_blendingEnabled;
113 int m_surfTexOESProgram;
114 int m_surfTexOESProgramInverted;
116 TransformationMatrix m_projectionMatrix;
117 GLuint m_textureBuffer[1];
119 TransformationMatrix m_documentToScreenMatrix;
120 TransformationMatrix m_documentToInvScreenMatrix;
123 FloatRect m_clipRect;
124 IntRect m_screenClip;
125 int m_titleBarHeight;
126 IntRect m_webViewRect;
129 int m_hProjectionMatrix;
132 int m_hVideoProjectionMatrix;
133 int m_hVideoTextureMatrix;
134 int m_hVideoTexSampler;
136 GLint m_hSTOESProjectionMatrix;
138 GLint m_hSTOESTexSampler;
139 GLint m_hSTOESPosition;
141 GLint m_hSTOESProjectionMatrixInverted;
142 GLint m_hSTOESAlphaInverted;
143 GLint m_hSTOESContrastInverted;
144 GLint m_hSTOESTexSamplerInverted;
145 GLint m_hSTOESPositionInverted;
151 GLint m_hVideoPosition;
154 } // namespace WebCore
156 #endif // USE(ACCELERATED_COMPOSITING)
157 #endif // ShaderProgram_h