blob: 90d6ea1bc1f060e19eb478c392c125eea211afc2 [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>
Romain Guy694b5192010-07-21 21:33:20 -070024#include <SkTypeface.h>
Romain Guy5cbbce52010-06-27 22:59:20 -070025
Romain Guye4d01122010-06-16 18:44:05 -070026#include <utils/Log.h>
Romain Guye2d345e2010-09-24 18:39:22 -070027#include <utils/StopWatch.h>
Romain Guye4d01122010-06-16 18:44:05 -070028
Romain Guy5b3b3522010-10-27 18:57:51 -070029#include <ui/Rect.h>
30
Romain Guy85bf02f2010-06-22 13:11:24 -070031#include "OpenGLRenderer.h"
Romain Guy0fe478e2010-11-08 12:08:41 -080032#include "DisplayListRenderer.h"
Romain Guya957eea2010-12-08 18:34:42 -080033#include "Vector.h"
Romain Guye4d01122010-06-16 18:44:05 -070034
35namespace android {
Romain Guy9d5316e2010-06-24 19:30:36 -070036namespace uirenderer {
37
38///////////////////////////////////////////////////////////////////////////////
39// Defines
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guy759ea802010-09-16 20:49:46 -070042#define RAD_TO_DEG (180.0f / 3.14159265f)
43#define MIN_ANGLE 0.001f
44
Romain Guydbc26d22010-10-11 17:58:29 -070045// TODO: This should be set in properties
46#define ALPHA_THRESHOLD (0x7f / PANEL_BIT_DEPTH)
47
Romain Guy9d5316e2010-06-24 19:30:36 -070048///////////////////////////////////////////////////////////////////////////////
49// Globals
50///////////////////////////////////////////////////////////////////////////////
51
Romain Guy889f8d12010-07-29 14:37:42 -070052/**
53 * Structure mapping Skia xfermodes to OpenGL blending factors.
54 */
55struct Blender {
56 SkXfermode::Mode mode;
57 GLenum src;
58 GLenum dst;
59}; // struct Blender
60
Romain Guy026c5e162010-06-28 17:12:22 -070061// In this array, the index of each Blender equals the value of the first
62// entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode]
63static const Blender gBlends[] = {
Romain Guyb146b122010-12-15 17:06:45 -080064 { SkXfermode::kClear_Mode, GL_ZERO, GL_ZERO },
65 { SkXfermode::kSrc_Mode, GL_ONE, GL_ZERO },
66 { SkXfermode::kDst_Mode, GL_ZERO, GL_ONE },
67 { SkXfermode::kSrcOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
68 { SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
69 { SkXfermode::kSrcIn_Mode, GL_DST_ALPHA, GL_ZERO },
70 { SkXfermode::kDstIn_Mode, GL_ZERO, GL_SRC_ALPHA },
71 { SkXfermode::kSrcOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
72 { SkXfermode::kDstOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
73 { SkXfermode::kSrcATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
74 { SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
75 { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }
Romain Guy026c5e162010-06-28 17:12:22 -070076};
Romain Guye4d01122010-06-16 18:44:05 -070077
Romain Guy87a76572010-09-13 18:11:21 -070078// This array contains the swapped version of each SkXfermode. For instance
79// this array's SrcOver blending mode is actually DstOver. You can refer to
80// createLayer() for more information on the purpose of this array.
Romain Guyf607bdc2010-09-10 19:20:06 -070081static const Blender gBlendsSwap[] = {
Romain Guyb146b122010-12-15 17:06:45 -080082 { SkXfermode::kClear_Mode, GL_ZERO, GL_ZERO },
83 { SkXfermode::kSrc_Mode, GL_ZERO, GL_ONE },
84 { SkXfermode::kDst_Mode, GL_ONE, GL_ZERO },
85 { SkXfermode::kSrcOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
86 { SkXfermode::kDstOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
87 { SkXfermode::kSrcIn_Mode, GL_ZERO, GL_SRC_ALPHA },
88 { SkXfermode::kDstIn_Mode, GL_DST_ALPHA, GL_ZERO },
89 { SkXfermode::kSrcOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
90 { SkXfermode::kDstOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
91 { SkXfermode::kSrcATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
92 { SkXfermode::kDstATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
93 { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }
Romain Guyf607bdc2010-09-10 19:20:06 -070094};
95
Romain Guy889f8d12010-07-29 14:37:42 -070096static const GLenum gTextureUnits[] = {
Romain Guyb146b122010-12-15 17:06:45 -080097 GL_TEXTURE0,
98 GL_TEXTURE1,
99 GL_TEXTURE2
Romain Guyd27977d2010-07-14 19:18:51 -0700100};
101
Romain Guyf6a11b82010-06-23 17:47:49 -0700102///////////////////////////////////////////////////////////////////////////////
103// Constructors/destructor
104///////////////////////////////////////////////////////////////////////////////
105
Romain Guyfb8b7632010-08-23 21:05:08 -0700106OpenGLRenderer::OpenGLRenderer(): mCaches(Caches::getInstance()) {
Romain Guy06f96e22010-07-30 19:18:16 -0700107 mShader = NULL;
Romain Guydb1938e2010-08-02 18:50:22 -0700108 mColorFilter = NULL;
Romain Guy1e45aae2010-08-13 19:39:53 -0700109 mHasShadow = false;
Romain Guy026c5e162010-06-28 17:12:22 -0700110
Romain Guyac670c02010-07-27 17:39:27 -0700111 memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));
112
Romain Guyae5575b2010-07-29 18:48:04 -0700113 mFirstSnapshot = new Snapshot;
Romain Guye4d01122010-06-16 18:44:05 -0700114}
115
Romain Guy85bf02f2010-06-22 13:11:24 -0700116OpenGLRenderer::~OpenGLRenderer() {
Romain Guy29d89972010-09-22 16:10:57 -0700117 // The context has already been destroyed at this point, do not call
118 // GL APIs. All GL state should be kept in Caches.h
Romain Guye4d01122010-06-16 18:44:05 -0700119}
120
Romain Guyf6a11b82010-06-23 17:47:49 -0700121///////////////////////////////////////////////////////////////////////////////
122// Setup
123///////////////////////////////////////////////////////////////////////////////
124
Romain Guy85bf02f2010-06-22 13:11:24 -0700125void OpenGLRenderer::setViewport(int width, int height) {
Romain Guy08ae3172010-06-21 19:35:50 -0700126 glViewport(0, 0, width, height);
Romain Guy260e1022010-07-12 14:41:06 -0700127 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
Romain Guybb9524b2010-06-22 18:56:38 -0700128
129 mWidth = width;
130 mHeight = height;
Romain Guyeb993562010-10-05 18:14:38 -0700131
132 mFirstSnapshot->height = height;
133 mFirstSnapshot->viewport.set(0, 0, width, height);
Romain Guy746b7402010-10-26 16:27:31 -0700134
135 mDirtyClip = false;
Romain Guye4d01122010-06-16 18:44:05 -0700136}
137
Romain Guy6b7bd242010-10-06 19:49:23 -0700138void OpenGLRenderer::prepare(bool opaque) {
Romain Guy7d7b5492011-01-24 16:33:45 -0800139 prepareDirty(0.0f, 0.0f, mWidth, mHeight, opaque);
140}
141
142void OpenGLRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) {
Romain Guyfe48f652010-11-11 15:36:56 -0800143 mCaches.clearGarbage();
144
Romain Guy8aef54f2010-09-01 15:13:49 -0700145 mSnapshot = new Snapshot(mFirstSnapshot,
146 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
Romain Guy8fb95422010-08-17 18:38:51 -0700147 mSaveCount = 1;
Romain Guyf6a11b82010-06-23 17:47:49 -0700148
Romain Guyfb8b7632010-08-23 21:05:08 -0700149 glViewport(0, 0, mWidth, mHeight);
150
Romain Guyd90f23e2010-09-09 11:47:54 -0700151 glDisable(GL_DITHER);
Romain Guybb9524b2010-06-22 18:56:38 -0700152
Romain Guy7d7b5492011-01-24 16:33:45 -0800153 glEnable(GL_SCISSOR_TEST);
154 glScissor(left, mSnapshot->height - bottom, right - left, bottom - top);
155 mSnapshot->setClip(left, top, right, bottom);
156
Romain Guy6b7bd242010-10-06 19:49:23 -0700157 if (!opaque) {
158 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
159 glClear(GL_COLOR_BUFFER_BIT);
160 }
Romain Guybb9524b2010-06-22 18:56:38 -0700161}
162
Romain Guyb025b9c2010-09-16 14:16:48 -0700163void OpenGLRenderer::finish() {
164#if DEBUG_OPENGL
165 GLenum status = GL_NO_ERROR;
166 while ((status = glGetError()) != GL_NO_ERROR) {
167 LOGD("GL error from OpenGLRenderer: 0x%x", status);
Romain Guya07105b2011-01-10 21:14:18 -0800168 switch (status) {
169 case GL_OUT_OF_MEMORY:
170 LOGE(" OpenGLRenderer is out of memory!");
171 break;
172 }
Romain Guyb025b9c2010-09-16 14:16:48 -0700173 }
174#endif
Romain Guyc15008e2010-11-10 11:59:15 -0800175#if DEBUG_MEMORY_USAGE
176 mCaches.dumpMemoryUsage();
Romain Guye190aa62010-11-10 19:01:29 -0800177#else
178 if (mCaches.getDebugLevel() & kDebugMemory) {
179 mCaches.dumpMemoryUsage();
180 }
Romain Guyc15008e2010-11-10 11:59:15 -0800181#endif
Romain Guyb025b9c2010-09-16 14:16:48 -0700182}
183
Romain Guy6c319ca2011-01-11 14:29:25 -0800184void OpenGLRenderer::interrupt() {
Romain Guyda8532c2010-08-31 11:50:35 -0700185 if (mCaches.currentProgram) {
186 if (mCaches.currentProgram->isInUse()) {
187 mCaches.currentProgram->remove();
188 mCaches.currentProgram = NULL;
189 }
190 }
Romain Guy50c0f092010-10-19 11:42:22 -0700191 mCaches.unbindMeshBuffer();
Romain Guyda8532c2010-08-31 11:50:35 -0700192}
193
Romain Guy6c319ca2011-01-11 14:29:25 -0800194void OpenGLRenderer::resume() {
Romain Guyeb993562010-10-05 18:14:38 -0700195 glViewport(0, 0, mSnapshot->viewport.getWidth(), mSnapshot->viewport.getHeight());
Romain Guyda8532c2010-08-31 11:50:35 -0700196
197 glEnable(GL_SCISSOR_TEST);
Romain Guy746b7402010-10-26 16:27:31 -0700198 dirtyClip();
Romain Guyda8532c2010-08-31 11:50:35 -0700199
Romain Guyf607bdc2010-09-10 19:20:06 -0700200 glDisable(GL_DITHER);
201
Romain Guy42f3a4b2011-01-19 13:42:26 -0800202 glBindFramebuffer(GL_FRAMEBUFFER, getTargetFbo());
Romain Guy03750a02010-10-18 14:06:08 -0700203 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guyf607bdc2010-09-10 19:20:06 -0700204
Romain Guy50c0f092010-10-19 11:42:22 -0700205 mCaches.blend = true;
206 glEnable(GL_BLEND);
207 glBlendFunc(mCaches.lastSrcMode, mCaches.lastDstMode);
208 glBlendEquation(GL_FUNC_ADD);
Romain Guyda8532c2010-08-31 11:50:35 -0700209}
210
Chet Haasedaf98e92011-01-10 14:10:36 -0800211bool OpenGLRenderer::callDrawGLFunction(Functor *functor) {
212 interrupt();
Romain Guyf90f8172011-01-25 22:53:24 -0800213 if (mDirtyClip) {
214 setScissorFromClip();
215 }
Chet Haasedaf98e92011-01-10 14:10:36 -0800216 status_t result = (*functor)();
217 resume();
218 return (result == 0) ? false : true;
219}
220
Romain Guyf6a11b82010-06-23 17:47:49 -0700221///////////////////////////////////////////////////////////////////////////////
222// State management
223///////////////////////////////////////////////////////////////////////////////
224
Romain Guybb9524b2010-06-22 18:56:38 -0700225int OpenGLRenderer::getSaveCount() const {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700226 return mSaveCount;
Romain Guybb9524b2010-06-22 18:56:38 -0700227}
228
229int OpenGLRenderer::save(int flags) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700230 return saveSnapshot(flags);
Romain Guybb9524b2010-06-22 18:56:38 -0700231}
232
233void OpenGLRenderer::restore() {
Romain Guy2542d192010-08-18 11:47:12 -0700234 if (mSaveCount > 1) {
235 restoreSnapshot();
Romain Guy7ae7ac42010-06-25 13:46:18 -0700236 }
Romain Guybb9524b2010-06-22 18:56:38 -0700237}
238
239void OpenGLRenderer::restoreToCount(int saveCount) {
Romain Guy8fb95422010-08-17 18:38:51 -0700240 if (saveCount < 1) saveCount = 1;
Romain Guybb9524b2010-06-22 18:56:38 -0700241
Romain Guy8fb95422010-08-17 18:38:51 -0700242 while (mSaveCount > saveCount) {
Romain Guy2542d192010-08-18 11:47:12 -0700243 restoreSnapshot();
Romain Guy7ae7ac42010-06-25 13:46:18 -0700244 }
Romain Guybb9524b2010-06-22 18:56:38 -0700245}
246
Romain Guy8aef54f2010-09-01 15:13:49 -0700247int OpenGLRenderer::saveSnapshot(int flags) {
248 mSnapshot = new Snapshot(mSnapshot, flags);
Romain Guy8fb95422010-08-17 18:38:51 -0700249 return mSaveCount++;
Romain Guybb9524b2010-06-22 18:56:38 -0700250}
251
252bool OpenGLRenderer::restoreSnapshot() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700253 bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet;
Romain Guybd6b79b2010-06-26 00:13:53 -0700254 bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer;
Romain Guyeb993562010-10-05 18:14:38 -0700255 bool restoreOrtho = mSnapshot->flags & Snapshot::kFlagDirtyOrtho;
Romain Guybb9524b2010-06-22 18:56:38 -0700256
Romain Guybd6b79b2010-06-26 00:13:53 -0700257 sp<Snapshot> current = mSnapshot;
258 sp<Snapshot> previous = mSnapshot->previous;
259
Romain Guyeb993562010-10-05 18:14:38 -0700260 if (restoreOrtho) {
261 Rect& r = previous->viewport;
262 glViewport(r.left, r.top, r.right, r.bottom);
263 mOrthoMatrix.load(current->orthoMatrix);
264 }
265
Romain Guy8b55f372010-08-18 17:10:07 -0700266 mSaveCount--;
267 mSnapshot = previous;
268
Romain Guy2542d192010-08-18 11:47:12 -0700269 if (restoreClip) {
Romain Guy746b7402010-10-26 16:27:31 -0700270 dirtyClip();
Romain Guy8fb95422010-08-17 18:38:51 -0700271 }
Romain Guy2542d192010-08-18 11:47:12 -0700272
Romain Guy5ec99242010-11-03 16:19:08 -0700273 if (restoreLayer) {
274 composeLayer(current, previous);
275 }
276
Romain Guy2542d192010-08-18 11:47:12 -0700277 return restoreClip;
Romain Guybb9524b2010-06-22 18:56:38 -0700278}
279
Romain Guyf6a11b82010-06-23 17:47:49 -0700280///////////////////////////////////////////////////////////////////////////////
Romain Guybd6b79b2010-06-26 00:13:53 -0700281// Layers
282///////////////////////////////////////////////////////////////////////////////
283
284int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700285 SkPaint* p, int flags) {
Romain Guyeb993562010-10-05 18:14:38 -0700286 const GLuint previousFbo = mSnapshot->fbo;
287 const int count = saveSnapshot(flags);
Romain Guyd55a8612010-06-28 17:42:46 -0700288
Romain Guyaf636eb2010-12-09 17:47:21 -0800289 if (!mSnapshot->isIgnored()) {
Romain Guye45362c2010-11-03 19:58:32 -0700290 int alpha = 255;
291 SkXfermode::Mode mode;
Romain Guyd55a8612010-06-28 17:42:46 -0700292
Romain Guye45362c2010-11-03 19:58:32 -0700293 if (p) {
294 alpha = p->getAlpha();
295 if (!mCaches.extensions.hasFramebufferFetch()) {
296 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
297 if (!isMode) {
298 // Assume SRC_OVER
299 mode = SkXfermode::kSrcOver_Mode;
300 }
301 } else {
302 mode = getXfermode(p->getXfermode());
Romain Guya5aed0d2010-09-09 14:42:43 -0700303 }
304 } else {
Romain Guye45362c2010-11-03 19:58:32 -0700305 mode = SkXfermode::kSrcOver_Mode;
Romain Guyd55a8612010-06-28 17:42:46 -0700306 }
Romain Guyd55a8612010-06-28 17:42:46 -0700307
Romain Guydbc26d22010-10-11 17:58:29 -0700308 createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags, previousFbo);
309 }
Romain Guyd55a8612010-06-28 17:42:46 -0700310
311 return count;
Romain Guybd6b79b2010-06-26 00:13:53 -0700312}
313
314int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
315 int alpha, int flags) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700316 if (alpha >= 255 - ALPHA_THRESHOLD) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700317 return saveLayer(left, top, right, bottom, NULL, flags);
Romain Guy8b55f372010-08-18 17:10:07 -0700318 } else {
Romain Guy8aef54f2010-09-01 15:13:49 -0700319 SkPaint paint;
320 paint.setAlpha(alpha);
321 return saveLayer(left, top, right, bottom, &paint, flags);
Romain Guy8b55f372010-08-18 17:10:07 -0700322 }
Romain Guyd55a8612010-06-28 17:42:46 -0700323}
Romain Guybd6b79b2010-06-26 00:13:53 -0700324
Romain Guy1c740bc2010-09-13 18:00:09 -0700325/**
326 * Layers are viewed by Skia are slightly different than layers in image editing
327 * programs (for instance.) When a layer is created, previously created layers
328 * and the frame buffer still receive every drawing command. For instance, if a
329 * layer is created and a shape intersecting the bounds of the layers and the
330 * framebuffer is draw, the shape will be drawn on both (unless the layer was
331 * created with the SkCanvas::kClipToLayer_SaveFlag flag.)
332 *
333 * A way to implement layers is to create an FBO for each layer, backed by an RGBA
334 * texture. Unfortunately, this is inefficient as it requires every primitive to
335 * be drawn n + 1 times, where n is the number of active layers. In practice this
336 * means, for every primitive:
337 * - Switch active frame buffer
338 * - Change viewport, clip and projection matrix
339 * - Issue the drawing
340 *
341 * Switching rendering target n + 1 times per drawn primitive is extremely costly.
Romain Guy6b7bd242010-10-06 19:49:23 -0700342 * To avoid this, layers are implemented in a different way here, at least in the
343 * general case. FBOs are used, as an optimization, when the "clip to layer" flag
344 * is set. When this flag is set we can redirect all drawing operations into a
345 * single FBO.
Romain Guy1c740bc2010-09-13 18:00:09 -0700346 *
347 * This implementation relies on the frame buffer being at least RGBA 8888. When
348 * a layer is created, only a texture is created, not an FBO. The content of the
349 * frame buffer contained within the layer's bounds is copied into this texture
Romain Guy87a76572010-09-13 18:11:21 -0700350 * using glCopyTexImage2D(). The layer's region is then cleared(1) in the frame
Romain Guy1c740bc2010-09-13 18:00:09 -0700351 * buffer and drawing continues as normal. This technique therefore treats the
352 * frame buffer as a scratch buffer for the layers.
353 *
354 * To compose the layers back onto the frame buffer, each layer texture
355 * (containing the original frame buffer data) is drawn as a simple quad over
356 * the frame buffer. The trick is that the quad is set as the composition
357 * destination in the blending equation, and the frame buffer becomes the source
358 * of the composition.
359 *
360 * Drawing layers with an alpha value requires an extra step before composition.
361 * An empty quad is drawn over the layer's region in the frame buffer. This quad
362 * is drawn with the rgba color (0,0,0,alpha). The alpha value offered by the
363 * quad is used to multiply the colors in the frame buffer. This is achieved by
364 * changing the GL blend functions for the GL_FUNC_ADD blend equation to
365 * GL_ZERO, GL_SRC_ALPHA.
366 *
367 * Because glCopyTexImage2D() can be slow, an alternative implementation might
368 * be use to draw a single clipped layer. The implementation described above
369 * is correct in every case.
Romain Guy87a76572010-09-13 18:11:21 -0700370 *
371 * (1) The frame buffer is actually not cleared right away. To allow the GPU
372 * to potentially optimize series of calls to glCopyTexImage2D, the frame
373 * buffer is left untouched until the first drawing operation. Only when
374 * something actually gets drawn are the layers regions cleared.
Romain Guy1c740bc2010-09-13 18:00:09 -0700375 */
Romain Guyd55a8612010-06-28 17:42:46 -0700376bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
Romain Guyeb993562010-10-05 18:14:38 -0700377 float right, float bottom, int alpha, SkXfermode::Mode mode,
378 int flags, GLuint previousFbo) {
379 LAYER_LOGD("Requesting layer %.2fx%.2f", right - left, bottom - top);
Romain Guyfb8b7632010-08-23 21:05:08 -0700380 LAYER_LOGD("Layer cache size = %d", mCaches.layerCache.getSize());
Romain Guy8ba548f2010-06-30 19:21:21 -0700381
Romain Guyeb993562010-10-05 18:14:38 -0700382 const bool fboLayer = flags & SkCanvas::kClipToLayer_SaveFlag;
383
Romain Guyf607bdc2010-09-10 19:20:06 -0700384 // Window coordinates of the layer
Romain Guy8aef54f2010-09-01 15:13:49 -0700385 Rect bounds(left, top, right, bottom);
Romain Guyae88e5e2010-10-22 17:49:18 -0700386 if (fboLayer) {
387 // Clear the previous layer regions before we change the viewport
388 clearLayerRegions();
389 } else {
Romain Guyeb993562010-10-05 18:14:38 -0700390 mSnapshot->transform->mapRect(bounds);
Romain Guyae517592010-10-22 10:40:27 -0700391
Romain Guyeb993562010-10-05 18:14:38 -0700392 // Layers only make sense if they are in the framebuffer's bounds
Romain Guy58ae6db2010-10-22 11:16:37 -0700393 bounds.intersect(*snapshot->clipRect);
Romain Guyae517592010-10-22 10:40:27 -0700394
Romain Guyae88e5e2010-10-22 17:49:18 -0700395 // We cannot work with sub-pixels in this case
396 bounds.snapToPixelBoundaries();
397
Romain Guyae517592010-10-22 10:40:27 -0700398 // When the layer is not an FBO, we may use glCopyTexImage so we
399 // need to make sure the layer does not extend outside the bounds
400 // of the framebuffer
401 bounds.intersect(snapshot->previous->viewport);
Romain Guyeb993562010-10-05 18:14:38 -0700402 }
Romain Guybf434112010-09-16 14:40:17 -0700403
Romain Guy746b7402010-10-26 16:27:31 -0700404 if (bounds.isEmpty() || bounds.getWidth() > mCaches.maxTextureSize ||
405 bounds.getHeight() > mCaches.maxTextureSize) {
Romain Guy32963c32010-12-10 14:43:41 -0800406 snapshot->empty = fboLayer;
Romain Guydbc26d22010-10-11 17:58:29 -0700407 } else {
Romain Guye45362c2010-11-03 19:58:32 -0700408 snapshot->invisible = snapshot->invisible || (alpha <= ALPHA_THRESHOLD && fboLayer);
Romain Guydbc26d22010-10-11 17:58:29 -0700409 }
410
411 // Bail out if we won't draw in this snapshot
Romain Guyaf636eb2010-12-09 17:47:21 -0800412 if (snapshot->invisible || snapshot->empty) {
Romain Guyb025b9c2010-09-16 14:16:48 -0700413 return false;
414 }
Romain Guyf18fd992010-07-08 11:45:51 -0700415
Romain Guy5b3b3522010-10-27 18:57:51 -0700416 glActiveTexture(gTextureUnits[0]);
Romain Guy8550c4c2010-10-08 15:49:53 -0700417 Layer* layer = mCaches.layerCache.get(bounds.getWidth(), bounds.getHeight());
Romain Guydda57022010-07-06 11:39:32 -0700418 if (!layer) {
Romain Guyf18fd992010-07-08 11:45:51 -0700419 return false;
Romain Guybd6b79b2010-06-26 00:13:53 -0700420 }
421
Romain Guydda57022010-07-06 11:39:32 -0700422 layer->mode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -0700423 layer->alpha = alpha;
Romain Guy8aef54f2010-09-01 15:13:49 -0700424 layer->layer.set(bounds);
Romain Guy8550c4c2010-10-08 15:49:53 -0700425 layer->texCoords.set(0.0f, bounds.getHeight() / float(layer->height),
426 bounds.getWidth() / float(layer->width), 0.0f);
Romain Guy171c5922011-01-06 10:04:23 -0800427 layer->colorFilter = mColorFilter;
Romain Guydda57022010-07-06 11:39:32 -0700428
Romain Guy8fb95422010-08-17 18:38:51 -0700429 // Save the layer in the snapshot
430 snapshot->flags |= Snapshot::kFlagIsLayer;
Romain Guydda57022010-07-06 11:39:32 -0700431 snapshot->layer = layer;
Romain Guy1d83e192010-08-17 11:37:00 -0700432
Romain Guyeb993562010-10-05 18:14:38 -0700433 if (fboLayer) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700434 return createFboLayer(layer, bounds, snapshot, previousFbo);
Romain Guyeb993562010-10-05 18:14:38 -0700435 } else {
436 // Copy the framebuffer into the layer
437 glBindTexture(GL_TEXTURE_2D, layer->texture);
Romain Guy514fb182011-01-19 14:38:29 -0800438 if (!bounds.isEmpty()) {
439 if (layer->empty) {
440 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left,
441 snapshot->height - bounds.bottom, layer->width, layer->height, 0);
442 layer->empty = false;
443 } else {
444 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bounds.left,
445 snapshot->height - bounds.bottom, bounds.getWidth(), bounds.getHeight());
446 }
447 // Enqueue the buffer coordinates to clear the corresponding region later
448 mLayers.push(new Rect(bounds));
Romain Guyae88e5e2010-10-22 17:49:18 -0700449 }
Romain Guyeb993562010-10-05 18:14:38 -0700450 }
Romain Guyf86ef572010-07-01 11:05:42 -0700451
Romain Guyd55a8612010-06-28 17:42:46 -0700452 return true;
Romain Guybd6b79b2010-06-26 00:13:53 -0700453}
454
Romain Guy5b3b3522010-10-27 18:57:51 -0700455bool OpenGLRenderer::createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
456 GLuint previousFbo) {
457 layer->fbo = mCaches.fboCache.get();
458
459#if RENDER_LAYERS_AS_REGIONS
460 snapshot->region = &snapshot->layer->region;
461 snapshot->flags |= Snapshot::kFlagFboTarget;
462#endif
463
464 Rect clip(bounds);
465 snapshot->transform->mapRect(clip);
466 clip.intersect(*snapshot->clipRect);
467 clip.snapToPixelBoundaries();
468 clip.intersect(snapshot->previous->viewport);
469
470 mat4 inverse;
471 inverse.loadInverse(*mSnapshot->transform);
472
473 inverse.mapRect(clip);
474 clip.snapToPixelBoundaries();
475 clip.intersect(bounds);
Romain Guy5ec99242010-11-03 16:19:08 -0700476 clip.translate(-bounds.left, -bounds.top);
Romain Guy5b3b3522010-10-27 18:57:51 -0700477
478 snapshot->flags |= Snapshot::kFlagIsFboLayer;
479 snapshot->fbo = layer->fbo;
480 snapshot->resetTransform(-bounds.left, -bounds.top, 0.0f);
Romain Guy5b3b3522010-10-27 18:57:51 -0700481 snapshot->resetClip(clip.left, clip.top, clip.right, clip.bottom);
482 snapshot->viewport.set(0.0f, 0.0f, bounds.getWidth(), bounds.getHeight());
483 snapshot->height = bounds.getHeight();
484 snapshot->flags |= Snapshot::kFlagDirtyOrtho;
485 snapshot->orthoMatrix.load(mOrthoMatrix);
486
487 // Bind texture to FBO
488 glBindFramebuffer(GL_FRAMEBUFFER, layer->fbo);
489 glBindTexture(GL_TEXTURE_2D, layer->texture);
490
491 // Initialize the texture if needed
492 if (layer->empty) {
493 layer->empty = false;
494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, layer->width, layer->height, 0,
495 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
496 }
497
498 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
499 layer->texture, 0);
500
501#if DEBUG_LAYERS_AS_REGIONS
502 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
503 if (status != GL_FRAMEBUFFER_COMPLETE) {
504 LOGE("Framebuffer incomplete (GL error code 0x%x)", status);
505
506 glBindFramebuffer(GL_FRAMEBUFFER, previousFbo);
507 glDeleteTextures(1, &layer->texture);
508 mCaches.fboCache.put(layer->fbo);
509
510 delete layer;
511
512 return false;
513 }
514#endif
515
516 // Clear the FBO, expand the clear region by 1 to get nice bilinear filtering
517 glScissor(clip.left - 1.0f, bounds.getHeight() - clip.bottom - 1.0f,
518 clip.getWidth() + 2.0f, clip.getHeight() + 2.0f);
519 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
520 glClear(GL_COLOR_BUFFER_BIT);
521
522 dirtyClip();
523
524 // Change the ortho projection
525 glViewport(0, 0, bounds.getWidth(), bounds.getHeight());
526 mOrthoMatrix.loadOrtho(0.0f, bounds.getWidth(), bounds.getHeight(), 0.0f, -1.0f, 1.0f);
527
528 return true;
529}
530
Romain Guy1c740bc2010-09-13 18:00:09 -0700531/**
532 * Read the documentation of createLayer() before doing anything in this method.
533 */
Romain Guy1d83e192010-08-17 11:37:00 -0700534void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
535 if (!current->layer) {
536 LOGE("Attempting to compose a layer that does not exist");
537 return;
538 }
539
Romain Guy5b3b3522010-10-27 18:57:51 -0700540 const bool fboLayer = current->flags & Snapshot::kFlagIsFboLayer;
Romain Guyeb993562010-10-05 18:14:38 -0700541
542 if (fboLayer) {
543 // Unbind current FBO and restore previous one
544 glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
545 }
546
Romain Guy1d83e192010-08-17 11:37:00 -0700547 Layer* layer = current->layer;
548 const Rect& rect = layer->layer;
549
Romain Guyeb993562010-10-05 18:14:38 -0700550 if (!fboLayer && layer->alpha < 255) {
Romain Guyf607bdc2010-09-10 19:20:06 -0700551 drawColorRect(rect.left, rect.top, rect.right, rect.bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -0700552 layer->alpha << 24, SkXfermode::kDstIn_Mode, true);
Romain Guy5b3b3522010-10-27 18:57:51 -0700553 // Required below, composeLayerRect() will divide by 255
554 layer->alpha = 255;
Romain Guyf607bdc2010-09-10 19:20:06 -0700555 }
556
Romain Guy03750a02010-10-18 14:06:08 -0700557 mCaches.unbindMeshBuffer();
Romain Guy8b55f372010-08-18 17:10:07 -0700558
Romain Guy746b7402010-10-26 16:27:31 -0700559 glActiveTexture(gTextureUnits[0]);
Romain Guy1d83e192010-08-17 11:37:00 -0700560
Romain Guy5b3b3522010-10-27 18:57:51 -0700561 // When the layer is stored in an FBO, we can save a bit of fillrate by
562 // drawing only the dirty region
563 if (fboLayer) {
564 dirtyLayer(rect.left, rect.top, rect.right, rect.bottom, *previous->transform);
Romain Guy171c5922011-01-06 10:04:23 -0800565 if (layer->colorFilter) {
566 setupColorFilter(layer->colorFilter);
567 }
Romain Guy5b3b3522010-10-27 18:57:51 -0700568 composeLayerRegion(layer, rect);
Romain Guy171c5922011-01-06 10:04:23 -0800569 if (layer->colorFilter) {
570 resetColorFilter();
571 }
Romain Guy5b3b3522010-10-27 18:57:51 -0700572 } else {
Romain Guy514fb182011-01-19 14:38:29 -0800573 if (!rect.isEmpty()) {
574 dirtyLayer(rect.left, rect.top, rect.right, rect.bottom);
575 composeLayerRect(layer, rect, true);
576 }
Romain Guy5b3b3522010-10-27 18:57:51 -0700577 }
Romain Guy8b55f372010-08-18 17:10:07 -0700578
Romain Guyeb993562010-10-05 18:14:38 -0700579 if (fboLayer) {
580 // Detach the texture from the FBO
581 glBindFramebuffer(GL_FRAMEBUFFER, current->fbo);
582 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
583 glBindFramebuffer(GL_FRAMEBUFFER, previous->fbo);
584
585 // Put the FBO name back in the cache, if it doesn't fit, it will be destroyed
586 mCaches.fboCache.put(current->fbo);
587 }
588
Romain Guy746b7402010-10-26 16:27:31 -0700589 dirtyClip();
590
Romain Guyeb993562010-10-05 18:14:38 -0700591 // Failing to add the layer to the cache should happen only if the layer is too large
Romain Guy8550c4c2010-10-08 15:49:53 -0700592 if (!mCaches.layerCache.put(layer)) {
Romain Guy1d83e192010-08-17 11:37:00 -0700593 LAYER_LOGD("Deleting layer");
Romain Guy1d83e192010-08-17 11:37:00 -0700594 glDeleteTextures(1, &layer->texture);
Romain Guy1d83e192010-08-17 11:37:00 -0700595 delete layer;
596 }
597}
598
Romain Guy5b3b3522010-10-27 18:57:51 -0700599void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) {
600 const Rect& texCoords = layer->texCoords;
601 resetDrawTextureTexCoords(texCoords.left, texCoords.top, texCoords.right, texCoords.bottom);
602
603 drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
604 layer->alpha / 255.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
605 &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount, swap, swap);
606
607 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
608}
609
610void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) {
611#if RENDER_LAYERS_AS_REGIONS
612 if (layer->region.isRect()) {
613 composeLayerRect(layer, rect);
614 layer->region.clear();
615 return;
616 }
617
618 if (!layer->region.isEmpty()) {
619 size_t count;
620 const android::Rect* rects = layer->region.getArray(&count);
621
Romain Guy5b3b3522010-10-27 18:57:51 -0700622 const float alpha = layer->alpha / 255.0f;
Romain Guy5b3b3522010-10-27 18:57:51 -0700623 const float texX = 1.0f / float(layer->width);
624 const float texY = 1.0f / float(layer->height);
Romain Guyf219da52011-01-16 12:54:25 -0800625 const float height = rect.getHeight();
Romain Guy5b3b3522010-10-27 18:57:51 -0700626
627 TextureVertex* mesh = mCaches.getRegionMesh();
628 GLsizei numQuads = 0;
629
Romain Guy7230a742011-01-10 22:26:16 -0800630 setupDraw();
631 setupDrawWithTexture();
632 setupDrawColor(alpha, alpha, alpha, alpha);
Romain Guyada830f2011-01-13 12:13:20 -0800633 setupDrawColorFilter();
Romain Guy7230a742011-01-10 22:26:16 -0800634 setupDrawBlending(layer->blend || layer->alpha < 255, layer->mode, false);
635 setupDrawProgram();
636 setupDrawDirtyRegionsDisabled();
637 setupDrawPureColorUniforms();
Romain Guyada830f2011-01-13 12:13:20 -0800638 setupDrawColorFilterUniforms();
Romain Guy7230a742011-01-10 22:26:16 -0800639 setupDrawTexture(layer->texture);
Romain Guyc038ea32011-01-12 15:08:47 -0800640 setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom);
Romain Guy7230a742011-01-10 22:26:16 -0800641 setupDrawMesh(&mesh[0].position[0], &mesh[0].texture[0]);
Romain Guy5b3b3522010-10-27 18:57:51 -0700642
643 for (size_t i = 0; i < count; i++) {
644 const android::Rect* r = &rects[i];
645
646 const float u1 = r->left * texX;
Romain Guyf219da52011-01-16 12:54:25 -0800647 const float v1 = (height - r->top) * texY;
Romain Guy5b3b3522010-10-27 18:57:51 -0700648 const float u2 = r->right * texX;
Romain Guyf219da52011-01-16 12:54:25 -0800649 const float v2 = (height - r->bottom) * texY;
Romain Guy5b3b3522010-10-27 18:57:51 -0700650
651 // TODO: Reject quads outside of the clip
652 TextureVertex::set(mesh++, r->left, r->top, u1, v1);
653 TextureVertex::set(mesh++, r->right, r->top, u2, v1);
654 TextureVertex::set(mesh++, r->left, r->bottom, u1, v2);
655 TextureVertex::set(mesh++, r->right, r->bottom, u2, v2);
656
657 numQuads++;
658
659 if (numQuads >= REGION_MESH_QUAD_COUNT) {
660 glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
661 numQuads = 0;
662 mesh = mCaches.getRegionMesh();
663 }
664 }
665
666 if (numQuads > 0) {
667 glDrawElements(GL_TRIANGLES, numQuads * 6, GL_UNSIGNED_SHORT, NULL);
668 }
669
670 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guy7230a742011-01-10 22:26:16 -0800671 finishDrawTexture();
Romain Guy5b3b3522010-10-27 18:57:51 -0700672
673#if DEBUG_LAYERS_AS_REGIONS
Romain Guy3a3133d2011-02-01 22:59:58 -0800674 drawRegionRects(layer->region);
Romain Guy5b3b3522010-10-27 18:57:51 -0700675#endif
676
677 layer->region.clear();
678 }
679#else
680 composeLayerRect(layer, rect);
681#endif
682}
683
Romain Guy3a3133d2011-02-01 22:59:58 -0800684void OpenGLRenderer::drawRegionRects(const Region& region) {
685#if DEBUG_LAYERS_AS_REGIONS
686 size_t count;
687 const android::Rect* rects = region.getArray(&count);
688
689 uint32_t colors[] = {
690 0x7fff0000, 0x7f00ff00,
691 0x7f0000ff, 0x7fff00ff,
692 };
693
694 int offset = 0;
695 int32_t top = rects[0].top;
696
697 for (size_t i = 0; i < count; i++) {
698 if (top != rects[i].top) {
699 offset ^= 0x2;
700 top = rects[i].top;
701 }
702
703 Rect r(rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
704 drawColorRect(r.left, r.top, r.right, r.bottom, colors[offset + (i & 0x1)],
705 SkXfermode::kSrcOver_Mode);
706 }
707#endif
708}
709
Romain Guy5b3b3522010-10-27 18:57:51 -0700710void OpenGLRenderer::dirtyLayer(const float left, const float top,
711 const float right, const float bottom, const mat4 transform) {
712#if RENDER_LAYERS_AS_REGIONS
Romain Guyf219da52011-01-16 12:54:25 -0800713 if (hasLayer()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700714 Rect bounds(left, top, right, bottom);
715 transform.mapRect(bounds);
Romain Guyf219da52011-01-16 12:54:25 -0800716 dirtyLayerUnchecked(bounds, getRegion());
Romain Guy5b3b3522010-10-27 18:57:51 -0700717 }
718#endif
719}
720
721void OpenGLRenderer::dirtyLayer(const float left, const float top,
722 const float right, const float bottom) {
723#if RENDER_LAYERS_AS_REGIONS
Romain Guyf219da52011-01-16 12:54:25 -0800724 if (hasLayer()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700725 Rect bounds(left, top, right, bottom);
Romain Guyf219da52011-01-16 12:54:25 -0800726 dirtyLayerUnchecked(bounds, getRegion());
Romain Guy1bd1bad2011-01-14 20:07:20 -0800727 }
728#endif
729}
730
731void OpenGLRenderer::dirtyLayerUnchecked(Rect& bounds, Region* region) {
732#if RENDER_LAYERS_AS_REGIONS
733 if (bounds.intersect(*mSnapshot->clipRect)) {
734 bounds.snapToPixelBoundaries();
735 android::Rect dirty(bounds.left, bounds.top, bounds.right, bounds.bottom);
736 if (!dirty.isEmpty()) {
737 region->orSelf(dirty);
Romain Guy5b3b3522010-10-27 18:57:51 -0700738 }
739 }
740#endif
741}
742
Romain Guy86942302010-09-12 13:02:16 -0700743void OpenGLRenderer::clearLayerRegions() {
Romain Guyaf636eb2010-12-09 17:47:21 -0800744 if (mLayers.size() == 0 || mSnapshot->isIgnored()) return;
Romain Guy86942302010-09-12 13:02:16 -0700745
Romain Guy5b3b3522010-10-27 18:57:51 -0700746 Rect clipRect(*mSnapshot->clipRect);
747 clipRect.snapToPixelBoundaries();
748
Romain Guy86942302010-09-12 13:02:16 -0700749 for (uint32_t i = 0; i < mLayers.size(); i++) {
750 Rect* bounds = mLayers.itemAt(i);
Romain Guy5b3b3522010-10-27 18:57:51 -0700751 if (clipRect.intersects(*bounds)) {
752 // Clear the framebuffer where the layer will draw
753 glScissor(bounds->left, mSnapshot->height - bounds->bottom,
754 bounds->getWidth(), bounds->getHeight());
755 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
756 glClear(GL_COLOR_BUFFER_BIT);
Romain Guy86942302010-09-12 13:02:16 -0700757
Romain Guy5b3b3522010-10-27 18:57:51 -0700758 // Restore the clip
759 dirtyClip();
760 }
Romain Guy86942302010-09-12 13:02:16 -0700761
762 delete bounds;
763 }
Romain Guy86942302010-09-12 13:02:16 -0700764
Romain Guy5b3b3522010-10-27 18:57:51 -0700765 mLayers.clear();
Romain Guy86942302010-09-12 13:02:16 -0700766}
767
Romain Guybd6b79b2010-06-26 00:13:53 -0700768///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -0700769// Transforms
770///////////////////////////////////////////////////////////////////////////////
771
772void OpenGLRenderer::translate(float dx, float dy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700773 mSnapshot->transform->translate(dx, dy, 0.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700774}
775
776void OpenGLRenderer::rotate(float degrees) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700777 mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700778}
779
780void OpenGLRenderer::scale(float sx, float sy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700781 mSnapshot->transform->scale(sx, sy, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700782}
783
Romain Guy807daf72011-01-18 11:19:19 -0800784void OpenGLRenderer::skew(float sx, float sy) {
785 mSnapshot->transform->skew(sx, sy);
786}
787
Romain Guyf6a11b82010-06-23 17:47:49 -0700788void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700789 mSnapshot->transform->load(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700790}
791
Romain Guy41030da2010-10-13 13:40:37 -0700792const float* OpenGLRenderer::getMatrix() const {
Romain Guy99bcdc52010-10-13 15:17:00 -0700793 if (mSnapshot->fbo != 0) {
794 return &mSnapshot->transform->data[0];
795 }
796 return &mIdentity.data[0];
Romain Guy41030da2010-10-13 13:40:37 -0700797}
798
Romain Guyf6a11b82010-06-23 17:47:49 -0700799void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700800 mSnapshot->transform->copyTo(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700801}
802
803void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guye5ebcb02010-10-15 13:57:28 -0700804 SkMatrix transform;
805 mSnapshot->transform->copyTo(transform);
806 transform.preConcat(*matrix);
807 mSnapshot->transform->load(transform);
Romain Guyf6a11b82010-06-23 17:47:49 -0700808}
809
810///////////////////////////////////////////////////////////////////////////////
811// Clipping
812///////////////////////////////////////////////////////////////////////////////
813
Romain Guybb9524b2010-06-22 18:56:38 -0700814void OpenGLRenderer::setScissorFromClip() {
Romain Guye5ebcb02010-10-15 13:57:28 -0700815 Rect clip(*mSnapshot->clipRect);
816 clip.snapToPixelBoundaries();
Romain Guyeb993562010-10-05 18:14:38 -0700817 glScissor(clip.left, mSnapshot->height - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy746b7402010-10-26 16:27:31 -0700818 mDirtyClip = false;
Romain Guy9d5316e2010-06-24 19:30:36 -0700819}
820
821const Rect& OpenGLRenderer::getClipBounds() {
Romain Guy079ba2c2010-07-16 14:12:24 -0700822 return mSnapshot->getLocalClip();
Romain Guybb9524b2010-06-22 18:56:38 -0700823}
824
Romain Guyc7d53492010-06-25 13:41:57 -0700825bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
Romain Guyaf636eb2010-12-09 17:47:21 -0800826 if (mSnapshot->isIgnored()) {
Romain Guydbc26d22010-10-11 17:58:29 -0700827 return true;
828 }
829
Romain Guy1d83e192010-08-17 11:37:00 -0700830 Rect r(left, top, right, bottom);
Romain Guy8aef54f2010-09-01 15:13:49 -0700831 mSnapshot->transform->mapRect(r);
Romain Guyd2a1ff02010-10-14 14:46:44 -0700832 r.snapToPixelBoundaries();
833
834 Rect clipRect(*mSnapshot->clipRect);
835 clipRect.snapToPixelBoundaries();
836
837 return !clipRect.intersects(r);
Romain Guyc7d53492010-06-25 13:41:57 -0700838}
839
Romain Guy079ba2c2010-07-16 14:12:24 -0700840bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
841 bool clipped = mSnapshot->clip(left, top, right, bottom, op);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700842 if (clipped) {
Romain Guy746b7402010-10-26 16:27:31 -0700843 dirtyClip();
Romain Guy7ae7ac42010-06-25 13:46:18 -0700844 }
Romain Guy8aef54f2010-09-01 15:13:49 -0700845 return !mSnapshot->clipRect->isEmpty();
Romain Guye4d01122010-06-16 18:44:05 -0700846}
847
Romain Guyf6a11b82010-06-23 17:47:49 -0700848///////////////////////////////////////////////////////////////////////////////
Romain Guy70ca14e2010-12-13 18:24:33 -0800849// Drawing commands
850///////////////////////////////////////////////////////////////////////////////
851
852void OpenGLRenderer::setupDraw() {
853 clearLayerRegions();
854 if (mDirtyClip) {
855 setScissorFromClip();
856 }
857 mDescription.reset();
858 mSetShaderColor = false;
859 mColorSet = false;
860 mColorA = mColorR = mColorG = mColorB = 0.0f;
861 mTextureUnit = 0;
862 mTrackDirtyRegions = true;
Romain Guy8d0d4782010-12-14 20:13:35 -0800863 mTexCoordsSlot = -1;
Romain Guy70ca14e2010-12-13 18:24:33 -0800864}
865
866void OpenGLRenderer::setupDrawWithTexture(bool isAlpha8) {
867 mDescription.hasTexture = true;
868 mDescription.hasAlpha8Texture = isAlpha8;
869}
870
871void OpenGLRenderer::setupDrawColor(int color) {
Romain Guy8d0d4782010-12-14 20:13:35 -0800872 setupDrawColor(color, (color >> 24) & 0xFF);
873}
874
875void OpenGLRenderer::setupDrawColor(int color, int alpha) {
876 mColorA = alpha / 255.0f;
Romain Guy70ca14e2010-12-13 18:24:33 -0800877 const float a = mColorA / 255.0f;
Romain Guyfa7952d2010-12-14 13:45:54 -0800878 mColorR = a * ((color >> 16) & 0xFF);
879 mColorG = a * ((color >> 8) & 0xFF);
880 mColorB = a * ((color ) & 0xFF);
Romain Guy70ca14e2010-12-13 18:24:33 -0800881 mColorSet = true;
882 mSetShaderColor = mDescription.setColor(mColorR, mColorG, mColorB, mColorA);
883}
884
Romain Guy86568192010-12-14 15:55:39 -0800885void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) {
886 mColorA = alpha / 255.0f;
887 const float a = mColorA / 255.0f;
888 mColorR = a * ((color >> 16) & 0xFF);
889 mColorG = a * ((color >> 8) & 0xFF);
890 mColorB = a * ((color ) & 0xFF);
891 mColorSet = true;
892 mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA);
893}
894
Romain Guy70ca14e2010-12-13 18:24:33 -0800895void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) {
896 mColorA = a;
897 mColorR = r;
898 mColorG = g;
899 mColorB = b;
900 mColorSet = true;
901 mSetShaderColor = mDescription.setColor(r, g, b, a);
902}
903
Romain Guy86568192010-12-14 15:55:39 -0800904void OpenGLRenderer::setupDrawAlpha8Color(float r, float g, float b, float a) {
905 mColorA = a;
906 mColorR = r;
907 mColorG = g;
908 mColorB = b;
909 mColorSet = true;
910 mSetShaderColor = mDescription.setAlpha8Color(r, g, b, a);
911}
912
Romain Guy70ca14e2010-12-13 18:24:33 -0800913void OpenGLRenderer::setupDrawShader() {
914 if (mShader) {
915 mShader->describe(mDescription, mCaches.extensions);
916 }
917}
918
919void OpenGLRenderer::setupDrawColorFilter() {
920 if (mColorFilter) {
921 mColorFilter->describe(mDescription, mCaches.extensions);
922 }
923}
924
925void OpenGLRenderer::setupDrawBlending(SkXfermode::Mode mode, bool swapSrcDst) {
926 chooseBlending((mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode,
927 mDescription, swapSrcDst);
928}
929
930void OpenGLRenderer::setupDrawBlending(bool blend, SkXfermode::Mode mode, bool swapSrcDst) {
931 chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode,
932 mDescription, swapSrcDst);
933}
934
935void OpenGLRenderer::setupDrawProgram() {
936 useProgram(mCaches.programCache.get(mDescription));
937}
938
939void OpenGLRenderer::setupDrawDirtyRegionsDisabled() {
940 mTrackDirtyRegions = false;
941}
942
943void OpenGLRenderer::setupDrawModelViewTranslate(float left, float top, float right, float bottom,
944 bool ignoreTransform) {
945 mModelView.loadTranslate(left, top, 0.0f);
946 if (!ignoreTransform) {
947 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
948 if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
949 } else {
950 mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
951 if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom);
952 }
953}
954
Romain Guy8d0d4782010-12-14 20:13:35 -0800955void OpenGLRenderer::setupDrawModelViewIdentity() {
956 mCaches.currentProgram->set(mOrthoMatrix, mIdentity, *mSnapshot->transform);
957}
958
Romain Guy70ca14e2010-12-13 18:24:33 -0800959void OpenGLRenderer::setupDrawModelView(float left, float top, float right, float bottom,
960 bool ignoreTransform, bool ignoreModelView) {
961 if (!ignoreModelView) {
962 mModelView.loadTranslate(left, top, 0.0f);
963 mModelView.scale(right - left, bottom - top, 1.0f);
Romain Guy70ca14e2010-12-13 18:24:33 -0800964 } else {
965 mModelView.loadIdentity();
966 }
Romain Guy86568192010-12-14 15:55:39 -0800967 bool dirty = right - left > 0.0f && bottom - top > 0.0f;
968 if (!ignoreTransform) {
969 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
970 if (mTrackDirtyRegions && dirty) {
971 dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
972 }
973 } else {
974 mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
975 if (mTrackDirtyRegions && dirty) dirtyLayer(left, top, right, bottom);
976 }
Romain Guy70ca14e2010-12-13 18:24:33 -0800977}
978
979void OpenGLRenderer::setupDrawColorUniforms() {
Romain Guy55368412010-12-14 10:59:41 -0800980 if (mColorSet || (mShader && mSetShaderColor)) {
Romain Guy70ca14e2010-12-13 18:24:33 -0800981 mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
982 }
983}
984
Romain Guy86568192010-12-14 15:55:39 -0800985void OpenGLRenderer::setupDrawPureColorUniforms() {
Romain Guy55368412010-12-14 10:59:41 -0800986 if (mSetShaderColor) {
Romain Guy86568192010-12-14 15:55:39 -0800987 mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
Romain Guy55368412010-12-14 10:59:41 -0800988 }
989}
990
Romain Guy70ca14e2010-12-13 18:24:33 -0800991void OpenGLRenderer::setupDrawShaderUniforms(bool ignoreTransform) {
992 if (mShader) {
993 if (ignoreTransform) {
994 mModelView.loadInverse(*mSnapshot->transform);
995 }
996 mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &mTextureUnit);
997 }
998}
999
Romain Guy8d0d4782010-12-14 20:13:35 -08001000void OpenGLRenderer::setupDrawShaderIdentityUniforms() {
1001 if (mShader) {
1002 mShader->setupProgram(mCaches.currentProgram, mIdentity, *mSnapshot, &mTextureUnit);
1003 }
1004}
1005
Romain Guy70ca14e2010-12-13 18:24:33 -08001006void OpenGLRenderer::setupDrawColorFilterUniforms() {
1007 if (mColorFilter) {
1008 mColorFilter->setupProgram(mCaches.currentProgram);
1009 }
1010}
1011
1012void OpenGLRenderer::setupDrawSimpleMesh() {
1013 mCaches.bindMeshBuffer();
1014 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
1015 gMeshStride, 0);
1016}
1017
1018void OpenGLRenderer::setupDrawTexture(GLuint texture) {
1019 bindTexture(texture);
1020 glUniform1i(mCaches.currentProgram->getUniform("sampler"), mTextureUnit++);
1021
1022 mTexCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
1023 glEnableVertexAttribArray(mTexCoordsSlot);
1024}
1025
1026void OpenGLRenderer::setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLuint vbo) {
1027 if (!vertices) {
1028 mCaches.bindMeshBuffer(vbo == 0 ? mCaches.meshBuffer : vbo);
1029 } else {
1030 mCaches.unbindMeshBuffer();
1031 }
1032 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
1033 gMeshStride, vertices);
Romain Guy8d0d4782010-12-14 20:13:35 -08001034 if (mTexCoordsSlot > 0) {
1035 glVertexAttribPointer(mTexCoordsSlot, 2, GL_FLOAT, GL_FALSE, gMeshStride, texCoords);
1036 }
Romain Guy70ca14e2010-12-13 18:24:33 -08001037}
1038
1039void OpenGLRenderer::finishDrawTexture() {
1040 glDisableVertexAttribArray(mTexCoordsSlot);
1041}
1042
1043///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -07001044// Drawing
1045///////////////////////////////////////////////////////////////////////////////
1046
Chet Haasedaf98e92011-01-10 14:10:36 -08001047bool OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t level) {
Romain Guy0fe478e2010-11-08 12:08:41 -08001048 // All the usual checks and setup operations (quickReject, setupDraw, etc.)
1049 // will be performed by the display list itself
1050 if (displayList) {
Chet Haasedaf98e92011-01-10 14:10:36 -08001051 return displayList->replay(*this, level);
Romain Guy0fe478e2010-11-08 12:08:41 -08001052 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001053 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001054}
1055
Chet Haase5c13d892010-10-08 08:37:55 -07001056void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -07001057 const float right = left + bitmap->width();
1058 const float bottom = top + bitmap->height();
1059
1060 if (quickReject(left, top, right, bottom)) {
1061 return;
1062 }
1063
Romain Guy86568192010-12-14 15:55:39 -08001064 glActiveTexture(gTextureUnits[0]);
Romain Guy8164c2d2010-10-25 18:03:28 -07001065 Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -07001066 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -07001067 const AutoTexture autoCleanup(texture);
1068
Romain Guy6926c722010-07-12 20:20:03 -07001069 drawTextureRect(left, top, right, bottom, texture, paint);
Romain Guyce0537b2010-06-29 21:05:21 -07001070}
1071
Chet Haase5c13d892010-10-08 08:37:55 -07001072void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Romain Guyf86ef572010-07-01 11:05:42 -07001073 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1074 const mat4 transform(*matrix);
1075 transform.mapRect(r);
1076
Romain Guy6926c722010-07-12 20:20:03 -07001077 if (quickReject(r.left, r.top, r.right, r.bottom)) {
1078 return;
1079 }
1080
Romain Guy86568192010-12-14 15:55:39 -08001081 glActiveTexture(gTextureUnits[0]);
Romain Guy8164c2d2010-10-25 18:03:28 -07001082 Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -07001083 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -07001084 const AutoTexture autoCleanup(texture);
1085
Romain Guy5b3b3522010-10-27 18:57:51 -07001086 // This could be done in a cheaper way, all we need is pass the matrix
1087 // to the vertex shader. The save/restore is a bit overkill.
1088 save(SkCanvas::kMatrix_SaveFlag);
1089 concatMatrix(matrix);
1090 drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint);
1091 restore();
Romain Guyf86ef572010-07-01 11:05:42 -07001092}
1093
Romain Guy5a7b4662011-01-20 19:09:30 -08001094void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1095 float* vertices, int* colors, SkPaint* paint) {
1096 // TODO: Do a quickReject
1097 if (!vertices || mSnapshot->isIgnored()) {
1098 return;
1099 }
1100
1101 glActiveTexture(gTextureUnits[0]);
1102 Texture* texture = mCaches.textureCache.get(bitmap);
1103 if (!texture) return;
1104 const AutoTexture autoCleanup(texture);
1105 setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
1106
1107 int alpha;
1108 SkXfermode::Mode mode;
1109 getAlphaAndMode(paint, &alpha, &mode);
1110
Romain Guy5a7b4662011-01-20 19:09:30 -08001111 const uint32_t count = meshWidth * meshHeight * 6;
Romain Guy5a7b4662011-01-20 19:09:30 -08001112
Romain Guya566b7c2011-01-23 16:36:11 -08001113 // TODO: Support the colors array
1114 TextureVertex mesh[count];
Romain Guy5a7b4662011-01-20 19:09:30 -08001115 TextureVertex* vertex = mesh;
1116 for (int32_t y = 0; y < meshHeight; y++) {
1117 for (int32_t x = 0; x < meshWidth; x++) {
1118 uint32_t i = (y * (meshWidth + 1) + x) * 2;
1119
1120 float u1 = float(x) / meshWidth;
1121 float u2 = float(x + 1) / meshWidth;
1122 float v1 = float(y) / meshHeight;
1123 float v2 = float(y + 1) / meshHeight;
1124
1125 int ax = i + (meshWidth + 1) * 2;
1126 int ay = ax + 1;
1127 int bx = i;
1128 int by = bx + 1;
1129 int cx = i + 2;
1130 int cy = cx + 1;
1131 int dx = i + (meshWidth + 1) * 2 + 2;
1132 int dy = dx + 1;
1133
1134 TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
1135 TextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1);
1136 TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
1137
1138 TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
1139 TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
1140 TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
1141 }
1142 }
1143
1144 drawTextureMesh(0.0f, 0.0f, 1.0f, 1.0f, texture->id, alpha / 255.0f,
1145 mode, texture->blend, &mesh[0].position[0], &mesh[0].texture[0],
1146 GL_TRIANGLES, count);
1147}
1148
Romain Guy8ba548f2010-06-30 19:21:21 -07001149void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
1150 float srcLeft, float srcTop, float srcRight, float srcBottom,
1151 float dstLeft, float dstTop, float dstRight, float dstBottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001152 SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -07001153 if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) {
1154 return;
1155 }
1156
Romain Guy746b7402010-10-26 16:27:31 -07001157 glActiveTexture(gTextureUnits[0]);
Romain Guy8164c2d2010-10-25 18:03:28 -07001158 Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -07001159 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -07001160 const AutoTexture autoCleanup(texture);
Romain Guy8164c2d2010-10-25 18:03:28 -07001161 setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
Romain Guy8ba548f2010-06-30 19:21:21 -07001162
Romain Guy8ba548f2010-06-30 19:21:21 -07001163 const float width = texture->width;
1164 const float height = texture->height;
1165
1166 const float u1 = srcLeft / width;
1167 const float v1 = srcTop / height;
1168 const float u2 = srcRight / width;
1169 const float v2 = srcBottom / height;
1170
Romain Guy03750a02010-10-18 14:06:08 -07001171 mCaches.unbindMeshBuffer();
Romain Guy8ba548f2010-06-30 19:21:21 -07001172 resetDrawTextureTexCoords(u1, v1, u2, v2);
1173
Romain Guy03750a02010-10-18 14:06:08 -07001174 int alpha;
1175 SkXfermode::Mode mode;
1176 getAlphaAndMode(paint, &alpha, &mode);
1177
Romain Guy6620c6d2010-12-06 18:07:02 -08001178 if (mSnapshot->transform->isPureTranslate()) {
1179 const float x = (int) floorf(dstLeft + mSnapshot->transform->getTranslateX() + 0.5f);
1180 const float y = (int) floorf(dstTop + mSnapshot->transform->getTranslateY() + 0.5f);
1181
1182 drawTextureMesh(x, y, x + (dstRight - dstLeft), y + (dstBottom - dstTop),
1183 texture->id, alpha / 255.0f, mode, texture->blend,
1184 &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
1185 GL_TRIANGLE_STRIP, gMeshCount, false, true);
1186 } else {
1187 drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, texture->id, alpha / 255.0f,
1188 mode, texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
1189 GL_TRIANGLE_STRIP, gMeshCount);
1190 }
Romain Guy8ba548f2010-06-30 19:21:21 -07001191
1192 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
1193}
1194
Romain Guy4aa90572010-09-26 18:40:37 -07001195void OpenGLRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001196 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001197 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -07001198 if (quickReject(left, top, right, bottom)) {
1199 return;
1200 }
1201
Romain Guy746b7402010-10-26 16:27:31 -07001202 glActiveTexture(gTextureUnits[0]);
Romain Guy8164c2d2010-10-25 18:03:28 -07001203 Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -07001204 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -07001205 const AutoTexture autoCleanup(texture);
Romain Guy8164c2d2010-10-25 18:03:28 -07001206 setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
Romain Guyf7f93552010-07-08 19:17:03 -07001207
1208 int alpha;
1209 SkXfermode::Mode mode;
1210 getAlphaAndMode(paint, &alpha, &mode);
1211
Romain Guy2728f962010-10-08 18:36:15 -07001212 const Patch* mesh = mCaches.patchCache.get(bitmap->width(), bitmap->height(),
Romain Guy4bb94202010-10-12 15:59:26 -07001213 right - left, bottom - top, xDivs, yDivs, colors, width, height, numColors);
Romain Guyf7f93552010-07-08 19:17:03 -07001214
Romain Guya5ef39a2010-12-03 16:48:20 -08001215 if (mesh && mesh->verticesCount > 0) {
Romain Guy6620c6d2010-12-06 18:07:02 -08001216 const bool pureTranslate = mSnapshot->transform->isPureTranslate();
Romain Guya5ef39a2010-12-03 16:48:20 -08001217#if RENDER_LAYERS_AS_REGIONS
Romain Guy5b3b3522010-10-27 18:57:51 -07001218 // Mark the current layer dirty where we are going to draw the patch
Romain Guy81683962011-01-24 20:40:18 -08001219 if (hasLayer() && mesh->hasEmptyQuads) {
Romain Guy5b3b3522010-10-27 18:57:51 -07001220 const size_t count = mesh->quads.size();
1221 for (size_t i = 0; i < count; i++) {
Romain Guy8ab40792010-12-07 13:30:10 -08001222 const Rect& bounds = mesh->quads.itemAt(i);
Romain Guy6620c6d2010-12-06 18:07:02 -08001223 if (pureTranslate) {
1224 const float x = (int) floorf(bounds.left + 0.5f);
1225 const float y = (int) floorf(bounds.top + 0.5f);
Romain Guy8ab40792010-12-07 13:30:10 -08001226 dirtyLayer(x, y, x + bounds.getWidth(), y + bounds.getHeight(),
Romain Guy6620c6d2010-12-06 18:07:02 -08001227 *mSnapshot->transform);
1228 } else {
1229 dirtyLayer(bounds.left, bounds.top, bounds.right, bounds.bottom,
1230 *mSnapshot->transform);
1231 }
Romain Guy5b3b3522010-10-27 18:57:51 -07001232 }
1233 }
Romain Guya5ef39a2010-12-03 16:48:20 -08001234#endif
Romain Guy5b3b3522010-10-27 18:57:51 -07001235
Romain Guy6620c6d2010-12-06 18:07:02 -08001236 if (pureTranslate) {
1237 const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
1238 const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
1239
1240 drawTextureMesh(x, y, x + right - left, y + bottom - top, texture->id, alpha / 255.0f,
1241 mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset,
1242 GL_TRIANGLES, mesh->verticesCount, false, true, mesh->meshBuffer,
1243 true, !mesh->hasEmptyQuads);
1244 } else {
1245 drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f,
1246 mode, texture->blend, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset,
1247 GL_TRIANGLES, mesh->verticesCount, false, false, mesh->meshBuffer,
1248 true, !mesh->hasEmptyQuads);
1249 }
Romain Guy054dc182010-10-15 17:55:25 -07001250 }
Romain Guyf7f93552010-07-08 19:17:03 -07001251}
1252
Chet Haase5c13d892010-10-08 08:37:55 -07001253void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyaf636eb2010-12-09 17:47:21 -08001254 if (mSnapshot->isIgnored()) return;
Romain Guydbc26d22010-10-11 17:58:29 -07001255
Romain Guya957eea2010-12-08 18:34:42 -08001256 const bool isAA = paint->isAntiAlias();
1257 const float strokeWidth = paint->getStrokeWidth() * 0.5f;
1258 // A stroke width of 0 has a special meaningin Skia:
1259 // it draws an unscaled 1px wide line
1260 const bool isHairLine = paint->getStrokeWidth() == 0.0f;
1261
Romain Guy759ea802010-09-16 20:49:46 -07001262 int alpha;
1263 SkXfermode::Mode mode;
1264 getAlphaAndMode(paint, &alpha, &mode);
1265
Romain Guya957eea2010-12-08 18:34:42 -08001266 int verticesCount = count >> 2;
Romain Guy7230a742011-01-10 22:26:16 -08001267 int generatedVerticesCount = 0;
Romain Guya957eea2010-12-08 18:34:42 -08001268 if (!isHairLine) {
1269 // TODO: AA needs more vertices
1270 verticesCount *= 6;
Romain Guyc95c8d62010-09-17 15:31:32 -07001271 } else {
Romain Guya957eea2010-12-08 18:34:42 -08001272 // TODO: AA will be different
1273 verticesCount *= 2;
Romain Guyc95c8d62010-09-17 15:31:32 -07001274 }
1275
Romain Guya957eea2010-12-08 18:34:42 -08001276 TextureVertex lines[verticesCount];
1277 TextureVertex* vertex = &lines[0];
Romain Guy759ea802010-09-16 20:49:46 -07001278
Romain Guy8d0d4782010-12-14 20:13:35 -08001279 setupDraw();
1280 setupDrawColor(paint->getColor(), alpha);
1281 setupDrawColorFilter();
1282 setupDrawShader();
1283 setupDrawBlending(mode);
1284 setupDrawProgram();
1285 setupDrawModelViewIdentity();
1286 setupDrawColorUniforms();
1287 setupDrawColorFilterUniforms();
1288 setupDrawShaderIdentityUniforms();
1289 setupDrawMesh(vertex);
Romain Guya957eea2010-12-08 18:34:42 -08001290
1291 if (!isHairLine) {
1292 // TODO: Handle the AA case
1293 for (int i = 0; i < count; i += 4) {
1294 // a = start point, b = end point
1295 vec2 a(points[i], points[i + 1]);
1296 vec2 b(points[i + 2], points[i + 3]);
1297
1298 // Bias to snap to the same pixels as Skia
1299 a += 0.375;
1300 b += 0.375;
1301
1302 // Find the normal to the line
1303 vec2 n = (b - a).copyNormalized() * strokeWidth;
1304 float x = n.x;
1305 n.x = -n.y;
1306 n.y = x;
1307
1308 // Four corners of the rectangle defining a thick line
1309 vec2 p1 = a - n;
1310 vec2 p2 = a + n;
1311 vec2 p3 = b + n;
1312 vec2 p4 = b - n;
1313
Romain Guy7230a742011-01-10 22:26:16 -08001314 const float left = fmin(p1.x, fmin(p2.x, fmin(p3.x, p4.x)));
1315 const float right = fmax(p1.x, fmax(p2.x, fmax(p3.x, p4.x)));
1316 const float top = fmin(p1.y, fmin(p2.y, fmin(p3.y, p4.y)));
1317 const float bottom = fmax(p1.y, fmax(p2.y, fmax(p3.y, p4.y)));
Romain Guya957eea2010-12-08 18:34:42 -08001318
Romain Guy7230a742011-01-10 22:26:16 -08001319 if (!quickReject(left, top, right, bottom)) {
1320 // Draw the line as 2 triangles, could be optimized
1321 // by using only 4 vertices and the correct indices
1322 // Also we should probably used non textured vertices
1323 // when line AA is disabled to save on bandwidth
1324 TextureVertex::set(vertex++, p1.x, p1.y, 0.0f, 0.0f);
1325 TextureVertex::set(vertex++, p2.x, p2.y, 0.0f, 0.0f);
1326 TextureVertex::set(vertex++, p3.x, p3.y, 0.0f, 0.0f);
1327 TextureVertex::set(vertex++, p1.x, p1.y, 0.0f, 0.0f);
1328 TextureVertex::set(vertex++, p3.x, p3.y, 0.0f, 0.0f);
1329 TextureVertex::set(vertex++, p4.x, p4.y, 0.0f, 0.0f);
1330
1331 generatedVerticesCount += 6;
1332
1333 dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
1334 }
Romain Guya957eea2010-12-08 18:34:42 -08001335 }
1336
Romain Guy7230a742011-01-10 22:26:16 -08001337 if (generatedVerticesCount > 0) {
1338 // GL_LINE does not give the result we want to match Skia
1339 glDrawArrays(GL_TRIANGLES, 0, generatedVerticesCount);
1340 }
Romain Guya957eea2010-12-08 18:34:42 -08001341 } else {
1342 // TODO: Handle the AA case
1343 for (int i = 0; i < count; i += 4) {
Romain Guy7230a742011-01-10 22:26:16 -08001344 const float left = fmin(points[i], points[i + 1]);
1345 const float right = fmax(points[i], points[i + 1]);
1346 const float top = fmin(points[i + 2], points[i + 3]);
1347 const float bottom = fmax(points[i + 2], points[i + 3]);
1348
1349 if (!quickReject(left, top, right, bottom)) {
1350 TextureVertex::set(vertex++, points[i], points[i + 1], 0.0f, 0.0f);
1351 TextureVertex::set(vertex++, points[i + 2], points[i + 3], 0.0f, 0.0f);
1352
1353 generatedVerticesCount += 2;
1354
1355 dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
1356 }
Romain Guya957eea2010-12-08 18:34:42 -08001357 }
Romain Guy8d0d4782010-12-14 20:13:35 -08001358
Romain Guy7230a742011-01-10 22:26:16 -08001359 if (generatedVerticesCount > 0) {
1360 glLineWidth(1.0f);
1361 glDrawArrays(GL_LINES, 0, generatedVerticesCount);
1362 }
Romain Guy29d89972010-09-22 16:10:57 -07001363 }
Romain Guy759ea802010-09-16 20:49:46 -07001364}
1365
Romain Guy85bf02f2010-06-22 13:11:24 -07001366void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guye45362c2010-11-03 19:58:32 -07001367 // No need to check against the clip, we fill the clip region
Romain Guyaf636eb2010-12-09 17:47:21 -08001368 if (mSnapshot->isIgnored()) return;
Romain Guye45362c2010-11-03 19:58:32 -07001369
Romain Guyae88e5e2010-10-22 17:49:18 -07001370 Rect& clip(*mSnapshot->clipRect);
1371 clip.snapToPixelBoundaries();
Romain Guy70ca14e2010-12-13 18:24:33 -08001372
Romain Guy3d58c032010-07-14 16:34:53 -07001373 drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
Romain Guyc7d53492010-06-25 13:41:57 -07001374}
Romain Guy9d5316e2010-06-24 19:30:36 -07001375
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001376void OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture, SkPaint* paint) {
Romain Guy01d58e42011-01-19 21:54:02 -08001377 if (!texture) return;
1378 const AutoTexture autoCleanup(texture);
1379
1380 const float x = left + texture->left - texture->offset;
1381 const float y = top + texture->top - texture->offset;
1382
1383 drawPathTexture(texture, x, y, paint);
1384}
1385
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001386void OpenGLRenderer::drawRoundRect(float left, float top, float right, float bottom,
1387 float rx, float ry, SkPaint* paint) {
1388 if (mSnapshot->isIgnored()) return;
1389
1390 glActiveTexture(gTextureUnits[0]);
1391 const PathTexture* texture = mCaches.roundRectShapeCache.getRoundRect(
1392 right - left, bottom - top, rx, ry, paint);
1393 drawShape(left, top, texture, paint);
1394}
1395
Romain Guy01d58e42011-01-19 21:54:02 -08001396void OpenGLRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1397 if (mSnapshot->isIgnored()) return;
1398
1399 glActiveTexture(gTextureUnits[0]);
Romain Guy01d58e42011-01-19 21:54:02 -08001400 const PathTexture* texture = mCaches.circleShapeCache.getCircle(radius, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001401 drawShape(x - radius, y - radius, texture, paint);
1402}
Romain Guy01d58e42011-01-19 21:54:02 -08001403
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001404void OpenGLRenderer::drawOval(float left, float top, float right, float bottom, SkPaint* paint) {
1405 if (mSnapshot->isIgnored()) return;
Romain Guy01d58e42011-01-19 21:54:02 -08001406
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001407 glActiveTexture(gTextureUnits[0]);
1408 const PathTexture* texture = mCaches.ovalShapeCache.getOval(right - left, bottom - top, paint);
1409 drawShape(left, top, texture, paint);
1410}
1411
Romain Guy8b2f5262011-01-23 16:15:02 -08001412void OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
1413 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
1414 if (mSnapshot->isIgnored()) return;
1415
1416 if (fabs(sweepAngle) >= 360.0f) {
1417 drawOval(left, top, right, bottom, paint);
1418 return;
1419 }
1420
1421 glActiveTexture(gTextureUnits[0]);
1422 const PathTexture* texture = mCaches.arcShapeCache.getArc(right - left, bottom - top,
1423 startAngle, sweepAngle, useCenter, paint);
1424 drawShape(left, top, texture, paint);
1425}
1426
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001427void OpenGLRenderer::drawRectAsShape(float left, float top, float right, float bottom,
1428 SkPaint* paint) {
1429 if (mSnapshot->isIgnored()) return;
1430
1431 glActiveTexture(gTextureUnits[0]);
1432 const PathTexture* texture = mCaches.rectShapeCache.getRect(right - left, bottom - top, paint);
1433 drawShape(left, top, texture, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001434}
1435
Chet Haase5c13d892010-10-08 08:37:55 -07001436void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, SkPaint* p) {
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001437 if (p->getStyle() != SkPaint::kFill_Style) {
1438 drawRectAsShape(left, top, right, bottom, p);
1439 return;
1440 }
1441
Romain Guy6926c722010-07-12 20:20:03 -07001442 if (quickReject(left, top, right, bottom)) {
1443 return;
1444 }
1445
Romain Guy026c5e162010-06-28 17:12:22 -07001446 SkXfermode::Mode mode;
Romain Guy746b7402010-10-26 16:27:31 -07001447 if (!mCaches.extensions.hasFramebufferFetch()) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001448 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
1449 if (!isMode) {
1450 // Assume SRC_OVER
1451 mode = SkXfermode::kSrcOver_Mode;
1452 }
1453 } else {
1454 mode = getXfermode(p->getXfermode());
Romain Guy026c5e162010-06-28 17:12:22 -07001455 }
1456
Romain Guy026c5e162010-06-28 17:12:22 -07001457 int color = p->getColor();
Romain Guy026c5e162010-06-28 17:12:22 -07001458 drawColorRect(left, top, right, bottom, color, mode);
Romain Guyc7d53492010-06-25 13:41:57 -07001459}
Romain Guy9d5316e2010-06-24 19:30:36 -07001460
Romain Guye8e62a42010-07-23 18:55:21 -07001461void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
1462 float x, float y, SkPaint* paint) {
Romain Guyb146b122010-12-15 17:06:45 -08001463 if (text == NULL || count == 0) {
Romain Guye8e62a42010-07-23 18:55:21 -07001464 return;
1465 }
Romain Guyaf636eb2010-12-09 17:47:21 -08001466 if (mSnapshot->isIgnored()) return;
Romain Guye2d345e2010-09-24 18:39:22 -07001467
Romain Guyf607bdc2010-09-10 19:20:06 -07001468 paint->setAntiAlias(true);
Romain Guye8e62a42010-07-23 18:55:21 -07001469
Romain Guya674ab72010-08-10 17:26:42 -07001470 float length = -1.0f;
Romain Guye8e62a42010-07-23 18:55:21 -07001471 switch (paint->getTextAlign()) {
1472 case SkPaint::kCenter_Align:
1473 length = paint->measureText(text, bytesCount);
1474 x -= length / 2.0f;
1475 break;
1476 case SkPaint::kRight_Align:
1477 length = paint->measureText(text, bytesCount);
1478 x -= length;
1479 break;
1480 default:
1481 break;
1482 }
1483
Romain Guy6620c6d2010-12-06 18:07:02 -08001484 // TODO: Handle paint->getTextScaleX()
Romain Guy3a3fa1b2010-12-06 18:47:50 -08001485 const float oldX = x;
1486 const float oldY = y;
Romain Guy6620c6d2010-12-06 18:07:02 -08001487 const bool pureTranslate = mSnapshot->transform->isPureTranslate();
1488 if (pureTranslate) {
1489 x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
1490 y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
1491 }
1492
Romain Guyb45c0c92010-08-26 20:35:23 -07001493 FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
1494 fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
Romain Guyfb8b7632010-08-23 21:05:08 -07001495 paint->getTextSize());
Romain Guye2d345e2010-09-24 18:39:22 -07001496
Romain Guy86568192010-12-14 15:55:39 -08001497 int alpha;
1498 SkXfermode::Mode mode;
1499 getAlphaAndMode(paint, &alpha, &mode);
Romain Guy9d13fe252010-10-15 16:06:03 -07001500
Romain Guy1e45aae2010-08-13 19:39:53 -07001501 if (mHasShadow) {
Romain Guyb45c0c92010-08-26 20:35:23 -07001502 mCaches.dropShadowCache.setFontRenderer(fontRenderer);
Romain Guyfb8b7632010-08-23 21:05:08 -07001503 const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
Romain Guy1e45aae2010-08-13 19:39:53 -07001504 count, mShadowRadius);
1505 const AutoTexture autoCleanup(shadow);
Romain Guy0a417492010-08-16 20:26:20 -07001506
Romain Guy86568192010-12-14 15:55:39 -08001507 const float sx = x - shadow->left + mShadowDx;
1508 const float sy = y - shadow->top + mShadowDy;
Romain Guy0a417492010-08-16 20:26:20 -07001509
Romain Guy86568192010-12-14 15:55:39 -08001510 const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
1511
1512 glActiveTexture(gTextureUnits[0]);
1513 setupDraw();
1514 setupDrawWithTexture(true);
1515 setupDrawAlpha8Color(mShadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
1516 setupDrawBlending(true, mode);
1517 setupDrawProgram();
1518 setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height, pureTranslate);
1519 setupDrawTexture(shadow->id);
1520 setupDrawPureColorUniforms();
1521 setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
1522
Romain Guy0a417492010-08-16 20:26:20 -07001523 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guy86568192010-12-14 15:55:39 -08001524 finishDrawTexture();
Romain Guy1e45aae2010-08-13 19:39:53 -07001525 }
1526
Romain Guyb146b122010-12-15 17:06:45 -08001527 if (paint->getAlpha() == 0 && paint->getXfermode() == NULL) {
1528 return;
1529 }
1530
Romain Guy6620c6d2010-12-06 18:07:02 -08001531 // Pick the appropriate texture filtering
1532 bool linearFilter = mSnapshot->transform->changesBounds();
1533 if (pureTranslate && !linearFilter) {
1534 linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f;
1535 }
Romain Guy5b3b3522010-10-27 18:57:51 -07001536
Romain Guy86568192010-12-14 15:55:39 -08001537 glActiveTexture(gTextureUnits[0]);
1538 setupDraw();
1539 setupDrawDirtyRegionsDisabled();
1540 setupDrawWithTexture(true);
1541 setupDrawAlpha8Color(paint->getColor(), alpha);
1542 setupDrawColorFilter();
1543 setupDrawShader();
1544 setupDrawBlending(true, mode);
1545 setupDrawProgram();
1546 setupDrawModelView(x, y, x, y, pureTranslate, true);
1547 setupDrawTexture(fontRenderer.getTexture(linearFilter));
1548 setupDrawPureColorUniforms();
1549 setupDrawColorFilterUniforms();
1550 setupDrawShaderUniforms(pureTranslate);
Romain Guy06f96e22010-07-30 19:18:16 -07001551
Romain Guy6620c6d2010-12-06 18:07:02 -08001552 const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip();
Romain Guy5b3b3522010-10-27 18:57:51 -07001553 Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
1554
1555#if RENDER_LAYERS_AS_REGIONS
Romain Guyf219da52011-01-16 12:54:25 -08001556 bool hasActiveLayer = hasLayer();
Romain Guy5b3b3522010-10-27 18:57:51 -07001557#else
Romain Guyf219da52011-01-16 12:54:25 -08001558 bool hasActiveLayer = false;
Romain Guy5b3b3522010-10-27 18:57:51 -07001559#endif
Romain Guy9d13fe252010-10-15 16:06:03 -07001560
Romain Guy03750a02010-10-18 14:06:08 -07001561 mCaches.unbindMeshBuffer();
Romain Guy6620c6d2010-12-06 18:07:02 -08001562 if (fontRenderer.renderText(paint, clip, text, 0, bytesCount, count, x, y,
Romain Guyf219da52011-01-16 12:54:25 -08001563 hasActiveLayer ? &bounds : NULL)) {
Romain Guy5b3b3522010-10-27 18:57:51 -07001564#if RENDER_LAYERS_AS_REGIONS
Romain Guyf219da52011-01-16 12:54:25 -08001565 if (hasActiveLayer) {
Romain Guy6620c6d2010-12-06 18:07:02 -08001566 if (!pureTranslate) {
1567 mSnapshot->transform->mapRect(bounds);
1568 }
Romain Guyf219da52011-01-16 12:54:25 -08001569 dirtyLayerUnchecked(bounds, getRegion());
Romain Guy5b3b3522010-10-27 18:57:51 -07001570 }
1571#endif
1572 }
Romain Guy694b5192010-07-21 21:33:20 -07001573
1574 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guyfb8b7632010-08-23 21:05:08 -07001575 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guya674ab72010-08-10 17:26:42 -07001576
Romain Guy3a3fa1b2010-12-06 18:47:50 -08001577 drawTextDecorations(text, bytesCount, length, oldX, oldY, paint);
Romain Guy694b5192010-07-21 21:33:20 -07001578}
1579
Romain Guy7fbcc042010-08-04 15:40:07 -07001580void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyaf636eb2010-12-09 17:47:21 -08001581 if (mSnapshot->isIgnored()) return;
Romain Guydbc26d22010-10-11 17:58:29 -07001582
Romain Guy01d58e42011-01-19 21:54:02 -08001583 glActiveTexture(gTextureUnits[0]);
Romain Guy7fbcc042010-08-04 15:40:07 -07001584
Romain Guyfb8b7632010-08-23 21:05:08 -07001585 const PathTexture* texture = mCaches.pathCache.get(path, paint);
Romain Guy9cccc2b2010-08-07 23:46:15 -07001586 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -07001587 const AutoTexture autoCleanup(texture);
Romain Guy7fbcc042010-08-04 15:40:07 -07001588
Romain Guy8b55f372010-08-18 17:10:07 -07001589 const float x = texture->left - texture->offset;
1590 const float y = texture->top - texture->offset;
1591
Romain Guy01d58e42011-01-19 21:54:02 -08001592 drawPathTexture(texture, x, y, paint);
Romain Guy7fbcc042010-08-04 15:40:07 -07001593}
1594
Romain Guyada830f2011-01-13 12:13:20 -08001595void OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
1596 if (!layer || quickReject(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight())) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001597 return;
1598 }
1599
1600 glActiveTexture(gTextureUnits[0]);
Romain Guy6c319ca2011-01-11 14:29:25 -08001601
1602 int alpha;
1603 SkXfermode::Mode mode;
1604 getAlphaAndMode(paint, &alpha, &mode);
1605
Romain Guyada830f2011-01-13 12:13:20 -08001606 layer->alpha = alpha;
1607 layer->mode = mode;
Romain Guy6c319ca2011-01-11 14:29:25 -08001608
Romain Guyf219da52011-01-16 12:54:25 -08001609#if RENDER_LAYERS_AS_REGIONS
Romain Guyc88e3572011-01-22 00:32:12 -08001610 if (!layer->region.isEmpty()) {
1611 if (layer->region.isRect()) {
1612 const Rect r(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight());
1613 composeLayerRect(layer, r);
1614 } else if (layer->mesh) {
Romain Guy81683962011-01-24 20:40:18 -08001615 const float a = alpha / 255.0f;
Romain Guyc88e3572011-01-22 00:32:12 -08001616 const Rect& rect = layer->layer;
Romain Guyf219da52011-01-16 12:54:25 -08001617
Romain Guyc88e3572011-01-22 00:32:12 -08001618 setupDraw();
1619 setupDrawWithTexture();
Romain Guy81683962011-01-24 20:40:18 -08001620 setupDrawColor(a, a, a, a);
Romain Guyc88e3572011-01-22 00:32:12 -08001621 setupDrawColorFilter();
1622 setupDrawBlending(layer->blend || layer->alpha < 255, layer->mode, false);
1623 setupDrawProgram();
Romain Guyc88e3572011-01-22 00:32:12 -08001624 setupDrawPureColorUniforms();
1625 setupDrawColorFilterUniforms();
1626 setupDrawTexture(layer->texture);
Romain Guy4f09f542011-01-26 22:41:43 -08001627 // TODO: The current layer, if any, will be dirtied with the bounding box
1628 // of the layer we are drawing. Since the layer we are drawing has
1629 // a mesh, we know the dirty region, we should use it instead
Romain Guyc88e3572011-01-22 00:32:12 -08001630 setupDrawModelViewTranslate(rect.left, rect.top, rect.right, rect.bottom);
1631 setupDrawMesh(&layer->mesh[0].position[0], &layer->mesh[0].texture[0]);
Romain Guyf219da52011-01-16 12:54:25 -08001632
Romain Guyc88e3572011-01-22 00:32:12 -08001633 glDrawElements(GL_TRIANGLES, layer->meshElementCount,
1634 GL_UNSIGNED_SHORT, layer->meshIndices);
Romain Guyf219da52011-01-16 12:54:25 -08001635
Romain Guyc88e3572011-01-22 00:32:12 -08001636 finishDrawTexture();
Romain Guy3a3133d2011-02-01 22:59:58 -08001637
1638#if DEBUG_LAYERS_AS_REGIONS
1639 drawRegionRects(layer->region);
1640#endif
Romain Guyc88e3572011-01-22 00:32:12 -08001641 }
Romain Guyf219da52011-01-16 12:54:25 -08001642 }
1643#else
Romain Guyada830f2011-01-13 12:13:20 -08001644 const Rect r(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight());
1645 composeLayerRect(layer, r);
Romain Guyf219da52011-01-16 12:54:25 -08001646#endif
Romain Guy6c319ca2011-01-11 14:29:25 -08001647}
1648
Romain Guy6926c722010-07-12 20:20:03 -07001649///////////////////////////////////////////////////////////////////////////////
Romain Guyd27977d2010-07-14 19:18:51 -07001650// Shaders
1651///////////////////////////////////////////////////////////////////////////////
1652
1653void OpenGLRenderer::resetShader() {
Romain Guy06f96e22010-07-30 19:18:16 -07001654 mShader = NULL;
Romain Guyd27977d2010-07-14 19:18:51 -07001655}
1656
Romain Guy06f96e22010-07-30 19:18:16 -07001657void OpenGLRenderer::setupShader(SkiaShader* shader) {
1658 mShader = shader;
1659 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001660 mShader->set(&mCaches.textureCache, &mCaches.gradientCache);
Romain Guy06f96e22010-07-30 19:18:16 -07001661 }
Romain Guy7fac2e12010-07-16 17:10:13 -07001662}
1663
Romain Guyd27977d2010-07-14 19:18:51 -07001664///////////////////////////////////////////////////////////////////////////////
Romain Guydb1938e2010-08-02 18:50:22 -07001665// Color filters
1666///////////////////////////////////////////////////////////////////////////////
1667
1668void OpenGLRenderer::resetColorFilter() {
1669 mColorFilter = NULL;
1670}
1671
1672void OpenGLRenderer::setupColorFilter(SkiaColorFilter* filter) {
1673 mColorFilter = filter;
1674}
1675
1676///////////////////////////////////////////////////////////////////////////////
Romain Guy1e45aae2010-08-13 19:39:53 -07001677// Drop shadow
1678///////////////////////////////////////////////////////////////////////////////
1679
1680void OpenGLRenderer::resetShadow() {
1681 mHasShadow = false;
1682}
1683
1684void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
1685 mHasShadow = true;
1686 mShadowRadius = radius;
1687 mShadowDx = dx;
1688 mShadowDy = dy;
1689 mShadowColor = color;
1690}
1691
1692///////////////////////////////////////////////////////////////////////////////
Romain Guy6926c722010-07-12 20:20:03 -07001693// Drawing implementation
1694///////////////////////////////////////////////////////////////////////////////
1695
Romain Guy01d58e42011-01-19 21:54:02 -08001696void OpenGLRenderer::drawPathTexture(const PathTexture* texture,
1697 float x, float y, SkPaint* paint) {
1698 if (quickReject(x, y, x + texture->width, y + texture->height)) {
1699 return;
1700 }
1701
1702 int alpha;
1703 SkXfermode::Mode mode;
1704 getAlphaAndMode(paint, &alpha, &mode);
1705
1706 setupDraw();
1707 setupDrawWithTexture(true);
1708 setupDrawAlpha8Color(paint->getColor(), alpha);
1709 setupDrawColorFilter();
1710 setupDrawShader();
1711 setupDrawBlending(true, mode);
1712 setupDrawProgram();
1713 setupDrawModelView(x, y, x + texture->width, y + texture->height);
1714 setupDrawTexture(texture->id);
1715 setupDrawPureColorUniforms();
1716 setupDrawColorFilterUniforms();
1717 setupDrawShaderUniforms();
1718 setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
1719
1720 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
1721
1722 finishDrawTexture();
1723}
1724
Romain Guyf607bdc2010-09-10 19:20:06 -07001725// Same values used by Skia
Romain Guy0a417492010-08-16 20:26:20 -07001726#define kStdStrikeThru_Offset (-6.0f / 21.0f)
1727#define kStdUnderline_Offset (1.0f / 9.0f)
1728#define kStdUnderline_Thickness (1.0f / 18.0f)
1729
1730void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float length,
1731 float x, float y, SkPaint* paint) {
1732 // Handle underline and strike-through
1733 uint32_t flags = paint->getFlags();
1734 if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
1735 float underlineWidth = length;
1736 // If length is > 0.0f, we already measured the text for the text alignment
1737 if (length <= 0.0f) {
1738 underlineWidth = paint->measureText(text, bytesCount);
1739 }
1740
1741 float offsetX = 0;
1742 switch (paint->getTextAlign()) {
1743 case SkPaint::kCenter_Align:
1744 offsetX = underlineWidth * 0.5f;
1745 break;
1746 case SkPaint::kRight_Align:
1747 offsetX = underlineWidth;
1748 break;
1749 default:
1750 break;
1751 }
1752
1753 if (underlineWidth > 0.0f) {
Romain Guye20ecbd2010-09-22 19:49:04 -07001754 const float textSize = paint->getTextSize();
Romain Guyf6834472011-01-23 13:32:12 -08001755 // TODO: Support stroke width < 1.0f when we have AA lines
1756 const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
Romain Guy0a417492010-08-16 20:26:20 -07001757
Romain Guye20ecbd2010-09-22 19:49:04 -07001758 const float left = x - offsetX;
Romain Guy0a417492010-08-16 20:26:20 -07001759 float top = 0.0f;
Romain Guye20ecbd2010-09-22 19:49:04 -07001760
Romain Guyf6834472011-01-23 13:32:12 -08001761 int linesCount = 0;
1762 if (flags & SkPaint::kUnderlineText_Flag) linesCount++;
1763 if (flags & SkPaint::kStrikeThruText_Flag) linesCount++;
1764
1765 const int pointsCount = 4 * linesCount;
Romain Guye20ecbd2010-09-22 19:49:04 -07001766 float points[pointsCount];
1767 int currentPoint = 0;
Romain Guy0a417492010-08-16 20:26:20 -07001768
1769 if (flags & SkPaint::kUnderlineText_Flag) {
1770 top = y + textSize * kStdUnderline_Offset;
Romain Guye20ecbd2010-09-22 19:49:04 -07001771 points[currentPoint++] = left;
1772 points[currentPoint++] = top;
1773 points[currentPoint++] = left + underlineWidth;
1774 points[currentPoint++] = top;
Romain Guy0a417492010-08-16 20:26:20 -07001775 }
1776
1777 if (flags & SkPaint::kStrikeThruText_Flag) {
1778 top = y + textSize * kStdStrikeThru_Offset;
Romain Guye20ecbd2010-09-22 19:49:04 -07001779 points[currentPoint++] = left;
1780 points[currentPoint++] = top;
1781 points[currentPoint++] = left + underlineWidth;
1782 points[currentPoint++] = top;
Romain Guy0a417492010-08-16 20:26:20 -07001783 }
Romain Guye20ecbd2010-09-22 19:49:04 -07001784
1785 SkPaint linesPaint(*paint);
1786 linesPaint.setStrokeWidth(strokeWidth);
1787
1788 drawLines(&points[0], pointsCount, &linesPaint);
Romain Guy0a417492010-08-16 20:26:20 -07001789 }
1790 }
1791}
1792
Romain Guy026c5e162010-06-28 17:12:22 -07001793void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -07001794 int color, SkXfermode::Mode mode, bool ignoreTransform) {
Romain Guyd27977d2010-07-14 19:18:51 -07001795 // If a shader is set, preserve only the alpha
Romain Guy06f96e22010-07-30 19:18:16 -07001796 if (mShader) {
Romain Guyd27977d2010-07-14 19:18:51 -07001797 color |= 0x00ffffff;
1798 }
1799
Romain Guy70ca14e2010-12-13 18:24:33 -08001800 setupDraw();
1801 setupDrawColor(color);
1802 setupDrawShader();
1803 setupDrawColorFilter();
1804 setupDrawBlending(mode);
1805 setupDrawProgram();
1806 setupDrawModelView(left, top, right, bottom, ignoreTransform);
1807 setupDrawColorUniforms();
1808 setupDrawShaderUniforms(ignoreTransform);
1809 setupDrawColorFilterUniforms();
1810 setupDrawSimpleMesh();
Romain Guyc0ac1932010-07-19 18:43:02 -07001811
Romain Guyc95c8d62010-09-17 15:31:32 -07001812 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
1813}
1814
Romain Guy82ba8142010-07-09 13:25:56 -07001815void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guy8164c2d2010-10-25 18:03:28 -07001816 Texture* texture, SkPaint* paint) {
Romain Guy82ba8142010-07-09 13:25:56 -07001817 int alpha;
1818 SkXfermode::Mode mode;
1819 getAlphaAndMode(paint, &alpha, &mode);
1820
Romain Guy8164c2d2010-10-25 18:03:28 -07001821 setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
1822
Romain Guy6620c6d2010-12-06 18:07:02 -08001823 if (mSnapshot->transform->isPureTranslate()) {
1824 const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
1825 const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
1826
1827 drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id,
1828 alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL,
1829 (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true);
1830 } else {
1831 drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
1832 texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset,
1833 GL_TRIANGLE_STRIP, gMeshCount);
1834 }
Romain Guy85bf02f2010-06-22 13:11:24 -07001835}
1836
Romain Guybd6b79b2010-06-26 00:13:53 -07001837void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -07001838 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) {
1839 drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend,
Romain Guy03750a02010-10-18 14:06:08 -07001840 (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount);
Romain Guyf7f93552010-07-08 19:17:03 -07001841}
1842
1843void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -07001844 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
Romain Guy6820ac82010-09-15 18:11:50 -07001845 GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
Romain Guy5b3b3522010-10-27 18:57:51 -07001846 bool swapSrcDst, bool ignoreTransform, GLuint vbo, bool ignoreScale, bool dirty) {
Romain Guy70ca14e2010-12-13 18:24:33 -08001847
Romain Guy746b7402010-10-26 16:27:31 -07001848 setupDraw();
Romain Guy70ca14e2010-12-13 18:24:33 -08001849 setupDrawWithTexture();
1850 setupDrawColor(alpha, alpha, alpha, alpha);
1851 setupDrawColorFilter();
1852 setupDrawBlending(blend, mode, swapSrcDst);
1853 setupDrawProgram();
1854 if (!dirty) {
1855 setupDrawDirtyRegionsDisabled();
Romain Guydb1938e2010-08-02 18:50:22 -07001856 }
Romain Guy5b3b3522010-10-27 18:57:51 -07001857 if (!ignoreScale) {
Romain Guy70ca14e2010-12-13 18:24:33 -08001858 setupDrawModelView(left, top, right, bottom, ignoreTransform);
Romain Guyf607bdc2010-09-10 19:20:06 -07001859 } else {
Romain Guy70ca14e2010-12-13 18:24:33 -08001860 setupDrawModelViewTranslate(left, top, right, bottom, ignoreTransform);
Romain Guyf607bdc2010-09-10 19:20:06 -07001861 }
Romain Guy86568192010-12-14 15:55:39 -08001862 setupDrawPureColorUniforms();
Romain Guy70ca14e2010-12-13 18:24:33 -08001863 setupDrawColorFilterUniforms();
1864 setupDrawTexture(texture);
1865 setupDrawMesh(vertices, texCoords, vbo);
Romain Guydb1938e2010-08-02 18:50:22 -07001866
Romain Guy6820ac82010-09-15 18:11:50 -07001867 glDrawArrays(drawMode, 0, elementsCount);
Romain Guy70ca14e2010-12-13 18:24:33 -08001868
1869 finishDrawTexture();
Romain Guy82ba8142010-07-09 13:25:56 -07001870}
1871
Romain Guya5aed0d2010-09-09 14:42:43 -07001872void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode,
Romain Guyf607bdc2010-09-10 19:20:06 -07001873 ProgramDescription& description, bool swapSrcDst) {
Romain Guy82ba8142010-07-09 13:25:56 -07001874 blend = blend || mode != SkXfermode::kSrcOver_Mode;
1875 if (blend) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001876 if (mode < SkXfermode::kPlus_Mode) {
1877 if (!mCaches.blend) {
1878 glEnable(GL_BLEND);
1879 }
Romain Guy82ba8142010-07-09 13:25:56 -07001880
Romain Guyf607bdc2010-09-10 19:20:06 -07001881 GLenum sourceMode = swapSrcDst ? gBlendsSwap[mode].src : gBlends[mode].src;
1882 GLenum destMode = swapSrcDst ? gBlendsSwap[mode].dst : gBlends[mode].dst;
Romain Guy82ba8142010-07-09 13:25:56 -07001883
Romain Guya5aed0d2010-09-09 14:42:43 -07001884 if (sourceMode != mCaches.lastSrcMode || destMode != mCaches.lastDstMode) {
1885 glBlendFunc(sourceMode, destMode);
1886 mCaches.lastSrcMode = sourceMode;
1887 mCaches.lastDstMode = destMode;
1888 }
1889 } else {
1890 // These blend modes are not supported by OpenGL directly and have
1891 // to be implemented using shaders. Since the shader will perform
1892 // the blending, turn blending off here
Romain Guy746b7402010-10-26 16:27:31 -07001893 if (mCaches.extensions.hasFramebufferFetch()) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001894 description.framebufferMode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -07001895 description.swapSrcDst = swapSrcDst;
Romain Guya5aed0d2010-09-09 14:42:43 -07001896 }
1897
1898 if (mCaches.blend) {
1899 glDisable(GL_BLEND);
1900 }
1901 blend = false;
Romain Guy82ba8142010-07-09 13:25:56 -07001902 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001903 } else if (mCaches.blend) {
Romain Guy82ba8142010-07-09 13:25:56 -07001904 glDisable(GL_BLEND);
1905 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001906 mCaches.blend = blend;
Romain Guybd6b79b2010-06-26 00:13:53 -07001907}
1908
Romain Guy889f8d12010-07-29 14:37:42 -07001909bool OpenGLRenderer::useProgram(Program* program) {
Romain Guyd27977d2010-07-14 19:18:51 -07001910 if (!program->isInUse()) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001911 if (mCaches.currentProgram != NULL) mCaches.currentProgram->remove();
Romain Guyd27977d2010-07-14 19:18:51 -07001912 program->use();
Romain Guyfb8b7632010-08-23 21:05:08 -07001913 mCaches.currentProgram = program;
Romain Guy6926c722010-07-12 20:20:03 -07001914 return false;
Romain Guy260e1022010-07-12 14:41:06 -07001915 }
Romain Guy6926c722010-07-12 20:20:03 -07001916 return true;
Romain Guy260e1022010-07-12 14:41:06 -07001917}
1918
Romain Guy026c5e162010-06-28 17:12:22 -07001919void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
Romain Guyac670c02010-07-27 17:39:27 -07001920 TextureVertex* v = &mMeshVertices[0];
Romain Guy82ba8142010-07-09 13:25:56 -07001921 TextureVertex::setUV(v++, u1, v1);
1922 TextureVertex::setUV(v++, u2, v1);
1923 TextureVertex::setUV(v++, u1, v2);
1924 TextureVertex::setUV(v++, u2, v2);
Romain Guy8ba548f2010-06-30 19:21:21 -07001925}
1926
Chet Haase5c13d892010-10-08 08:37:55 -07001927void OpenGLRenderer::getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
Romain Guy8ba548f2010-06-30 19:21:21 -07001928 if (paint) {
Romain Guy746b7402010-10-26 16:27:31 -07001929 if (!mCaches.extensions.hasFramebufferFetch()) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001930 const bool isMode = SkXfermode::IsMode(paint->getXfermode(), mode);
1931 if (!isMode) {
1932 // Assume SRC_OVER
1933 *mode = SkXfermode::kSrcOver_Mode;
1934 }
1935 } else {
1936 *mode = getXfermode(paint->getXfermode());
Romain Guy8ba548f2010-06-30 19:21:21 -07001937 }
1938
1939 // Skia draws using the color's alpha channel if < 255
1940 // Otherwise, it uses the paint's alpha
1941 int color = paint->getColor();
1942 *alpha = (color >> 24) & 0xFF;
1943 if (*alpha == 255) {
1944 *alpha = paint->getAlpha();
1945 }
1946 } else {
1947 *mode = SkXfermode::kSrcOver_Mode;
1948 *alpha = 255;
1949 }
Romain Guy026c5e162010-06-28 17:12:22 -07001950}
1951
Romain Guya5aed0d2010-09-09 14:42:43 -07001952SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
1953 if (mode == NULL) {
1954 return SkXfermode::kSrcOver_Mode;
1955 }
1956 return mode->fMode;
1957}
1958
Romain Guy746b7402010-10-26 16:27:31 -07001959void OpenGLRenderer::setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT) {
Romain Guy8164c2d2010-10-25 18:03:28 -07001960 bool bound = false;
1961 if (wrapS != texture->wrapS) {
1962 glBindTexture(GL_TEXTURE_2D, texture->id);
1963 bound = true;
1964 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
1965 texture->wrapS = wrapS;
1966 }
1967 if (wrapT != texture->wrapT) {
Romain Guy3e3ba152010-10-25 18:33:16 -07001968 if (!bound) {
Romain Guy3e3ba152010-10-25 18:33:16 -07001969 glBindTexture(GL_TEXTURE_2D, texture->id);
1970 }
Romain Guy8164c2d2010-10-25 18:03:28 -07001971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
1972 texture->wrapT = wrapT;
1973 }
Romain Guya1db5742010-07-20 13:09:13 -07001974}
1975
Romain Guy9d5316e2010-06-24 19:30:36 -07001976}; // namespace uirenderer
Romain Guye4d01122010-06-16 18:44:05 -07001977}; // namespace android