blob: 670d049956f91e89e33506bfb0459fb085415c58 [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>
27
Romain Guy85bf02f2010-06-22 13:11:24 -070028#include "OpenGLRenderer.h"
Romain Guye4d01122010-06-16 18:44:05 -070029
30namespace android {
Romain Guy9d5316e2010-06-24 19:30:36 -070031namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
Romain Guy06f96e22010-07-30 19:18:16 -070037#define REQUIRED_TEXTURE_UNITS_COUNT 3
38
Romain Guydda57022010-07-06 11:39:32 -070039// Generates simple and textured vertices
Romain Guybd6b79b2010-06-26 00:13:53 -070040#define FV(x, y, u, v) { { x, y }, { u, v } }
Romain Guy9d5316e2010-06-24 19:30:36 -070041
42///////////////////////////////////////////////////////////////////////////////
43// Globals
44///////////////////////////////////////////////////////////////////////////////
45
Romain Guy026c5e162010-06-28 17:12:22 -070046// This array is never used directly but used as a memcpy source in the
47// OpenGLRenderer constructor
Romain Guyac670c02010-07-27 17:39:27 -070048static const TextureVertex gMeshVertices[] = {
Romain Guyc1396e92010-06-30 17:56:19 -070049 FV(0.0f, 0.0f, 0.0f, 0.0f),
50 FV(1.0f, 0.0f, 1.0f, 0.0f),
51 FV(0.0f, 1.0f, 0.0f, 1.0f),
52 FV(1.0f, 1.0f, 1.0f, 1.0f)
Romain Guybd6b79b2010-06-26 00:13:53 -070053};
Romain Guyac670c02010-07-27 17:39:27 -070054static const GLsizei gMeshStride = sizeof(TextureVertex);
55static const GLsizei gMeshCount = 4;
Romain Guybd6b79b2010-06-26 00:13:53 -070056
Romain Guy889f8d12010-07-29 14:37:42 -070057/**
58 * Structure mapping Skia xfermodes to OpenGL blending factors.
59 */
60struct Blender {
61 SkXfermode::Mode mode;
62 GLenum src;
63 GLenum dst;
64}; // struct Blender
65
Romain Guy026c5e162010-06-28 17:12:22 -070066// In this array, the index of each Blender equals the value of the first
67// entry. For instance, gBlends[1] == gBlends[SkXfermode::kSrc_Mode]
68static const Blender gBlends[] = {
69 { SkXfermode::kClear_Mode, GL_ZERO, GL_ZERO },
70 { SkXfermode::kSrc_Mode, GL_ONE, GL_ZERO },
71 { SkXfermode::kDst_Mode, GL_ZERO, GL_ONE },
72 { SkXfermode::kSrcOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
73 { SkXfermode::kDstOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
74 { SkXfermode::kSrcIn_Mode, GL_DST_ALPHA, GL_ZERO },
75 { SkXfermode::kDstIn_Mode, GL_ZERO, GL_SRC_ALPHA },
76 { SkXfermode::kSrcOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
77 { SkXfermode::kDstOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
78 { SkXfermode::kSrcATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
79 { SkXfermode::kDstATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
80 { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }
81};
Romain Guye4d01122010-06-16 18:44:05 -070082
Romain Guy87a76572010-09-13 18:11:21 -070083// This array contains the swapped version of each SkXfermode. For instance
84// this array's SrcOver blending mode is actually DstOver. You can refer to
85// createLayer() for more information on the purpose of this array.
Romain Guyf607bdc2010-09-10 19:20:06 -070086static const Blender gBlendsSwap[] = {
87 { SkXfermode::kClear_Mode, GL_ZERO, GL_ZERO },
88 { SkXfermode::kSrc_Mode, GL_ZERO, GL_ONE },
89 { SkXfermode::kDst_Mode, GL_ONE, GL_ZERO },
90 { SkXfermode::kSrcOver_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE },
91 { SkXfermode::kDstOver_Mode, GL_ONE, GL_ONE_MINUS_SRC_ALPHA },
92 { SkXfermode::kSrcIn_Mode, GL_ZERO, GL_SRC_ALPHA },
93 { SkXfermode::kDstIn_Mode, GL_DST_ALPHA, GL_ZERO },
94 { SkXfermode::kSrcOut_Mode, GL_ZERO, GL_ONE_MINUS_SRC_ALPHA },
95 { SkXfermode::kDstOut_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ZERO },
96 { SkXfermode::kSrcATop_Mode, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA },
97 { SkXfermode::kDstATop_Mode, GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA },
98 { SkXfermode::kXor_Mode, GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA }
99};
100
Romain Guy889f8d12010-07-29 14:37:42 -0700101static const GLenum gTextureUnits[] = {
Romain Guy06f96e22010-07-30 19:18:16 -0700102 GL_TEXTURE0,
103 GL_TEXTURE1,
104 GL_TEXTURE2
Romain Guyd27977d2010-07-14 19:18:51 -0700105};
106
Romain Guyf6a11b82010-06-23 17:47:49 -0700107///////////////////////////////////////////////////////////////////////////////
108// Constructors/destructor
109///////////////////////////////////////////////////////////////////////////////
110
Romain Guyfb8b7632010-08-23 21:05:08 -0700111OpenGLRenderer::OpenGLRenderer(): mCaches(Caches::getInstance()) {
Romain Guy85bf02f2010-06-22 13:11:24 -0700112 LOGD("Create OpenGLRenderer");
Romain Guy9d5316e2010-06-24 19:30:36 -0700113
Romain Guy06f96e22010-07-30 19:18:16 -0700114 mShader = NULL;
Romain Guydb1938e2010-08-02 18:50:22 -0700115 mColorFilter = NULL;
Romain Guy1e45aae2010-08-13 19:39:53 -0700116 mHasShadow = false;
Romain Guy026c5e162010-06-28 17:12:22 -0700117
Romain Guyac670c02010-07-27 17:39:27 -0700118 memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices));
119
Romain Guyae5575b2010-07-29 18:48:04 -0700120 mFirstSnapshot = new Snapshot;
121
122 GLint maxTextureUnits;
123 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
124 if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
Romain Guy889f8d12010-07-29 14:37:42 -0700125 LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
126 }
Romain Guyb025b9c2010-09-16 14:16:48 -0700127
128 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
Romain Guye4d01122010-06-16 18:44:05 -0700129}
130
Romain Guy85bf02f2010-06-22 13:11:24 -0700131OpenGLRenderer::~OpenGLRenderer() {
132 LOGD("Destroy OpenGLRenderer");
Romain Guye4d01122010-06-16 18:44:05 -0700133}
134
Romain Guyf6a11b82010-06-23 17:47:49 -0700135///////////////////////////////////////////////////////////////////////////////
136// Setup
137///////////////////////////////////////////////////////////////////////////////
138
Romain Guy85bf02f2010-06-22 13:11:24 -0700139void OpenGLRenderer::setViewport(int width, int height) {
Romain Guy08ae3172010-06-21 19:35:50 -0700140 glViewport(0, 0, width, height);
Romain Guy260e1022010-07-12 14:41:06 -0700141 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
Romain Guybb9524b2010-06-22 18:56:38 -0700142
143 mWidth = width;
144 mHeight = height;
Romain Guye4d01122010-06-16 18:44:05 -0700145}
146
Romain Guy85bf02f2010-06-22 13:11:24 -0700147void OpenGLRenderer::prepare() {
Romain Guy8aef54f2010-09-01 15:13:49 -0700148 mSnapshot = new Snapshot(mFirstSnapshot,
149 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
Romain Guy8fb95422010-08-17 18:38:51 -0700150 mSaveCount = 1;
Romain Guyf6a11b82010-06-23 17:47:49 -0700151
Romain Guyfb8b7632010-08-23 21:05:08 -0700152 glViewport(0, 0, mWidth, mHeight);
153
Romain Guyd90f23e2010-09-09 11:47:54 -0700154 glDisable(GL_DITHER);
Romain Guy08ae3172010-06-21 19:35:50 -0700155 glDisable(GL_SCISSOR_TEST);
Romain Guybb9524b2010-06-22 18:56:38 -0700156
Romain Guy08ae3172010-06-21 19:35:50 -0700157 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
158 glClear(GL_COLOR_BUFFER_BIT);
Romain Guybb9524b2010-06-22 18:56:38 -0700159
Romain Guy08ae3172010-06-21 19:35:50 -0700160 glEnable(GL_SCISSOR_TEST);
Romain Guyc7d53492010-06-25 13:41:57 -0700161 glScissor(0, 0, mWidth, mHeight);
Romain Guyf6a11b82010-06-23 17:47:49 -0700162
Romain Guyb82da652010-07-30 11:36:12 -0700163 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guybb9524b2010-06-22 18:56:38 -0700164}
165
Romain Guyb025b9c2010-09-16 14:16:48 -0700166void OpenGLRenderer::finish() {
167#if DEBUG_OPENGL
168 GLenum status = GL_NO_ERROR;
169 while ((status = glGetError()) != GL_NO_ERROR) {
170 LOGD("GL error from OpenGLRenderer: 0x%x", status);
171 }
172#endif
173}
174
Romain Guyda8532c2010-08-31 11:50:35 -0700175void OpenGLRenderer::acquireContext() {
176 if (mCaches.currentProgram) {
177 if (mCaches.currentProgram->isInUse()) {
178 mCaches.currentProgram->remove();
179 mCaches.currentProgram = NULL;
180 }
181 }
182}
183
184void OpenGLRenderer::releaseContext() {
Romain Guyf607bdc2010-09-10 19:20:06 -0700185 glViewport(0, 0, mWidth, mHeight);
Romain Guyda8532c2010-08-31 11:50:35 -0700186
187 glEnable(GL_SCISSOR_TEST);
188 setScissorFromClip();
189
Romain Guyf607bdc2010-09-10 19:20:06 -0700190 glDisable(GL_DITHER);
191
192 glBindFramebuffer(GL_FRAMEBUFFER, 0);
193
Romain Guyda8532c2010-08-31 11:50:35 -0700194 if (mCaches.blend) {
195 glEnable(GL_BLEND);
196 glBlendFunc(mCaches.lastSrcMode, mCaches.lastDstMode);
Romain Guyf607bdc2010-09-10 19:20:06 -0700197 glBlendEquation(GL_FUNC_ADD);
Romain Guyda8532c2010-08-31 11:50:35 -0700198 } else {
199 glDisable(GL_BLEND);
200 }
201}
202
Romain Guyf6a11b82010-06-23 17:47:49 -0700203///////////////////////////////////////////////////////////////////////////////
204// State management
205///////////////////////////////////////////////////////////////////////////////
206
Romain Guybb9524b2010-06-22 18:56:38 -0700207int OpenGLRenderer::getSaveCount() const {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700208 return mSaveCount;
Romain Guybb9524b2010-06-22 18:56:38 -0700209}
210
211int OpenGLRenderer::save(int flags) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700212 return saveSnapshot(flags);
Romain Guybb9524b2010-06-22 18:56:38 -0700213}
214
215void OpenGLRenderer::restore() {
Romain Guy2542d192010-08-18 11:47:12 -0700216 if (mSaveCount > 1) {
217 restoreSnapshot();
Romain Guy7ae7ac42010-06-25 13:46:18 -0700218 }
Romain Guybb9524b2010-06-22 18:56:38 -0700219}
220
221void OpenGLRenderer::restoreToCount(int saveCount) {
Romain Guy8fb95422010-08-17 18:38:51 -0700222 if (saveCount < 1) saveCount = 1;
Romain Guybb9524b2010-06-22 18:56:38 -0700223
Romain Guy8fb95422010-08-17 18:38:51 -0700224 while (mSaveCount > saveCount) {
Romain Guy2542d192010-08-18 11:47:12 -0700225 restoreSnapshot();
Romain Guy7ae7ac42010-06-25 13:46:18 -0700226 }
Romain Guybb9524b2010-06-22 18:56:38 -0700227}
228
Romain Guy8aef54f2010-09-01 15:13:49 -0700229int OpenGLRenderer::saveSnapshot(int flags) {
230 mSnapshot = new Snapshot(mSnapshot, flags);
Romain Guy8fb95422010-08-17 18:38:51 -0700231 return mSaveCount++;
Romain Guybb9524b2010-06-22 18:56:38 -0700232}
233
234bool OpenGLRenderer::restoreSnapshot() {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700235 bool restoreClip = mSnapshot->flags & Snapshot::kFlagClipSet;
Romain Guybd6b79b2010-06-26 00:13:53 -0700236 bool restoreLayer = mSnapshot->flags & Snapshot::kFlagIsLayer;
Romain Guybb9524b2010-06-22 18:56:38 -0700237
Romain Guybd6b79b2010-06-26 00:13:53 -0700238 sp<Snapshot> current = mSnapshot;
239 sp<Snapshot> previous = mSnapshot->previous;
240
Romain Guy8b55f372010-08-18 17:10:07 -0700241 mSaveCount--;
242 mSnapshot = previous;
243
Romain Guybd6b79b2010-06-26 00:13:53 -0700244 if (restoreLayer) {
Romain Guyd55a8612010-06-28 17:42:46 -0700245 composeLayer(current, previous);
Romain Guybd6b79b2010-06-26 00:13:53 -0700246 }
247
Romain Guy2542d192010-08-18 11:47:12 -0700248 if (restoreClip) {
249 setScissorFromClip();
Romain Guy8fb95422010-08-17 18:38:51 -0700250 }
Romain Guy2542d192010-08-18 11:47:12 -0700251
252 return restoreClip;
Romain Guybb9524b2010-06-22 18:56:38 -0700253}
254
Romain Guyf6a11b82010-06-23 17:47:49 -0700255///////////////////////////////////////////////////////////////////////////////
Romain Guybd6b79b2010-06-26 00:13:53 -0700256// Layers
257///////////////////////////////////////////////////////////////////////////////
258
259int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
260 const SkPaint* p, int flags) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700261 int count = saveSnapshot(flags);
Romain Guyd55a8612010-06-28 17:42:46 -0700262
263 int alpha = 255;
264 SkXfermode::Mode mode;
265
266 if (p) {
267 alpha = p->getAlpha();
Romain Guya5aed0d2010-09-09 14:42:43 -0700268 if (!mExtensions.hasFramebufferFetch()) {
269 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
270 if (!isMode) {
271 // Assume SRC_OVER
272 mode = SkXfermode::kSrcOver_Mode;
273 }
274 } else {
275 mode = getXfermode(p->getXfermode());
Romain Guyd55a8612010-06-28 17:42:46 -0700276 }
277 } else {
278 mode = SkXfermode::kSrcOver_Mode;
279 }
280
Romain Guyf607bdc2010-09-10 19:20:06 -0700281 createLayer(mSnapshot, left, top, right, bottom, alpha, mode, flags);
Romain Guyd55a8612010-06-28 17:42:46 -0700282
283 return count;
Romain Guybd6b79b2010-06-26 00:13:53 -0700284}
285
286int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
287 int alpha, int flags) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700288 if (alpha == 0xff) {
289 return saveLayer(left, top, right, bottom, NULL, flags);
Romain Guy8b55f372010-08-18 17:10:07 -0700290 } else {
Romain Guy8aef54f2010-09-01 15:13:49 -0700291 SkPaint paint;
292 paint.setAlpha(alpha);
293 return saveLayer(left, top, right, bottom, &paint, flags);
Romain Guy8b55f372010-08-18 17:10:07 -0700294 }
Romain Guyd55a8612010-06-28 17:42:46 -0700295}
Romain Guybd6b79b2010-06-26 00:13:53 -0700296
Romain Guy1c740bc2010-09-13 18:00:09 -0700297/**
298 * Layers are viewed by Skia are slightly different than layers in image editing
299 * programs (for instance.) When a layer is created, previously created layers
300 * and the frame buffer still receive every drawing command. For instance, if a
301 * layer is created and a shape intersecting the bounds of the layers and the
302 * framebuffer is draw, the shape will be drawn on both (unless the layer was
303 * created with the SkCanvas::kClipToLayer_SaveFlag flag.)
304 *
305 * A way to implement layers is to create an FBO for each layer, backed by an RGBA
306 * texture. Unfortunately, this is inefficient as it requires every primitive to
307 * be drawn n + 1 times, where n is the number of active layers. In practice this
308 * means, for every primitive:
309 * - Switch active frame buffer
310 * - Change viewport, clip and projection matrix
311 * - Issue the drawing
312 *
313 * Switching rendering target n + 1 times per drawn primitive is extremely costly.
314 * To avoid this, layers are implemented in a different way here.
315 *
316 * This implementation relies on the frame buffer being at least RGBA 8888. When
317 * a layer is created, only a texture is created, not an FBO. The content of the
318 * frame buffer contained within the layer's bounds is copied into this texture
Romain Guy87a76572010-09-13 18:11:21 -0700319 * using glCopyTexImage2D(). The layer's region is then cleared(1) in the frame
Romain Guy1c740bc2010-09-13 18:00:09 -0700320 * buffer and drawing continues as normal. This technique therefore treats the
321 * frame buffer as a scratch buffer for the layers.
322 *
323 * To compose the layers back onto the frame buffer, each layer texture
324 * (containing the original frame buffer data) is drawn as a simple quad over
325 * the frame buffer. The trick is that the quad is set as the composition
326 * destination in the blending equation, and the frame buffer becomes the source
327 * of the composition.
328 *
329 * Drawing layers with an alpha value requires an extra step before composition.
330 * An empty quad is drawn over the layer's region in the frame buffer. This quad
331 * is drawn with the rgba color (0,0,0,alpha). The alpha value offered by the
332 * quad is used to multiply the colors in the frame buffer. This is achieved by
333 * changing the GL blend functions for the GL_FUNC_ADD blend equation to
334 * GL_ZERO, GL_SRC_ALPHA.
335 *
336 * Because glCopyTexImage2D() can be slow, an alternative implementation might
337 * be use to draw a single clipped layer. The implementation described above
338 * is correct in every case.
Romain Guy87a76572010-09-13 18:11:21 -0700339 *
340 * (1) The frame buffer is actually not cleared right away. To allow the GPU
341 * to potentially optimize series of calls to glCopyTexImage2D, the frame
342 * buffer is left untouched until the first drawing operation. Only when
343 * something actually gets drawn are the layers regions cleared.
Romain Guy1c740bc2010-09-13 18:00:09 -0700344 */
Romain Guyd55a8612010-06-28 17:42:46 -0700345bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
346 float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) {
Romain Guyd27977d2010-07-14 19:18:51 -0700347 LAYER_LOGD("Requesting layer %fx%f", right - left, bottom - top);
Romain Guyfb8b7632010-08-23 21:05:08 -0700348 LAYER_LOGD("Layer cache size = %d", mCaches.layerCache.getSize());
Romain Guy8ba548f2010-06-30 19:21:21 -0700349
Romain Guyf607bdc2010-09-10 19:20:06 -0700350 // Window coordinates of the layer
Romain Guy8aef54f2010-09-01 15:13:49 -0700351 Rect bounds(left, top, right, bottom);
Romain Guyf607bdc2010-09-10 19:20:06 -0700352 mSnapshot->transform->mapRect(bounds);
Romain Guy8aef54f2010-09-01 15:13:49 -0700353
Romain Guy8411f332010-09-13 17:27:57 -0700354 // Layers only make sense if they are in the framebuffer's bounds
355 bounds.intersect(*mSnapshot->clipRect);
Romain Guyb025b9c2010-09-16 14:16:48 -0700356 if (bounds.isEmpty() || bounds.getWidth() > mMaxTextureSize ||
357 bounds.getHeight() > mMaxTextureSize) {
358 return false;
359 }
Romain Guyf18fd992010-07-08 11:45:51 -0700360
Romain Guy8411f332010-09-13 17:27:57 -0700361 LayerSize size(bounds.getWidth(), bounds.getHeight());
Romain Guyf607bdc2010-09-10 19:20:06 -0700362 Layer* layer = mCaches.layerCache.get(size);
Romain Guydda57022010-07-06 11:39:32 -0700363 if (!layer) {
Romain Guyf18fd992010-07-08 11:45:51 -0700364 return false;
Romain Guybd6b79b2010-06-26 00:13:53 -0700365 }
366
Romain Guydda57022010-07-06 11:39:32 -0700367 layer->mode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -0700368 layer->alpha = alpha;
Romain Guy8aef54f2010-09-01 15:13:49 -0700369 layer->layer.set(bounds);
Romain Guydda57022010-07-06 11:39:32 -0700370
Romain Guy8fb95422010-08-17 18:38:51 -0700371 // Save the layer in the snapshot
372 snapshot->flags |= Snapshot::kFlagIsLayer;
Romain Guydda57022010-07-06 11:39:32 -0700373 snapshot->layer = layer;
Romain Guy1d83e192010-08-17 11:37:00 -0700374
Romain Guyf607bdc2010-09-10 19:20:06 -0700375 // Copy the framebuffer into the layer
376 glBindTexture(GL_TEXTURE_2D, layer->texture);
377 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left, mHeight - bounds.bottom,
378 bounds.getWidth(), bounds.getHeight(), 0);
379
Romain Guyf607bdc2010-09-10 19:20:06 -0700380 if (flags & SkCanvas::kClipToLayer_SaveFlag) {
Romain Guy86942302010-09-12 13:02:16 -0700381 if (mSnapshot->clipTransformed(bounds)) setScissorFromClip();
Romain Guyf607bdc2010-09-10 19:20:06 -0700382 }
383
Romain Guy86942302010-09-12 13:02:16 -0700384 // Enqueue the buffer coordinates to clear the corresponding region later
385 mLayers.push(new Rect(bounds));
Romain Guyf86ef572010-07-01 11:05:42 -0700386
Romain Guyd55a8612010-06-28 17:42:46 -0700387 return true;
Romain Guybd6b79b2010-06-26 00:13:53 -0700388}
389
Romain Guy1c740bc2010-09-13 18:00:09 -0700390/**
391 * Read the documentation of createLayer() before doing anything in this method.
392 */
Romain Guy1d83e192010-08-17 11:37:00 -0700393void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
394 if (!current->layer) {
395 LOGE("Attempting to compose a layer that does not exist");
396 return;
397 }
398
Romain Guy1d83e192010-08-17 11:37:00 -0700399 // Restore the clip from the previous snapshot
Romain Guy8aef54f2010-09-01 15:13:49 -0700400 const Rect& clip = *previous->clipRect;
Romain Guyf607bdc2010-09-10 19:20:06 -0700401 glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy1d83e192010-08-17 11:37:00 -0700402
403 Layer* layer = current->layer;
404 const Rect& rect = layer->layer;
405
Romain Guyf607bdc2010-09-10 19:20:06 -0700406 if (layer->alpha < 255) {
Romain Guyf607bdc2010-09-10 19:20:06 -0700407 drawColorRect(rect.left, rect.top, rect.right, rect.bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -0700408 layer->alpha << 24, SkXfermode::kDstIn_Mode, true);
Romain Guyf607bdc2010-09-10 19:20:06 -0700409 }
410
411 // Layers are already drawn with a top-left origin, don't flip the texture
Romain Guy8b55f372010-08-18 17:10:07 -0700412 resetDrawTextureTexCoords(0.0f, 1.0f, 1.0f, 0.0f);
413
Romain Guyf607bdc2010-09-10 19:20:06 -0700414 drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
415 1.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
Romain Guy6820ac82010-09-15 18:11:50 -0700416 &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount, true, true);
Romain Guy1d83e192010-08-17 11:37:00 -0700417
Romain Guy8b55f372010-08-18 17:10:07 -0700418 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
419
Romain Guy1d83e192010-08-17 11:37:00 -0700420 LayerSize size(rect.getWidth(), rect.getHeight());
421 // Failing to add the layer to the cache should happen only if the
422 // layer is too large
Romain Guyfb8b7632010-08-23 21:05:08 -0700423 if (!mCaches.layerCache.put(size, layer)) {
Romain Guy1d83e192010-08-17 11:37:00 -0700424 LAYER_LOGD("Deleting layer");
425
Romain Guy1d83e192010-08-17 11:37:00 -0700426 glDeleteTextures(1, &layer->texture);
427
428 delete layer;
429 }
430}
431
Romain Guy86942302010-09-12 13:02:16 -0700432void OpenGLRenderer::clearLayerRegions() {
433 if (mLayers.size() == 0) return;
434
435 for (uint32_t i = 0; i < mLayers.size(); i++) {
436 Rect* bounds = mLayers.itemAt(i);
437
438 // Clear the framebuffer where the layer will draw
439 glScissor(bounds->left, mHeight - bounds->bottom,
440 bounds->getWidth(), bounds->getHeight());
441 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
442 glClear(GL_COLOR_BUFFER_BIT);
443
444 delete bounds;
445 }
446 mLayers.clear();
447
448 // Restore the clip
449 setScissorFromClip();
450}
451
Romain Guybd6b79b2010-06-26 00:13:53 -0700452///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -0700453// Transforms
454///////////////////////////////////////////////////////////////////////////////
455
456void OpenGLRenderer::translate(float dx, float dy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700457 mSnapshot->transform->translate(dx, dy, 0.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700458}
459
460void OpenGLRenderer::rotate(float degrees) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700461 mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700462}
463
464void OpenGLRenderer::scale(float sx, float sy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700465 mSnapshot->transform->scale(sx, sy, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700466}
467
468void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700469 mSnapshot->transform->load(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700470}
471
472void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700473 mSnapshot->transform->copyTo(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700474}
475
476void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700477 mat4 m(*matrix);
Romain Guy8aef54f2010-09-01 15:13:49 -0700478 mSnapshot->transform->multiply(m);
Romain Guyf6a11b82010-06-23 17:47:49 -0700479}
480
481///////////////////////////////////////////////////////////////////////////////
482// Clipping
483///////////////////////////////////////////////////////////////////////////////
484
Romain Guybb9524b2010-06-22 18:56:38 -0700485void OpenGLRenderer::setScissorFromClip() {
Romain Guy8aef54f2010-09-01 15:13:49 -0700486 const Rect& clip = *mSnapshot->clipRect;
Romain Guyf607bdc2010-09-10 19:20:06 -0700487 glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy9d5316e2010-06-24 19:30:36 -0700488}
489
490const Rect& OpenGLRenderer::getClipBounds() {
Romain Guy079ba2c2010-07-16 14:12:24 -0700491 return mSnapshot->getLocalClip();
Romain Guybb9524b2010-06-22 18:56:38 -0700492}
493
Romain Guyc7d53492010-06-25 13:41:57 -0700494bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
Romain Guy1d83e192010-08-17 11:37:00 -0700495 Rect r(left, top, right, bottom);
Romain Guy8aef54f2010-09-01 15:13:49 -0700496 mSnapshot->transform->mapRect(r);
497 return !mSnapshot->clipRect->intersects(r);
Romain Guyc7d53492010-06-25 13:41:57 -0700498}
499
Romain Guy079ba2c2010-07-16 14:12:24 -0700500bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
501 bool clipped = mSnapshot->clip(left, top, right, bottom, op);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700502 if (clipped) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700503 setScissorFromClip();
504 }
Romain Guy8aef54f2010-09-01 15:13:49 -0700505 return !mSnapshot->clipRect->isEmpty();
Romain Guye4d01122010-06-16 18:44:05 -0700506}
507
Romain Guyf6a11b82010-06-23 17:47:49 -0700508///////////////////////////////////////////////////////////////////////////////
509// Drawing
510///////////////////////////////////////////////////////////////////////////////
511
Romain Guyc1396e92010-06-30 17:56:19 -0700512void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700513 const float right = left + bitmap->width();
514 const float bottom = top + bitmap->height();
515
516 if (quickReject(left, top, right, bottom)) {
517 return;
518 }
519
Romain Guy61c8c9c2010-08-09 20:48:09 -0700520 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700521 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700522 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700523 const AutoTexture autoCleanup(texture);
524
Romain Guy6926c722010-07-12 20:20:03 -0700525 drawTextureRect(left, top, right, bottom, texture, paint);
Romain Guyce0537b2010-06-29 21:05:21 -0700526}
527
Romain Guyf86ef572010-07-01 11:05:42 -0700528void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint) {
529 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
530 const mat4 transform(*matrix);
531 transform.mapRect(r);
532
Romain Guy6926c722010-07-12 20:20:03 -0700533 if (quickReject(r.left, r.top, r.right, r.bottom)) {
534 return;
535 }
536
Romain Guy61c8c9c2010-08-09 20:48:09 -0700537 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700538 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700539 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700540 const AutoTexture autoCleanup(texture);
541
Romain Guy82ba8142010-07-09 13:25:56 -0700542 drawTextureRect(r.left, r.top, r.right, r.bottom, texture, paint);
Romain Guyf86ef572010-07-01 11:05:42 -0700543}
544
Romain Guy8ba548f2010-06-30 19:21:21 -0700545void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
546 float srcLeft, float srcTop, float srcRight, float srcBottom,
547 float dstLeft, float dstTop, float dstRight, float dstBottom,
Romain Guyf86ef572010-07-01 11:05:42 -0700548 const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700549 if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) {
550 return;
551 }
552
Romain Guy61c8c9c2010-08-09 20:48:09 -0700553 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700554 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700555 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700556 const AutoTexture autoCleanup(texture);
Romain Guy8ba548f2010-06-30 19:21:21 -0700557
Romain Guy8ba548f2010-06-30 19:21:21 -0700558 const float width = texture->width;
559 const float height = texture->height;
560
561 const float u1 = srcLeft / width;
562 const float v1 = srcTop / height;
563 const float u2 = srcRight / width;
564 const float v2 = srcBottom / height;
565
566 resetDrawTextureTexCoords(u1, v1, u2, v2);
567
Romain Guy82ba8142010-07-09 13:25:56 -0700568 drawTextureRect(dstLeft, dstTop, dstRight, dstBottom, texture, paint);
Romain Guy8ba548f2010-06-30 19:21:21 -0700569
570 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
571}
572
Romain Guydeba7852010-07-07 17:54:48 -0700573void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
574 float left, float top, float right, float bottom, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700575 if (quickReject(left, top, right, bottom)) {
576 return;
577 }
578
Romain Guy61c8c9c2010-08-09 20:48:09 -0700579 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700580 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700581 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700582 const AutoTexture autoCleanup(texture);
Romain Guyf7f93552010-07-08 19:17:03 -0700583
584 int alpha;
585 SkXfermode::Mode mode;
586 getAlphaAndMode(paint, &alpha, &mode);
587
Romain Guyfb8b7632010-08-23 21:05:08 -0700588 Patch* mesh = mCaches.patchCache.get(patch);
Romain Guyfb5e23c2010-07-09 13:52:56 -0700589 mesh->updateVertices(bitmap, left, top, right, bottom,
590 &patch->xDivs[0], &patch->yDivs[0], patch->numXDivs, patch->numYDivs);
Romain Guyf7f93552010-07-08 19:17:03 -0700591
592 // Specify right and bottom as +1.0f from left/top to prevent scaling since the
593 // patch mesh already defines the final size
Romain Guya9794742010-07-13 11:37:54 -0700594 drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha / 255.0f,
595 mode, texture->blend, &mesh->vertices[0].position[0],
Romain Guy6820ac82010-09-15 18:11:50 -0700596 &mesh->vertices[0].texture[0], GL_TRIANGLES, mesh->verticesCount);
Romain Guyf7f93552010-07-08 19:17:03 -0700597}
598
Romain Guy85bf02f2010-06-22 13:11:24 -0700599void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700600 const Rect& clip = *mSnapshot->clipRect;
Romain Guy3d58c032010-07-14 16:34:53 -0700601 drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
Romain Guyc7d53492010-06-25 13:41:57 -0700602}
Romain Guy9d5316e2010-06-24 19:30:36 -0700603
Romain Guybd6b79b2010-06-26 00:13:53 -0700604void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, const SkPaint* p) {
Romain Guy6926c722010-07-12 20:20:03 -0700605 if (quickReject(left, top, right, bottom)) {
606 return;
607 }
608
Romain Guy026c5e162010-06-28 17:12:22 -0700609 SkXfermode::Mode mode;
Romain Guya5aed0d2010-09-09 14:42:43 -0700610 if (!mExtensions.hasFramebufferFetch()) {
611 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
612 if (!isMode) {
613 // Assume SRC_OVER
614 mode = SkXfermode::kSrcOver_Mode;
615 }
616 } else {
617 mode = getXfermode(p->getXfermode());
Romain Guy026c5e162010-06-28 17:12:22 -0700618 }
619
620 // Skia draws using the color's alpha channel if < 255
621 // Otherwise, it uses the paint's alpha
622 int color = p->getColor();
Romain Guyd27977d2010-07-14 19:18:51 -0700623 if (((color >> 24) & 0xff) == 255) {
Romain Guy026c5e162010-06-28 17:12:22 -0700624 color |= p->getAlpha() << 24;
625 }
626
627 drawColorRect(left, top, right, bottom, color, mode);
Romain Guyc7d53492010-06-25 13:41:57 -0700628}
Romain Guy9d5316e2010-06-24 19:30:36 -0700629
Romain Guye8e62a42010-07-23 18:55:21 -0700630void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
631 float x, float y, SkPaint* paint) {
Romain Guyf607bdc2010-09-10 19:20:06 -0700632 if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
Romain Guye8e62a42010-07-23 18:55:21 -0700633 return;
634 }
Romain Guyf607bdc2010-09-10 19:20:06 -0700635 paint->setAntiAlias(true);
Romain Guye8e62a42010-07-23 18:55:21 -0700636
Romain Guya674ab72010-08-10 17:26:42 -0700637 float length = -1.0f;
Romain Guye8e62a42010-07-23 18:55:21 -0700638 switch (paint->getTextAlign()) {
639 case SkPaint::kCenter_Align:
640 length = paint->measureText(text, bytesCount);
641 x -= length / 2.0f;
642 break;
643 case SkPaint::kRight_Align:
644 length = paint->measureText(text, bytesCount);
645 x -= length;
646 break;
647 default:
648 break;
649 }
650
Romain Guy694b5192010-07-21 21:33:20 -0700651 int alpha;
652 SkXfermode::Mode mode;
653 getAlphaAndMode(paint, &alpha, &mode);
654
Romain Guy2542d192010-08-18 11:47:12 -0700655 uint32_t color = paint->getColor();
656 const GLfloat a = alpha / 255.0f;
657 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
658 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
659 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
660
Romain Guyb45c0c92010-08-26 20:35:23 -0700661 FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
662 fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
Romain Guyfb8b7632010-08-23 21:05:08 -0700663 paint->getTextSize());
Romain Guy1e45aae2010-08-13 19:39:53 -0700664 if (mHasShadow) {
665 glActiveTexture(gTextureUnits[0]);
Romain Guyb45c0c92010-08-26 20:35:23 -0700666 mCaches.dropShadowCache.setFontRenderer(fontRenderer);
Romain Guyfb8b7632010-08-23 21:05:08 -0700667 const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
Romain Guy1e45aae2010-08-13 19:39:53 -0700668 count, mShadowRadius);
669 const AutoTexture autoCleanup(shadow);
Romain Guy0a417492010-08-16 20:26:20 -0700670
Romain Guy2542d192010-08-18 11:47:12 -0700671 setupShadow(shadow, x, y, mode, a);
Romain Guy0a417492010-08-16 20:26:20 -0700672
673 // Draw the mesh
674 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyfb8b7632010-08-23 21:05:08 -0700675 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guy1e45aae2010-08-13 19:39:53 -0700676 }
677
Romain Guy06f96e22010-07-30 19:18:16 -0700678 GLuint textureUnit = 0;
Romain Guydb1938e2010-08-02 18:50:22 -0700679 glActiveTexture(gTextureUnits[textureUnit]);
Romain Guy06f96e22010-07-30 19:18:16 -0700680
Romain Guyb45c0c92010-08-26 20:35:23 -0700681 setupTextureAlpha8(fontRenderer.getTexture(), 0, 0, textureUnit, x, y, r, g, b, a,
Romain Guy0a417492010-08-16 20:26:20 -0700682 mode, false, true);
Romain Guy06f96e22010-07-30 19:18:16 -0700683
Romain Guy09147fb2010-07-22 13:08:20 -0700684 const Rect& clip = mSnapshot->getLocalClip();
Romain Guy86942302010-09-12 13:02:16 -0700685 clearLayerRegions();
Romain Guyb45c0c92010-08-26 20:35:23 -0700686 fontRenderer.renderText(paint, &clip, text, 0, bytesCount, count, x, y);
Romain Guy694b5192010-07-21 21:33:20 -0700687
688 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700689 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guya674ab72010-08-10 17:26:42 -0700690
Romain Guy0a417492010-08-16 20:26:20 -0700691 drawTextDecorations(text, bytesCount, length, x, y, paint);
Romain Guy694b5192010-07-21 21:33:20 -0700692}
693
Romain Guy7fbcc042010-08-04 15:40:07 -0700694void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
695 GLuint textureUnit = 0;
696 glActiveTexture(gTextureUnits[textureUnit]);
697
Romain Guyfb8b7632010-08-23 21:05:08 -0700698 const PathTexture* texture = mCaches.pathCache.get(path, paint);
Romain Guy9cccc2b2010-08-07 23:46:15 -0700699 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700700 const AutoTexture autoCleanup(texture);
Romain Guy7fbcc042010-08-04 15:40:07 -0700701
Romain Guy8b55f372010-08-18 17:10:07 -0700702 const float x = texture->left - texture->offset;
703 const float y = texture->top - texture->offset;
704
705 if (quickReject(x, y, x + texture->width, y + texture->height)) {
706 return;
707 }
708
Romain Guy7fbcc042010-08-04 15:40:07 -0700709 int alpha;
710 SkXfermode::Mode mode;
711 getAlphaAndMode(paint, &alpha, &mode);
712
713 uint32_t color = paint->getColor();
714 const GLfloat a = alpha / 255.0f;
715 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
716 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
717 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
718
Romain Guy0a417492010-08-16 20:26:20 -0700719 setupTextureAlpha8(texture, textureUnit, x, y, r, g, b, a, mode, true, true);
720
Romain Guy86942302010-09-12 13:02:16 -0700721 clearLayerRegions();
722
Romain Guy0a417492010-08-16 20:26:20 -0700723 // Draw the mesh
724 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyfb8b7632010-08-23 21:05:08 -0700725 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guy7fbcc042010-08-04 15:40:07 -0700726}
727
Romain Guy6926c722010-07-12 20:20:03 -0700728///////////////////////////////////////////////////////////////////////////////
Romain Guyd27977d2010-07-14 19:18:51 -0700729// Shaders
730///////////////////////////////////////////////////////////////////////////////
731
732void OpenGLRenderer::resetShader() {
Romain Guy06f96e22010-07-30 19:18:16 -0700733 mShader = NULL;
Romain Guyd27977d2010-07-14 19:18:51 -0700734}
735
Romain Guy06f96e22010-07-30 19:18:16 -0700736void OpenGLRenderer::setupShader(SkiaShader* shader) {
737 mShader = shader;
738 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700739 mShader->set(&mCaches.textureCache, &mCaches.gradientCache);
Romain Guy06f96e22010-07-30 19:18:16 -0700740 }
Romain Guy7fac2e12010-07-16 17:10:13 -0700741}
742
Romain Guyd27977d2010-07-14 19:18:51 -0700743///////////////////////////////////////////////////////////////////////////////
Romain Guydb1938e2010-08-02 18:50:22 -0700744// Color filters
745///////////////////////////////////////////////////////////////////////////////
746
747void OpenGLRenderer::resetColorFilter() {
748 mColorFilter = NULL;
749}
750
751void OpenGLRenderer::setupColorFilter(SkiaColorFilter* filter) {
752 mColorFilter = filter;
753}
754
755///////////////////////////////////////////////////////////////////////////////
Romain Guy1e45aae2010-08-13 19:39:53 -0700756// Drop shadow
757///////////////////////////////////////////////////////////////////////////////
758
759void OpenGLRenderer::resetShadow() {
760 mHasShadow = false;
761}
762
763void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
764 mHasShadow = true;
765 mShadowRadius = radius;
766 mShadowDx = dx;
767 mShadowDy = dy;
768 mShadowColor = color;
769}
770
771///////////////////////////////////////////////////////////////////////////////
Romain Guy6926c722010-07-12 20:20:03 -0700772// Drawing implementation
773///////////////////////////////////////////////////////////////////////////////
774
Romain Guy0a417492010-08-16 20:26:20 -0700775void OpenGLRenderer::setupShadow(const ShadowTexture* texture, float x, float y,
Romain Guy2542d192010-08-18 11:47:12 -0700776 SkXfermode::Mode mode, float alpha) {
Romain Guy0a417492010-08-16 20:26:20 -0700777 const float sx = x - texture->left + mShadowDx;
778 const float sy = y - texture->top + mShadowDy;
779
Romain Guy2542d192010-08-18 11:47:12 -0700780 const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
781 const GLfloat a = shadowAlpha < 255 ? shadowAlpha / 255.0f : alpha;
Romain Guy0a417492010-08-16 20:26:20 -0700782 const GLfloat r = a * ((mShadowColor >> 16) & 0xFF) / 255.0f;
783 const GLfloat g = a * ((mShadowColor >> 8) & 0xFF) / 255.0f;
784 const GLfloat b = a * ((mShadowColor ) & 0xFF) / 255.0f;
785
786 GLuint textureUnit = 0;
787 setupTextureAlpha8(texture, textureUnit, sx, sy, r, g, b, a, mode, true, false);
788}
789
790void OpenGLRenderer::setupTextureAlpha8(const Texture* texture, GLuint& textureUnit,
791 float x, float y, float r, float g, float b, float a, SkXfermode::Mode mode,
792 bool transforms, bool applyFilters) {
793 setupTextureAlpha8(texture->id, texture->width, texture->height, textureUnit,
794 x, y, r, g, b, a, mode, transforms, applyFilters);
795}
796
797void OpenGLRenderer::setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
798 GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
799 SkXfermode::Mode mode, bool transforms, bool applyFilters) {
800 // Describe the required shaders
801 ProgramDescription description;
802 description.hasTexture = true;
803 description.hasAlpha8Texture = true;
804
805 if (applyFilters) {
806 if (mShader) {
807 mShader->describe(description, mExtensions);
808 }
809 if (mColorFilter) {
810 mColorFilter->describe(description, mExtensions);
811 }
812 }
813
Romain Guya5aed0d2010-09-09 14:42:43 -0700814 // Setup the blending mode
815 chooseBlending(true, mode, description);
816
Romain Guy0a417492010-08-16 20:26:20 -0700817 // Build and use the appropriate shader
Romain Guyfb8b7632010-08-23 21:05:08 -0700818 useProgram(mCaches.programCache.get(description));
Romain Guy0a417492010-08-16 20:26:20 -0700819
Romain Guy0a417492010-08-16 20:26:20 -0700820 bindTexture(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, textureUnit);
Romain Guyfb8b7632010-08-23 21:05:08 -0700821 glUniform1i(mCaches.currentProgram->getUniform("sampler"), textureUnit);
Romain Guy0a417492010-08-16 20:26:20 -0700822
Romain Guyfb8b7632010-08-23 21:05:08 -0700823 int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
Romain Guy0a417492010-08-16 20:26:20 -0700824 glEnableVertexAttribArray(texCoordsSlot);
825
826 // Setup attributes
Romain Guyfb8b7632010-08-23 21:05:08 -0700827 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guy0a417492010-08-16 20:26:20 -0700828 gMeshStride, &mMeshVertices[0].position[0]);
829 glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE,
830 gMeshStride, &mMeshVertices[0].texture[0]);
831
832 // Setup uniforms
833 if (transforms) {
834 mModelView.loadTranslate(x, y, 0.0f);
835 mModelView.scale(width, height, 1.0f);
836 } else {
837 mModelView.loadIdentity();
838 }
Romain Guy8aef54f2010-09-01 15:13:49 -0700839 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
Romain Guyfb8b7632010-08-23 21:05:08 -0700840 glUniform4f(mCaches.currentProgram->color, r, g, b, a);
Romain Guy0a417492010-08-16 20:26:20 -0700841
842 textureUnit++;
843 if (applyFilters) {
844 // Setup attributes and uniforms required by the shaders
845 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700846 mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &textureUnit);
Romain Guy0a417492010-08-16 20:26:20 -0700847 }
848 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700849 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guy0a417492010-08-16 20:26:20 -0700850 }
851 }
852}
853
Romain Guyf607bdc2010-09-10 19:20:06 -0700854// Same values used by Skia
Romain Guy0a417492010-08-16 20:26:20 -0700855#define kStdStrikeThru_Offset (-6.0f / 21.0f)
856#define kStdUnderline_Offset (1.0f / 9.0f)
857#define kStdUnderline_Thickness (1.0f / 18.0f)
858
859void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float length,
860 float x, float y, SkPaint* paint) {
861 // Handle underline and strike-through
862 uint32_t flags = paint->getFlags();
863 if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
864 float underlineWidth = length;
865 // If length is > 0.0f, we already measured the text for the text alignment
866 if (length <= 0.0f) {
867 underlineWidth = paint->measureText(text, bytesCount);
868 }
869
870 float offsetX = 0;
871 switch (paint->getTextAlign()) {
872 case SkPaint::kCenter_Align:
873 offsetX = underlineWidth * 0.5f;
874 break;
875 case SkPaint::kRight_Align:
876 offsetX = underlineWidth;
877 break;
878 default:
879 break;
880 }
881
882 if (underlineWidth > 0.0f) {
883 float textSize = paint->getTextSize();
884 float height = textSize * kStdUnderline_Thickness;
885
886 float left = x - offsetX;
887 float top = 0.0f;
888 float right = left + underlineWidth;
889 float bottom = 0.0f;
890
891 if (flags & SkPaint::kUnderlineText_Flag) {
892 top = y + textSize * kStdUnderline_Offset;
893 bottom = top + height;
894 drawRect(left, top, right, bottom, paint);
895 }
896
897 if (flags & SkPaint::kStrikeThruText_Flag) {
898 top = y + textSize * kStdStrikeThru_Offset;
899 bottom = top + height;
900 drawRect(left, top, right, bottom, paint);
901 }
902 }
903 }
904}
905
Romain Guy026c5e162010-06-28 17:12:22 -0700906void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -0700907 int color, SkXfermode::Mode mode, bool ignoreTransform) {
Romain Guy86942302010-09-12 13:02:16 -0700908 clearLayerRegions();
909
Romain Guyd27977d2010-07-14 19:18:51 -0700910 // If a shader is set, preserve only the alpha
Romain Guy06f96e22010-07-30 19:18:16 -0700911 if (mShader) {
Romain Guyd27977d2010-07-14 19:18:51 -0700912 color |= 0x00ffffff;
913 }
914
915 // Render using pre-multiplied alpha
Romain Guy026c5e162010-06-28 17:12:22 -0700916 const int alpha = (color >> 24) & 0xFF;
Romain Guyd27977d2010-07-14 19:18:51 -0700917 const GLfloat a = alpha / 255.0f;
Romain Guyc0ac1932010-07-19 18:43:02 -0700918 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
919 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
920 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
921
Romain Guy06f96e22010-07-30 19:18:16 -0700922 GLuint textureUnit = 0;
Romain Guy9d5316e2010-06-24 19:30:36 -0700923
Romain Guy06f96e22010-07-30 19:18:16 -0700924 // Describe the required shaders
Romain Guy889f8d12010-07-29 14:37:42 -0700925 ProgramDescription description;
Romain Guy06f96e22010-07-30 19:18:16 -0700926 if (mShader) {
927 mShader->describe(description, mExtensions);
Romain Guy6926c722010-07-12 20:20:03 -0700928 }
Romain Guydb1938e2010-08-02 18:50:22 -0700929 if (mColorFilter) {
930 mColorFilter->describe(description, mExtensions);
931 }
Romain Guyd27977d2010-07-14 19:18:51 -0700932
Romain Guy1c740bc2010-09-13 18:00:09 -0700933 // Setup the blending mode
934 chooseBlending(alpha < 255 || (mShader && mShader->blend()), mode, description);
Romain Guya5aed0d2010-09-09 14:42:43 -0700935
Romain Guy06f96e22010-07-30 19:18:16 -0700936 // Build and use the appropriate shader
Romain Guyfb8b7632010-08-23 21:05:08 -0700937 useProgram(mCaches.programCache.get(description));
Romain Guy06f96e22010-07-30 19:18:16 -0700938
939 // Setup attributes
Romain Guyfb8b7632010-08-23 21:05:08 -0700940 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guy06f96e22010-07-30 19:18:16 -0700941 gMeshStride, &mMeshVertices[0].position[0]);
942
943 // Setup uniforms
944 mModelView.loadTranslate(left, top, 0.0f);
945 mModelView.scale(right - left, bottom - top, 1.0f);
Romain Guyd27977d2010-07-14 19:18:51 -0700946 if (!ignoreTransform) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700947 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
Romain Guyd27977d2010-07-14 19:18:51 -0700948 } else {
949 mat4 identity;
Romain Guyfb8b7632010-08-23 21:05:08 -0700950 mCaches.currentProgram->set(mOrthoMatrix, mModelView, identity);
Romain Guyd27977d2010-07-14 19:18:51 -0700951 }
Romain Guyfb8b7632010-08-23 21:05:08 -0700952 glUniform4f(mCaches.currentProgram->color, r, g, b, a);
Romain Guy9d5316e2010-06-24 19:30:36 -0700953
Romain Guy06f96e22010-07-30 19:18:16 -0700954 // Setup attributes and uniforms required by the shaders
955 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700956 mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &textureUnit);
Romain Guyc0ac1932010-07-19 18:43:02 -0700957 }
Romain Guydb1938e2010-08-02 18:50:22 -0700958 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700959 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guydb1938e2010-08-02 18:50:22 -0700960 }
Romain Guyc0ac1932010-07-19 18:43:02 -0700961
Romain Guy06f96e22010-07-30 19:18:16 -0700962 // Draw the mesh
Romain Guy889f8d12010-07-29 14:37:42 -0700963 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyd27977d2010-07-14 19:18:51 -0700964}
965
Romain Guy82ba8142010-07-09 13:25:56 -0700966void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700967 const Texture* texture, const SkPaint* paint) {
Romain Guy82ba8142010-07-09 13:25:56 -0700968 int alpha;
969 SkXfermode::Mode mode;
970 getAlphaAndMode(paint, &alpha, &mode);
971
Romain Guy6820ac82010-09-15 18:11:50 -0700972 drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
973 texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
974 GL_TRIANGLE_STRIP, gMeshCount);
Romain Guy85bf02f2010-06-22 13:11:24 -0700975}
976
Romain Guybd6b79b2010-06-26 00:13:53 -0700977void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700978 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) {
979 drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend,
Romain Guy6820ac82010-09-15 18:11:50 -0700980 &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
981 GL_TRIANGLE_STRIP, gMeshCount);
Romain Guyf7f93552010-07-08 19:17:03 -0700982}
983
984void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700985 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
Romain Guy6820ac82010-09-15 18:11:50 -0700986 GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
Romain Guyf607bdc2010-09-10 19:20:06 -0700987 bool swapSrcDst, bool ignoreTransform) {
Romain Guy86942302010-09-12 13:02:16 -0700988 clearLayerRegions();
989
Romain Guy889f8d12010-07-29 14:37:42 -0700990 ProgramDescription description;
991 description.hasTexture = true;
Romain Guydb1938e2010-08-02 18:50:22 -0700992 if (mColorFilter) {
993 mColorFilter->describe(description, mExtensions);
994 }
Romain Guy889f8d12010-07-29 14:37:42 -0700995
Romain Guybd6b79b2010-06-26 00:13:53 -0700996 mModelView.loadTranslate(left, top, 0.0f);
997 mModelView.scale(right - left, bottom - top, 1.0f);
998
Romain Guyf607bdc2010-09-10 19:20:06 -0700999 chooseBlending(blend || alpha < 1.0f, mode, description, swapSrcDst);
Romain Guya5aed0d2010-09-09 14:42:43 -07001000
Romain Guyfb8b7632010-08-23 21:05:08 -07001001 useProgram(mCaches.programCache.get(description));
Romain Guyf607bdc2010-09-10 19:20:06 -07001002 if (!ignoreTransform) {
1003 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
1004 } else {
1005 mat4 m;
1006 mCaches.currentProgram->set(mOrthoMatrix, mModelView, m);
1007 }
Romain Guybd6b79b2010-06-26 00:13:53 -07001008
Romain Guy889f8d12010-07-29 14:37:42 -07001009 // Texture
Romain Guy06f96e22010-07-30 19:18:16 -07001010 bindTexture(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0);
Romain Guyfb8b7632010-08-23 21:05:08 -07001011 glUniform1i(mCaches.currentProgram->getUniform("sampler"), 0);
Romain Guyc1396e92010-06-30 17:56:19 -07001012
Romain Guya9794742010-07-13 11:37:54 -07001013 // Always premultiplied
Romain Guyfb8b7632010-08-23 21:05:08 -07001014 glUniform4f(mCaches.currentProgram->color, alpha, alpha, alpha, alpha);
Romain Guybd6b79b2010-06-26 00:13:53 -07001015
Romain Guy889f8d12010-07-29 14:37:42 -07001016 // Mesh
Romain Guyfb8b7632010-08-23 21:05:08 -07001017 int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
Romain Guy889f8d12010-07-29 14:37:42 -07001018 glEnableVertexAttribArray(texCoordsSlot);
Romain Guyfb8b7632010-08-23 21:05:08 -07001019 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guyac670c02010-07-27 17:39:27 -07001020 gMeshStride, vertices);
Romain Guy889f8d12010-07-29 14:37:42 -07001021 glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE, gMeshStride, texCoords);
Romain Guybd6b79b2010-06-26 00:13:53 -07001022
Romain Guydb1938e2010-08-02 18:50:22 -07001023 // Color filter
1024 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001025 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guydb1938e2010-08-02 18:50:22 -07001026 }
1027
Romain Guy6820ac82010-09-15 18:11:50 -07001028 glDrawArrays(drawMode, 0, elementsCount);
Romain Guy889f8d12010-07-29 14:37:42 -07001029 glDisableVertexAttribArray(texCoordsSlot);
Romain Guy82ba8142010-07-09 13:25:56 -07001030}
1031
Romain Guya5aed0d2010-09-09 14:42:43 -07001032void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode,
Romain Guyf607bdc2010-09-10 19:20:06 -07001033 ProgramDescription& description, bool swapSrcDst) {
Romain Guy82ba8142010-07-09 13:25:56 -07001034 blend = blend || mode != SkXfermode::kSrcOver_Mode;
1035 if (blend) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001036 if (mode < SkXfermode::kPlus_Mode) {
1037 if (!mCaches.blend) {
1038 glEnable(GL_BLEND);
1039 }
Romain Guy82ba8142010-07-09 13:25:56 -07001040
Romain Guyf607bdc2010-09-10 19:20:06 -07001041 GLenum sourceMode = swapSrcDst ? gBlendsSwap[mode].src : gBlends[mode].src;
1042 GLenum destMode = swapSrcDst ? gBlendsSwap[mode].dst : gBlends[mode].dst;
Romain Guy82ba8142010-07-09 13:25:56 -07001043
Romain Guya5aed0d2010-09-09 14:42:43 -07001044 if (sourceMode != mCaches.lastSrcMode || destMode != mCaches.lastDstMode) {
1045 glBlendFunc(sourceMode, destMode);
1046 mCaches.lastSrcMode = sourceMode;
1047 mCaches.lastDstMode = destMode;
1048 }
1049 } else {
1050 // These blend modes are not supported by OpenGL directly and have
1051 // to be implemented using shaders. Since the shader will perform
1052 // the blending, turn blending off here
1053 if (mExtensions.hasFramebufferFetch()) {
1054 description.framebufferMode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -07001055 description.swapSrcDst = swapSrcDst;
Romain Guya5aed0d2010-09-09 14:42:43 -07001056 }
1057
1058 if (mCaches.blend) {
1059 glDisable(GL_BLEND);
1060 }
1061 blend = false;
Romain Guy82ba8142010-07-09 13:25:56 -07001062 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001063 } else if (mCaches.blend) {
Romain Guy82ba8142010-07-09 13:25:56 -07001064 glDisable(GL_BLEND);
1065 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001066 mCaches.blend = blend;
Romain Guybd6b79b2010-06-26 00:13:53 -07001067}
1068
Romain Guy889f8d12010-07-29 14:37:42 -07001069bool OpenGLRenderer::useProgram(Program* program) {
Romain Guyd27977d2010-07-14 19:18:51 -07001070 if (!program->isInUse()) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001071 if (mCaches.currentProgram != NULL) mCaches.currentProgram->remove();
Romain Guyd27977d2010-07-14 19:18:51 -07001072 program->use();
Romain Guyfb8b7632010-08-23 21:05:08 -07001073 mCaches.currentProgram = program;
Romain Guy6926c722010-07-12 20:20:03 -07001074 return false;
Romain Guy260e1022010-07-12 14:41:06 -07001075 }
Romain Guy6926c722010-07-12 20:20:03 -07001076 return true;
Romain Guy260e1022010-07-12 14:41:06 -07001077}
1078
Romain Guy026c5e162010-06-28 17:12:22 -07001079void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
Romain Guyac670c02010-07-27 17:39:27 -07001080 TextureVertex* v = &mMeshVertices[0];
Romain Guy82ba8142010-07-09 13:25:56 -07001081 TextureVertex::setUV(v++, u1, v1);
1082 TextureVertex::setUV(v++, u2, v1);
1083 TextureVertex::setUV(v++, u1, v2);
1084 TextureVertex::setUV(v++, u2, v2);
Romain Guy8ba548f2010-06-30 19:21:21 -07001085}
1086
1087void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
1088 if (paint) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001089 if (!mExtensions.hasFramebufferFetch()) {
1090 const bool isMode = SkXfermode::IsMode(paint->getXfermode(), mode);
1091 if (!isMode) {
1092 // Assume SRC_OVER
1093 *mode = SkXfermode::kSrcOver_Mode;
1094 }
1095 } else {
1096 *mode = getXfermode(paint->getXfermode());
Romain Guy8ba548f2010-06-30 19:21:21 -07001097 }
1098
1099 // Skia draws using the color's alpha channel if < 255
1100 // Otherwise, it uses the paint's alpha
1101 int color = paint->getColor();
1102 *alpha = (color >> 24) & 0xFF;
1103 if (*alpha == 255) {
1104 *alpha = paint->getAlpha();
1105 }
1106 } else {
1107 *mode = SkXfermode::kSrcOver_Mode;
1108 *alpha = 255;
1109 }
Romain Guy026c5e162010-06-28 17:12:22 -07001110}
1111
Romain Guya5aed0d2010-09-09 14:42:43 -07001112SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
1113 if (mode == NULL) {
1114 return SkXfermode::kSrcOver_Mode;
1115 }
1116 return mode->fMode;
1117}
1118
Romain Guy889f8d12010-07-29 14:37:42 -07001119void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit) {
1120 glActiveTexture(gTextureUnits[textureUnit]);
Romain Guyae5575b2010-07-29 18:48:04 -07001121 glBindTexture(GL_TEXTURE_2D, texture);
Romain Guya1db5742010-07-20 13:09:13 -07001122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
1123 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
1124}
1125
Romain Guy9d5316e2010-06-24 19:30:36 -07001126}; // namespace uirenderer
Romain Guye4d01122010-06-16 18:44:05 -07001127}; // namespace android