blob: d6c00534d6551e90719a3240f5300c202e8f3d10 [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 Guydda570202010-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 Guybf434112010-09-16 14:40:17 -0700356 bounds.snapToPixelBoundaries();
357
Romain Guyb025b9c2010-09-16 14:16:48 -0700358 if (bounds.isEmpty() || bounds.getWidth() > mMaxTextureSize ||
359 bounds.getHeight() > mMaxTextureSize) {
360 return false;
361 }
Romain Guyf18fd992010-07-08 11:45:51 -0700362
Romain Guy8411f332010-09-13 17:27:57 -0700363 LayerSize size(bounds.getWidth(), bounds.getHeight());
Romain Guyf607bdc2010-09-10 19:20:06 -0700364 Layer* layer = mCaches.layerCache.get(size);
Romain Guydda570202010-07-06 11:39:32 -0700365 if (!layer) {
Romain Guyf18fd992010-07-08 11:45:51 -0700366 return false;
Romain Guybd6b79b2010-06-26 00:13:53 -0700367 }
368
Romain Guydda570202010-07-06 11:39:32 -0700369 layer->mode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -0700370 layer->alpha = alpha;
Romain Guy8aef54f2010-09-01 15:13:49 -0700371 layer->layer.set(bounds);
Romain Guydda570202010-07-06 11:39:32 -0700372
Romain Guy8fb95422010-08-17 18:38:51 -0700373 // Save the layer in the snapshot
374 snapshot->flags |= Snapshot::kFlagIsLayer;
Romain Guydda570202010-07-06 11:39:32 -0700375 snapshot->layer = layer;
Romain Guy1d83e192010-08-17 11:37:00 -0700376
Romain Guyf607bdc2010-09-10 19:20:06 -0700377 // Copy the framebuffer into the layer
378 glBindTexture(GL_TEXTURE_2D, layer->texture);
379 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.left, mHeight - bounds.bottom,
380 bounds.getWidth(), bounds.getHeight(), 0);
381
Romain Guyf607bdc2010-09-10 19:20:06 -0700382 if (flags & SkCanvas::kClipToLayer_SaveFlag) {
Romain Guy86942302010-09-12 13:02:16 -0700383 if (mSnapshot->clipTransformed(bounds)) setScissorFromClip();
Romain Guyf607bdc2010-09-10 19:20:06 -0700384 }
385
Romain Guy86942302010-09-12 13:02:16 -0700386 // Enqueue the buffer coordinates to clear the corresponding region later
387 mLayers.push(new Rect(bounds));
Romain Guyf86ef572010-07-01 11:05:42 -0700388
Romain Guyd55a8612010-06-28 17:42:46 -0700389 return true;
Romain Guybd6b79b2010-06-26 00:13:53 -0700390}
391
Romain Guy1c740bc2010-09-13 18:00:09 -0700392/**
393 * Read the documentation of createLayer() before doing anything in this method.
394 */
Romain Guy1d83e192010-08-17 11:37:00 -0700395void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) {
396 if (!current->layer) {
397 LOGE("Attempting to compose a layer that does not exist");
398 return;
399 }
400
Romain Guy1d83e192010-08-17 11:37:00 -0700401 // Restore the clip from the previous snapshot
Romain Guy8aef54f2010-09-01 15:13:49 -0700402 const Rect& clip = *previous->clipRect;
Romain Guyf607bdc2010-09-10 19:20:06 -0700403 glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy1d83e192010-08-17 11:37:00 -0700404
405 Layer* layer = current->layer;
406 const Rect& rect = layer->layer;
407
Romain Guyf607bdc2010-09-10 19:20:06 -0700408 if (layer->alpha < 255) {
Romain Guyf607bdc2010-09-10 19:20:06 -0700409 drawColorRect(rect.left, rect.top, rect.right, rect.bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -0700410 layer->alpha << 24, SkXfermode::kDstIn_Mode, true);
Romain Guyf607bdc2010-09-10 19:20:06 -0700411 }
412
413 // Layers are already drawn with a top-left origin, don't flip the texture
Romain Guy8b55f372010-08-18 17:10:07 -0700414 resetDrawTextureTexCoords(0.0f, 1.0f, 1.0f, 0.0f);
415
Romain Guyf607bdc2010-09-10 19:20:06 -0700416 drawTextureMesh(rect.left, rect.top, rect.right, rect.bottom, layer->texture,
417 1.0f, layer->mode, layer->blend, &mMeshVertices[0].position[0],
Romain Guy6820ac82010-09-15 18:11:50 -0700418 &mMeshVertices[0].texture[0], GL_TRIANGLE_STRIP, gMeshCount, true, true);
Romain Guy1d83e192010-08-17 11:37:00 -0700419
Romain Guy8b55f372010-08-18 17:10:07 -0700420 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
421
Romain Guy1d83e192010-08-17 11:37:00 -0700422 LayerSize size(rect.getWidth(), rect.getHeight());
423 // Failing to add the layer to the cache should happen only if the
424 // layer is too large
Romain Guyfb8b7632010-08-23 21:05:08 -0700425 if (!mCaches.layerCache.put(size, layer)) {
Romain Guy1d83e192010-08-17 11:37:00 -0700426 LAYER_LOGD("Deleting layer");
427
Romain Guy1d83e192010-08-17 11:37:00 -0700428 glDeleteTextures(1, &layer->texture);
429
430 delete layer;
431 }
432}
433
Romain Guy86942302010-09-12 13:02:16 -0700434void OpenGLRenderer::clearLayerRegions() {
435 if (mLayers.size() == 0) return;
436
437 for (uint32_t i = 0; i < mLayers.size(); i++) {
438 Rect* bounds = mLayers.itemAt(i);
439
440 // Clear the framebuffer where the layer will draw
441 glScissor(bounds->left, mHeight - bounds->bottom,
442 bounds->getWidth(), bounds->getHeight());
443 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
444 glClear(GL_COLOR_BUFFER_BIT);
445
446 delete bounds;
447 }
448 mLayers.clear();
449
450 // Restore the clip
451 setScissorFromClip();
452}
453
Romain Guybd6b79b2010-06-26 00:13:53 -0700454///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -0700455// Transforms
456///////////////////////////////////////////////////////////////////////////////
457
458void OpenGLRenderer::translate(float dx, float dy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700459 mSnapshot->transform->translate(dx, dy, 0.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700460}
461
462void OpenGLRenderer::rotate(float degrees) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700463 mSnapshot->transform->rotate(degrees, 0.0f, 0.0f, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700464}
465
466void OpenGLRenderer::scale(float sx, float sy) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700467 mSnapshot->transform->scale(sx, sy, 1.0f);
Romain Guyf6a11b82010-06-23 17:47:49 -0700468}
469
470void OpenGLRenderer::setMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700471 mSnapshot->transform->load(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700472}
473
474void OpenGLRenderer::getMatrix(SkMatrix* matrix) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700475 mSnapshot->transform->copyTo(*matrix);
Romain Guyf6a11b82010-06-23 17:47:49 -0700476}
477
478void OpenGLRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700479 mat4 m(*matrix);
Romain Guy8aef54f2010-09-01 15:13:49 -0700480 mSnapshot->transform->multiply(m);
Romain Guyf6a11b82010-06-23 17:47:49 -0700481}
482
483///////////////////////////////////////////////////////////////////////////////
484// Clipping
485///////////////////////////////////////////////////////////////////////////////
486
Romain Guybb9524b2010-06-22 18:56:38 -0700487void OpenGLRenderer::setScissorFromClip() {
Romain Guy8aef54f2010-09-01 15:13:49 -0700488 const Rect& clip = *mSnapshot->clipRect;
Romain Guyf607bdc2010-09-10 19:20:06 -0700489 glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight());
Romain Guy9d5316e2010-06-24 19:30:36 -0700490}
491
492const Rect& OpenGLRenderer::getClipBounds() {
Romain Guy079ba2c2010-07-16 14:12:24 -0700493 return mSnapshot->getLocalClip();
Romain Guybb9524b2010-06-22 18:56:38 -0700494}
495
Romain Guyc7d53492010-06-25 13:41:57 -0700496bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
Romain Guy1d83e192010-08-17 11:37:00 -0700497 Rect r(left, top, right, bottom);
Romain Guy8aef54f2010-09-01 15:13:49 -0700498 mSnapshot->transform->mapRect(r);
499 return !mSnapshot->clipRect->intersects(r);
Romain Guyc7d53492010-06-25 13:41:57 -0700500}
501
Romain Guy079ba2c2010-07-16 14:12:24 -0700502bool OpenGLRenderer::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) {
503 bool clipped = mSnapshot->clip(left, top, right, bottom, op);
Romain Guy7ae7ac42010-06-25 13:46:18 -0700504 if (clipped) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700505 setScissorFromClip();
506 }
Romain Guy8aef54f2010-09-01 15:13:49 -0700507 return !mSnapshot->clipRect->isEmpty();
Romain Guye4d01122010-06-16 18:44:05 -0700508}
509
Romain Guyf6a11b82010-06-23 17:47:49 -0700510///////////////////////////////////////////////////////////////////////////////
511// Drawing
512///////////////////////////////////////////////////////////////////////////////
513
Romain Guyc1396e92010-06-30 17:56:19 -0700514void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700515 const float right = left + bitmap->width();
516 const float bottom = top + bitmap->height();
517
518 if (quickReject(left, top, right, bottom)) {
519 return;
520 }
521
Romain Guy61c8c9c2010-08-09 20:48:09 -0700522 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700523 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b92010-08-07 23:46:15 -0700524 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700525 const AutoTexture autoCleanup(texture);
526
Romain Guy6926c722010-07-12 20:20:03 -0700527 drawTextureRect(left, top, right, bottom, texture, paint);
Romain Guyce0537b2010-06-29 21:05:21 -0700528}
529
Romain Guyf86ef572010-07-01 11:05:42 -0700530void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint) {
531 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
532 const mat4 transform(*matrix);
533 transform.mapRect(r);
534
Romain Guy6926c722010-07-12 20:20:03 -0700535 if (quickReject(r.left, r.top, r.right, r.bottom)) {
536 return;
537 }
538
Romain Guy61c8c9c2010-08-09 20:48:09 -0700539 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700540 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b92010-08-07 23:46:15 -0700541 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700542 const AutoTexture autoCleanup(texture);
543
Romain Guy82ba8142010-07-09 13:25:56 -0700544 drawTextureRect(r.left, r.top, r.right, r.bottom, texture, paint);
Romain Guyf86ef572010-07-01 11:05:42 -0700545}
546
Romain Guy8ba548f2010-06-30 19:21:21 -0700547void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
548 float srcLeft, float srcTop, float srcRight, float srcBottom,
549 float dstLeft, float dstTop, float dstRight, float dstBottom,
Romain Guyf86ef572010-07-01 11:05:42 -0700550 const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700551 if (quickReject(dstLeft, dstTop, dstRight, dstBottom)) {
552 return;
553 }
554
Romain Guy61c8c9c2010-08-09 20:48:09 -0700555 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700556 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b92010-08-07 23:46:15 -0700557 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700558 const AutoTexture autoCleanup(texture);
Romain Guy8ba548f2010-06-30 19:21:21 -0700559
Romain Guy8ba548f2010-06-30 19:21:21 -0700560 const float width = texture->width;
561 const float height = texture->height;
562
563 const float u1 = srcLeft / width;
564 const float v1 = srcTop / height;
565 const float u2 = srcRight / width;
566 const float v2 = srcBottom / height;
567
568 resetDrawTextureTexCoords(u1, v1, u2, v2);
569
Romain Guy82ba8142010-07-09 13:25:56 -0700570 drawTextureRect(dstLeft, dstTop, dstRight, dstBottom, texture, paint);
Romain Guy8ba548f2010-06-30 19:21:21 -0700571
572 resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
573}
574
Romain Guydeba7852010-07-07 17:54:48 -0700575void OpenGLRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
576 float left, float top, float right, float bottom, const SkPaint* paint) {
Romain Guy6926c722010-07-12 20:20:03 -0700577 if (quickReject(left, top, right, bottom)) {
578 return;
579 }
580
Romain Guy61c8c9c2010-08-09 20:48:09 -0700581 glActiveTexture(GL_TEXTURE0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700582 const Texture* texture = mCaches.textureCache.get(bitmap);
Romain Guy9cccc2b92010-08-07 23:46:15 -0700583 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700584 const AutoTexture autoCleanup(texture);
Romain Guyf7f93552010-07-08 19:17:03 -0700585
586 int alpha;
587 SkXfermode::Mode mode;
588 getAlphaAndMode(paint, &alpha, &mode);
589
Romain Guyfb8b7632010-08-23 21:05:08 -0700590 Patch* mesh = mCaches.patchCache.get(patch);
Romain Guyfb5e23c2010-07-09 13:52:56 -0700591 mesh->updateVertices(bitmap, left, top, right, bottom,
592 &patch->xDivs[0], &patch->yDivs[0], patch->numXDivs, patch->numYDivs);
Romain Guyf7f93552010-07-08 19:17:03 -0700593
594 // Specify right and bottom as +1.0f from left/top to prevent scaling since the
595 // patch mesh already defines the final size
Romain Guya9794742010-07-13 11:37:54 -0700596 drawTextureMesh(left, top, left + 1.0f, top + 1.0f, texture->id, alpha / 255.0f,
597 mode, texture->blend, &mesh->vertices[0].position[0],
Romain Guy6820ac82010-09-15 18:11:50 -0700598 &mesh->vertices[0].texture[0], GL_TRIANGLES, mesh->verticesCount);
Romain Guyf7f93552010-07-08 19:17:03 -0700599}
600
Romain Guy85bf02f2010-06-22 13:11:24 -0700601void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700602 const Rect& clip = *mSnapshot->clipRect;
Romain Guy3d58c032010-07-14 16:34:53 -0700603 drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
Romain Guyc7d53492010-06-25 13:41:57 -0700604}
Romain Guy9d5316e2010-06-24 19:30:36 -0700605
Romain Guybd6b79b2010-06-26 00:13:53 -0700606void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, const SkPaint* p) {
Romain Guy6926c722010-07-12 20:20:03 -0700607 if (quickReject(left, top, right, bottom)) {
608 return;
609 }
610
Romain Guy026c5e162010-06-28 17:12:22 -0700611 SkXfermode::Mode mode;
Romain Guya5aed0d2010-09-09 14:42:43 -0700612 if (!mExtensions.hasFramebufferFetch()) {
613 const bool isMode = SkXfermode::IsMode(p->getXfermode(), &mode);
614 if (!isMode) {
615 // Assume SRC_OVER
616 mode = SkXfermode::kSrcOver_Mode;
617 }
618 } else {
619 mode = getXfermode(p->getXfermode());
Romain Guy026c5e162010-06-28 17:12:22 -0700620 }
621
622 // Skia draws using the color's alpha channel if < 255
623 // Otherwise, it uses the paint's alpha
624 int color = p->getColor();
Romain Guyd27977d2010-07-14 19:18:51 -0700625 if (((color >> 24) & 0xff) == 255) {
Romain Guy026c5e162010-06-28 17:12:22 -0700626 color |= p->getAlpha() << 24;
627 }
628
629 drawColorRect(left, top, right, bottom, color, mode);
Romain Guyc7d53492010-06-25 13:41:57 -0700630}
Romain Guy9d5316e2010-06-24 19:30:36 -0700631
Romain Guye8e62a42010-07-23 18:55:21 -0700632void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
633 float x, float y, SkPaint* paint) {
Romain Guyf607bdc2010-09-10 19:20:06 -0700634 if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
Romain Guye8e62a42010-07-23 18:55:21 -0700635 return;
636 }
Romain Guyf607bdc2010-09-10 19:20:06 -0700637 paint->setAntiAlias(true);
Romain Guye8e62a42010-07-23 18:55:21 -0700638
Romain Guya674ab72010-08-10 17:26:42 -0700639 float length = -1.0f;
Romain Guye8e62a42010-07-23 18:55:21 -0700640 switch (paint->getTextAlign()) {
641 case SkPaint::kCenter_Align:
642 length = paint->measureText(text, bytesCount);
643 x -= length / 2.0f;
644 break;
645 case SkPaint::kRight_Align:
646 length = paint->measureText(text, bytesCount);
647 x -= length;
648 break;
649 default:
650 break;
651 }
652
Romain Guy694b5192010-07-21 21:33:20 -0700653 int alpha;
654 SkXfermode::Mode mode;
655 getAlphaAndMode(paint, &alpha, &mode);
656
Romain Guy2542d192010-08-18 11:47:12 -0700657 uint32_t color = paint->getColor();
658 const GLfloat a = alpha / 255.0f;
659 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
660 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
661 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
662
Romain Guyb45c0c92010-08-26 20:35:23 -0700663 FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
664 fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
Romain Guyfb8b7632010-08-23 21:05:08 -0700665 paint->getTextSize());
Romain Guy1e45aae2010-08-13 19:39:53 -0700666 if (mHasShadow) {
667 glActiveTexture(gTextureUnits[0]);
Romain Guyb45c0c92010-08-26 20:35:23 -0700668 mCaches.dropShadowCache.setFontRenderer(fontRenderer);
Romain Guyfb8b7632010-08-23 21:05:08 -0700669 const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
Romain Guy1e45aae2010-08-13 19:39:53 -0700670 count, mShadowRadius);
671 const AutoTexture autoCleanup(shadow);
Romain Guy0a417492010-08-16 20:26:20 -0700672
Romain Guy2542d192010-08-18 11:47:12 -0700673 setupShadow(shadow, x, y, mode, a);
Romain Guy0a417492010-08-16 20:26:20 -0700674
675 // Draw the mesh
676 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyfb8b7632010-08-23 21:05:08 -0700677 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guy1e45aae2010-08-13 19:39:53 -0700678 }
679
Romain Guy06f96e22010-07-30 19:18:16 -0700680 GLuint textureUnit = 0;
Romain Guydb1938e2010-08-02 18:50:22 -0700681 glActiveTexture(gTextureUnits[textureUnit]);
Romain Guy06f96e22010-07-30 19:18:16 -0700682
Romain Guyb45c0c92010-08-26 20:35:23 -0700683 setupTextureAlpha8(fontRenderer.getTexture(), 0, 0, textureUnit, x, y, r, g, b, a,
Romain Guy0a417492010-08-16 20:26:20 -0700684 mode, false, true);
Romain Guy06f96e22010-07-30 19:18:16 -0700685
Romain Guy09147fb2010-07-22 13:08:20 -0700686 const Rect& clip = mSnapshot->getLocalClip();
Romain Guy86942302010-09-12 13:02:16 -0700687 clearLayerRegions();
Romain Guyb45c0c92010-08-26 20:35:23 -0700688 fontRenderer.renderText(paint, &clip, text, 0, bytesCount, count, x, y);
Romain Guy694b5192010-07-21 21:33:20 -0700689
690 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Romain Guyfb8b7632010-08-23 21:05:08 -0700691 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guya674ab72010-08-10 17:26:42 -0700692
Romain Guy0a417492010-08-16 20:26:20 -0700693 drawTextDecorations(text, bytesCount, length, x, y, paint);
Romain Guy694b5192010-07-21 21:33:20 -0700694}
695
Romain Guy7fbcc042010-08-04 15:40:07 -0700696void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
697 GLuint textureUnit = 0;
698 glActiveTexture(gTextureUnits[textureUnit]);
699
Romain Guyfb8b7632010-08-23 21:05:08 -0700700 const PathTexture* texture = mCaches.pathCache.get(path, paint);
Romain Guy9cccc2b92010-08-07 23:46:15 -0700701 if (!texture) return;
Romain Guy22158e12010-08-06 11:18:34 -0700702 const AutoTexture autoCleanup(texture);
Romain Guy7fbcc042010-08-04 15:40:07 -0700703
Romain Guy8b55f372010-08-18 17:10:07 -0700704 const float x = texture->left - texture->offset;
705 const float y = texture->top - texture->offset;
706
707 if (quickReject(x, y, x + texture->width, y + texture->height)) {
708 return;
709 }
710
Romain Guy7fbcc042010-08-04 15:40:07 -0700711 int alpha;
712 SkXfermode::Mode mode;
713 getAlphaAndMode(paint, &alpha, &mode);
714
715 uint32_t color = paint->getColor();
716 const GLfloat a = alpha / 255.0f;
717 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
718 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
719 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
720
Romain Guy0a417492010-08-16 20:26:20 -0700721 setupTextureAlpha8(texture, textureUnit, x, y, r, g, b, a, mode, true, true);
722
Romain Guy86942302010-09-12 13:02:16 -0700723 clearLayerRegions();
724
Romain Guy0a417492010-08-16 20:26:20 -0700725 // Draw the mesh
726 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyfb8b7632010-08-23 21:05:08 -0700727 glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
Romain Guy7fbcc042010-08-04 15:40:07 -0700728}
729
Romain Guy6926c722010-07-12 20:20:03 -0700730///////////////////////////////////////////////////////////////////////////////
Romain Guyd27977d2010-07-14 19:18:51 -0700731// Shaders
732///////////////////////////////////////////////////////////////////////////////
733
734void OpenGLRenderer::resetShader() {
Romain Guy06f96e22010-07-30 19:18:16 -0700735 mShader = NULL;
Romain Guyd27977d2010-07-14 19:18:51 -0700736}
737
Romain Guy06f96e22010-07-30 19:18:16 -0700738void OpenGLRenderer::setupShader(SkiaShader* shader) {
739 mShader = shader;
740 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700741 mShader->set(&mCaches.textureCache, &mCaches.gradientCache);
Romain Guy06f96e22010-07-30 19:18:16 -0700742 }
Romain Guy7fac2e12010-07-16 17:10:13 -0700743}
744
Romain Guyd27977d2010-07-14 19:18:51 -0700745///////////////////////////////////////////////////////////////////////////////
Romain Guydb1938e2010-08-02 18:50:22 -0700746// Color filters
747///////////////////////////////////////////////////////////////////////////////
748
749void OpenGLRenderer::resetColorFilter() {
750 mColorFilter = NULL;
751}
752
753void OpenGLRenderer::setupColorFilter(SkiaColorFilter* filter) {
754 mColorFilter = filter;
755}
756
757///////////////////////////////////////////////////////////////////////////////
Romain Guy1e45aae2010-08-13 19:39:53 -0700758// Drop shadow
759///////////////////////////////////////////////////////////////////////////////
760
761void OpenGLRenderer::resetShadow() {
762 mHasShadow = false;
763}
764
765void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
766 mHasShadow = true;
767 mShadowRadius = radius;
768 mShadowDx = dx;
769 mShadowDy = dy;
770 mShadowColor = color;
771}
772
773///////////////////////////////////////////////////////////////////////////////
Romain Guy6926c722010-07-12 20:20:03 -0700774// Drawing implementation
775///////////////////////////////////////////////////////////////////////////////
776
Romain Guy0a417492010-08-16 20:26:20 -0700777void OpenGLRenderer::setupShadow(const ShadowTexture* texture, float x, float y,
Romain Guy2542d192010-08-18 11:47:12 -0700778 SkXfermode::Mode mode, float alpha) {
Romain Guy0a417492010-08-16 20:26:20 -0700779 const float sx = x - texture->left + mShadowDx;
780 const float sy = y - texture->top + mShadowDy;
781
Romain Guy2542d192010-08-18 11:47:12 -0700782 const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
783 const GLfloat a = shadowAlpha < 255 ? shadowAlpha / 255.0f : alpha;
Romain Guy0a417492010-08-16 20:26:20 -0700784 const GLfloat r = a * ((mShadowColor >> 16) & 0xFF) / 255.0f;
785 const GLfloat g = a * ((mShadowColor >> 8) & 0xFF) / 255.0f;
786 const GLfloat b = a * ((mShadowColor ) & 0xFF) / 255.0f;
787
788 GLuint textureUnit = 0;
789 setupTextureAlpha8(texture, textureUnit, sx, sy, r, g, b, a, mode, true, false);
790}
791
792void OpenGLRenderer::setupTextureAlpha8(const Texture* texture, GLuint& textureUnit,
793 float x, float y, float r, float g, float b, float a, SkXfermode::Mode mode,
794 bool transforms, bool applyFilters) {
795 setupTextureAlpha8(texture->id, texture->width, texture->height, textureUnit,
796 x, y, r, g, b, a, mode, transforms, applyFilters);
797}
798
799void OpenGLRenderer::setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
800 GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
801 SkXfermode::Mode mode, bool transforms, bool applyFilters) {
802 // Describe the required shaders
803 ProgramDescription description;
804 description.hasTexture = true;
805 description.hasAlpha8Texture = true;
806
807 if (applyFilters) {
808 if (mShader) {
809 mShader->describe(description, mExtensions);
810 }
811 if (mColorFilter) {
812 mColorFilter->describe(description, mExtensions);
813 }
814 }
815
Romain Guya5aed0d2010-09-09 14:42:43 -0700816 // Setup the blending mode
817 chooseBlending(true, mode, description);
818
Romain Guy0a417492010-08-16 20:26:20 -0700819 // Build and use the appropriate shader
Romain Guyfb8b7632010-08-23 21:05:08 -0700820 useProgram(mCaches.programCache.get(description));
Romain Guy0a417492010-08-16 20:26:20 -0700821
Romain Guy0a417492010-08-16 20:26:20 -0700822 bindTexture(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, textureUnit);
Romain Guyfb8b7632010-08-23 21:05:08 -0700823 glUniform1i(mCaches.currentProgram->getUniform("sampler"), textureUnit);
Romain Guy0a417492010-08-16 20:26:20 -0700824
Romain Guyfb8b7632010-08-23 21:05:08 -0700825 int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
Romain Guy0a417492010-08-16 20:26:20 -0700826 glEnableVertexAttribArray(texCoordsSlot);
827
828 // Setup attributes
Romain Guyfb8b7632010-08-23 21:05:08 -0700829 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guy0a417492010-08-16 20:26:20 -0700830 gMeshStride, &mMeshVertices[0].position[0]);
831 glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE,
832 gMeshStride, &mMeshVertices[0].texture[0]);
833
834 // Setup uniforms
835 if (transforms) {
836 mModelView.loadTranslate(x, y, 0.0f);
837 mModelView.scale(width, height, 1.0f);
838 } else {
839 mModelView.loadIdentity();
840 }
Romain Guy8aef54f2010-09-01 15:13:49 -0700841 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
Romain Guyfb8b7632010-08-23 21:05:08 -0700842 glUniform4f(mCaches.currentProgram->color, r, g, b, a);
Romain Guy0a417492010-08-16 20:26:20 -0700843
844 textureUnit++;
845 if (applyFilters) {
846 // Setup attributes and uniforms required by the shaders
847 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700848 mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &textureUnit);
Romain Guy0a417492010-08-16 20:26:20 -0700849 }
850 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700851 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guy0a417492010-08-16 20:26:20 -0700852 }
853 }
854}
855
Romain Guyf607bdc2010-09-10 19:20:06 -0700856// Same values used by Skia
Romain Guy0a417492010-08-16 20:26:20 -0700857#define kStdStrikeThru_Offset (-6.0f / 21.0f)
858#define kStdUnderline_Offset (1.0f / 9.0f)
859#define kStdUnderline_Thickness (1.0f / 18.0f)
860
861void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float length,
862 float x, float y, SkPaint* paint) {
863 // Handle underline and strike-through
864 uint32_t flags = paint->getFlags();
865 if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
866 float underlineWidth = length;
867 // If length is > 0.0f, we already measured the text for the text alignment
868 if (length <= 0.0f) {
869 underlineWidth = paint->measureText(text, bytesCount);
870 }
871
872 float offsetX = 0;
873 switch (paint->getTextAlign()) {
874 case SkPaint::kCenter_Align:
875 offsetX = underlineWidth * 0.5f;
876 break;
877 case SkPaint::kRight_Align:
878 offsetX = underlineWidth;
879 break;
880 default:
881 break;
882 }
883
884 if (underlineWidth > 0.0f) {
885 float textSize = paint->getTextSize();
886 float height = textSize * kStdUnderline_Thickness;
887
888 float left = x - offsetX;
889 float top = 0.0f;
890 float right = left + underlineWidth;
891 float bottom = 0.0f;
892
893 if (flags & SkPaint::kUnderlineText_Flag) {
894 top = y + textSize * kStdUnderline_Offset;
895 bottom = top + height;
896 drawRect(left, top, right, bottom, paint);
897 }
898
899 if (flags & SkPaint::kStrikeThruText_Flag) {
900 top = y + textSize * kStdStrikeThru_Offset;
901 bottom = top + height;
902 drawRect(left, top, right, bottom, paint);
903 }
904 }
905 }
906}
907
Romain Guy026c5e162010-06-28 17:12:22 -0700908void OpenGLRenderer::drawColorRect(float left, float top, float right, float bottom,
Romain Guy1c740bc2010-09-13 18:00:09 -0700909 int color, SkXfermode::Mode mode, bool ignoreTransform) {
Romain Guy86942302010-09-12 13:02:16 -0700910 clearLayerRegions();
911
Romain Guyd27977d2010-07-14 19:18:51 -0700912 // If a shader is set, preserve only the alpha
Romain Guy06f96e22010-07-30 19:18:16 -0700913 if (mShader) {
Romain Guyd27977d2010-07-14 19:18:51 -0700914 color |= 0x00ffffff;
915 }
916
917 // Render using pre-multiplied alpha
Romain Guy026c5e162010-06-28 17:12:22 -0700918 const int alpha = (color >> 24) & 0xFF;
Romain Guyd27977d2010-07-14 19:18:51 -0700919 const GLfloat a = alpha / 255.0f;
Romain Guyc0ac1932010-07-19 18:43:02 -0700920 const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
921 const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
922 const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
923
Romain Guy06f96e22010-07-30 19:18:16 -0700924 GLuint textureUnit = 0;
Romain Guy9d5316e2010-06-24 19:30:36 -0700925
Romain Guy06f96e22010-07-30 19:18:16 -0700926 // Describe the required shaders
Romain Guy889f8d12010-07-29 14:37:42 -0700927 ProgramDescription description;
Romain Guy06f96e22010-07-30 19:18:16 -0700928 if (mShader) {
929 mShader->describe(description, mExtensions);
Romain Guy6926c722010-07-12 20:20:03 -0700930 }
Romain Guydb1938e2010-08-02 18:50:22 -0700931 if (mColorFilter) {
932 mColorFilter->describe(description, mExtensions);
933 }
Romain Guyd27977d2010-07-14 19:18:51 -0700934
Romain Guy1c740bc2010-09-13 18:00:09 -0700935 // Setup the blending mode
936 chooseBlending(alpha < 255 || (mShader && mShader->blend()), mode, description);
Romain Guya5aed0d2010-09-09 14:42:43 -0700937
Romain Guy06f96e22010-07-30 19:18:16 -0700938 // Build and use the appropriate shader
Romain Guyfb8b7632010-08-23 21:05:08 -0700939 useProgram(mCaches.programCache.get(description));
Romain Guy06f96e22010-07-30 19:18:16 -0700940
941 // Setup attributes
Romain Guyfb8b7632010-08-23 21:05:08 -0700942 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guy06f96e22010-07-30 19:18:16 -0700943 gMeshStride, &mMeshVertices[0].position[0]);
944
945 // Setup uniforms
946 mModelView.loadTranslate(left, top, 0.0f);
947 mModelView.scale(right - left, bottom - top, 1.0f);
Romain Guyd27977d2010-07-14 19:18:51 -0700948 if (!ignoreTransform) {
Romain Guy8aef54f2010-09-01 15:13:49 -0700949 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
Romain Guyd27977d2010-07-14 19:18:51 -0700950 } else {
951 mat4 identity;
Romain Guyfb8b7632010-08-23 21:05:08 -0700952 mCaches.currentProgram->set(mOrthoMatrix, mModelView, identity);
Romain Guyd27977d2010-07-14 19:18:51 -0700953 }
Romain Guyfb8b7632010-08-23 21:05:08 -0700954 glUniform4f(mCaches.currentProgram->color, r, g, b, a);
Romain Guy9d5316e2010-06-24 19:30:36 -0700955
Romain Guy06f96e22010-07-30 19:18:16 -0700956 // Setup attributes and uniforms required by the shaders
957 if (mShader) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700958 mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &textureUnit);
Romain Guyc0ac1932010-07-19 18:43:02 -0700959 }
Romain Guydb1938e2010-08-02 18:50:22 -0700960 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -0700961 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guydb1938e2010-08-02 18:50:22 -0700962 }
Romain Guyc0ac1932010-07-19 18:43:02 -0700963
Romain Guy06f96e22010-07-30 19:18:16 -0700964 // Draw the mesh
Romain Guy889f8d12010-07-29 14:37:42 -0700965 glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
Romain Guyd27977d2010-07-14 19:18:51 -0700966}
967
Romain Guy82ba8142010-07-09 13:25:56 -0700968void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700969 const Texture* texture, const SkPaint* paint) {
Romain Guy82ba8142010-07-09 13:25:56 -0700970 int alpha;
971 SkXfermode::Mode mode;
972 getAlphaAndMode(paint, &alpha, &mode);
973
Romain Guy6820ac82010-09-15 18:11:50 -0700974 drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
975 texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
976 GL_TRIANGLE_STRIP, gMeshCount);
Romain Guy85bf02f2010-06-22 13:11:24 -0700977}
978
Romain Guybd6b79b2010-06-26 00:13:53 -0700979void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700980 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend) {
981 drawTextureMesh(left, top, right, bottom, texture, alpha, mode, blend,
Romain Guy6820ac82010-09-15 18:11:50 -0700982 &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
983 GL_TRIANGLE_STRIP, gMeshCount);
Romain Guyf7f93552010-07-08 19:17:03 -0700984}
985
986void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float bottom,
Romain Guya9794742010-07-13 11:37:54 -0700987 GLuint texture, float alpha, SkXfermode::Mode mode, bool blend,
Romain Guy6820ac82010-09-15 18:11:50 -0700988 GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
Romain Guyf607bdc2010-09-10 19:20:06 -0700989 bool swapSrcDst, bool ignoreTransform) {
Romain Guy86942302010-09-12 13:02:16 -0700990 clearLayerRegions();
991
Romain Guy889f8d12010-07-29 14:37:42 -0700992 ProgramDescription description;
993 description.hasTexture = true;
Romain Guydb1938e2010-08-02 18:50:22 -0700994 if (mColorFilter) {
995 mColorFilter->describe(description, mExtensions);
996 }
Romain Guy889f8d12010-07-29 14:37:42 -0700997
Romain Guybd6b79b2010-06-26 00:13:53 -0700998 mModelView.loadTranslate(left, top, 0.0f);
999 mModelView.scale(right - left, bottom - top, 1.0f);
1000
Romain Guyf607bdc2010-09-10 19:20:06 -07001001 chooseBlending(blend || alpha < 1.0f, mode, description, swapSrcDst);
Romain Guya5aed0d2010-09-09 14:42:43 -07001002
Romain Guyfb8b7632010-08-23 21:05:08 -07001003 useProgram(mCaches.programCache.get(description));
Romain Guyf607bdc2010-09-10 19:20:06 -07001004 if (!ignoreTransform) {
1005 mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
1006 } else {
1007 mat4 m;
1008 mCaches.currentProgram->set(mOrthoMatrix, mModelView, m);
1009 }
Romain Guybd6b79b2010-06-26 00:13:53 -07001010
Romain Guy889f8d12010-07-29 14:37:42 -07001011 // Texture
Romain Guy06f96e22010-07-30 19:18:16 -07001012 bindTexture(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0);
Romain Guyfb8b7632010-08-23 21:05:08 -07001013 glUniform1i(mCaches.currentProgram->getUniform("sampler"), 0);
Romain Guyc1396e92010-06-30 17:56:19 -07001014
Romain Guya9794742010-07-13 11:37:54 -07001015 // Always premultiplied
Romain Guyfb8b7632010-08-23 21:05:08 -07001016 glUniform4f(mCaches.currentProgram->color, alpha, alpha, alpha, alpha);
Romain Guybd6b79b2010-06-26 00:13:53 -07001017
Romain Guy889f8d12010-07-29 14:37:42 -07001018 // Mesh
Romain Guyfb8b7632010-08-23 21:05:08 -07001019 int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
Romain Guy889f8d12010-07-29 14:37:42 -07001020 glEnableVertexAttribArray(texCoordsSlot);
Romain Guyfb8b7632010-08-23 21:05:08 -07001021 glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
Romain Guyac670c02010-07-27 17:39:27 -07001022 gMeshStride, vertices);
Romain Guy889f8d12010-07-29 14:37:42 -07001023 glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE, gMeshStride, texCoords);
Romain Guybd6b79b2010-06-26 00:13:53 -07001024
Romain Guydb1938e2010-08-02 18:50:22 -07001025 // Color filter
1026 if (mColorFilter) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001027 mColorFilter->setupProgram(mCaches.currentProgram);
Romain Guydb1938e2010-08-02 18:50:22 -07001028 }
1029
Romain Guy6820ac82010-09-15 18:11:50 -07001030 glDrawArrays(drawMode, 0, elementsCount);
Romain Guy889f8d12010-07-29 14:37:42 -07001031 glDisableVertexAttribArray(texCoordsSlot);
Romain Guy82ba8142010-07-09 13:25:56 -07001032}
1033
Romain Guya5aed0d2010-09-09 14:42:43 -07001034void OpenGLRenderer::chooseBlending(bool blend, SkXfermode::Mode mode,
Romain Guyf607bdc2010-09-10 19:20:06 -07001035 ProgramDescription& description, bool swapSrcDst) {
Romain Guy82ba8142010-07-09 13:25:56 -07001036 blend = blend || mode != SkXfermode::kSrcOver_Mode;
1037 if (blend) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001038 if (mode < SkXfermode::kPlus_Mode) {
1039 if (!mCaches.blend) {
1040 glEnable(GL_BLEND);
1041 }
Romain Guy82ba8142010-07-09 13:25:56 -07001042
Romain Guyf607bdc2010-09-10 19:20:06 -07001043 GLenum sourceMode = swapSrcDst ? gBlendsSwap[mode].src : gBlends[mode].src;
1044 GLenum destMode = swapSrcDst ? gBlendsSwap[mode].dst : gBlends[mode].dst;
Romain Guy82ba8142010-07-09 13:25:56 -07001045
Romain Guya5aed0d2010-09-09 14:42:43 -07001046 if (sourceMode != mCaches.lastSrcMode || destMode != mCaches.lastDstMode) {
1047 glBlendFunc(sourceMode, destMode);
1048 mCaches.lastSrcMode = sourceMode;
1049 mCaches.lastDstMode = destMode;
1050 }
1051 } else {
1052 // These blend modes are not supported by OpenGL directly and have
1053 // to be implemented using shaders. Since the shader will perform
1054 // the blending, turn blending off here
1055 if (mExtensions.hasFramebufferFetch()) {
1056 description.framebufferMode = mode;
Romain Guyf607bdc2010-09-10 19:20:06 -07001057 description.swapSrcDst = swapSrcDst;
Romain Guya5aed0d2010-09-09 14:42:43 -07001058 }
1059
1060 if (mCaches.blend) {
1061 glDisable(GL_BLEND);
1062 }
1063 blend = false;
Romain Guy82ba8142010-07-09 13:25:56 -07001064 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001065 } else if (mCaches.blend) {
Romain Guy82ba8142010-07-09 13:25:56 -07001066 glDisable(GL_BLEND);
1067 }
Romain Guyfb8b7632010-08-23 21:05:08 -07001068 mCaches.blend = blend;
Romain Guybd6b79b2010-06-26 00:13:53 -07001069}
1070
Romain Guy889f8d12010-07-29 14:37:42 -07001071bool OpenGLRenderer::useProgram(Program* program) {
Romain Guyd27977d2010-07-14 19:18:51 -07001072 if (!program->isInUse()) {
Romain Guyfb8b7632010-08-23 21:05:08 -07001073 if (mCaches.currentProgram != NULL) mCaches.currentProgram->remove();
Romain Guyd27977d2010-07-14 19:18:51 -07001074 program->use();
Romain Guyfb8b7632010-08-23 21:05:08 -07001075 mCaches.currentProgram = program;
Romain Guy6926c722010-07-12 20:20:03 -07001076 return false;
Romain Guy260e1022010-07-12 14:41:06 -07001077 }
Romain Guy6926c722010-07-12 20:20:03 -07001078 return true;
Romain Guy260e1022010-07-12 14:41:06 -07001079}
1080
Romain Guy026c5e162010-06-28 17:12:22 -07001081void OpenGLRenderer::resetDrawTextureTexCoords(float u1, float v1, float u2, float v2) {
Romain Guyac670c02010-07-27 17:39:27 -07001082 TextureVertex* v = &mMeshVertices[0];
Romain Guy82ba8142010-07-09 13:25:56 -07001083 TextureVertex::setUV(v++, u1, v1);
1084 TextureVertex::setUV(v++, u2, v1);
1085 TextureVertex::setUV(v++, u1, v2);
1086 TextureVertex::setUV(v++, u2, v2);
Romain Guy8ba548f2010-06-30 19:21:21 -07001087}
1088
1089void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
1090 if (paint) {
Romain Guya5aed0d2010-09-09 14:42:43 -07001091 if (!mExtensions.hasFramebufferFetch()) {
1092 const bool isMode = SkXfermode::IsMode(paint->getXfermode(), mode);
1093 if (!isMode) {
1094 // Assume SRC_OVER
1095 *mode = SkXfermode::kSrcOver_Mode;
1096 }
1097 } else {
1098 *mode = getXfermode(paint->getXfermode());
Romain Guy8ba548f2010-06-30 19:21:21 -07001099 }
1100
1101 // Skia draws using the color's alpha channel if < 255
1102 // Otherwise, it uses the paint's alpha
1103 int color = paint->getColor();
1104 *alpha = (color >> 24) & 0xFF;
1105 if (*alpha == 255) {
1106 *alpha = paint->getAlpha();
1107 }
1108 } else {
1109 *mode = SkXfermode::kSrcOver_Mode;
1110 *alpha = 255;
1111 }
Romain Guy026c5e162010-06-28 17:12:22 -07001112}
1113
Romain Guya5aed0d2010-09-09 14:42:43 -07001114SkXfermode::Mode OpenGLRenderer::getXfermode(SkXfermode* mode) {
1115 if (mode == NULL) {
1116 return SkXfermode::kSrcOver_Mode;
1117 }
1118 return mode->fMode;
1119}
1120
Romain Guy889f8d12010-07-29 14:37:42 -07001121void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit) {
1122 glActiveTexture(gTextureUnits[textureUnit]);
Romain Guyae5575b2010-07-29 18:48:04 -07001123 glBindTexture(GL_TEXTURE_2D, texture);
Romain Guya1db5742010-07-20 13:09:13 -07001124 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
1125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
1126}
1127
Romain Guy9d5316e2010-06-24 19:30:36 -07001128}; // namespace uirenderer
Romain Guye4d01122010-06-16 18:44:05 -07001129}; // namespace android