blob: 731862b1469e7bddabf4a10e9fb80c41d5800a10 [file] [log] [blame]
Romain Guye4d01122010-06-16 18:44:05 -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
Romain Guy85bf02f2010-06-22 13:11:24 -070017#define LOG_TAG "OpenGLRenderer"
Romain Guye4d01122010-06-16 18:44:05 -070018
19#include <stdlib.h>
20#include <stdint.h>
21#include <sys/types.h>
22
Romain Guy5cbbce52010-06-27 22:59:20 -070023#include <SkCanvas.h>
24
Romain Guy121e22422010-07-01 18:26:52 -070025#include <cutils/properties.h>
Romain Guye4d01122010-06-16 18:44:05 -070026#include <utils/Log.h>
27
Romain Guy85bf02f2010-06-22 13:11:24 -070028#include "OpenGLRenderer.h"
Romain Guye4d01122010-06-16 18:44:05 -070029
30namespace android {
Romain Guy9d5316e2010-06-24 19:30:36 -070031namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
Romain Guy121e22422010-07-01 18:26:52 -070037// These properties are defined in mega-bytes
38#define PROPERTY_TEXTURE_CACHE_SIZE "ro.hwui.texture_cache_size"
39#define PROPERTY_LAYER_CACHE_SIZE "ro.hwui.layer_cache_size"
40
Romain Guydda570202010-07-06 11:39:32 -070041#define DEFAULT_TEXTURE_CACHE_SIZE 20
42#define DEFAULT_LAYER_CACHE_SIZE 10
Romain Guyf7f93552010-07-08 19:17:03 -070043#define DEFAULT_PATCH_CACHE_SIZE 100
Romain Guydda570202010-07-06 11:39:32 -070044
Romain Guy121e22422010-07-01 18:26:52 -070045// Converts a number of mega-bytes into bytes
46#define MB(s) s * 1024 * 1024
47
Romain Guydda570202010-07-06 11:39:32 -070048// Generates simple and textured vertices
Romain Guybd6b79b2010-06-26 00:13:53 -070049#define SV(x, y) { { x, y } }
50#define FV(x, y, u, v) { { x, y }, { u, v } }
Romain Guy9d5316e2010-06-24 19:30:36 -070051
52///////////////////////////////////////////////////////////////////////////////
53// Globals
54///////////////////////////////////////////////////////////////////////////////
55
Romain Guy026c5e162010-06-28 17:12:22 -070056static const SimpleVertex gDrawColorVertices[] = {
Romain Guybd6b79b2010-06-26 00:13:53 -070057 SV(0.0f, 0.0f),
58 SV(1.0f, 0.0f),
59 SV(0.0f, 1.0f),
60 SV(1.0f, 1.0f)
Romain Guy9d5316e2010-06-24 19:30:36 -070061};
Romain Guy026c5e162010-06-28 17:12:22 -070062static const GLsizei gDrawColorVertexStride = sizeof(SimpleVertex);
63static const GLsizei gDrawColorVertexCount = 4;
Romain Guy9d5316e2010-06-24 19:30:36 -070064
Romain Guy026c5e162010-06-28 17:12:22 -070065// This array is never used directly but used as a memcpy source in the
66// OpenGLRenderer constructor
67static const TextureVertex gDrawTextureVertices[] = {
Romain Guyc1396e92010-06-30 17:56:19 -070068 FV(0.0f, 0.0f, 0.0f, 0.0f),
69 FV(1.0f, 0.0f, 1.0f, 0.0f),
70 FV(0.0f, 1.0f, 0.0f, 1.0f),
71 FV(1.0f, 1.0f, 1.0f, 1.0f)
Romain Guybd6b79b2010-06-26 00:13:53 -070072};
Romain Guy026c5e162010-06-28 17:12:22 -070073static const GLsizei gDrawTextureVertexStride = sizeof(TextureVertex);
74static const GLsizei gDrawTextureVertexCount = 4;
Romain Guybd6b79b2010-06-26 00:13:53 -070075
Romain Guy026c5e162010-06-28 17:12:22 -070076// In this array, the index of each Blender equals the value of the first
77// entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode]
78static const Blender gBlends[] = {
79 { SkXfermode::kClear_Mode, GL_ZERO, GL_ZERO },
80 { SkXfermode::kSrc_Mode, GL_ONE, GL_ZERO },
81 { SkXfermode::kDst_Mode, GL_ZERO, GL_ONE },
82 { SkXfermode::kSrcOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
83 { SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
84 { SkXfermode::kSrcIn_Mode, GL_DST_ALPHA, GL_ZERO },
85 { SkXfermode::kDstIn_Mode, GL_ZERO, GL_SRC_ALPHA },
86 { SkXfermode::kSrcOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
87 { SkXfermode::kDstOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
88 { SkXfermode::kSrcATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
89 { SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
90 { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }
91};
Romain Guye4d01122010-06-16 18:44:05 -070092
Romain Guyd27977d2010-07-14 19:18:51 -070093static const GLint gTileModes[] = {
94 GL_CLAMP_TO_EDGE, // == SkShader::kClamp_TileMode
95 GL_REPEAT, // == SkShader::kRepeat_Mode
96 GL_MIRRORED_REPEAT // == SkShader::kMirror_TileMode
97};
98
Romain Guyf6a11b82010-06-23 17:47:49 -070099///////////////////////////////////////////////////////////////////////////////
100// Constructors/destructor
101///////////////////////////////////////////////////////////////////////////////
102
Romain Guydda570202010-07-06 11:39:32 -0700103OpenGLRenderer::OpenGLRenderer():
Romain Guy82ba8142010-07-09 13:25:56 -0700104 mBlend(false), mLastSrcMode(GL_ZERO), mLastDstMode(GL_ZERO),
Romain Guydda570202010-07-06 11:39:32 -0700105 mTextureCache(MB(DEFAULT_TEXTURE_CACHE_SIZE)),
Romain Guyf7f93552010-07-08 19:17:03 -0700106 mLayerCache(MB(DEFAULT_LAYER_CACHE_SIZE)),
107 mPatchCache(DEFAULT_PATCH_CACHE_SIZE) {
Romain Guy85bf02f2010-06-22 13:11:24 -0700108 LOGD("Create OpenGLRenderer");
Romain Guy9d5316e2010-06-24 19:30:36 -0700109
Romain Guy121e22422010-07-01 18:26:52 -0700110 char property[PROPERTY_VALUE_MAX];
111 if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, NULL) > 0) {
Romain Guydda570202010-07-06 11:39:32 -0700112 LOGD(" Setting texture cache size to %sMB", property);
Romain Guy121e22422010-07-01 18:26:52 -0700113 mTextureCache.setMaxSize(MB(atoi(property)));
Romain Guydda570202010-07-06 11:39:32 -0700114 } else {
115 LOGD(" Using default texture cache size of %dMB", DEFAULT_TEXTURE_CACHE_SIZE);
116 }
117
118 if (property_get(PROPERTY_LAYER_CACHE_SIZE, property, NULL) > 0) {
119 LOGD(" Setting layer cache size to %sMB", property);
120 mLayerCache.setMaxSize(MB(atoi(property)));
121 } else {
122 LOGD(" Using default layer cache size of %dMB", DEFAULT_LAYER_CACHE_SIZE);
Romain Guy121e22422010-07-01 18:26:52 -0700123 }
124
Romain Guyd27977d2010-07-14 19:18:51 -0700125 mDrawColorProgram = new DrawColorProgram;
126 mDrawTextureProgram = new DrawTextureProgram;
Romain Guyf9764a42010-07-16 23:13:33 -0700127 mDrawLinearGradientProgram = new DrawLinearGradientProgram;
Romain Guyd27977d2010-07-14 19:18:51 -0700128 mCurrentProgram = mDrawTextureProgram;
129
130 mShader = kShaderNone;
131 mShaderTileX = SkShader::kClamp_TileMode;
132 mShaderTileY = SkShader::kClamp_TileMode;
133 mShaderMatrix = NULL;
134 mShaderBitmap = NULL;
Romain Guy026c5e162010-06-28 17:12:22 -0700135
Romain Guy1e793862010-07-16 15:07:42 -0700136 mLastTexture = 0;
137
Romain Guy026c5e162010-06-28 17:12:22 -0700138 memcpy(mDrawTextureVertices, gDrawTextureVertices, sizeof(gDrawTextureVertices));
Romain Guye4d01122010-06-16 18:44:05 -0700139}
140
Romain Guy85bf02f2010-06-22 13:11:24 -0700141OpenGLRenderer::~OpenGLRenderer() {
142 LOGD("Destroy OpenGLRenderer");
Romain Guyce0537b2010-06-29 21:05:21 -0700143
144 mTextureCache.clear();
Romain Guydda570202010-07-06 11:39:32 -0700145 mLayerCache.clear();
Romain Guy6926c722010-07-12 20:20:03 -0700146 mPatchCache.clear();
Romain Guye4d01122010-06-16 18:44:05 -0700147}
148
Romain Guyf6a11b82010-06-23 17:47:49 -0700149///////////////////////////////////////////////////////////////////////////////
150// Setup
151///////////////////////////////////////////////////////////////////////////////
152
Romain Guy85bf02f2010-06-22 13:11:24 -0700153void OpenGLRenderer::setViewport(int width, int height) {
Romain Guy08ae3172010-06-21 19:35:50 -0700154 glViewport(0, 0, width, height);
155
Romain Guy260e1022010-07-12 14:41:06 -0700156 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
Romain Guybb9524b2010-06-22 18:56:38 -0700157
158 mWidth = width;
159 mHeight = height;
Romain Guyf86ef572010-07-01 11:05:42 -0700160 mFirstSnapshot.height = height;
Romain Guye4d01122010-06-16 18:44:05 -0700161}
162
Romain Guy85bf02f2010-06-22 13:11:24 -0700163void OpenGLRenderer::prepare() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700164 mSnapshot = &mFirstSnapshot;
165 mSaveCount = 0;
Romain Guyf6a11b82010-06-23 17:47:49 -0700166
Romain Guy08ae3172010-06-21 19:35:50 -0700167 glDisable(GL_SCISSOR_TEST);
Romain Guybb9524b2010-06-22 18:56:38 -0700168
Romain Guy08ae3172010-06-21 19:35:50 -0700169 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
170 glClear(GL_COLOR_BUFFER_BIT);
Romain Guybb9524b2010-06-22 18:56:38 -0700171
Romain Guy08ae3172010-06-21 19:35:50 -0700172 glEnable(GL_SCISSOR_TEST);
Romain Guyc7d53492010-06-25 13:41:57 -0700173 glScissor(0, 0, mWidth, mHeight);
Romain Guyf6a11b82010-06-23 17:47:49 -0700174
Romain Guybb9524b2010-06-22 18:56:38 -0700175 mSnapshot->clipRect.set(0.0f, 0.0f, mWidth, mHeight);
176}
177
Romain Guyf6a11b82010-06-23 17:47:49 -0700178///////////////////////////////////////////////////////////////////////////////
179// State management
180///////////////////////////////////////////////////////////////////////////////
181
Romain Guybb9524b2010-06-22 18:56:38 -0700182int OpenGLRenderer::getSaveCount() const {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700183 return mSaveCount;
Romain Guybb9524b2010-06-22 18:56:38 -0700184}
185
186int OpenGLRenderer::save(int flags) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700187 return saveSnapshot();
Romain Guybb9524b2010-06-22 18:56:38 -0700188}
189
190void OpenGLRenderer::restore() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700191 if (mSaveCount == 0) return;
Romain Guybb9524b2010-06-22 18:56:38 -0700192
Romain Guy7ae7ac42010-06-25 13:46:18 -0700193 if (restoreSnapshot()) {
194 setScissorFromClip();
195 }
Romain Guybb9524b2010-06-22 18:56:38 -0700196}
197
198void OpenGLRenderer::restoreToCount(int saveCount) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700199 if (saveCount <= 0 || saveCount > mSaveCount) return;
Romain Guybb9524b2010-06-22 18:56:38 -0700200
Romain Guy7ae7ac42010-06-25 13:46:18 -0700201 bool restoreClip = false;
Romain Guybb9524b2010-06-22 18:56:38 -0700202
Romain Guy7ae7ac42010-06-25 13:46:18 -0700203 while (mSaveCount != saveCount - 1) {
204 restoreClip |= restoreSnapshot();
205 }
Romain Guybb9524b2010-06-22 18:56:38 -0700206
Romain Guy7ae7ac42010-06-25 13:46:18 -0700207 if (restoreClip) {
208 setScissorFromClip();
209 }
Romain Guybb9524b2010-06-22 18:56:38 -0700210}
211
212int OpenGLRenderer::saveSnapshot() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700213 mSnapshot = new Snapshot(mSnapshot);
214 return ++mSaveCount;
Romain Guybb9524b2010-06-22 18:56:38 -0700215}
216
217bool OpenGLRenderer::restoreSnapshot() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700218 bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet;
Romain Guybd6b79b2010-06-26 00:13:53 -0700219 bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer;
Romain Guyf86ef572010-07-01 11:05:42 -0700220 bool restoreOrtho = mSnapshot->flags & Snapshot::kFlagDirtyOrtho;
Romain Guybb9524b2010-06-22 18:56:38 -0700221
Romain Guybd6b79b2010-06-26 00:13:53 -0700222 sp<Snapshot> current = mSnapshot;
223 sp<Snapshot> previous = mSnapshot->previous;
224
Romain Guyf86ef572010-07-01 11:05:42 -0700225 if (restoreOrtho) {
Romain Guy260e1022010-07-12 14:41:06 -0700226 mOrthoMatrix.load(current->orthoMatrix);
Romain Guyf86ef572010-07-01 11:05:42 -0700227 }
228
Romain Guybd6b79b2010-06-26 00:13:53 -0700229 if (restoreLayer) {
Romain Guyd55a8612010-06-28 17:42:46 -0700230 composeLayer(current, previous);
Romain Guybd6b79b2010-06-26 00:13:53 -0700231 }
232
233 mSnapshot = previous;
Romain Guy7ae7ac42010-06-25 13:46:18 -0700234 mSaveCount--;
Romain Guyf6a11b82010-06-23 17:47:49 -0700235
Romain Guy7ae7ac42010-06-25 13:46:18 -0700236 return restoreClip;
Romain Guybb9524b2010-06-22 18:56:38 -0700237}
238
Romain Guyd55a8612010-06-28 17:42:46 -0700239void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
Romain Guydda570202010-07-06 11:39:32 -0700240 if (!current->layer) {
241 LOGE("Attempting to compose a layer that does not exist");
242 return;
243 }
244
Romain Guyd55a8612010-06-28 17:42:46 -0700245 // Unbind current FBO and restore previous one
246 // Most of the time, previous->fbo will be 0 to bind the default buffer
247 glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
248
249 // Restore the clip from the previous snapshot
Romain Guy079ba2c2010-07-16 14:12:24 -0700250 const Rect& clip = previous->clipRect;
Romain Guyd55a8612010-06-28 17:42:46 -0700251 glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
252
Romain Guydda570202010-07-06 11:39:32 -0700253 Layer* layer = current->layer;
254
Romain Guyd55a8612010-06-28 17:42:46 -0700255 // Compute the correct texture coordinates for the FBO texture
256 // The texture is currently as big as the window but drawn with
257 // a quad of the appropriate size
Romain Guydda570202010-07-06 11:39:32 -0700258 const Rect& rect = layer->layer;
Romain Guyd55a8612010-06-28 17:42:46 -0700259
Romain Guydda570202010-07-06 11:39:32 -0700260 drawTextureRect(rect.left, rect.top, rect.right, rect.bottom,
Romain Guya9794742010-07-13 11:37:54 -0700261 layer->texture, layer->alpha, layer->mode, layer->blend);
Romain Guyd55a8612010-06-28 17:42:46 -0700262
Romain Guydda570202010-07-06 11:39:32 -0700263 LayerSize size(rect.getWidth(), rect.getHeight());
Romain Guyf18fd992010-07-08 11:45:51 -0700264 // Failing to add the layer to the cache should happen only if the
265 // layer is too large
Romain Guydda570202010-07-06 11:39:32 -0700266 if (!mLayerCache.put(size, layer)) {
267 LAYER_LOGD("Deleting layer");
268
269 glDeleteFramebuffers(1, &layer->fbo);
270 glDeleteTextures(1, &layer->texture);
271
272 delete layer;
273 }
Romain Guyd55a8612010-06-28 17:42:46 -0700274}
275
Romain Guyf6a11b82010-06-23 17:47:49 -0700276///////////////////////////////////////////////////////////////////////////////
Romain Guybd6b79b2010-06-26 00:13:53 -0700277// Layers
278///////////////////////////////////////////////////////////////////////////////
279
280int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
281 const SkPaint* p, int flags) {
Romain Guyd55a8612010-06-28 17:42:46 -0700282 int count = saveSnapshot();
283
284 int alpha = 255;
285 SkXfermode::Mode mode;
286
287 if (p) {
288 alpha = p->getAlpha();
289 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
290 if (!isMode) {
291 // Assume SRC_OVER
292 mode = SkXfermode::kSrcOver_Mode;
293 }
294 } else {
295 mode = SkXfermode::kSrcOver_Mode;
296 }
297
298 createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags);
299
300 return count;
Romain Guybd6b79b2010-06-26 00:13:53 -0700301}
302
303int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
304 int alpha, int flags) {
305 int count = saveSnapshot();
Romain Guyd55a8612010-06-28 17:42:46 -0700306 createLayer(mSnapshot, left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
307 return count;
308}
Romain Guybd6b79b2010-06-26 00:13:53 -0700309
Romain Guyd55a8612010-06-28 17:42:46 -0700310bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
311 float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) {
Romain Guybd6b79b2010-06-26 00:13:53 -0700312
Romain Guyd27977d2010-07-14 19:18:51 -0700313 LAYER_LOGD("Requesting layer %fx%f", right - left, bottom - top);
Romain Guydda570202010-07-06 11:39:32 -0700314 LAYER_LOGD("Layer cache size = %d", mLayerCache.getSize());
Romain Guy8ba548f2010-06-30 19:21:21 -0700315
Romain Guyf18fd992010-07-08 11:45:51 -0700316 GLuint previousFbo = snapshot->previous.get() ? snapshot->previous->fbo : 0;
317 LayerSize size(right - left, bottom - top);
318
Romain Guyf18fd992010-07-08 11:45:51 -0700319 Layer* layer = mLayerCache.get(size, previousFbo);
Romain Guydda570202010-07-06 11:39:32 -0700320 if (!layer) {
Romain Guyf18fd992010-07-08 11:45:51 -0700321 return false;
Romain Guybd6b79b2010-06-26 00:13:53 -0700322 }
323
Romain Guyf18fd992010-07-08 11:45:51 -0700324 glBindFramebuffer(GL_FRAMEBUFFER, layer->fbo);
325
Romain Guyf86ef572010-07-01 11:05:42 -0700326 // Clear the FBO
327 glDisable(GL_SCISSOR_TEST);
328 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
329 glClear(GL_COLOR_BUFFER_BIT);
330 glEnable(GL_SCISSOR_TEST);
331
Romain Guydda570202010-07-06 11:39:32 -0700332 // Save the layer in the snapshot
Romain Guyd55a8612010-06-28 17:42:46 -0700333 snapshot->flags |= Snapshot::kFlagIsLayer;
Romain Guydda570202010-07-06 11:39:32 -0700334 layer->mode = mode;
335 layer->alpha = alpha / 255.0f;
336 layer->layer.set(left, top, right, bottom);
337
338 snapshot->layer = layer;
339 snapshot->fbo = layer->fbo;
Romain Guyd55a8612010-06-28 17:42:46 -0700340
Romain Guyf86ef572010-07-01 11:05:42 -0700341 // Creates a new snapshot to draw into the FBO
342 saveSnapshot();
343 // TODO: This doesn't preserve other transformations (check Skia first)
344 mSnapshot->transform.loadTranslate(-left, -top, 0.0f);
Romain Guy079ba2c2010-07-16 14:12:24 -0700345 mSnapshot->setClip(0.0f, 0.0f, right - left, bottom - top);
Romain Guyf86ef572010-07-01 11:05:42 -0700346 mSnapshot->height = bottom - top;
347 setScissorFromClip();
348
Romain Guy079ba2c2010-07-16 14:12:24 -0700349 mSnapshot->flags = Snapshot::kFlagDirtyOrtho | Snapshot::kFlagClipSet;
Romain Guy260e1022010-07-12 14:41:06 -0700350 mSnapshot->orthoMatrix.load(mOrthoMatrix);
Romain Guyf86ef572010-07-01 11:05:42 -0700351
352 // Change the ortho projection
Romain Guy260e1022010-07-12 14:41:06 -0700353 mOrthoMatrix.loadOrtho(0.0f, right - left, bottom - top, 0.0f, 0.0f, 1.0f);
Romain Guyf86ef572010-07-01 11:05:42 -0700354
Romain Guyd55a8612010-06-28 17:42:46 -0700355 return true;
Romain Guybd6b79b2010-06-26 00:13:53 -0700356}
357
358///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -0700359// Transforms
360///////////////////////////////////////////////////////////////////////////////
361
362void OpenGLRenderer::translate(float dx, float dy) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700363 mSnapshot->transform.translate(dx, dy, 0.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700364}
365
366void OpenGLRenderer::rotate(float degrees) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700367 mSnapshot->transform.rotate(degrees, 0.0f, 0.0f, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700368}
369
370void OpenGLRenderer::scale(float sx, float sy) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700371 mSnapshot->transform.scale(sx, sy, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700372}
373
374void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700375 mSnapshot->transform.load(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700376}
377
378void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700379 mSnapshot->transform.copyTo(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700380}
381
382void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700383 mat4 m(*matrix);
384 mSnapshot->transform.multiply(m);
Romain Guyf6a11b82010-06-23 17:47:49 -0700385}
386
387///////////////////////////////////////////////////////////////////////////////
388// Clipping
389///////////////////////////////////////////////////////////////////////////////
390
Romain Guybb9524b2010-06-22 18:56:38 -0700391void OpenGLRenderer::setScissorFromClip() {
Romain Guy079ba2c2010-07-16 14:12:24 -0700392 const Rect& clip = mSnapshot->clipRect;
Romain Guyf86ef572010-07-01 11:05:42 -0700393 glScissor(clip.left, mSnapshot->height - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy9d5316e2010-06-24 19:30:36 -0700394}
395
396const Rect& OpenGLRenderer::getClipBounds() {
Romain Guy079ba2c2010-07-16 14:12:24 -0700397 return mSnapshot->getLocalClip();
Romain Guybb9524b2010-06-22 18:56:38 -0700398}
399
Romain Guyc7d53492010-06-25 13:41:57 -0700400bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
Romain Guyc7d53492010-06-25 13:41:57 -0700401 Rect r(left, top, right, bottom);
Romain Guy079ba2c2010-07-16 14:12:24 -0700402 mSnapshot->transform.mapRect(r);
Romain Guyc7d53492010-06-25 13:41:57 -0700403 return !mSnapshot->clipRect.intersects(r);
404}
405
Romain Guy079ba2c2010-07-16 14:12:24 -0700406bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
407 bool clipped = mSnapshot->clip(left, top, right, bottom, op);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700408 if (clipped) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700409 setScissorFromClip();
410 }
Romain Guy079ba2c2010-07-16 14:12:24 -0700411 return !mSnapshot->clipRect.isEmpty();
Romain Guye4d01122010-06-16 18:44:05 -0700412}
413
Romain Guyf6a11b82010-06-23 17:47:49 -0700414///////////////////////////////////////////////////////////////////////////////
415// Drawing
416///////////////////////////////////////////////////////////////////////////////
417
Romain Guyc1396e92010-06-30 17:56:19 -0700418void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700419 const float right = left + bitmap->width();
420 const float bottom = top + bitmap->height();
421
422 if (quickReject(left, top, right, bottom)) {
423 return;
424 }
425
Romain Guyf86ef572010-07-01 11:05:42 -0700426 const Texture* texture = mTextureCache.get(bitmap);
Romain Guy6926c722010-07-12 20:20:03 -0700427 drawTextureRect(left, top, right, bottom, texture, paint);
Romain Guyce0537b2010-06-29 21:05:21 -0700428}
429
Romain Guyf86ef572010-07-01 11:05:42 -0700430void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint) {
431 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
432 const mat4 transform(*matrix);
433 transform.mapRect(r);
434
Romain Guy6926c722010-07-12 20:20:03 -0700435 if (quickReject(r.left, r.top, r.right, r.bottom)) {
436 return;
437 }
438
Romain Guyf86ef572010-07-01 11:05:42 -0700439 const Texture* texture = mTextureCache.get(bitmap);
Romain Guy82ba8142010-07-09 13:25:56 -0700440 drawTextureRect(r.left, r.top, r.right, r.bottom, texture, paint);
Romain Guyf86ef572010-07-01 11:05:42 -0700441}
442
Romain Guy8ba548f2010-06-30 19:21:21 -0700443void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
444 float srcLeft, float srcTop, float srcRight, float srcBottom,
445 float dstLeft, float dstTop, float dstRight, float dstBottom,
Romain Guyf86ef572010-07-01 11:05:42 -0700446 const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700447 if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) {
448 return;
449 }
450
Romain Guyf86ef572010-07-01 11:05:42 -0700451 const Texture* texture = mTextureCache.get(bitmap);
Romain Guy8ba548f2010-06-30 19:21:21 -0700452
Romain Guy8ba548f2010-06-30 19:21:21 -0700453 const float width = texture->width;
454 const float height = texture->height;
455
456 const float u1 = srcLeft / width;
457 const float v1 = srcTop / height;
458 const float u2 = srcRight / width;
459 const float v2 = srcBottom / height;
460
461 resetDrawTextureTexCoords(u1, v1, u2, v2);
462
Romain Guy82ba8142010-07-09 13:25:56 -0700463 drawTextureRect(dstLeft, dstTop, dstRight, dstBottom, texture, paint);
Romain Guy8ba548f2010-06-30 19:21:21 -0700464
465 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
466}
467
Romain Guydeba7852010-07-07 17:54:48 -0700468void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
469 float left, float top, float right, float bottom, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700470 if (quickReject(left, top, right, bottom)) {
471 return;
472 }
473
Romain Guyf7f93552010-07-08 19:17:03 -0700474 const Texture* texture = mTextureCache.get(bitmap);
475
476 int alpha;
477 SkXfermode::Mode mode;
478 getAlphaAndMode(paint, &alpha, &mode);
479
Romain Guyf7f93552010-07-08 19:17:03 -0700480 Patch* mesh = mPatchCache.get(patch);
Romain Guyfb5e23c2010-07-09 13:52:56 -0700481 mesh->updateVertices(bitmap, left, top, right, bottom,
482 &patch->xDivs[0], &patch->yDivs[0], patch->numXDivs, patch->numYDivs);
Romain Guyf7f93552010-07-08 19:17:03 -0700483
484 // Specify right and bottom as +1.0f from left/top to prevent scaling since the
485 // patch mesh already defines the final size
Romain Guya9794742010-07-13 11:37:54 -0700486 drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha / 255.0f,
487 mode, texture->blend, &mesh->vertices[0].position[0],
Romain Guy16202fc2010-07-09 16:13:28 -0700488 &mesh->vertices[0].texture[0], mesh->indices, mesh->indicesCount);
Romain Guyf7f93552010-07-08 19:17:03 -0700489}
490
Romain Guy85bf02f2010-06-22 13:11:24 -0700491void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guy079ba2c2010-07-16 14:12:24 -0700492 const Rect& clip = mSnapshot->clipRect;
Romain Guy3d58c032010-07-14 16:34:53 -0700493 drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
Romain Guyc7d53492010-06-25 13:41:57 -0700494}
Romain Guy9d5316e2010-06-24 19:30:36 -0700495
Romain Guybd6b79b2010-06-26 00:13:53 -0700496void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, const SkPaint* p) {
Romain Guy6926c722010-07-12 20:20:03 -0700497 if (quickReject(left, top, right, bottom)) {
498 return;
499 }
500
Romain Guy026c5e162010-06-28 17:12:22 -0700501 SkXfermode::Mode mode;
502
503 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
504 if (!isMode) {
505 // Assume SRC_OVER
506 mode = SkXfermode::kSrcOver_Mode;
507 }
508
509 // Skia draws using the color's alpha channel if < 255
510 // Otherwise, it uses the paint's alpha
511 int color = p->getColor();
Romain Guyd27977d2010-07-14 19:18:51 -0700512 if (((color >> 24) & 0xff) == 255) {
Romain Guy026c5e162010-06-28 17:12:22 -0700513 color |= p->getAlpha() << 24;
514 }
515
516 drawColorRect(left, top, right, bottom, color, mode);
Romain Guyc7d53492010-06-25 13:41:57 -0700517}
Romain Guy9d5316e2010-06-24 19:30:36 -0700518
Romain Guy6926c722010-07-12 20:20:03 -0700519///////////////////////////////////////////////////////////////////////////////
Romain Guyd27977d2010-07-14 19:18:51 -0700520// Shaders
521///////////////////////////////////////////////////////////////////////////////
522
523void OpenGLRenderer::resetShader() {
524 mShader = OpenGLRenderer::kShaderNone;
Romain Guyf9764a42010-07-16 23:13:33 -0700525 mShaderKey = NULL;
Romain Guyd27977d2010-07-14 19:18:51 -0700526 mShaderBlend = false;
527 mShaderTileX = SkShader::kClamp_TileMode;
528 mShaderTileY = SkShader::kClamp_TileMode;
529}
530
531void OpenGLRenderer::setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX,
532 SkShader::TileMode tileY, SkMatrix* matrix, bool hasAlpha) {
Romain Guy7fac2e12010-07-16 17:10:13 -0700533 mShader = OpenGLRenderer::kShaderBitmap;
Romain Guyd27977d2010-07-14 19:18:51 -0700534 mShaderBlend = hasAlpha;
535 mShaderBitmap = bitmap;
536 mShaderTileX = tileX;
537 mShaderTileY = tileY;
538 mShaderMatrix = matrix;
539}
540
Romain Guyf9764a42010-07-16 23:13:33 -0700541void OpenGLRenderer::setupLinearGradientShader(SkShader* shader, float* bounds,uint32_t* colors,
Romain Guy7fac2e12010-07-16 17:10:13 -0700542 float* positions, SkShader::TileMode tileMode, SkMatrix* matrix, bool hasAlpha) {
Romain Guyf9764a42010-07-16 23:13:33 -0700543 // TODO: We should use a struct to describe each shader
Romain Guy7fac2e12010-07-16 17:10:13 -0700544 mShader = OpenGLRenderer::kShaderLinearGradient;
Romain Guyf9764a42010-07-16 23:13:33 -0700545 mShaderKey = shader;
Romain Guy7fac2e12010-07-16 17:10:13 -0700546 mShaderBlend = hasAlpha;
547 mShaderTileX = tileMode;
548 mShaderTileY = tileMode;
549 mShaderMatrix = matrix;
550 mShaderBounds = bounds;
551 mShaderColors = colors;
552 mShaderPositions = positions;
553}
554
Romain Guyd27977d2010-07-14 19:18:51 -0700555///////////////////////////////////////////////////////////////////////////////
Romain Guy6926c722010-07-12 20:20:03 -0700556// Drawing implementation
557///////////////////////////////////////////////////////////////////////////////
558
Romain Guy026c5e162010-06-28 17:12:22 -0700559void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
Romain Guy3d58c032010-07-14 16:34:53 -0700560 int color, SkXfermode::Mode mode, bool ignoreTransform) {
Romain Guyd27977d2010-07-14 19:18:51 -0700561 // If a shader is set, preserve only the alpha
562 if (mShader != kShaderNone) {
563 color |= 0x00ffffff;
564 }
565
566 // Render using pre-multiplied alpha
Romain Guy026c5e162010-06-28 17:12:22 -0700567 const int alpha = (color >> 24) & 0xFF;
Romain Guyd27977d2010-07-14 19:18:51 -0700568 const GLfloat a = alpha / 255.0f;
569 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
570 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
571 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
572
573 switch (mShader) {
Romain Guy7fac2e12010-07-16 17:10:13 -0700574 case OpenGLRenderer::kShaderBitmap:
Romain Guyd27977d2010-07-14 19:18:51 -0700575 drawBitmapShader(left, top, right, bottom, a, mode);
576 return;
Romain Guy7fac2e12010-07-16 17:10:13 -0700577 case OpenGLRenderer::kShaderLinearGradient:
578 // TODO: Generate gradient texture, set appropriate shader
579 break;
Romain Guyd27977d2010-07-14 19:18:51 -0700580 default:
581 break;
582 }
Romain Guy026c5e162010-06-28 17:12:22 -0700583
Romain Guy6926c722010-07-12 20:20:03 -0700584 // Pre-multiplication happens when setting the shader color
Romain Guyd27977d2010-07-14 19:18:51 -0700585 chooseBlending(alpha < 255 || mShaderBlend, mode);
Romain Guy9d5316e2010-06-24 19:30:36 -0700586
Romain Guyc7d53492010-06-25 13:41:57 -0700587 mModelView.loadTranslate(left, top, 0.0f);
588 mModelView.scale(right - left, bottom - top, 1.0f);
Romain Guy9d5316e2010-06-24 19:30:36 -0700589
Romain Guy079ba2c2010-07-16 14:12:24 -0700590 if (!useProgram(mDrawColorProgram)) {
Romain Guy6926c722010-07-12 20:20:03 -0700591 const GLvoid* p = &gDrawColorVertices[0].position[0];
Romain Guy079ba2c2010-07-16 14:12:24 -0700592 glVertexAttribPointer(mDrawColorProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guy6926c722010-07-12 20:20:03 -0700593 gDrawColorVertexStride, p);
594 }
Romain Guyd27977d2010-07-14 19:18:51 -0700595
596 if (!ignoreTransform) {
Romain Guy079ba2c2010-07-16 14:12:24 -0700597 mDrawColorProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);
Romain Guyd27977d2010-07-14 19:18:51 -0700598 } else {
599 mat4 identity;
Romain Guy079ba2c2010-07-16 14:12:24 -0700600 mDrawColorProgram->set(mOrthoMatrix, mModelView, identity);
Romain Guyd27977d2010-07-14 19:18:51 -0700601 }
602
Romain Guy079ba2c2010-07-16 14:12:24 -0700603 glUniform4f(mDrawColorProgram->color, r, g, b, a);
Romain Guy9d5316e2010-06-24 19:30:36 -0700604
Romain Guyc7d53492010-06-25 13:41:57 -0700605 glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawColorVertexCount);
Romain Guy82ba8142010-07-09 13:25:56 -0700606}
Romain Guy026c5e162010-06-28 17:12:22 -0700607
Romain Guyd27977d2010-07-14 19:18:51 -0700608void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float bottom,
609 float alpha, SkXfermode::Mode mode) {
610 const Texture* texture = mTextureCache.get(mShaderBitmap);
611
612 const float width = texture->width;
613 const float height = texture->height;
614
615 // This could be done in the vertex shader but we have only 4 vertices
616 float u1 = 0.0f;
617 float v1 = 0.0f;
618 float u2 = right - left;
619 float v2 = bottom - top;
620
621 if (mShaderMatrix) {
622 SkMatrix inverse;
623 mShaderMatrix->invert(&inverse);
624 mat4 m(inverse);
625 Rect r(u1, v1, u2, v2);
626 m.mapRect(r);
627
628 u1 = r.left;
629 u2 = r.right;
630 v1 = r.top;
631 v2 = r.bottom;
632 }
633
634 u1 /= width;
635 u2 /= width;
636 v1 /= height;
637 v2 /= height;
638
639 resetDrawTextureTexCoords(u1, v1, u2, v2);
640
641 drawTextureMesh(left, top, right, bottom, texture->id, alpha, mode, texture->blend,
642 &mDrawTextureVertices[0].position[0], &mDrawTextureVertices[0].texture[0], NULL);
643
644 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
645}
646
Romain Guy82ba8142010-07-09 13:25:56 -0700647void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700648 const Texture* texture, const SkPaint* paint) {
Romain Guy82ba8142010-07-09 13:25:56 -0700649 int alpha;
650 SkXfermode::Mode mode;
651 getAlphaAndMode(paint, &alpha, &mode);
652
Romain Guya9794742010-07-13 11:37:54 -0700653 drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode, texture->blend,
654 &mDrawTextureVertices[0].position[0], &mDrawTextureVertices[0].texture[0], NULL);
Romain Guy85bf02f2010-06-22 13:11:24 -0700655}
656
Romain Guybd6b79b2010-06-26 00:13:53 -0700657void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700658 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) {
659 drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend,
Romain Guyf7f93552010-07-08 19:17:03 -0700660 &mDrawTextureVertices[0].position[0], &mDrawTextureVertices[0].texture[0], NULL);
661}
662
663void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700664 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
Romain Guyf7f93552010-07-08 19:17:03 -0700665 GLvoid* vertices, GLvoid* texCoords, GLvoid* indices, GLsizei elementsCount) {
Romain Guybd6b79b2010-06-26 00:13:53 -0700666 mModelView.loadTranslate(left, top, 0.0f);
667 mModelView.scale(right - left, bottom - top, 1.0f);
668
Romain Guyd27977d2010-07-14 19:18:51 -0700669 useProgram(mDrawTextureProgram);
670 mDrawTextureProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);
Romain Guybd6b79b2010-06-26 00:13:53 -0700671
Romain Guya9794742010-07-13 11:37:54 -0700672 chooseBlending(blend || alpha < 1.0f, mode);
Romain Guyd55a8612010-06-28 17:42:46 -0700673
Romain Guy1e793862010-07-16 15:07:42 -0700674 if (texture != mLastTexture) {
675 glBindTexture(GL_TEXTURE_2D, texture);
676 mLastTexture = texture;
677 }
678 // TODO: Don't set the texture parameters every time
Romain Guyd27977d2010-07-14 19:18:51 -0700679 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gTileModes[mShaderTileX]);
680 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gTileModes[mShaderTileY]);
Romain Guyc1396e92010-06-30 17:56:19 -0700681
Romain Guya9794742010-07-13 11:37:54 -0700682 // Always premultiplied
Romain Guyd27977d2010-07-14 19:18:51 -0700683 glUniform4f(mDrawTextureProgram->color, alpha, alpha, alpha, alpha);
Romain Guybd6b79b2010-06-26 00:13:53 -0700684
Romain Guyd27977d2010-07-14 19:18:51 -0700685 glVertexAttribPointer(mDrawTextureProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guyf7f93552010-07-08 19:17:03 -0700686 gDrawTextureVertexStride, vertices);
Romain Guyd27977d2010-07-14 19:18:51 -0700687 glVertexAttribPointer(mDrawTextureProgram->texCoords, 2, GL_FLOAT, GL_FALSE,
Romain Guyf7f93552010-07-08 19:17:03 -0700688 gDrawTextureVertexStride, texCoords);
Romain Guybd6b79b2010-06-26 00:13:53 -0700689
Romain Guyf7f93552010-07-08 19:17:03 -0700690 if (!indices) {
691 glDrawArrays(GL_TRIANGLE_STRIP, 0, gDrawTextureVertexCount);
692 } else {
693 glDrawElements(GL_TRIANGLES, elementsCount, GL_UNSIGNED_SHORT, indices);
694 }
Romain Guy82ba8142010-07-09 13:25:56 -0700695}
696
697void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode, bool isPremultiplied) {
698 // In theory we should not blend if the mode is Src, but it's rare enough
699 // that it's not worth it
700 blend = blend || mode != SkXfermode::kSrcOver_Mode;
701 if (blend) {
702 if (!mBlend) {
703 glEnable(GL_BLEND);
704 }
705
706 GLenum sourceMode = gBlends[mode].src;
707 GLenum destMode = gBlends[mode].dst;
708 if (!isPremultiplied && sourceMode == GL_ONE) {
709 sourceMode = GL_SRC_ALPHA;
710 }
711
712 if (sourceMode != mLastSrcMode || destMode != mLastDstMode) {
713 glBlendFunc(sourceMode, destMode);
714 mLastSrcMode = sourceMode;
715 mLastDstMode = destMode;
716 }
717 } else if (mBlend) {
718 glDisable(GL_BLEND);
719 }
720 mBlend = blend;
Romain Guybd6b79b2010-06-26 00:13:53 -0700721}
722
Romain Guyd27977d2010-07-14 19:18:51 -0700723bool OpenGLRenderer::useProgram(const sp<Program>& program) {
724 if (!program->isInUse()) {
725 mCurrentProgram->remove();
726 program->use();
727 mCurrentProgram = program;
Romain Guy6926c722010-07-12 20:20:03 -0700728 return false;
Romain Guy260e1022010-07-12 14:41:06 -0700729 }
Romain Guy6926c722010-07-12 20:20:03 -0700730 return true;
Romain Guy260e1022010-07-12 14:41:06 -0700731}
732
Romain Guy026c5e162010-06-28 17:12:22 -0700733void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
Romain Guy82ba8142010-07-09 13:25:56 -0700734 TextureVertex* v = &mDrawTextureVertices[0];
735 TextureVertex::setUV(v++, u1, v1);
736 TextureVertex::setUV(v++, u2, v1);
737 TextureVertex::setUV(v++, u1, v2);
738 TextureVertex::setUV(v++, u2, v2);
Romain Guy8ba548f2010-06-30 19:21:21 -0700739}
740
741void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
742 if (paint) {
743 const bool isMode = SkXfermode::IsMode(paint->getXfermode(), mode);
744 if (!isMode) {
745 // Assume SRC_OVER
746 *mode = SkXfermode::kSrcOver_Mode;
747 }
748
749 // Skia draws using the color's alpha channel if < 255
750 // Otherwise, it uses the paint's alpha
751 int color = paint->getColor();
752 *alpha = (color >> 24) & 0xFF;
753 if (*alpha == 255) {
754 *alpha = paint->getAlpha();
755 }
756 } else {
757 *mode = SkXfermode::kSrcOver_Mode;
758 *alpha = 255;
759 }
Romain Guy026c5e162010-06-28 17:12:22 -0700760}
761
Romain Guy9d5316e2010-06-24 19:30:36 -0700762}; // namespace uirenderer
Romain Guye4d01122010-06-16 18:44:05 -0700763}; // namespace android