blob: d601f01dce647b5ee942a3d21fc23f05b5475cd4 [file] [log] [blame]
Romain Guyac670c02010-07-27 17:39:27 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include <utils/String8.h>
20
Romain Guya60c3882011-08-01 15:28:16 -070021#include "Caches.h"
Romain Guyac670c02010-07-27 17:39:27 -070022#include "ProgramCache.h"
23
24namespace android {
25namespace uirenderer {
26
27///////////////////////////////////////////////////////////////////////////////
Romain Guy707b2f72010-10-11 16:34:59 -070028// Defines
29///////////////////////////////////////////////////////////////////////////////
30
31#define MODULATE_OP_NO_MODULATE 0
32#define MODULATE_OP_MODULATE 1
33#define MODULATE_OP_MODULATE_A8 2
34
35///////////////////////////////////////////////////////////////////////////////
Romain Guyac670c02010-07-27 17:39:27 -070036// Vertex shaders snippets
37///////////////////////////////////////////////////////////////////////////////
38
Romain Guyac670c02010-07-27 17:39:27 -070039const char* gVS_Header_Attributes =
40 "attribute vec4 position;\n";
41const char* gVS_Header_Attributes_TexCoords =
42 "attribute vec2 texCoords;\n";
Chet Haase99585ad2011-05-02 15:00:16 -070043const char* gVS_Header_Attributes_AAParameters =
44 "attribute float vtxWidth;\n"
45 "attribute float vtxLength;\n";
Romain Guyaa6c24c2011-04-28 18:40:04 -070046const char* gVS_Header_Uniforms_TextureTransform =
47 "uniform mat4 mainTextureTransform;\n";
Romain Guyac670c02010-07-27 17:39:27 -070048const char* gVS_Header_Uniforms =
49 "uniform mat4 transform;\n";
Romain Guyed6fcb02011-03-21 13:11:28 -070050const char* gVS_Header_Uniforms_IsPoint =
Romain Guy80bbfb12011-03-23 16:56:28 -070051 "uniform mediump float pointSize;\n";
Romain Guyee916f12010-09-20 17:53:08 -070052const char* gVS_Header_Uniforms_HasGradient[3] = {
53 // Linear
Romain Guyee916f12010-09-20 17:53:08 -070054 "uniform mat4 screenSpace;\n",
55 // Circular
Romain Guyddb80be2010-09-20 19:04:33 -070056 "uniform mat4 screenSpace;\n",
Romain Guyee916f12010-09-20 17:53:08 -070057 // Sweep
Romain Guyee916f12010-09-20 17:53:08 -070058 "uniform mat4 screenSpace;\n"
59};
Romain Guy889f8d12010-07-29 14:37:42 -070060const char* gVS_Header_Uniforms_HasBitmap =
61 "uniform mat4 textureTransform;\n"
Romain Guy80bbfb12011-03-23 16:56:28 -070062 "uniform mediump vec2 textureDimension;\n";
Romain Guyac670c02010-07-27 17:39:27 -070063const char* gVS_Header_Varyings_HasTexture =
64 "varying vec2 outTexCoords;\n";
Chet Haase99585ad2011-05-02 15:00:16 -070065const char* gVS_Header_Varyings_IsAA =
66 "varying float widthProportion;\n"
67 "varying float lengthProportion;\n";
Romain Guy63553472012-07-18 20:04:14 -070068const char* gVS_Header_Varyings_HasBitmap =
69 "varying highp vec2 outBitmapTexCoords;\n";
70const char* gVS_Header_Varyings_PointHasBitmap =
71 "varying highp vec2 outPointBitmapTexCoords;\n";
Romain Guy8e025de2012-07-18 17:44:07 -070072// TODO: These values are used to sample from textures,
73// they may need to be highp
Romain Guy42e1e0d2012-07-30 14:47:51 -070074const char* gVS_Header_Varyings_HasGradient[6] = {
Romain Guyee916f12010-09-20 17:53:08 -070075 // Linear
Romain Guy63553472012-07-18 20:04:14 -070076 "varying highp vec2 linear;\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -070077 "varying highp float linear;\n",
Romain Guyee916f12010-09-20 17:53:08 -070078 // Circular
Romain Guy63553472012-07-18 20:04:14 -070079 "varying highp vec2 circular;\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -070080 "varying highp vec2 circular;\n",
Romain Guyee916f12010-09-20 17:53:08 -070081 // Sweep
Romain Guy42e1e0d2012-07-30 14:47:51 -070082 "varying highp vec2 sweep;\n",
83 "varying highp vec2 sweep;\n",
Romain Guyee916f12010-09-20 17:53:08 -070084};
Romain Guyac670c02010-07-27 17:39:27 -070085const char* gVS_Main =
86 "\nvoid main(void) {\n";
87const char* gVS_Main_OutTexCoords =
88 " outTexCoords = texCoords;\n";
Romain Guyaa6c24c2011-04-28 18:40:04 -070089const char* gVS_Main_OutTransformedTexCoords =
90 " outTexCoords = (mainTextureTransform * vec4(texCoords, 0.0, 1.0)).xy;\n";
Romain Guy42e1e0d2012-07-30 14:47:51 -070091const char* gVS_Main_OutGradient[6] = {
Romain Guyee916f12010-09-20 17:53:08 -070092 // Linear
Romain Guy7537f852010-10-11 14:38:28 -070093 " linear = vec2((screenSpace * position).x, 0.5);\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -070094 " linear = (screenSpace * position).x;\n",
Romain Guyee916f12010-09-20 17:53:08 -070095 // Circular
Romain Guy14830942010-10-07 15:07:45 -070096 " circular = (screenSpace * position).xy;\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -070097 " circular = (screenSpace * position).xy;\n",
Romain Guyee916f12010-09-20 17:53:08 -070098 // Sweep
Romain Guy42e1e0d2012-07-30 14:47:51 -070099 " sweep = (screenSpace * position).xy;\n",
100 " sweep = (screenSpace * position).xy;\n",
Romain Guyee916f12010-09-20 17:53:08 -0700101};
Romain Guy889f8d12010-07-29 14:37:42 -0700102const char* gVS_Main_OutBitmapTexCoords =
Romain Guy707b2f72010-10-11 16:34:59 -0700103 " outBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
Romain Guyed6fcb02011-03-21 13:11:28 -0700104const char* gVS_Main_OutPointBitmapTexCoords =
105 " outPointBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
Romain Guyac670c02010-07-27 17:39:27 -0700106const char* gVS_Main_Position =
107 " gl_Position = transform * position;\n";
Romain Guyed6fcb02011-03-21 13:11:28 -0700108const char* gVS_Main_PointSize =
109 " gl_PointSize = pointSize;\n";
Chet Haase99585ad2011-05-02 15:00:16 -0700110const char* gVS_Main_AA =
111 " widthProportion = vtxWidth;\n"
112 " lengthProportion = vtxLength;\n";
Romain Guyac670c02010-07-27 17:39:27 -0700113const char* gVS_Footer =
114 "}\n\n";
115
116///////////////////////////////////////////////////////////////////////////////
117// Fragment shaders snippets
118///////////////////////////////////////////////////////////////////////////////
119
Romain Guya5aed0d2010-09-09 14:42:43 -0700120const char* gFS_Header_Extension_FramebufferFetch =
121 "#extension GL_NV_shader_framebuffer_fetch : enable\n\n";
Romain Guyaa6c24c2011-04-28 18:40:04 -0700122const char* gFS_Header_Extension_ExternalTexture =
123 "#extension GL_OES_EGL_image_external : require\n\n";
Romain Guyac670c02010-07-27 17:39:27 -0700124const char* gFS_Header =
125 "precision mediump float;\n\n";
126const char* gFS_Uniforms_Color =
127 "uniform vec4 color;\n";
Chet Haase99585ad2011-05-02 15:00:16 -0700128const char* gFS_Uniforms_AA =
Chet Haase5b0200b2011-04-13 17:58:08 -0700129 "uniform float boundaryWidth;\n"
Chet Haase99585ad2011-05-02 15:00:16 -0700130 "uniform float inverseBoundaryWidth;\n"
131 "uniform float boundaryLength;\n"
132 "uniform float inverseBoundaryLength;\n";
Romain Guyed6fcb02011-03-21 13:11:28 -0700133const char* gFS_Header_Uniforms_PointHasBitmap =
134 "uniform vec2 textureDimension;\n"
135 "uniform float pointSize;\n";
Romain Guyac670c02010-07-27 17:39:27 -0700136const char* gFS_Uniforms_TextureSampler =
137 "uniform sampler2D sampler;\n";
Romain Guyaa6c24c2011-04-28 18:40:04 -0700138const char* gFS_Uniforms_ExternalTextureSampler =
139 "uniform samplerExternalOES sampler;\n";
Romain Guy42e1e0d2012-07-30 14:47:51 -0700140const char* gFS_Uniforms_GradientSampler[6] = {
Romain Guyee916f12010-09-20 17:53:08 -0700141 // Linear
142 "uniform sampler2D gradientSampler;\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -0700143 "uniform vec4 startColor;\n"
144 "uniform vec4 endColor;\n",
Romain Guyee916f12010-09-20 17:53:08 -0700145 // Circular
146 "uniform sampler2D gradientSampler;\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -0700147 "uniform vec4 startColor;\n"
148 "uniform vec4 endColor;\n",
Romain Guyee916f12010-09-20 17:53:08 -0700149 // Sweep
Romain Guy42e1e0d2012-07-30 14:47:51 -0700150 "uniform sampler2D gradientSampler;\n",
151 "uniform vec4 startColor;\n"
152 "uniform vec4 endColor;\n",
Romain Guyee916f12010-09-20 17:53:08 -0700153};
Romain Guyac670c02010-07-27 17:39:27 -0700154const char* gFS_Uniforms_BitmapSampler =
155 "uniform sampler2D bitmapSampler;\n";
156const char* gFS_Uniforms_ColorOp[4] = {
157 // None
158 "",
159 // Matrix
160 "uniform mat4 colorMatrix;\n"
161 "uniform vec4 colorMatrixVector;\n",
162 // Lighting
Romain Guydb1938e2010-08-02 18:50:22 -0700163 "uniform vec4 lightingMul;\n"
164 "uniform vec4 lightingAdd;\n",
Romain Guyac670c02010-07-27 17:39:27 -0700165 // PorterDuff
Romain Guydb1938e2010-08-02 18:50:22 -0700166 "uniform vec4 colorBlend;\n"
Romain Guyac670c02010-07-27 17:39:27 -0700167};
Romain Guy41210632012-07-16 17:04:24 -0700168const char* gFS_Uniforms_Gamma =
169 "uniform float gamma;\n";
170
Romain Guyac670c02010-07-27 17:39:27 -0700171const char* gFS_Main =
172 "\nvoid main(void) {\n"
Romain Guy7fbcc042010-08-04 15:40:07 -0700173 " lowp vec4 fragColor;\n";
Romain Guy707b2f72010-10-11 16:34:59 -0700174
Romain Guyed6fcb02011-03-21 13:11:28 -0700175const char* gFS_Main_PointBitmapTexCoords =
Romain Guy63553472012-07-18 20:04:14 -0700176 " highp vec2 outBitmapTexCoords = outPointBitmapTexCoords + "
Romain Guyed6fcb02011-03-21 13:11:28 -0700177 "((gl_PointCoord - vec2(0.5, 0.5)) * textureDimension * vec2(pointSize, pointSize));\n";
178
Romain Guy707b2f72010-10-11 16:34:59 -0700179// Fast cases
180const char* gFS_Fast_SingleColor =
181 "\nvoid main(void) {\n"
182 " gl_FragColor = color;\n"
183 "}\n\n";
184const char* gFS_Fast_SingleTexture =
185 "\nvoid main(void) {\n"
186 " gl_FragColor = texture2D(sampler, outTexCoords);\n"
187 "}\n\n";
188const char* gFS_Fast_SingleModulateTexture =
189 "\nvoid main(void) {\n"
190 " gl_FragColor = color.a * texture2D(sampler, outTexCoords);\n"
191 "}\n\n";
192const char* gFS_Fast_SingleA8Texture =
193 "\nvoid main(void) {\n"
Romain Guy9db91242010-10-12 13:13:09 -0700194 " gl_FragColor = texture2D(sampler, outTexCoords);\n"
Romain Guy707b2f72010-10-11 16:34:59 -0700195 "}\n\n";
Romain Guy41210632012-07-16 17:04:24 -0700196const char* gFS_Fast_SingleA8Texture_ApplyGamma =
197 "\nvoid main(void) {\n"
198 " gl_FragColor = vec4(0.0, 0.0, 0.0, pow(texture2D(sampler, outTexCoords).a, gamma));\n"
199 "}\n\n";
Romain Guy707b2f72010-10-11 16:34:59 -0700200const char* gFS_Fast_SingleModulateA8Texture =
201 "\nvoid main(void) {\n"
202 " gl_FragColor = color * texture2D(sampler, outTexCoords).a;\n"
203 "}\n\n";
Romain Guy41210632012-07-16 17:04:24 -0700204const char* gFS_Fast_SingleModulateA8Texture_ApplyGamma =
205 "\nvoid main(void) {\n"
206 " gl_FragColor = color * pow(texture2D(sampler, outTexCoords).a, gamma);\n"
207 "}\n\n";
Romain Guy42e1e0d2012-07-30 14:47:51 -0700208const char* gFS_Fast_SingleGradient[2] = {
Romain Guy707b2f72010-10-11 16:34:59 -0700209 "\nvoid main(void) {\n"
210 " gl_FragColor = texture2D(gradientSampler, linear);\n"
Romain Guy42e1e0d2012-07-30 14:47:51 -0700211 "}\n\n",
212 "\nvoid main(void) {\n"
213 " gl_FragColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n"
214 "}\n\n"
215};
216const char* gFS_Fast_SingleModulateGradient[2] = {
Romain Guy707b2f72010-10-11 16:34:59 -0700217 "\nvoid main(void) {\n"
218 " gl_FragColor = color.a * texture2D(gradientSampler, linear);\n"
Romain Guy42e1e0d2012-07-30 14:47:51 -0700219 "}\n\n",
220 "\nvoid main(void) {\n"
221 " gl_FragColor = color.a * mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n"
222 "}\n\n"
223};
Romain Guy707b2f72010-10-11 16:34:59 -0700224
225// General case
Romain Guyac670c02010-07-27 17:39:27 -0700226const char* gFS_Main_FetchColor =
227 " fragColor = color;\n";
Romain Guy740bf2b2011-04-26 15:33:10 -0700228const char* gFS_Main_ModulateColor =
229 " fragColor *= color.a;\n";
Romain Guy41210632012-07-16 17:04:24 -0700230const char* gFS_Main_ModulateColor_ApplyGamma =
231 " fragColor *= pow(color.a, gamma);\n";
Chet Haase99585ad2011-05-02 15:00:16 -0700232const char* gFS_Main_AccountForAA =
233 " if (widthProportion < boundaryWidth) {\n"
234 " fragColor *= (widthProportion * inverseBoundaryWidth);\n"
235 " } else if (widthProportion > (1.0 - boundaryWidth)) {\n"
236 " fragColor *= ((1.0 - widthProportion) * inverseBoundaryWidth);\n"
237 " }\n"
238 " if (lengthProportion < boundaryLength) {\n"
239 " fragColor *= (lengthProportion * inverseBoundaryLength);\n"
240 " } else if (lengthProportion > (1.0 - boundaryLength)) {\n"
241 " fragColor *= ((1.0 - lengthProportion) * inverseBoundaryLength);\n"
Chet Haase5b0200b2011-04-13 17:58:08 -0700242 " }\n";
Romain Guy707b2f72010-10-11 16:34:59 -0700243const char* gFS_Main_FetchTexture[2] = {
244 // Don't modulate
245 " fragColor = texture2D(sampler, outTexCoords);\n",
246 // Modulate
247 " fragColor = color * texture2D(sampler, outTexCoords);\n"
248};
249const char* gFS_Main_FetchA8Texture[2] = {
250 // Don't modulate
Romain Guy9db91242010-10-12 13:13:09 -0700251 " fragColor = texture2D(sampler, outTexCoords);\n",
Romain Guy707b2f72010-10-11 16:34:59 -0700252 // Modulate
253 " fragColor = color * texture2D(sampler, outTexCoords).a;\n"
254};
Romain Guy42e1e0d2012-07-30 14:47:51 -0700255const char* gFS_Main_FetchGradient[6] = {
Romain Guyee916f12010-09-20 17:53:08 -0700256 // Linear
Romain Guy7537f852010-10-11 14:38:28 -0700257 " vec4 gradientColor = texture2D(gradientSampler, linear);\n",
Romain Guy42e1e0d2012-07-30 14:47:51 -0700258 " vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
Romain Guyee916f12010-09-20 17:53:08 -0700259 // Circular
Romain Guy42e1e0d2012-07-30 14:47:51 -0700260 " vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",
261 " vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
Romain Guyee916f12010-09-20 17:53:08 -0700262 // Sweep
Romain Guy63553472012-07-18 20:04:14 -0700263 " highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
Romain Guy42e1e0d2012-07-30 14:47:51 -0700264 " vec4 gradientColor = texture2D(gradientSampler, vec2(index - floor(index), 0.5));\n",
265 " highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
266 " vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
Romain Guyee916f12010-09-20 17:53:08 -0700267};
Romain Guyac670c02010-07-27 17:39:27 -0700268const char* gFS_Main_FetchBitmap =
269 " vec4 bitmapColor = texture2D(bitmapSampler, outBitmapTexCoords);\n";
Romain Guy889f8d12010-07-29 14:37:42 -0700270const char* gFS_Main_FetchBitmapNpot =
271 " vec4 bitmapColor = texture2D(bitmapSampler, wrap(outBitmapTexCoords));\n";
Romain Guyac670c02010-07-27 17:39:27 -0700272const char* gFS_Main_BlendShadersBG =
Romain Guyac670c02010-07-27 17:39:27 -0700273 " fragColor = blendShaders(gradientColor, bitmapColor)";
Romain Guy06f96e22010-07-30 19:18:16 -0700274const char* gFS_Main_BlendShadersGB =
275 " fragColor = blendShaders(bitmapColor, gradientColor)";
Romain Guy707b2f72010-10-11 16:34:59 -0700276const char* gFS_Main_BlendShaders_Modulate[3] = {
277 // Don't modulate
278 ";\n",
279 // Modulate
280 " * fragColor.a;\n",
281 // Modulate with alpha 8 texture
282 " * texture2D(sampler, outTexCoords).a;\n"
283};
284const char* gFS_Main_GradientShader_Modulate[3] = {
285 // Don't modulate
286 " fragColor = gradientColor;\n",
287 // Modulate
288 " fragColor = gradientColor * fragColor.a;\n",
289 // Modulate with alpha 8 texture
290 " fragColor = gradientColor * texture2D(sampler, outTexCoords).a;\n"
291 };
292const char* gFS_Main_BitmapShader_Modulate[3] = {
293 // Don't modulate
294 " fragColor = bitmapColor;\n",
295 // Modulate
296 " fragColor = bitmapColor * fragColor.a;\n",
297 // Modulate with alpha 8 texture
298 " fragColor = bitmapColor * texture2D(sampler, outTexCoords).a;\n"
299 };
Romain Guyac670c02010-07-27 17:39:27 -0700300const char* gFS_Main_FragColor =
301 " gl_FragColor = fragColor;\n";
Romain Guya5aed0d2010-09-09 14:42:43 -0700302const char* gFS_Main_FragColor_Blend =
303 " gl_FragColor = blendFramebuffer(fragColor, gl_LastFragColor);\n";
Romain Guyf607bdc2010-09-10 19:20:06 -0700304const char* gFS_Main_FragColor_Blend_Swap =
305 " gl_FragColor = blendFramebuffer(gl_LastFragColor, fragColor);\n";
Romain Guyac670c02010-07-27 17:39:27 -0700306const char* gFS_Main_ApplyColorOp[4] = {
307 // None
308 "",
309 // Matrix
Romain Guydb1938e2010-08-02 18:50:22 -0700310 // TODO: Fix premultiplied alpha computations for color matrix
Romain Guyac670c02010-07-27 17:39:27 -0700311 " fragColor *= colorMatrix;\n"
Romain Guydb1938e2010-08-02 18:50:22 -0700312 " fragColor += colorMatrixVector;\n"
313 " fragColor.rgb *= fragColor.a;\n",
Romain Guyac670c02010-07-27 17:39:27 -0700314 // Lighting
Romain Guydb1938e2010-08-02 18:50:22 -0700315 " float lightingAlpha = fragColor.a;\n"
316 " fragColor = min(fragColor * lightingMul + (lightingAdd * lightingAlpha), lightingAlpha);\n"
317 " fragColor.a = lightingAlpha;\n",
Romain Guyac670c02010-07-27 17:39:27 -0700318 // PorterDuff
319 " fragColor = blendColors(colorBlend, fragColor);\n"
320};
321const char* gFS_Footer =
322 "}\n\n";
323
324///////////////////////////////////////////////////////////////////////////////
325// PorterDuff snippets
326///////////////////////////////////////////////////////////////////////////////
327
Romain Guy48daa542010-08-10 19:21:34 -0700328const char* gBlendOps[18] = {
Romain Guyac670c02010-07-27 17:39:27 -0700329 // Clear
330 "return vec4(0.0, 0.0, 0.0, 0.0);\n",
331 // Src
332 "return src;\n",
333 // Dst
334 "return dst;\n",
335 // SrcOver
Romain Guy06f96e22010-07-30 19:18:16 -0700336 "return src + dst * (1.0 - src.a);\n",
Romain Guyac670c02010-07-27 17:39:27 -0700337 // DstOver
Romain Guy06f96e22010-07-30 19:18:16 -0700338 "return dst + src * (1.0 - dst.a);\n",
Romain Guyac670c02010-07-27 17:39:27 -0700339 // SrcIn
Romain Guy06f96e22010-07-30 19:18:16 -0700340 "return src * dst.a;\n",
Romain Guyac670c02010-07-27 17:39:27 -0700341 // DstIn
Romain Guy06f96e22010-07-30 19:18:16 -0700342 "return dst * src.a;\n",
Romain Guyac670c02010-07-27 17:39:27 -0700343 // SrcOut
Romain Guy06f96e22010-07-30 19:18:16 -0700344 "return src * (1.0 - dst.a);\n",
Romain Guyac670c02010-07-27 17:39:27 -0700345 // DstOut
Romain Guy06f96e22010-07-30 19:18:16 -0700346 "return dst * (1.0 - src.a);\n",
Romain Guyac670c02010-07-27 17:39:27 -0700347 // SrcAtop
348 "return vec4(src.rgb * dst.a + (1.0 - src.a) * dst.rgb, dst.a);\n",
349 // DstAtop
350 "return vec4(dst.rgb * src.a + (1.0 - dst.a) * src.rgb, src.a);\n",
351 // Xor
Romain Guy48daa542010-08-10 19:21:34 -0700352 "return vec4(src.rgb * (1.0 - dst.a) + (1.0 - src.a) * dst.rgb, "
Romain Guyac670c02010-07-27 17:39:27 -0700353 "src.a + dst.a - 2.0 * src.a * dst.a);\n",
Romain Guy48daa542010-08-10 19:21:34 -0700354 // Add
355 "return min(src + dst, 1.0);\n",
356 // Multiply
357 "return src * dst;\n",
358 // Screen
359 "return src + dst - src * dst;\n",
360 // Overlay
361 "return clamp(vec4(mix("
362 "2.0 * src.rgb * dst.rgb + src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a), "
363 "src.a * dst.a - 2.0 * (dst.a - dst.rgb) * (src.a - src.rgb) + src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a), "
364 "step(dst.a, 2.0 * dst.rgb)), "
365 "src.a + dst.a - src.a * dst.a), 0.0, 1.0);\n",
366 // Darken
367 "return vec4(src.rgb * (1.0 - dst.a) + (1.0 - src.a) * dst.rgb + "
368 "min(src.rgb * dst.a, dst.rgb * src.a), src.a + dst.a - src.a * dst.a);\n",
369 // Lighten
370 "return vec4(src.rgb * (1.0 - dst.a) + (1.0 - src.a) * dst.rgb + "
371 "max(src.rgb * dst.a, dst.rgb * src.a), src.a + dst.a - src.a * dst.a);\n",
Romain Guyac670c02010-07-27 17:39:27 -0700372};
373
374///////////////////////////////////////////////////////////////////////////////
375// Constructors/destructors
376///////////////////////////////////////////////////////////////////////////////
377
378ProgramCache::ProgramCache() {
379}
380
381ProgramCache::~ProgramCache() {
382 clear();
383}
384
385///////////////////////////////////////////////////////////////////////////////
386// Cache management
387///////////////////////////////////////////////////////////////////////////////
388
389void ProgramCache::clear() {
Romain Guy67f27952010-12-07 20:09:23 -0800390 PROGRAM_LOGD("Clearing program cache");
391
Romain Guyac670c02010-07-27 17:39:27 -0700392 size_t count = mCache.size();
393 for (size_t i = 0; i < count; i++) {
394 delete mCache.valueAt(i);
395 }
396 mCache.clear();
397}
398
399Program* ProgramCache::get(const ProgramDescription& description) {
400 programid key = description.key();
401 ssize_t index = mCache.indexOfKey(key);
402 Program* program = NULL;
403 if (index < 0) {
Romain Guyee916f12010-09-20 17:53:08 -0700404 description.log("Could not find program");
Romain Guyac670c02010-07-27 17:39:27 -0700405 program = generateProgram(description, key);
406 mCache.add(key, program);
407 } else {
408 program = mCache.valueAt(index);
409 }
410 return program;
411}
412
413///////////////////////////////////////////////////////////////////////////////
414// Program generation
415///////////////////////////////////////////////////////////////////////////////
416
417Program* ProgramCache::generateProgram(const ProgramDescription& description, programid key) {
418 String8 vertexShader = generateVertexShader(description);
419 String8 fragmentShader = generateFragmentShader(description);
420
Romain Guy42e1e0d2012-07-30 14:47:51 -0700421 return new Program(description, vertexShader.string(), fragmentShader.string());
422}
423
424static inline size_t gradientIndex(const ProgramDescription& description) {
425 return description.gradientType * 2 + description.isSimpleGradient;
Romain Guyac670c02010-07-27 17:39:27 -0700426}
427
428String8 ProgramCache::generateVertexShader(const ProgramDescription& description) {
429 // Add attributes
430 String8 shader(gVS_Header_Attributes);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700431 if (description.hasTexture || description.hasExternalTexture) {
Romain Guyac670c02010-07-27 17:39:27 -0700432 shader.append(gVS_Header_Attributes_TexCoords);
433 }
Chet Haase99585ad2011-05-02 15:00:16 -0700434 if (description.isAA) {
435 shader.append(gVS_Header_Attributes_AAParameters);
Chet Haase5b0200b2011-04-13 17:58:08 -0700436 }
Romain Guyac670c02010-07-27 17:39:27 -0700437 // Uniforms
438 shader.append(gVS_Header_Uniforms);
Romain Guy8f0095c2011-05-02 17:24:22 -0700439 if (description.hasTextureTransform) {
Romain Guyaa6c24c2011-04-28 18:40:04 -0700440 shader.append(gVS_Header_Uniforms_TextureTransform);
441 }
Romain Guyac670c02010-07-27 17:39:27 -0700442 if (description.hasGradient) {
Romain Guyee916f12010-09-20 17:53:08 -0700443 shader.append(gVS_Header_Uniforms_HasGradient[description.gradientType]);
Romain Guyac670c02010-07-27 17:39:27 -0700444 }
Romain Guy889f8d12010-07-29 14:37:42 -0700445 if (description.hasBitmap) {
446 shader.append(gVS_Header_Uniforms_HasBitmap);
447 }
Romain Guyed6fcb02011-03-21 13:11:28 -0700448 if (description.isPoint) {
449 shader.append(gVS_Header_Uniforms_IsPoint);
450 }
Romain Guyac670c02010-07-27 17:39:27 -0700451 // Varyings
Romain Guyaa6c24c2011-04-28 18:40:04 -0700452 if (description.hasTexture || description.hasExternalTexture) {
Romain Guyac670c02010-07-27 17:39:27 -0700453 shader.append(gVS_Header_Varyings_HasTexture);
454 }
Chet Haase99585ad2011-05-02 15:00:16 -0700455 if (description.isAA) {
456 shader.append(gVS_Header_Varyings_IsAA);
Chet Haase5b0200b2011-04-13 17:58:08 -0700457 }
Romain Guyac670c02010-07-27 17:39:27 -0700458 if (description.hasGradient) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700459 shader.append(gVS_Header_Varyings_HasGradient[gradientIndex(description)]);
Romain Guyac670c02010-07-27 17:39:27 -0700460 }
461 if (description.hasBitmap) {
Romain Guyed6fcb02011-03-21 13:11:28 -0700462 shader.append(description.isPoint ?
Romain Guy63553472012-07-18 20:04:14 -0700463 gVS_Header_Varyings_PointHasBitmap :
464 gVS_Header_Varyings_HasBitmap);
Romain Guyac670c02010-07-27 17:39:27 -0700465 }
466
467 // Begin the shader
468 shader.append(gVS_Main); {
Romain Guy8f0095c2011-05-02 17:24:22 -0700469 if (description.hasTextureTransform) {
Romain Guyaa6c24c2011-04-28 18:40:04 -0700470 shader.append(gVS_Main_OutTransformedTexCoords);
Romain Guy8f0095c2011-05-02 17:24:22 -0700471 } else if (description.hasTexture || description.hasExternalTexture) {
472 shader.append(gVS_Main_OutTexCoords);
Romain Guyaa6c24c2011-04-28 18:40:04 -0700473 }
Chet Haase99585ad2011-05-02 15:00:16 -0700474 if (description.isAA) {
475 shader.append(gVS_Main_AA);
Chet Haase5b0200b2011-04-13 17:58:08 -0700476 }
Romain Guyac670c02010-07-27 17:39:27 -0700477 if (description.hasGradient) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700478 shader.append(gVS_Main_OutGradient[gradientIndex(description)]);
Romain Guyac670c02010-07-27 17:39:27 -0700479 }
Romain Guy889f8d12010-07-29 14:37:42 -0700480 if (description.hasBitmap) {
Romain Guyed6fcb02011-03-21 13:11:28 -0700481 shader.append(description.isPoint ?
482 gVS_Main_OutPointBitmapTexCoords :
483 gVS_Main_OutBitmapTexCoords);
484 }
485 if (description.isPoint) {
486 shader.append(gVS_Main_PointSize);
Romain Guy889f8d12010-07-29 14:37:42 -0700487 }
Romain Guyac670c02010-07-27 17:39:27 -0700488 // Output transformed position
489 shader.append(gVS_Main_Position);
490 }
491 // End the shader
492 shader.append(gVS_Footer);
493
494 PROGRAM_LOGD("*** Generated vertex shader:\n\n%s", shader.string());
495
496 return shader;
497}
498
499String8 ProgramCache::generateFragmentShader(const ProgramDescription& description) {
Romain Guya5aed0d2010-09-09 14:42:43 -0700500 String8 shader;
501
Romain Guy707b2f72010-10-11 16:34:59 -0700502 const bool blendFramebuffer = description.framebufferMode >= SkXfermode::kPlus_Mode;
Romain Guya5aed0d2010-09-09 14:42:43 -0700503 if (blendFramebuffer) {
504 shader.append(gFS_Header_Extension_FramebufferFetch);
505 }
Romain Guyaa6c24c2011-04-28 18:40:04 -0700506 if (description.hasExternalTexture) {
507 shader.append(gFS_Header_Extension_ExternalTexture);
508 }
Romain Guya5aed0d2010-09-09 14:42:43 -0700509
510 shader.append(gFS_Header);
Romain Guyac670c02010-07-27 17:39:27 -0700511
512 // Varyings
Romain Guyaa6c24c2011-04-28 18:40:04 -0700513 if (description.hasTexture || description.hasExternalTexture) {
Romain Guyac670c02010-07-27 17:39:27 -0700514 shader.append(gVS_Header_Varyings_HasTexture);
515 }
Chet Haase99585ad2011-05-02 15:00:16 -0700516 if (description.isAA) {
517 shader.append(gVS_Header_Varyings_IsAA);
Chet Haase5b0200b2011-04-13 17:58:08 -0700518 }
Romain Guyac670c02010-07-27 17:39:27 -0700519 if (description.hasGradient) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700520 shader.append(gVS_Header_Varyings_HasGradient[gradientIndex(description)]);
Romain Guyac670c02010-07-27 17:39:27 -0700521 }
522 if (description.hasBitmap) {
Romain Guyed6fcb02011-03-21 13:11:28 -0700523 shader.append(description.isPoint ?
Romain Guy63553472012-07-18 20:04:14 -0700524 gVS_Header_Varyings_PointHasBitmap :
525 gVS_Header_Varyings_HasBitmap);
Romain Guyac670c02010-07-27 17:39:27 -0700526 }
527
Romain Guyac670c02010-07-27 17:39:27 -0700528 // Uniforms
Romain Guy707b2f72010-10-11 16:34:59 -0700529 int modulateOp = MODULATE_OP_NO_MODULATE;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700530 const bool singleColor = !description.hasTexture && !description.hasExternalTexture &&
Romain Guy707b2f72010-10-11 16:34:59 -0700531 !description.hasGradient && !description.hasBitmap;
532
533 if (description.modulate || singleColor) {
534 shader.append(gFS_Uniforms_Color);
535 if (!singleColor) modulateOp = MODULATE_OP_MODULATE;
536 }
Romain Guyac670c02010-07-27 17:39:27 -0700537 if (description.hasTexture) {
538 shader.append(gFS_Uniforms_TextureSampler);
Romain Guy8f0095c2011-05-02 17:24:22 -0700539 } else if (description.hasExternalTexture) {
Romain Guyaa6c24c2011-04-28 18:40:04 -0700540 shader.append(gFS_Uniforms_ExternalTextureSampler);
541 }
Chet Haase99585ad2011-05-02 15:00:16 -0700542 if (description.isAA) {
543 shader.append(gFS_Uniforms_AA);
Chet Haase5b0200b2011-04-13 17:58:08 -0700544 }
Romain Guyac670c02010-07-27 17:39:27 -0700545 if (description.hasGradient) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700546 shader.append(gFS_Uniforms_GradientSampler[gradientIndex(description)]);
Romain Guyac670c02010-07-27 17:39:27 -0700547 }
Romain Guyed6fcb02011-03-21 13:11:28 -0700548 if (description.hasBitmap && description.isPoint) {
549 shader.append(gFS_Header_Uniforms_PointHasBitmap);
550 }
Romain Guy41210632012-07-16 17:04:24 -0700551 if (description.hasGammaCorrection) {
552 shader.append(gFS_Uniforms_Gamma);
553 }
Romain Guy707b2f72010-10-11 16:34:59 -0700554
555 // Optimization for common cases
Chet Haase99585ad2011-05-02 15:00:16 -0700556 if (!description.isAA && !blendFramebuffer &&
Chet Haase5b0200b2011-04-13 17:58:08 -0700557 description.colorOp == ProgramDescription::kColorNone && !description.isPoint) {
Romain Guy707b2f72010-10-11 16:34:59 -0700558 bool fast = false;
559
560 const bool noShader = !description.hasGradient && !description.hasBitmap;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700561 const bool singleTexture = (description.hasTexture || description.hasExternalTexture) &&
Romain Guy707b2f72010-10-11 16:34:59 -0700562 !description.hasAlpha8Texture && noShader;
563 const bool singleA8Texture = description.hasTexture &&
564 description.hasAlpha8Texture && noShader;
Romain Guyaa6c24c2011-04-28 18:40:04 -0700565 const bool singleGradient = !description.hasTexture && !description.hasExternalTexture &&
Romain Guy707b2f72010-10-11 16:34:59 -0700566 description.hasGradient && !description.hasBitmap &&
567 description.gradientType == ProgramDescription::kGradientLinear;
568
569 if (singleColor) {
570 shader.append(gFS_Fast_SingleColor);
571 fast = true;
572 } else if (singleTexture) {
573 if (!description.modulate) {
574 shader.append(gFS_Fast_SingleTexture);
575 } else {
576 shader.append(gFS_Fast_SingleModulateTexture);
577 }
578 fast = true;
579 } else if (singleA8Texture) {
580 if (!description.modulate) {
Romain Guy41210632012-07-16 17:04:24 -0700581 if (description.hasGammaCorrection) {
582 shader.append(gFS_Fast_SingleA8Texture_ApplyGamma);
583 } else {
584 shader.append(gFS_Fast_SingleA8Texture);
585 }
Romain Guy707b2f72010-10-11 16:34:59 -0700586 } else {
Romain Guy41210632012-07-16 17:04:24 -0700587 if (description.hasGammaCorrection) {
588 shader.append(gFS_Fast_SingleModulateA8Texture_ApplyGamma);
589 } else {
590 shader.append(gFS_Fast_SingleModulateA8Texture);
591 }
Romain Guy707b2f72010-10-11 16:34:59 -0700592 }
593 fast = true;
594 } else if (singleGradient) {
595 if (!description.modulate) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700596 shader.append(gFS_Fast_SingleGradient[description.isSimpleGradient]);
Romain Guy707b2f72010-10-11 16:34:59 -0700597 } else {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700598 shader.append(gFS_Fast_SingleModulateGradient[description.isSimpleGradient]);
Romain Guy707b2f72010-10-11 16:34:59 -0700599 }
600 fast = true;
601 }
602
603 if (fast) {
Romain Guyc15008e2010-11-10 11:59:15 -0800604#if DEBUG_PROGRAMS
Romain Guy707b2f72010-10-11 16:34:59 -0700605 PROGRAM_LOGD("*** Fast case:\n");
606 PROGRAM_LOGD("*** Generated fragment shader:\n\n");
607 printLongString(shader);
Romain Guyc15008e2010-11-10 11:59:15 -0800608#endif
Romain Guy707b2f72010-10-11 16:34:59 -0700609
610 return shader;
611 }
612 }
613
Romain Guyac670c02010-07-27 17:39:27 -0700614 if (description.hasBitmap) {
615 shader.append(gFS_Uniforms_BitmapSampler);
616 }
617 shader.append(gFS_Uniforms_ColorOp[description.colorOp]);
618
619 // Generate required functions
620 if (description.hasGradient && description.hasBitmap) {
Romain Guy48daa542010-08-10 19:21:34 -0700621 generateBlend(shader, "blendShaders", description.shadersMode);
Romain Guyac670c02010-07-27 17:39:27 -0700622 }
623 if (description.colorOp == ProgramDescription::kColorBlend) {
Romain Guy48daa542010-08-10 19:21:34 -0700624 generateBlend(shader, "blendColors", description.colorMode);
Romain Guyac670c02010-07-27 17:39:27 -0700625 }
Romain Guya5aed0d2010-09-09 14:42:43 -0700626 if (blendFramebuffer) {
627 generateBlend(shader, "blendFramebuffer", description.framebufferMode);
628 }
Romain Guy889f8d12010-07-29 14:37:42 -0700629 if (description.isBitmapNpot) {
630 generateTextureWrap(shader, description.bitmapWrapS, description.bitmapWrapT);
631 }
Romain Guyac670c02010-07-27 17:39:27 -0700632
633 // Begin the shader
634 shader.append(gFS_Main); {
635 // Stores the result in fragColor directly
Romain Guyaa6c24c2011-04-28 18:40:04 -0700636 if (description.hasTexture || description.hasExternalTexture) {
Romain Guyac670c02010-07-27 17:39:27 -0700637 if (description.hasAlpha8Texture) {
Romain Guy707b2f72010-10-11 16:34:59 -0700638 if (!description.hasGradient && !description.hasBitmap) {
639 shader.append(gFS_Main_FetchA8Texture[modulateOp]);
640 }
Romain Guyac670c02010-07-27 17:39:27 -0700641 } else {
Romain Guy707b2f72010-10-11 16:34:59 -0700642 shader.append(gFS_Main_FetchTexture[modulateOp]);
Romain Guyac670c02010-07-27 17:39:27 -0700643 }
644 } else {
Romain Guy707b2f72010-10-11 16:34:59 -0700645 if ((!description.hasGradient && !description.hasBitmap) || description.modulate) {
646 shader.append(gFS_Main_FetchColor);
647 }
Romain Guyac670c02010-07-27 17:39:27 -0700648 }
Chet Haase99585ad2011-05-02 15:00:16 -0700649 if (description.isAA) {
650 shader.append(gFS_Main_AccountForAA);
Chet Haase5b0200b2011-04-13 17:58:08 -0700651 }
Romain Guyac670c02010-07-27 17:39:27 -0700652 if (description.hasGradient) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700653 shader.append(gFS_Main_FetchGradient[gradientIndex(description)]);
Romain Guyac670c02010-07-27 17:39:27 -0700654 }
655 if (description.hasBitmap) {
Romain Guyed6fcb02011-03-21 13:11:28 -0700656 if (description.isPoint) {
657 shader.append(gFS_Main_PointBitmapTexCoords);
658 }
Romain Guy889f8d12010-07-29 14:37:42 -0700659 if (!description.isBitmapNpot) {
660 shader.append(gFS_Main_FetchBitmap);
661 } else {
662 shader.append(gFS_Main_FetchBitmapNpot);
663 }
Romain Guyac670c02010-07-27 17:39:27 -0700664 }
Romain Guy740bf2b2011-04-26 15:33:10 -0700665 bool applyModulate = false;
Romain Guyac670c02010-07-27 17:39:27 -0700666 // Case when we have two shaders set
667 if (description.hasGradient && description.hasBitmap) {
Romain Guy707b2f72010-10-11 16:34:59 -0700668 int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp;
Romain Guyac670c02010-07-27 17:39:27 -0700669 if (description.isBitmapFirst) {
670 shader.append(gFS_Main_BlendShadersBG);
671 } else {
672 shader.append(gFS_Main_BlendShadersGB);
673 }
Romain Guy707b2f72010-10-11 16:34:59 -0700674 shader.append(gFS_Main_BlendShaders_Modulate[op]);
Romain Guy740bf2b2011-04-26 15:33:10 -0700675 applyModulate = true;
Romain Guy889f8d12010-07-29 14:37:42 -0700676 } else {
677 if (description.hasGradient) {
Romain Guy707b2f72010-10-11 16:34:59 -0700678 int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp;
679 shader.append(gFS_Main_GradientShader_Modulate[op]);
Romain Guy740bf2b2011-04-26 15:33:10 -0700680 applyModulate = true;
Romain Guy889f8d12010-07-29 14:37:42 -0700681 } else if (description.hasBitmap) {
Romain Guy707b2f72010-10-11 16:34:59 -0700682 int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp;
683 shader.append(gFS_Main_BitmapShader_Modulate[op]);
Romain Guy740bf2b2011-04-26 15:33:10 -0700684 applyModulate = true;
Romain Guy889f8d12010-07-29 14:37:42 -0700685 }
Romain Guyac670c02010-07-27 17:39:27 -0700686 }
Romain Guy740bf2b2011-04-26 15:33:10 -0700687 if (description.modulate && applyModulate) {
Romain Guy41210632012-07-16 17:04:24 -0700688 if (description.hasGammaCorrection) {
689 shader.append(gFS_Main_ModulateColor_ApplyGamma);
690 } else {
691 shader.append(gFS_Main_ModulateColor);
692 }
Romain Guy740bf2b2011-04-26 15:33:10 -0700693 }
Romain Guyac670c02010-07-27 17:39:27 -0700694 // Apply the color op if needed
695 shader.append(gFS_Main_ApplyColorOp[description.colorOp]);
696 // Output the fragment
Romain Guya5aed0d2010-09-09 14:42:43 -0700697 if (!blendFramebuffer) {
698 shader.append(gFS_Main_FragColor);
699 } else {
Romain Guyf607bdc2010-09-10 19:20:06 -0700700 shader.append(!description.swapSrcDst ?
701 gFS_Main_FragColor_Blend : gFS_Main_FragColor_Blend_Swap);
Romain Guya5aed0d2010-09-09 14:42:43 -0700702 }
Romain Guyac670c02010-07-27 17:39:27 -0700703 }
704 // End the shader
705 shader.append(gFS_Footer);
706
Romain Guyc15008e2010-11-10 11:59:15 -0800707#if DEBUG_PROGRAMS
Romain Guydb1938e2010-08-02 18:50:22 -0700708 PROGRAM_LOGD("*** Generated fragment shader:\n\n");
709 printLongString(shader);
Romain Guyc15008e2010-11-10 11:59:15 -0800710#endif
Romain Guydb1938e2010-08-02 18:50:22 -0700711
Romain Guyac670c02010-07-27 17:39:27 -0700712 return shader;
713}
714
Romain Guy48daa542010-08-10 19:21:34 -0700715void ProgramCache::generateBlend(String8& shader, const char* name, SkXfermode::Mode mode) {
Romain Guyac670c02010-07-27 17:39:27 -0700716 shader.append("\nvec4 ");
717 shader.append(name);
718 shader.append("(vec4 src, vec4 dst) {\n");
719 shader.append(" ");
Romain Guy48daa542010-08-10 19:21:34 -0700720 shader.append(gBlendOps[mode]);
Romain Guyac670c02010-07-27 17:39:27 -0700721 shader.append("}\n");
722}
723
Romain Guy889f8d12010-07-29 14:37:42 -0700724void ProgramCache::generateTextureWrap(String8& shader, GLenum wrapS, GLenum wrapT) {
Romain Guy63553472012-07-18 20:04:14 -0700725 shader.append("\nhighp vec2 wrap(highp vec2 texCoords) {\n");
Romain Guy889f8d12010-07-29 14:37:42 -0700726 if (wrapS == GL_MIRRORED_REPEAT) {
Romain Guy63553472012-07-18 20:04:14 -0700727 shader.append(" highp float xMod2 = mod(texCoords.x, 2.0);\n");
Romain Guy889f8d12010-07-29 14:37:42 -0700728 shader.append(" if (xMod2 > 1.0) xMod2 = 2.0 - xMod2;\n");
729 }
730 if (wrapT == GL_MIRRORED_REPEAT) {
Romain Guy63553472012-07-18 20:04:14 -0700731 shader.append(" highp float yMod2 = mod(texCoords.y, 2.0);\n");
Romain Guy889f8d12010-07-29 14:37:42 -0700732 shader.append(" if (yMod2 > 1.0) yMod2 = 2.0 - yMod2;\n");
733 }
734 shader.append(" return vec2(");
735 switch (wrapS) {
Romain Guy61c8c9c2010-08-09 20:48:09 -0700736 case GL_CLAMP_TO_EDGE:
737 shader.append("texCoords.x");
738 break;
Romain Guy889f8d12010-07-29 14:37:42 -0700739 case GL_REPEAT:
740 shader.append("mod(texCoords.x, 1.0)");
741 break;
742 case GL_MIRRORED_REPEAT:
743 shader.append("xMod2");
744 break;
745 }
746 shader.append(", ");
747 switch (wrapT) {
Romain Guy61c8c9c2010-08-09 20:48:09 -0700748 case GL_CLAMP_TO_EDGE:
749 shader.append("texCoords.y");
750 break;
Romain Guy889f8d12010-07-29 14:37:42 -0700751 case GL_REPEAT:
752 shader.append("mod(texCoords.y, 1.0)");
753 break;
754 case GL_MIRRORED_REPEAT:
755 shader.append("yMod2");
756 break;
757 }
758 shader.append(");\n");
759 shader.append("}\n");
760}
761
Romain Guydb1938e2010-08-02 18:50:22 -0700762void ProgramCache::printLongString(const String8& shader) const {
763 ssize_t index = 0;
764 ssize_t lastIndex = 0;
765 const char* str = shader.string();
766 while ((index = shader.find("\n", index)) > -1) {
767 String8 line(str, index - lastIndex);
768 if (line.length() == 0) line.append("\n");
769 PROGRAM_LOGD("%s", line.string());
770 index++;
771 str += (index - lastIndex);
772 lastIndex = index;
773 }
774}
775
Romain Guyac670c02010-07-27 17:39:27 -0700776}; // namespace uirenderer
777}; // namespace android