blob: 8916efd0f75baaf3050b021b8f5cc6a2ba9266ac [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 Guy211efea2012-07-31 21:16:07 -0700253 Caches::getInstance().dither.setupProgram(program, textureUnit);
254
Romain Guye3095e02010-10-06 16:57:29 -0700255 mat4 screenSpace;
256 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guy06f96e22010-07-30 19:18:16 -0700257 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
258}
259
Romain Guy759ea802010-09-16 20:49:46 -0700260void SkiaLinearGradientShader::updateTransforms(Program* program, const mat4& modelView,
261 const Snapshot& snapshot) {
Romain Guye3095e02010-10-06 16:57:29 -0700262 mat4 screenSpace;
263 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guy759ea802010-09-16 20:49:46 -0700264 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
265}
266
Romain Guy06f96e22010-07-30 19:18:16 -0700267///////////////////////////////////////////////////////////////////////////////
Romain Guyddb80be2010-09-20 19:04:33 -0700268// Circular gradient shader
269///////////////////////////////////////////////////////////////////////////////
270
Romain Guy14830942010-10-07 15:07:45 -0700271static void toCircularUnitMatrix(const float x, const float y, const float radius,
272 SkMatrix* matrix) {
273 const float inv = 1.0f / radius;
274 matrix->setTranslate(-x, -y);
275 matrix->postScale(inv, inv);
276}
277
Romain Guyddb80be2010-09-20 19:04:33 -0700278SkiaCircularGradientShader::SkiaCircularGradientShader(float x, float y, float radius,
279 uint32_t* colors, float* positions, int count, SkShader* key, SkShader::TileMode tileMode,
280 SkMatrix* matrix, bool blend):
281 SkiaSweepGradientShader(kCircularGradient, x, y, colors, positions, count, key,
Romain Guy14830942010-10-07 15:07:45 -0700282 tileMode, matrix, blend) {
283 SkMatrix unitMatrix;
284 toCircularUnitMatrix(x, y, radius, &unitMatrix);
285 mUnitMatrix.load(unitMatrix);
286
287 updateLocalMatrix(matrix);
Romain Guyddb80be2010-09-20 19:04:33 -0700288}
289
Romain Guy24c00212011-01-14 15:31:00 -0800290SkiaShader* SkiaCircularGradientShader::copy() {
291 SkiaCircularGradientShader* copy = new SkiaCircularGradientShader();
292 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800293 copy->mColors = new uint32_t[mCount];
294 memcpy(copy->mColors, mColors, sizeof(uint32_t) * mCount);
295 copy->mPositions = new float[mCount];
296 memcpy(copy->mPositions, mPositions, sizeof(float) * mCount);
Romain Guy24c00212011-01-14 15:31:00 -0800297 copy->mCount = mCount;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700298 copy->mIsSimple = mIsSimple;
Romain Guy24c00212011-01-14 15:31:00 -0800299 return copy;
300}
301
Romain Guyddb80be2010-09-20 19:04:33 -0700302void SkiaCircularGradientShader::describe(ProgramDescription& description,
303 const Extensions& extensions) {
304 description.hasGradient = true;
305 description.gradientType = ProgramDescription::kGradientCircular;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700306 description.isSimpleGradient = mIsSimple;
Romain Guyddb80be2010-09-20 19:04:33 -0700307}
308
Romain Guyddb80be2010-09-20 19:04:33 -0700309///////////////////////////////////////////////////////////////////////////////
Romain Guyee916f12010-09-20 17:53:08 -0700310// Sweep gradient shader
311///////////////////////////////////////////////////////////////////////////////
312
Romain Guy14830942010-10-07 15:07:45 -0700313static void toSweepUnitMatrix(const float x, const float y, SkMatrix* matrix) {
314 matrix->setTranslate(-x, -y);
315}
316
Romain Guyee916f12010-09-20 17:53:08 -0700317SkiaSweepGradientShader::SkiaSweepGradientShader(float x, float y, uint32_t* colors,
318 float* positions, int count, SkShader* key, SkMatrix* matrix, bool blend):
319 SkiaShader(kSweepGradient, key, SkShader::kClamp_TileMode,
320 SkShader::kClamp_TileMode, matrix, blend),
Romain Guy14830942010-10-07 15:07:45 -0700321 mColors(colors), mPositions(positions), mCount(count) {
322 SkMatrix unitMatrix;
323 toSweepUnitMatrix(x, y, &unitMatrix);
324 mUnitMatrix.load(unitMatrix);
325
326 updateLocalMatrix(matrix);
Romain Guy42e1e0d2012-07-30 14:47:51 -0700327
328 mIsSimple = count == 2;
Romain Guyee916f12010-09-20 17:53:08 -0700329}
330
Romain Guyddb80be2010-09-20 19:04:33 -0700331SkiaSweepGradientShader::SkiaSweepGradientShader(Type type, float x, float y, uint32_t* colors,
332 float* positions, int count, SkShader* key, SkShader::TileMode tileMode,
333 SkMatrix* matrix, bool blend):
334 SkiaShader(type, key, tileMode, tileMode, matrix, blend),
Romain Guy14830942010-10-07 15:07:45 -0700335 mColors(colors), mPositions(positions), mCount(count) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700336
337 mIsSimple = count == 2 && tileMode == SkShader::kClamp_TileMode;
Romain Guyddb80be2010-09-20 19:04:33 -0700338}
339
Romain Guyee916f12010-09-20 17:53:08 -0700340SkiaSweepGradientShader::~SkiaSweepGradientShader() {
341 delete[] mColors;
342 delete[] mPositions;
343}
344
Romain Guy24c00212011-01-14 15:31:00 -0800345SkiaShader* SkiaSweepGradientShader::copy() {
346 SkiaSweepGradientShader* copy = new SkiaSweepGradientShader();
347 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800348 copy->mColors = new uint32_t[mCount];
349 memcpy(copy->mColors, mColors, sizeof(uint32_t) * mCount);
350 copy->mPositions = new float[mCount];
351 memcpy(copy->mPositions, mPositions, sizeof(float) * mCount);
Romain Guy24c00212011-01-14 15:31:00 -0800352 copy->mCount = mCount;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700353 copy->mIsSimple = mIsSimple;
Romain Guy24c00212011-01-14 15:31:00 -0800354 return copy;
355}
356
Romain Guyee916f12010-09-20 17:53:08 -0700357void SkiaSweepGradientShader::describe(ProgramDescription& description,
358 const Extensions& extensions) {
359 description.hasGradient = true;
360 description.gradientType = ProgramDescription::kGradientSweep;
Romain Guy42e1e0d2012-07-30 14:47:51 -0700361 description.isSimpleGradient = mIsSimple;
Romain Guyee916f12010-09-20 17:53:08 -0700362}
363
364void SkiaSweepGradientShader::setupProgram(Program* program, const mat4& modelView,
365 const Snapshot& snapshot, GLuint* textureUnit) {
Romain Guy42e1e0d2012-07-30 14:47:51 -0700366 if (CC_UNLIKELY(!mIsSimple)) {
367 GLuint textureSlot = (*textureUnit)++;
368 Caches::getInstance().activeTexture(textureSlot);
Romain Guyee916f12010-09-20 17:53:08 -0700369
Romain Guy42e1e0d2012-07-30 14:47:51 -0700370 Texture* texture = mGradientCache->get(mColors, mPositions, mCount);
371
372 // Uniforms
373 bindTexture(texture, gTileModes[mTileX], gTileModes[mTileY]);
374 glUniform1i(program->getUniform("gradientSampler"), textureSlot);
375 } else {
376 bindUniformColor(program->getUniform("startColor"), mColors[0]);
377 bindUniformColor(program->getUniform("endColor"), mColors[1]);
378 }
Romain Guyee916f12010-09-20 17:53:08 -0700379
Romain Guy211efea2012-07-31 21:16:07 -0700380 Caches::getInstance().dither.setupProgram(program, textureUnit);
381
Romain Guy14830942010-10-07 15:07:45 -0700382 mat4 screenSpace;
383 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guyee916f12010-09-20 17:53:08 -0700384 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
385}
386
387void SkiaSweepGradientShader::updateTransforms(Program* program, const mat4& modelView,
388 const Snapshot& snapshot) {
Romain Guy14830942010-10-07 15:07:45 -0700389 mat4 screenSpace;
390 computeScreenSpaceMatrix(screenSpace, modelView);
Romain Guyee916f12010-09-20 17:53:08 -0700391 glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]);
392}
393
394///////////////////////////////////////////////////////////////////////////////
Romain Guy06f96e22010-07-30 19:18:16 -0700395// Compose shader
396///////////////////////////////////////////////////////////////////////////////
397
398SkiaComposeShader::SkiaComposeShader(SkiaShader* first, SkiaShader* second,
399 SkXfermode::Mode mode, SkShader* key):
400 SkiaShader(kCompose, key, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode,
Romain Guy43ccf462011-01-14 18:51:01 -0800401 NULL, first->blend() || second->blend()),
402 mFirst(first), mSecond(second), mMode(mode), mCleanup(false) {
403}
404
405SkiaComposeShader::~SkiaComposeShader() {
406 if (mCleanup) {
407 delete mFirst;
408 delete mSecond;
409 }
Romain Guy06f96e22010-07-30 19:18:16 -0700410}
411
Romain Guy24c00212011-01-14 15:31:00 -0800412SkiaShader* SkiaComposeShader::copy() {
413 SkiaComposeShader* copy = new SkiaComposeShader();
414 copy->copyFrom(*this);
Romain Guy43ccf462011-01-14 18:51:01 -0800415 copy->mFirst = mFirst->copy();
416 copy->mSecond = mSecond->copy();
Romain Guy24c00212011-01-14 15:31:00 -0800417 copy->mMode = mMode;
Romain Guy43ccf462011-01-14 18:51:01 -0800418 copy->cleanup();
Romain Guy24c00212011-01-14 15:31:00 -0800419 return copy;
420}
421
Romain Guy06f96e22010-07-30 19:18:16 -0700422void SkiaComposeShader::set(TextureCache* textureCache, GradientCache* gradientCache) {
423 SkiaShader::set(textureCache, gradientCache);
424 mFirst->set(textureCache, gradientCache);
425 mSecond->set(textureCache, gradientCache);
426}
427
428void SkiaComposeShader::describe(ProgramDescription& description, const Extensions& extensions) {
429 mFirst->describe(description, extensions);
430 mSecond->describe(description, extensions);
431 if (mFirst->type() == kBitmap) {
432 description.isBitmapFirst = true;
433 }
434 description.shadersMode = mMode;
435}
436
437void SkiaComposeShader::setupProgram(Program* program, const mat4& modelView,
438 const Snapshot& snapshot, GLuint* textureUnit) {
439 mFirst->setupProgram(program, modelView, snapshot, textureUnit);
440 mSecond->setupProgram(program, modelView, snapshot, textureUnit);
441}
442
443}; // namespace uirenderer
444}; // namespace android