blob: 71e17395447450ed9758698559ff07d500a1bda9 [file] [log] [blame]
Romain Guy06f96e22010-07-30 19:18:16 -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/Log.h>
20
21#include <SkMatrix.h>
22
Romain Guya1d3c912011-12-13 14:55:06 -080023#include "Caches.h"
Romain Guy06f96e22010-07-30 19:18:16 -070024#include "SkiaShader.h"
25#include "Texture.h"
26#include "Matrix.h"
27
28namespace android {
29namespace uirenderer {
30
31///////////////////////////////////////////////////////////////////////////////
32// Support
33///////////////////////////////////////////////////////////////////////////////
34
Romain Guy06f96e22010-07-30 19:18:16 -070035static const GLint gTileModes[] = {
36 GL_CLAMP_TO_EDGE, // == SkShader::kClamp_TileMode
37 GL_REPEAT, // == SkShader::kRepeat_Mode
38 GL_MIRRORED_REPEAT // == SkShader::kMirror_TileMode
39};
40
Romain Guy42e1e0d2012-07-30 14:47:51 -070041/**
42 * This function does not work for n == 0.
43 */
44static inline bool isPowerOfTwo(unsigned int n) {
45 return !(n & (n - 1));
46}
47
48static inline void bindUniformColor(int slot, uint32_t color) {
49 glUniform4f(slot,
50 ((color >> 16) & 0xff) / 255.0f,
51 ((color >> 8) & 0xff) / 255.0f,
52 ((color ) & 0xff) / 255.0f,
53 ((color >> 24) & 0xff) / 255.0f);
54}
55
Romain Guy06f96e22010-07-30 19:18:16 -070056///////////////////////////////////////////////////////////////////////////////
57// Base shader
58///////////////////////////////////////////////////////////////////////////////
59
Romain Guy24c00212011-01-14 15:31:00 -080060void SkiaShader::copyFrom(const SkiaShader& shader) {
61 mType = shader.mType;
62 mKey = shader.mKey;
63 mTileX = shader.mTileX;
64 mTileY = shader.mTileY;
65 mBlend = shader.mBlend;
66 mUnitMatrix = shader.mUnitMatrix;
67 mShaderMatrix = shader.mShaderMatrix;
68 mGenerationId = shader.mGenerationId;
69}
70
Romain Guy06f96e22010-07-30 19:18:16 -070071SkiaShader::SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX,
72 SkShader::TileMode tileY, SkMatrix* matrix, bool blend):
Romain Guy14830942010-10-07 15:07:45 -070073 mType(type), mKey(key), mTileX(tileX), mTileY(tileY), mBlend(blend) {
74 setMatrix(matrix);
Romain Guy24c00212011-01-14 15:31:00 -080075 mGenerationId = 0;
Romain Guy06f96e22010-07-30 19:18:16 -070076}
77
78SkiaShader::~SkiaShader() {
79}
80
81void SkiaShader::describe(ProgramDescription& description, const Extensions& extensions) {
82}
83
84void SkiaShader::setupProgram(Program* program, const mat4& modelView, const Snapshot& snapshot,
85 GLuint* textureUnit) {
86}
87
Romain Guy01d06572010-11-11 12:06:27 -080088void SkiaShader::bindTexture(Texture* texture, GLenum wrapS, GLenum wrapT) {
Romain Guy8164c2d2010-10-25 18:03:28 -070089 glBindTexture(GL_TEXTURE_2D, texture->id);
Romain Guyd21b6e12011-11-30 20:21:23 -080090 texture->setWrapST(wrapS, wrapT);
Romain Guy06f96e22010-07-30 19:18:16 -070091}
92
Romain Guy14830942010-10-07 15:07:45 -070093void SkiaShader::computeScreenSpaceMatrix(mat4& screenSpace, const mat4& modelView) {
94 screenSpace.loadMultiply(mUnitMatrix, mShaderMatrix);
95 screenSpace.multiply(modelView);
96}
97
Romain Guy06f96e22010-07-30 19:18:16 -070098///////////////////////////////////////////////////////////////////////////////
99// Bitmap shader
100///////////////////////////////////////////////////////////////////////////////
101
102SkiaBitmapShader::SkiaBitmapShader(SkBitmap* bitmap, SkShader* key, SkShader::TileMode tileX,
103 SkShader::TileMode tileY, SkMatrix* matrix, bool blend):
Romain Guy9cccc2b2010-08-07 23:46:15 -0700104 SkiaShader(kBitmap, key, tileX, tileY, matrix, blend), mBitmap(bitmap), mTexture(NULL) {
Romain Guy14830942010-10-07 15:07:45 -0700105 updateLocalMatrix(matrix);
Romain Guy06f96e22010-07-30 19:18:16 -0700106}
107
Romain Guy24c00212011-01-14 15:31:00 -0800108SkiaShader* SkiaBitmapShader::copy() {
109 SkiaBitmapShader* copy = new SkiaBitmapShader();
110 copy->copyFrom(*this);
111 copy->mBitmap = mBitmap;
112 return copy;
113}
114
Romain Guy06f96e22010-07-30 19:18:16 -0700115void SkiaBitmapShader::describe(ProgramDescription& description, const Extensions& extensions) {
Romain Guy8164c2d2010-10-25 18:03:28 -0700116 Texture* texture = mTextureCache->get(mBitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700117 if (!texture) return;
118 mTexture = texture;
Romain Guy06f96e22010-07-30 19:18:16 -0700119
120 const float width = texture->width;
121 const float height = texture->height;
122
123 description.hasBitmap = true;
124 // The driver does not support non-power of two mirrored/repeated
125 // textures, so do it ourselves
Romain Guy61c8c9c2010-08-09 20:48:09 -0700126 if (!extensions.hasNPot() && (!isPowerOfTwo(width) || !isPowerOfTwo(height)) &&
127 (mTileX != SkShader::kClamp_TileMode || mTileY != SkShader::kClamp_TileMode)) {
Romain Guy06f96e22010-07-30 19:18:16 -0700128 description.isBitmapNpot = true;
129 description.bitmapWrapS = gTileModes[mTileX];
130 description.bitmapWrapT = gTileModes[mTileY];
Romain Guy29d89972010-09-22 16:10:57 -0700131 mWrapS = GL_CLAMP_TO_EDGE;
132 mWrapT = GL_CLAMP_TO_EDGE;
133 } else {
134 mWrapS = gTileModes[mTileX];
135 mWrapT = gTileModes[mTileY];
Romain Guy06f96e22010-07-30 19:18:16 -0700136 }
137}
138
139void SkiaBitmapShader::setupProgram(Program* program, const mat4& modelView,
140 const Snapshot& snapshot, GLuint* textureUnit) {
141 GLuint textureSlot = (*textureUnit)++;
Romain Guya1d3c912011-12-13 14:55:06 -0800142 Caches::getInstance().activeTexture(textureSlot);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700143
Romain Guy8164c2d2010-10-25 18:03:28 -0700144 Texture* texture = mTexture;
Romain Guy9cccc2b2010-08-07 23:46:15 -0700145 mTexture = NULL;
146 if (!texture) return;
147 const AutoTexture autoCleanup(texture);
Romain Guy06f96e22010-07-30 19:18:16 -0700148
149 const float width = texture->width;
150 const float height = texture->height;
151
152 mat4 textureTransform;
Romain Guy14830942010-10-07 15:07:45 -0700153 computeScreenSpaceMatrix(textureTransform, modelView);
Romain Guy06f96e22010-07-30 19:18:16 -0700154
155 // Uniforms
Romain Guy01d06572010-11-11 12:06:27 -0800156 bindTexture(texture, mWrapS, mWrapT);
Romain Guyb5014982011-07-28 15:39:12 -0700157 // Assume linear here; we should really check the transform in
158 // ::updateTransforms() but we don't have the texture object
159 // available at that point. The optimization is not worth the
160 // effort for now.
Romain Guyd21b6e12011-11-30 20:21:23 -0800161 texture->setFilter(GL_LINEAR);
Romain Guye3c26852011-07-25 16:36:01 -0700162
Romain Guy06f96e22010-07-30 19:18:16 -0700163 glUniform1i(program->getUniform("bitmapSampler"), textureSlot);
164 glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
165 GL_FALSE, &textureTransform.data[0]);
166 glUniform2f(program->getUniform("textureDimension"), 1.0f / width, 1.0f / height);
167}
168
Romain Guy759ea802010-09-16 20:49:46 -0700169void SkiaBitmapShader::updateTransforms(Program* program, const mat4& modelView,
170 const Snapshot& snapshot) {
171 mat4 textureTransform;
Romain Guy14830942010-10-07 15:07:45 -0700172 computeScreenSpaceMatrix(textureTransform, modelView);
Romain Guy759ea802010-09-16 20:49:46 -0700173 glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
174 GL_FALSE, &textureTransform.data[0]);
175}
176
Romain Guy06f96e22010-07-30 19:18:16 -0700177///////////////////////////////////////////////////////////////////////////////
178// Linear gradient shader
179///////////////////////////////////////////////////////////////////////////////
180
Romain Guye3095e02010-10-06 16:57:29 -0700181static void toUnitMatrix(const SkPoint pts[2], SkMatrix* matrix) {
182 SkVector vec = pts[1] - pts[0];
183 const float mag = vec.length();
184 const float inv = mag ? 1.0f / mag : 0;
185
186 vec.scale(inv);
187 matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
188 matrix->postTranslate(-pts[0].fX, -pts[0].fY);
189 matrix->postScale(inv, inv);
190}
191
Romain Guy06f96e22010-07-30 19:18:16 -0700192SkiaLinearGradientShader::SkiaLinearGradientShader(float* bounds, uint32_t* colors,
193 float* positions, int count, SkShader* key, SkShader::TileMode tileMode,
194 SkMatrix* matrix, bool blend):
195 SkiaShader(kLinearGradient, key, tileMode, tileMode, matrix, blend),
196 mBounds(bounds), mColors(colors), mPositions(positions), mCount(count) {
Romain Guye3095e02010-10-06 16:57:29 -0700197 SkPoint points[2];
198 points[0].set(bounds[0], bounds[1]);
199 points[1].set(bounds[2], bounds[3]);
200
201 SkMatrix unitMatrix;
202 toUnitMatrix(points, &unitMatrix);
203 mUnitMatrix.load(unitMatrix);
204
205 updateLocalMatrix(matrix);
Romain Guy42e1e0d2012-07-30 14:47:51 -0700206
207 mIsSimple = count == 2 && tileMode == SkShader::kClamp_TileMode;
Romain Guy06f96e22010-07-30 19:18:16 -0700208}
209
210SkiaLinearGradientShader::~SkiaLinearGradientShader() {
Romain Guy25ee0372010-08-06 10:57:58 -0700211 delete[] mBounds;
212 delete[] mColors;
213 delete[] mPositions;
Romain Guy06f96e22010-07-30 19:18:16 -0700214}
215
Romain Guy24c00212011-01-14 15:31:00 -0800216SkiaShader* SkiaLinearGradientShader::copy() {
217 SkiaLinearGradientShader* copy = new SkiaLinearGradientShader();
218 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800219 copy->mBounds = new float[4];
220 memcpy(copy->mBounds, mBounds, sizeof(float) * 4);
221 copy->mColors = new uint32_t[mCount];
222 memcpy(copy->mColors, mColors, sizeof(uint32_t) * mCount);
223 copy->mPositions = new float[mCount];
224 memcpy(copy->mPositions, mPositions, sizeof(float) * mCount);
Romain Guy24c00212011-01-14 15:31:00 -0800225 copy->mCount = mCount;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700226 copy->mIsSimple = mIsSimple;
Romain Guy24c00212011-01-14 15:31:00 -0800227 return copy;
228}
229
Romain Guy06f96e22010-07-30 19:18:16 -0700230void SkiaLinearGradientShader::describe(ProgramDescription& description,
231 const Extensions& extensions) {
232 description.hasGradient = true;
Romain Guyee916f12010-09-20 17:53:08 -0700233 description.gradientType = ProgramDescription::kGradientLinear;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700234 description.isSimpleGradient = mIsSimple;
Romain Guy06f96e22010-07-30 19:18:16 -0700235}
236
237void SkiaLinearGradientShader::setupProgram(Program* program, const mat4& modelView,
238 const Snapshot& snapshot, GLuint* textureUnit) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700239 if (CC_UNLIKELY(!mIsSimple)) {
240 GLuint textureSlot = (*textureUnit)++;
241 Caches::getInstance().activeTexture(textureSlot);
Romain Guy06f96e22010-07-30 19:18:16 -0700242
Romain Guy42e1e0d2012-07-30 14:47:51 -0700243 Texture* texture = mGradientCache->get(mColors, mPositions, mCount);
244
245 // Uniforms
246 bindTexture(texture, gTileModes[mTileX], gTileModes[mTileY]);
247 glUniform1i(program->getUniform("gradientSampler"), textureSlot);
248 } else {
249 bindUniformColor(program->getUniform("startColor"), mColors[0]);
250 bindUniformColor(program->getUniform("endColor"), mColors[1]);
251 }
Romain Guy06f96e22010-07-30 19:18:16 -0700252
Romain Guye3095e02010-10-06 16:57:29 -0700253 mat4 screenSpace;
254 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guy06f96e22010-07-30 19:18:16 -0700255 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
256}
257
Romain Guy759ea802010-09-16 20:49:46 -0700258void SkiaLinearGradientShader::updateTransforms(Program* program, const mat4& modelView,
259 const Snapshot& snapshot) {
Romain Guye3095e02010-10-06 16:57:29 -0700260 mat4 screenSpace;
261 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guy759ea802010-09-16 20:49:46 -0700262 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
263}
264
Romain Guy06f96e22010-07-30 19:18:16 -0700265///////////////////////////////////////////////////////////////////////////////
Romain Guyddb80be2010-09-20 19:04:33 -0700266// Circular gradient shader
267///////////////////////////////////////////////////////////////////////////////
268
Romain Guy14830942010-10-07 15:07:45 -0700269static void toCircularUnitMatrix(const float x, const float y, const float radius,
270 SkMatrix* matrix) {
271 const float inv = 1.0f / radius;
272 matrix->setTranslate(-x, -y);
273 matrix->postScale(inv, inv);
274}
275
Romain Guyddb80be2010-09-20 19:04:33 -0700276SkiaCircularGradientShader::SkiaCircularGradientShader(float x, float y, float radius,
277 uint32_t* colors, float* positions, int count, SkShader* key, SkShader::TileMode tileMode,
278 SkMatrix* matrix, bool blend):
279 SkiaSweepGradientShader(kCircularGradient, x, y, colors, positions, count, key,
Romain Guy14830942010-10-07 15:07:45 -0700280 tileMode, matrix, blend) {
281 SkMatrix unitMatrix;
282 toCircularUnitMatrix(x, y, radius, &unitMatrix);
283 mUnitMatrix.load(unitMatrix);
284
285 updateLocalMatrix(matrix);
Romain Guyddb80be2010-09-20 19:04:33 -0700286}
287
Romain Guy24c00212011-01-14 15:31:00 -0800288SkiaShader* SkiaCircularGradientShader::copy() {
289 SkiaCircularGradientShader* copy = new SkiaCircularGradientShader();
290 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800291 copy->mColors = new uint32_t[mCount];
292 memcpy(copy->mColors, mColors, sizeof(uint32_t) * mCount);
293 copy->mPositions = new float[mCount];
294 memcpy(copy->mPositions, mPositions, sizeof(float) * mCount);
Romain Guy24c00212011-01-14 15:31:00 -0800295 copy->mCount = mCount;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700296 copy->mIsSimple = mIsSimple;
Romain Guy24c00212011-01-14 15:31:00 -0800297 return copy;
298}
299
Romain Guyddb80be2010-09-20 19:04:33 -0700300void SkiaCircularGradientShader::describe(ProgramDescription& description,
301 const Extensions& extensions) {
302 description.hasGradient = true;
303 description.gradientType = ProgramDescription::kGradientCircular;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700304 description.isSimpleGradient = mIsSimple;
Romain Guyddb80be2010-09-20 19:04:33 -0700305}
306
Romain Guyddb80be2010-09-20 19:04:33 -0700307///////////////////////////////////////////////////////////////////////////////
Romain Guyee916f12010-09-20 17:53:08 -0700308// Sweep gradient shader
309///////////////////////////////////////////////////////////////////////////////
310
Romain Guy14830942010-10-07 15:07:45 -0700311static void toSweepUnitMatrix(const float x, const float y, SkMatrix* matrix) {
312 matrix->setTranslate(-x, -y);
313}
314
Romain Guyee916f12010-09-20 17:53:08 -0700315SkiaSweepGradientShader::SkiaSweepGradientShader(float x, float y, uint32_t* colors,
316 float* positions, int count, SkShader* key, SkMatrix* matrix, bool blend):
317 SkiaShader(kSweepGradient, key, SkShader::kClamp_TileMode,
318 SkShader::kClamp_TileMode, matrix, blend),
Romain Guy14830942010-10-07 15:07:45 -0700319 mColors(colors), mPositions(positions), mCount(count) {
320 SkMatrix unitMatrix;
321 toSweepUnitMatrix(x, y, &unitMatrix);
322 mUnitMatrix.load(unitMatrix);
323
324 updateLocalMatrix(matrix);
Romain Guy42e1e0d2012-07-30 14:47:51 -0700325
326 mIsSimple = count == 2;
Romain Guyee916f12010-09-20 17:53:08 -0700327}
328
Romain Guyddb80be2010-09-20 19:04:33 -0700329SkiaSweepGradientShader::SkiaSweepGradientShader(Type type, float x, float y, uint32_t* colors,
330 float* positions, int count, SkShader* key, SkShader::TileMode tileMode,
331 SkMatrix* matrix, bool blend):
332 SkiaShader(type, key, tileMode, tileMode, matrix, blend),
Romain Guy14830942010-10-07 15:07:45 -0700333 mColors(colors), mPositions(positions), mCount(count) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700334
335 mIsSimple = count == 2 && tileMode == SkShader::kClamp_TileMode;
Romain Guyddb80be2010-09-20 19:04:33 -0700336}
337
Romain Guyee916f12010-09-20 17:53:08 -0700338SkiaSweepGradientShader::~SkiaSweepGradientShader() {
339 delete[] mColors;
340 delete[] mPositions;
341}
342
Romain Guy24c00212011-01-14 15:31:00 -0800343SkiaShader* SkiaSweepGradientShader::copy() {
344 SkiaSweepGradientShader* copy = new SkiaSweepGradientShader();
345 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800346 copy->mColors = new uint32_t[mCount];
347 memcpy(copy->mColors, mColors, sizeof(uint32_t) * mCount);
348 copy->mPositions = new float[mCount];
349 memcpy(copy->mPositions, mPositions, sizeof(float) * mCount);
Romain Guy24c00212011-01-14 15:31:00 -0800350 copy->mCount = mCount;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700351 copy->mIsSimple = mIsSimple;
Romain Guy24c00212011-01-14 15:31:00 -0800352 return copy;
353}
354
Romain Guyee916f12010-09-20 17:53:08 -0700355void SkiaSweepGradientShader::describe(ProgramDescription& description,
356 const Extensions& extensions) {
357 description.hasGradient = true;
358 description.gradientType = ProgramDescription::kGradientSweep;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700359 description.isSimpleGradient = mIsSimple;
Romain Guyee916f12010-09-20 17:53:08 -0700360}
361
362void SkiaSweepGradientShader::setupProgram(Program* program, const mat4& modelView,
363 const Snapshot& snapshot, GLuint* textureUnit) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700364 if (CC_UNLIKELY(!mIsSimple)) {
365 GLuint textureSlot = (*textureUnit)++;
366 Caches::getInstance().activeTexture(textureSlot);
Romain Guyee916f12010-09-20 17:53:08 -0700367
Romain Guy42e1e0d2012-07-30 14:47:51 -0700368 Texture* texture = mGradientCache->get(mColors, mPositions, mCount);
369
370 // Uniforms
371 bindTexture(texture, gTileModes[mTileX], gTileModes[mTileY]);
372 glUniform1i(program->getUniform("gradientSampler"), textureSlot);
373 } else {
374 bindUniformColor(program->getUniform("startColor"), mColors[0]);
375 bindUniformColor(program->getUniform("endColor"), mColors[1]);
376 }
Romain Guyee916f12010-09-20 17:53:08 -0700377
Romain Guy14830942010-10-07 15:07:45 -0700378 mat4 screenSpace;
379 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guyee916f12010-09-20 17:53:08 -0700380 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
381}
382
383void SkiaSweepGradientShader::updateTransforms(Program* program, const mat4& modelView,
384 const Snapshot& snapshot) {
Romain Guy14830942010-10-07 15:07:45 -0700385 mat4 screenSpace;
386 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guyee916f12010-09-20 17:53:08 -0700387 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
388}
389
390///////////////////////////////////////////////////////////////////////////////
Romain Guy06f96e22010-07-30 19:18:16 -0700391// Compose shader
392///////////////////////////////////////////////////////////////////////////////
393
394SkiaComposeShader::SkiaComposeShader(SkiaShader* first, SkiaShader* second,
395 SkXfermode::Mode mode, SkShader* key):
396 SkiaShader(kCompose, key, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
Romain Guy43ccf462011-01-14 18:51:01 -0800397 NULL, first->blend() || second->blend()),
398 mFirst(first), mSecond(second), mMode(mode), mCleanup(false) {
399}
400
401SkiaComposeShader::~SkiaComposeShader() {
402 if (mCleanup) {
403 delete mFirst;
404 delete mSecond;
405 }
Romain Guy06f96e22010-07-30 19:18:16 -0700406}
407
Romain Guy24c00212011-01-14 15:31:00 -0800408SkiaShader* SkiaComposeShader::copy() {
409 SkiaComposeShader* copy = new SkiaComposeShader();
410 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800411 copy->mFirst = mFirst->copy();
412 copy->mSecond = mSecond->copy();
Romain Guy24c00212011-01-14 15:31:00 -0800413 copy->mMode = mMode;
Romain Guy43ccf462011-01-14 18:51:01 -0800414 copy->cleanup();
Romain Guy24c00212011-01-14 15:31:00 -0800415 return copy;
416}
417
Romain Guy06f96e22010-07-30 19:18:16 -0700418void SkiaComposeShader::set(TextureCache* textureCache, GradientCache* gradientCache) {
419 SkiaShader::set(textureCache, gradientCache);
420 mFirst->set(textureCache, gradientCache);
421 mSecond->set(textureCache, gradientCache);
422}
423
424void SkiaComposeShader::describe(ProgramDescription& description, const Extensions& extensions) {
425 mFirst->describe(description, extensions);
426 mSecond->describe(description, extensions);
427 if (mFirst->type() == kBitmap) {
428 description.isBitmapFirst = true;
429 }
430 description.shadersMode = mMode;
431}
432
433void SkiaComposeShader::setupProgram(Program* program, const mat4& modelView,
434 const Snapshot& snapshot, GLuint* textureUnit) {
435 mFirst->setupProgram(program, modelView, snapshot, textureUnit);
436 mSecond->setupProgram(program, modelView, snapshot, textureUnit);
437}
438
439}; // namespace uirenderer
440}; // namespace android