blob: f0c9ce4748906946f22de5a9f1250ae332779e60 [file] [log] [blame]
Romain Guy4aa90572010-09-26 18:40:37 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
Romain Guyd5a85fb2012-03-13 11:18:20 -070019#include <SkCamera.h>
Chet Haase9c1e23b2011-03-24 10:51:31 -070020
Romain Guy65549432012-03-26 16:45:05 -070021#include <private/hwui/DrawGlInfo.h>
22
Chet Haase9c1e23b2011-03-24 10:51:31 -070023#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070024#include "DisplayListRenderer.h"
Chet Haase9c1e23b2011-03-24 10:51:31 -070025#include "Caches.h"
Romain Guy13631f32012-01-30 17:41:55 -080026
Romain Guy4aa90572010-09-26 18:40:37 -070027namespace android {
28namespace uirenderer {
29
30///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070031// Display list
32///////////////////////////////////////////////////////////////////////////////
33
Romain Guyffac7fc2011-01-13 17:21:49 -080034const char* DisplayList::OP_NAMES[] = {
Romain Guyffac7fc2011-01-13 17:21:49 -080035 "Save",
36 "Restore",
37 "RestoreToCount",
38 "SaveLayer",
39 "SaveLayerAlpha",
40 "Translate",
41 "Rotate",
42 "Scale",
Romain Guy4cf6e2f2011-01-23 11:35:13 -080043 "Skew",
Romain Guyffac7fc2011-01-13 17:21:49 -080044 "SetMatrix",
45 "ConcatMatrix",
46 "ClipRect",
Romain Guy735738c2012-12-03 12:34:51 -080047 "ClipPath",
48 "ClipRegion",
Romain Guyffac7fc2011-01-13 17:21:49 -080049 "DrawDisplayList",
50 "DrawLayer",
51 "DrawBitmap",
52 "DrawBitmapMatrix",
53 "DrawBitmapRect",
Romain Guye651cc62012-05-14 19:44:40 -070054 "DrawBitmapData",
Romain Guy5a7b4662011-01-20 19:09:30 -080055 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -080056 "DrawPatch",
57 "DrawColor",
58 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -080059 "DrawRoundRect",
60 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -080061 "DrawOval",
Romain Guy8b2f5262011-01-23 16:15:02 -080062 "DrawArc",
Romain Guyffac7fc2011-01-13 17:21:49 -080063 "DrawPath",
64 "DrawLines",
Romain Guyed6fcb02011-03-21 13:11:28 -070065 "DrawPoints",
Romain Guy325740f2012-02-24 16:48:34 -080066 "DrawTextOnPath",
Romain Guyeb9a5362012-01-17 17:39:26 -080067 "DrawPosText",
Romain Guyc2525952012-07-27 16:41:22 -070068 "DrawText",
Romain Guy672433d2013-01-04 19:05:13 -080069 "DrawRects",
Romain Guyffac7fc2011-01-13 17:21:49 -080070 "ResetShader",
71 "SetupShader",
72 "ResetColorFilter",
73 "SetupColorFilter",
74 "ResetShadow",
Chet Haasedaf98e92011-01-10 14:10:36 -080075 "SetupShadow",
Romain Guy5ff9df62012-01-23 17:09:05 -080076 "ResetPaintFilter",
77 "SetupPaintFilter",
Chet Haasedaf98e92011-01-10 14:10:36 -080078 "DrawGLFunction"
Romain Guyffac7fc2011-01-13 17:21:49 -080079};
80
Chet Haase9c1e23b2011-03-24 10:51:31 -070081void DisplayList::outputLogBuffer(int fd) {
82 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
83 if (logBuffer.isEmpty()) {
84 return;
85 }
Romain Guy65b345f2011-07-27 18:51:50 -070086
Chet Haase9c1e23b2011-03-24 10:51:31 -070087 FILE *file = fdopen(fd, "a");
Romain Guy65b345f2011-07-27 18:51:50 -070088
Chet Haase9c1e23b2011-03-24 10:51:31 -070089 fprintf(file, "\nRecent DisplayList operations\n");
90 logBuffer.outputCommands(file, OP_NAMES);
Romain Guy65b345f2011-07-27 18:51:50 -070091
92 String8 cachesLog;
93 Caches::getInstance().dumpMemoryUsage(cachesLog);
94 fprintf(file, "\nCaches:\n%s", cachesLog.string());
95 fprintf(file, "\n");
96
Chet Haase9c1e23b2011-03-24 10:51:31 -070097 fflush(file);
98}
99
Chet Haase491189f2012-03-13 11:42:34 -0700100DisplayList::DisplayList(const DisplayListRenderer& recorder) :
Chet Haase9420abd2012-03-29 16:28:32 -0700101 mTransformMatrix(NULL), mTransformCamera(NULL), mTransformMatrix3D(NULL),
102 mStaticMatrix(NULL), mAnimationMatrix(NULL) {
Chet Haase491189f2012-03-13 11:42:34 -0700103
Chet Haase5977baa2011-01-05 18:01:22 -0800104 initFromDisplayListRenderer(recorder);
105}
106
107DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -0800108 clearResources();
109}
110
Romain Guybb0acdf2012-03-05 13:44:35 -0800111void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {
112 if (displayList) {
113 DISPLAY_LIST_LOGD("Deferring display list destruction");
114 Caches::getInstance().deleteDisplayListDeferred(displayList);
115 }
116}
117
Chet Haased63cbd12011-02-03 16:32:46 -0800118void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -0800119 sk_free((void*) mReader.base());
Romain Guy034de6b2012-09-27 19:01:55 -0700120 mReader.setMemory(NULL, 0);
Chet Haase5977baa2011-01-05 18:01:22 -0800121
Chet Haase1271e2c2012-04-20 09:54:27 -0700122 delete mTransformMatrix;
123 delete mTransformCamera;
124 delete mTransformMatrix3D;
125 delete mStaticMatrix;
126 delete mAnimationMatrix;
Romain Guy58ecc202012-09-07 11:58:36 -0700127
Chet Haase1271e2c2012-04-20 09:54:27 -0700128 mTransformMatrix = NULL;
129 mTransformCamera = NULL;
130 mTransformMatrix3D = NULL;
131 mStaticMatrix = NULL;
132 mAnimationMatrix = NULL;
Chet Haasea1cff502012-02-21 13:43:44 -0800133
Chet Haase5977baa2011-01-05 18:01:22 -0800134 Caches& caches = Caches::getInstance();
Romain Guy54c1a642012-09-27 17:55:46 -0700135 caches.unregisterFunctors(mFunctorCount);
Romain Guy58ecc202012-09-07 11:58:36 -0700136 caches.resourceCache.lock();
Chet Haase5977baa2011-01-05 18:01:22 -0800137
138 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -0700139 caches.resourceCache.decrementRefcountLocked(mBitmapResources.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800140 }
Chet Haase5977baa2011-01-05 18:01:22 -0800141
Romain Guy49c5fc02012-05-15 11:10:01 -0700142 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
143 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
Romain Guy58ecc202012-09-07 11:58:36 -0700144 caches.resourceCache.decrementRefcountLocked(bitmap);
145 caches.resourceCache.destructorLocked(bitmap);
Romain Guy49c5fc02012-05-15 11:10:01 -0700146 }
Romain Guy49c5fc02012-05-15 11:10:01 -0700147
Romain Guyd586ad92011-06-22 16:14:36 -0700148 for (size_t i = 0; i < mFilterResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -0700149 caches.resourceCache.decrementRefcountLocked(mFilterResources.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700150 }
Romain Guyd586ad92011-06-22 16:14:36 -0700151
Romain Guy24c00212011-01-14 15:31:00 -0800152 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -0700153 caches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
154 caches.resourceCache.destructorLocked(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800155 }
Romain Guy58ecc202012-09-07 11:58:36 -0700156
157 for (size_t i = 0; i < mSourcePaths.size(); i++) {
158 caches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
159 }
160
Chet Haase603f6de2012-09-14 15:31:25 -0700161 for (size_t i = 0; i < mLayers.size(); i++) {
162 caches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
163 }
164
Romain Guy58ecc202012-09-07 11:58:36 -0700165 caches.resourceCache.unlock();
Chet Haase5977baa2011-01-05 18:01:22 -0800166
167 for (size_t i = 0; i < mPaints.size(); i++) {
168 delete mPaints.itemAt(i);
169 }
Chet Haase5977baa2011-01-05 18:01:22 -0800170
Romain Guy735738c2012-12-03 12:34:51 -0800171 for (size_t i = 0; i < mRegions.size(); i++) {
172 delete mRegions.itemAt(i);
173 }
174
Romain Guy2fc941e2011-02-03 15:06:05 -0800175 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700176 SkPath* path = mPaths.itemAt(i);
177 caches.pathCache.remove(path);
178 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800179 }
Chet Haased34dd712012-05-02 18:50:34 -0700180
Chet Haase5977baa2011-01-05 18:01:22 -0800181 for (size_t i = 0; i < mMatrices.size(); i++) {
182 delete mMatrices.itemAt(i);
183 }
Romain Guy58ecc202012-09-07 11:58:36 -0700184
185 mBitmapResources.clear();
186 mOwnedBitmapResources.clear();
187 mFilterResources.clear();
188 mShaders.clear();
189 mSourcePaths.clear();
190 mPaints.clear();
Romain Guy735738c2012-12-03 12:34:51 -0800191 mRegions.clear();
Romain Guy58ecc202012-09-07 11:58:36 -0700192 mPaths.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800193 mMatrices.clear();
Chet Haase603f6de2012-09-14 15:31:25 -0700194 mLayers.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800195}
196
Chet Haase6a2d17f2012-09-30 12:14:13 -0700197void DisplayList::reset() {
198 clearResources();
199 init();
200}
201
Chet Haased63cbd12011-02-03 16:32:46 -0800202void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700203
Chet Haased63cbd12011-02-03 16:32:46 -0800204 if (reusing) {
205 // re-using display list - clear out previous allocations
206 clearResources();
207 }
Romain Guy034de6b2012-09-27 19:01:55 -0700208
209 init();
Chet Haased63cbd12011-02-03 16:32:46 -0800210
Chet Haase6a2d17f2012-09-30 12:14:13 -0700211 const SkWriter32& writer = recorder.writeStream();
Romain Guy034de6b2012-09-27 19:01:55 -0700212 if (writer.size() == 0) {
213 return;
214 }
215
Romain Guy65b345f2011-07-27 18:51:50 -0700216 mSize = writer.size();
217 void* buffer = sk_malloc_throw(mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700218 writer.flatten(buffer);
Romain Guy65b345f2011-07-27 18:51:50 -0700219 mReader.setMemory(buffer, mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700220
Romain Guy54c1a642012-09-27 17:55:46 -0700221 mFunctorCount = recorder.getFunctorCount();
222
Chet Haase5c13d892010-10-08 08:37:55 -0700223 Caches& caches = Caches::getInstance();
Romain Guy54c1a642012-09-27 17:55:46 -0700224 caches.registerFunctors(mFunctorCount);
Romain Guy58ecc202012-09-07 11:58:36 -0700225 caches.resourceCache.lock();
Romain Guyb051e892010-09-28 19:09:36 -0700226
Romain Guy49c5fc02012-05-15 11:10:01 -0700227 const Vector<SkBitmap*>& bitmapResources = recorder.getBitmapResources();
Chet Haase5c13d892010-10-08 08:37:55 -0700228 for (size_t i = 0; i < bitmapResources.size(); i++) {
229 SkBitmap* resource = bitmapResources.itemAt(i);
230 mBitmapResources.add(resource);
Romain Guy58ecc202012-09-07 11:58:36 -0700231 caches.resourceCache.incrementRefcountLocked(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700232 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700233
Romain Guy49c5fc02012-05-15 11:10:01 -0700234 const Vector<SkBitmap*> &ownedBitmapResources = recorder.getOwnedBitmapResources();
235 for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
236 SkBitmap* resource = ownedBitmapResources.itemAt(i);
237 mOwnedBitmapResources.add(resource);
Romain Guy58ecc202012-09-07 11:58:36 -0700238 caches.resourceCache.incrementRefcountLocked(resource);
Romain Guy49c5fc02012-05-15 11:10:01 -0700239 }
240
241 const Vector<SkiaColorFilter*>& filterResources = recorder.getFilterResources();
Romain Guyd586ad92011-06-22 16:14:36 -0700242 for (size_t i = 0; i < filterResources.size(); i++) {
243 SkiaColorFilter* resource = filterResources.itemAt(i);
244 mFilterResources.add(resource);
Romain Guy58ecc202012-09-07 11:58:36 -0700245 caches.resourceCache.incrementRefcountLocked(resource);
Romain Guyd586ad92011-06-22 16:14:36 -0700246 }
247
Romain Guy49c5fc02012-05-15 11:10:01 -0700248 const Vector<SkiaShader*>& shaders = recorder.getShaders();
Romain Guy24c00212011-01-14 15:31:00 -0800249 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700250 SkiaShader* resource = shaders.itemAt(i);
251 mShaders.add(resource);
Romain Guy58ecc202012-09-07 11:58:36 -0700252 caches.resourceCache.incrementRefcountLocked(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700253 }
254
Romain Guy58ecc202012-09-07 11:58:36 -0700255 const SortedVector<SkPath*>& sourcePaths = recorder.getSourcePaths();
256 for (size_t i = 0; i < sourcePaths.size(); i++) {
257 mSourcePaths.add(sourcePaths.itemAt(i));
258 caches.resourceCache.incrementRefcountLocked(sourcePaths.itemAt(i));
259 }
260
Chet Haase603f6de2012-09-14 15:31:25 -0700261 const Vector<Layer*>& layers = recorder.getLayers();
262 for (size_t i = 0; i < layers.size(); i++) {
263 mLayers.add(layers.itemAt(i));
264 caches.resourceCache.incrementRefcountLocked(layers.itemAt(i));
265 }
266
Romain Guy58ecc202012-09-07 11:58:36 -0700267 caches.resourceCache.unlock();
268
Romain Guy735738c2012-12-03 12:34:51 -0800269 mPaints.appendVector(recorder.getPaints());
270 mRegions.appendVector(recorder.getRegions());
271 mPaths.appendVector(recorder.getPaths());
272 mMatrices.appendVector(recorder.getMatrices());
Romain Guyb051e892010-09-28 19:09:36 -0700273}
274
Romain Guyb051e892010-09-28 19:09:36 -0700275void DisplayList::init() {
Romain Guy65b345f2011-07-27 18:51:50 -0700276 mSize = 0;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700277 mIsRenderable = true;
Romain Guy034de6b2012-09-27 19:01:55 -0700278 mFunctorCount = 0;
Chet Haase6a2d17f2012-09-30 12:14:13 -0700279 mLeft = 0;
280 mTop = 0;
281 mRight = 0;
282 mBottom = 0;
283 mClipChildren = true;
284 mAlpha = 1;
285 mMultipliedAlpha = 255;
286 mHasOverlappingRendering = true;
287 mTranslationX = 0;
288 mTranslationY = 0;
289 mRotation = 0;
290 mRotationX = 0;
291 mRotationY= 0;
292 mScaleX = 1;
293 mScaleY = 1;
294 mPivotX = 0;
295 mPivotY = 0;
296 mCameraDistance = 0;
297 mMatrixDirty = false;
298 mMatrixFlags = 0;
299 mPrevWidth = -1;
300 mPrevHeight = -1;
301 mWidth = 0;
302 mHeight = 0;
303 mPivotExplicitlySet = false;
304 mCaching = false;
Romain Guy65b345f2011-07-27 18:51:50 -0700305}
306
307size_t DisplayList::getSize() {
308 return mSize;
Romain Guyb051e892010-09-28 19:09:36 -0700309}
310
Chet Haaseed30fd82011-04-22 16:18:45 -0700311/**
312 * This function is a simplified version of replay(), where we simply retrieve and log the
313 * display list. This function should remain in sync with the replay() function.
314 */
315void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
316 TextContainer text;
317
318 uint32_t count = (level + 1) * 2;
319 char indent[count + 1];
320 for (uint32_t i = 0; i < count; i++) {
321 indent[i] = ' ';
322 }
323 indent[count] = '\0';
Romain Guyddf74372012-05-22 14:07:07 -0700324 ALOGD("%sStart display list (%p, %s, render=%d)", (char*) indent + 2, this,
325 mName.string(), isRenderable());
Chet Haaseed30fd82011-04-22 16:18:45 -0700326
Chet Haase1271e2c2012-04-20 09:54:27 -0700327 ALOGD("%s%s %d", indent, "Save", SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
Chet Haaseed30fd82011-04-22 16:18:45 -0700328 int saveCount = renderer.getSaveCount() - 1;
329
Chet Haasea1cff502012-02-21 13:43:44 -0800330 outputViewProperties(renderer, (char*) indent);
Chet Haaseed30fd82011-04-22 16:18:45 -0700331 mReader.rewind();
332
333 while (!mReader.eof()) {
334 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800335 if (op & OP_MAY_BE_SKIPPED_MASK) {
336 int skip = mReader.readInt();
337 ALOGD("%sSkip %d", (char*) indent, skip);
338 op &= ~OP_MAY_BE_SKIPPED_MASK;
Chet Haasea1cff502012-02-21 13:43:44 -0800339 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700340
341 switch (op) {
342 case DrawGLFunction: {
343 Functor *functor = (Functor *) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000344 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Chet Haaseed30fd82011-04-22 16:18:45 -0700345 }
346 break;
347 case Save: {
348 int rendererNum = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000349 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
Chet Haaseed30fd82011-04-22 16:18:45 -0700350 }
351 break;
352 case Restore: {
Steve Block5baa3a62011-12-20 16:23:08 +0000353 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700354 }
355 break;
356 case RestoreToCount: {
357 int restoreCount = saveCount + getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000358 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
Chet Haaseed30fd82011-04-22 16:18:45 -0700359 }
360 break;
361 case SaveLayer: {
362 float f1 = getFloat();
363 float f2 = getFloat();
364 float f3 = getFloat();
365 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800366 SkPaint* paint = getPaint(renderer);
Chet Haaseed30fd82011-04-22 16:18:45 -0700367 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000368 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800369 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
Chet Haaseed30fd82011-04-22 16:18:45 -0700370 }
371 break;
372 case SaveLayerAlpha: {
373 float f1 = getFloat();
374 float f2 = getFloat();
375 float f3 = getFloat();
376 float f4 = getFloat();
377 int alpha = getInt();
378 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000379 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800380 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
Chet Haaseed30fd82011-04-22 16:18:45 -0700381 }
382 break;
383 case Translate: {
384 float f1 = getFloat();
385 float f2 = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000386 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700387 }
388 break;
389 case Rotate: {
390 float rotation = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000391 ALOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
Chet Haaseed30fd82011-04-22 16:18:45 -0700392 }
393 break;
394 case Scale: {
395 float sx = getFloat();
396 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000397 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700398 }
399 break;
400 case Skew: {
401 float sx = getFloat();
402 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000403 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700404 }
405 break;
406 case SetMatrix: {
407 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000408 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700409 }
410 break;
411 case ConcatMatrix: {
412 SkMatrix* matrix = getMatrix();
Chet Haasea1cff502012-02-21 13:43:44 -0800413 ALOGD("%s%s new concat %p: [%f, %f, %f] [%f, %f, %f] [%f, %f, %f]",
414 (char*) indent, OP_NAMES[op], matrix, matrix->get(0), matrix->get(1),
415 matrix->get(2), matrix->get(3), matrix->get(4), matrix->get(5),
416 matrix->get(6), matrix->get(7), matrix->get(8));
Chet Haaseed30fd82011-04-22 16:18:45 -0700417 }
418 break;
419 case ClipRect: {
420 float f1 = getFloat();
421 float f2 = getFloat();
422 float f3 = getFloat();
423 float f4 = getFloat();
424 int regionOp = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000425 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800426 f1, f2, f3, f4, regionOp);
Chet Haaseed30fd82011-04-22 16:18:45 -0700427 }
428 break;
Romain Guy735738c2012-12-03 12:34:51 -0800429 case ClipPath: {
430 SkPath* path = getPath();
431 int regionOp = getInt();
432 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], regionOp);
433 }
434 break;
435 case ClipRegion: {
436 SkRegion* region = getRegion();
437 int regionOp = getInt();
438 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], regionOp);
439 }
440 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700441 case DrawDisplayList: {
442 DisplayList* displayList = getDisplayList();
Romain Guy33f6beb2012-02-16 19:24:51 -0800443 int32_t flags = getInt();
444 ALOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
Chet Haase1271e2c2012-04-20 09:54:27 -0700445 displayList, mWidth, mHeight, flags, level + 1);
Chet Haaseed30fd82011-04-22 16:18:45 -0700446 renderer.outputDisplayList(displayList, level + 1);
447 }
448 break;
449 case DrawLayer: {
450 Layer* layer = (Layer*) getInt();
451 float x = getFloat();
452 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800453 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000454 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800455 layer, x, y, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700456 }
457 break;
458 case DrawBitmap: {
459 SkBitmap* bitmap = getBitmap();
460 float x = getFloat();
461 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800462 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000463 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800464 bitmap, x, y, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700465 }
466 break;
467 case DrawBitmapMatrix: {
468 SkBitmap* bitmap = getBitmap();
469 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800470 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000471 ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800472 bitmap, matrix, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700473 }
474 break;
475 case DrawBitmapRect: {
476 SkBitmap* bitmap = getBitmap();
477 float f1 = getFloat();
478 float f2 = getFloat();
479 float f3 = getFloat();
480 float f4 = getFloat();
481 float f5 = getFloat();
482 float f6 = getFloat();
483 float f7 = getFloat();
484 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800485 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000486 ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800487 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700488 }
489 break;
Romain Guye651cc62012-05-14 19:44:40 -0700490 case DrawBitmapData: {
491 SkBitmap* bitmap = getBitmapData();
492 float x = getFloat();
493 float y = getFloat();
494 SkPaint* paint = getPaint(renderer);
495 ALOGD("%s%s %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], x, y, paint);
496 }
497 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700498 case DrawBitmapMesh: {
499 int verticesCount = 0;
500 uint32_t colorsCount = 0;
501 SkBitmap* bitmap = getBitmap();
502 uint32_t meshWidth = getInt();
503 uint32_t meshHeight = getInt();
504 float* vertices = getFloats(verticesCount);
505 bool hasColors = getInt();
506 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800507 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000508 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700509 }
510 break;
511 case DrawPatch: {
512 int32_t* xDivs = NULL;
513 int32_t* yDivs = NULL;
514 uint32_t* colors = NULL;
515 uint32_t xDivsCount = 0;
516 uint32_t yDivsCount = 0;
517 int8_t numColors = 0;
518 SkBitmap* bitmap = getBitmap();
519 xDivs = getInts(xDivsCount);
520 yDivs = getInts(yDivsCount);
521 colors = getUInts(numColors);
Romain Guya62f1722011-10-19 17:06:19 -0700522 float left = getFloat();
523 float top = getFloat();
524 float right = getFloat();
525 float bottom = getFloat();
Romain Guybe6f9dc2012-07-16 12:41:17 -0700526 int alpha = getInt();
527 SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000528 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
Romain Guya62f1722011-10-19 17:06:19 -0700529 left, top, right, bottom);
Chet Haaseed30fd82011-04-22 16:18:45 -0700530 }
531 break;
532 case DrawColor: {
533 int color = getInt();
534 int xferMode = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000535 ALOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haaseed30fd82011-04-22 16:18:45 -0700536 }
537 break;
538 case DrawRect: {
539 float f1 = getFloat();
540 float f2 = getFloat();
541 float f3 = getFloat();
542 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800543 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000544 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800545 f1, f2, f3, f4, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700546 }
547 break;
548 case DrawRoundRect: {
549 float f1 = getFloat();
550 float f2 = getFloat();
551 float f3 = getFloat();
552 float f4 = getFloat();
553 float f5 = getFloat();
554 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800555 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000556 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800557 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700558 }
559 break;
560 case DrawCircle: {
561 float f1 = getFloat();
562 float f2 = getFloat();
563 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800564 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000565 ALOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800566 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700567 }
568 break;
569 case DrawOval: {
570 float f1 = getFloat();
571 float f2 = getFloat();
572 float f3 = getFloat();
573 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800574 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000575 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800576 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700577 }
578 break;
579 case DrawArc: {
580 float f1 = getFloat();
581 float f2 = getFloat();
582 float f3 = getFloat();
583 float f4 = getFloat();
584 float f5 = getFloat();
585 float f6 = getFloat();
586 int i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800587 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000588 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800589 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700590 }
591 break;
592 case DrawPath: {
593 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800594 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000595 ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700596 }
597 break;
598 case DrawLines: {
599 int count = 0;
600 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800601 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000602 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700603 }
604 break;
605 case DrawPoints: {
606 int count = 0;
607 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800608 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000609 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700610 }
611 break;
Romain Guy325740f2012-02-24 16:48:34 -0800612 case DrawTextOnPath: {
613 getText(&text);
614 int32_t count = getInt();
615 SkPath* path = getPath();
616 float hOffset = getFloat();
617 float vOffset = getFloat();
618 SkPaint* paint = getPaint(renderer);
619 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
620 text.text(), text.length(), count, paint);
621 }
622 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800623 case DrawPosText: {
624 getText(&text);
625 int count = getInt();
626 int positionsCount = 0;
627 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800628 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800629 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800630 text.text(), text.length(), count, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -0800631 }
Raph Levien996e57c2012-07-23 15:22:52 -0700632 break;
Romain Guyc2525952012-07-27 16:41:22 -0700633 case DrawText: {
Raph Levien996e57c2012-07-23 15:22:52 -0700634 getText(&text);
Romain Guy18edb812012-08-03 16:06:55 -0700635 int32_t count = getInt();
636 float x = getFloat();
637 float y = getFloat();
638 int32_t positionsCount = 0;
Raph Levien996e57c2012-07-23 15:22:52 -0700639 float* positions = getFloats(positionsCount);
640 SkPaint* paint = getPaint(renderer);
Romain Guy18edb812012-08-03 16:06:55 -0700641 float length = getFloat();
Raph Levien996e57c2012-07-23 15:22:52 -0700642 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
643 text.text(), text.length(), count, paint);
644 }
645 break;
Romain Guy672433d2013-01-04 19:05:13 -0800646 case DrawRects: {
647 int32_t count = 0;
648 float* rects = getFloats(count);
649 SkPaint* paint = getPaint(renderer);
650 ALOGD("%s%s %d, %p", (char*) indent, OP_NAMES[op], count / 4, paint);
651 }
652 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700653 case ResetShader: {
Steve Block5baa3a62011-12-20 16:23:08 +0000654 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700655 }
656 break;
657 case SetupShader: {
658 SkiaShader* shader = getShader();
Steve Block5baa3a62011-12-20 16:23:08 +0000659 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
Chet Haaseed30fd82011-04-22 16:18:45 -0700660 }
661 break;
662 case ResetColorFilter: {
Steve Block5baa3a62011-12-20 16:23:08 +0000663 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700664 }
665 break;
666 case SetupColorFilter: {
667 SkiaColorFilter *colorFilter = getColorFilter();
Steve Block5baa3a62011-12-20 16:23:08 +0000668 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
Chet Haaseed30fd82011-04-22 16:18:45 -0700669 }
670 break;
671 case ResetShadow: {
Steve Block5baa3a62011-12-20 16:23:08 +0000672 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700673 }
674 break;
675 case SetupShadow: {
676 float radius = getFloat();
677 float dx = getFloat();
678 float dy = getFloat();
679 int color = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000680 ALOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800681 radius, dx, dy, color);
Chet Haaseed30fd82011-04-22 16:18:45 -0700682 }
683 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800684 case ResetPaintFilter: {
685 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
686 }
687 break;
688 case SetupPaintFilter: {
689 int clearBits = getInt();
690 int setBits = getInt();
691 ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
692 }
693 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700694 default:
Steve Block5baa3a62011-12-20 16:23:08 +0000695 ALOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -0800696 (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700697 break;
698 }
699 }
Chet Haasea1cff502012-02-21 13:43:44 -0800700 ALOGD("%sDone (%p, %s)", (char*) indent + 2, this, mName.string());
Chet Haaseed30fd82011-04-22 16:18:45 -0700701}
702
Chet Haasea1cff502012-02-21 13:43:44 -0800703void DisplayList::updateMatrix() {
704 if (mMatrixDirty) {
705 if (!mTransformMatrix) {
706 mTransformMatrix = new SkMatrix();
707 }
708 if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) {
709 mTransformMatrix->reset();
710 } else {
711 if (!mPivotExplicitlySet) {
712 if (mWidth != mPrevWidth || mHeight != mPrevHeight) {
713 mPrevWidth = mWidth;
714 mPrevHeight = mHeight;
715 mPivotX = mPrevWidth / 2;
716 mPivotY = mPrevHeight / 2;
717 }
718 }
719 if ((mMatrixFlags & ROTATION_3D) == 0) {
720 mTransformMatrix->setTranslate(mTranslationX, mTranslationY);
721 mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY);
722 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
723 } else {
724 if (!mTransformCamera) {
725 mTransformCamera = new Sk3DView();
726 mTransformMatrix3D = new SkMatrix();
727 }
728 mTransformMatrix->reset();
729 mTransformCamera->save();
730 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
731 mTransformCamera->rotateX(mRotationX);
732 mTransformCamera->rotateY(mRotationY);
733 mTransformCamera->rotateZ(-mRotation);
734 mTransformCamera->getMatrix(mTransformMatrix3D);
735 mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY);
736 mTransformMatrix3D->postTranslate(mPivotX + mTranslationX,
737 mPivotY + mTranslationY);
738 mTransformMatrix->postConcat(*mTransformMatrix3D);
739 mTransformCamera->restore();
740 }
741 }
742 mMatrixDirty = false;
743 }
744}
745
746void DisplayList::outputViewProperties(OpenGLRenderer& renderer, char* indent) {
Chet Haase1271e2c2012-04-20 09:54:27 -0700747 updateMatrix();
748 if (mLeft != 0 || mTop != 0) {
749 ALOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
750 }
751 if (mStaticMatrix) {
752 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
753 indent, "ConcatMatrix (static)", mStaticMatrix,
754 mStaticMatrix->get(0), mStaticMatrix->get(1),
755 mStaticMatrix->get(2), mStaticMatrix->get(3),
756 mStaticMatrix->get(4), mStaticMatrix->get(5),
757 mStaticMatrix->get(6), mStaticMatrix->get(7),
758 mStaticMatrix->get(8));
759 }
760 if (mAnimationMatrix) {
761 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
762 indent, "ConcatMatrix (animation)", mAnimationMatrix,
763 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
764 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
765 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
766 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
767 mAnimationMatrix->get(8));
768 }
769 if (mMatrixFlags != 0) {
770 if (mMatrixFlags == TRANSLATION) {
771 ALOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
772 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700773 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700774 indent, "ConcatMatrix", mTransformMatrix,
775 mTransformMatrix->get(0), mTransformMatrix->get(1),
776 mTransformMatrix->get(2), mTransformMatrix->get(3),
777 mTransformMatrix->get(4), mTransformMatrix->get(5),
778 mTransformMatrix->get(6), mTransformMatrix->get(7),
779 mTransformMatrix->get(8));
Chet Haase9420abd2012-03-29 16:28:32 -0700780 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700781 }
782 if (mAlpha < 1 && !mCaching) {
Chet Haase3561d062012-10-23 12:54:51 -0700783 if (!mHasOverlappingRendering) {
784 ALOGD("%s%s %.2f", indent, "SetAlpha", mAlpha);
785 } else {
786 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
787 if (mClipChildren) {
788 flags |= SkCanvas::kClipToLayer_SaveFlag;
789 }
790 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
791 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
792 mMultipliedAlpha, flags);
Chet Haasea1cff502012-02-21 13:43:44 -0800793 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700794 }
795 if (mClipChildren) {
796 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
797 (float) mRight - mLeft, (float) mBottom - mTop);
Chet Haasea1cff502012-02-21 13:43:44 -0800798 }
799}
800
Chet Haase1271e2c2012-04-20 09:54:27 -0700801void DisplayList::setViewProperties(OpenGLRenderer& renderer, uint32_t level) {
Chet Haasea1cff502012-02-21 13:43:44 -0800802#if DEBUG_DISPLAY_LIST
803 uint32_t count = (level + 1) * 2;
804 char indent[count + 1];
805 for (uint32_t i = 0; i < count; i++) {
806 indent[i] = ' ';
807 }
808 indent[count] = '\0';
809#endif
Chet Haase1271e2c2012-04-20 09:54:27 -0700810 updateMatrix();
811 if (mLeft != 0 || mTop != 0) {
812 DISPLAY_LIST_LOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
813 renderer.translate(mLeft, mTop);
814 }
815 if (mStaticMatrix) {
816 DISPLAY_LIST_LOGD(
817 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
818 indent, "ConcatMatrix (static)", mStaticMatrix,
819 mStaticMatrix->get(0), mStaticMatrix->get(1),
820 mStaticMatrix->get(2), mStaticMatrix->get(3),
821 mStaticMatrix->get(4), mStaticMatrix->get(5),
822 mStaticMatrix->get(6), mStaticMatrix->get(7),
823 mStaticMatrix->get(8));
824 renderer.concatMatrix(mStaticMatrix);
825 } else if (mAnimationMatrix) {
826 DISPLAY_LIST_LOGD(
827 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
828 indent, "ConcatMatrix (animation)", mAnimationMatrix,
829 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
830 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
831 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
832 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
833 mAnimationMatrix->get(8));
834 renderer.concatMatrix(mAnimationMatrix);
835 }
836 if (mMatrixFlags != 0) {
837 if (mMatrixFlags == TRANSLATION) {
838 DISPLAY_LIST_LOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
839 renderer.translate(mTranslationX, mTranslationY);
840 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700841 DISPLAY_LIST_LOGD(
842 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700843 indent, "ConcatMatrix", mTransformMatrix,
844 mTransformMatrix->get(0), mTransformMatrix->get(1),
845 mTransformMatrix->get(2), mTransformMatrix->get(3),
846 mTransformMatrix->get(4), mTransformMatrix->get(5),
847 mTransformMatrix->get(6), mTransformMatrix->get(7),
848 mTransformMatrix->get(8));
849 renderer.concatMatrix(mTransformMatrix);
Chet Haasea1cff502012-02-21 13:43:44 -0800850 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700851 }
852 if (mAlpha < 1 && !mCaching) {
853 if (!mHasOverlappingRendering) {
854 DISPLAY_LIST_LOGD("%s%s %.2f", indent, "SetAlpha", mAlpha);
855 renderer.setAlpha(mAlpha);
856 } else {
857 // TODO: should be able to store the size of a DL at record time and not
858 // have to pass it into this call. In fact, this information might be in the
859 // location/size info that we store with the new native transform data.
860 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
861 if (mClipChildren) {
862 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800863 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700864 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
865 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
866 mMultipliedAlpha, flags);
867 renderer.saveLayerAlpha(0, 0, mRight - mLeft, mBottom - mTop,
868 mMultipliedAlpha, flags);
Chet Haasea1cff502012-02-21 13:43:44 -0800869 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700870 }
871 if (mClipChildren) {
872 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
873 (float) mRight - mLeft, (float) mBottom - mTop);
874 renderer.clipRect(0, 0, mRight - mLeft, mBottom - mTop,
875 SkRegion::kIntersect_Op);
Chet Haasea1cff502012-02-21 13:43:44 -0800876 }
877}
878
Chet Haaseed30fd82011-04-22 16:18:45 -0700879/**
880 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
881 * in the output() function, since that function processes the same list of opcodes for the
882 * purposes of logging display list info for a given view.
883 */
Chet Haase1271e2c2012-04-20 09:54:27 -0700884status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level) {
Chet Haase48659092012-05-31 15:21:51 -0700885 status_t drawGlStatus = DrawGlInfo::kStatusDone;
Romain Guyb051e892010-09-28 19:09:36 -0700886 TextContainer text;
887 mReader.rewind();
888
Romain Guyffac7fc2011-01-13 17:21:49 -0800889#if DEBUG_DISPLAY_LIST
890 uint32_t count = (level + 1) * 2;
891 char indent[count + 1];
892 for (uint32_t i = 0; i < count; i++) {
893 indent[i] = ' ';
894 }
895 indent[count] = '\0';
Chet Haasea23eed82012-04-12 15:19:04 -0700896 Rect* clipRect = renderer.getClipRect();
897 DISPLAY_LIST_LOGD("%sStart display list (%p, %s), clipRect: %.0f, %.f, %.0f, %.0f",
898 (char*) indent + 2, this, mName.string(), clipRect->left, clipRect->top,
899 clipRect->right, clipRect->bottom);
Romain Guyffac7fc2011-01-13 17:21:49 -0800900#endif
Romain Guyb051e892010-09-28 19:09:36 -0700901
Romain Guy13631f32012-01-30 17:41:55 -0800902 renderer.startMark(mName.string());
Romain Guy8a4ac612012-07-17 17:32:48 -0700903
Chet Haase1271e2c2012-04-20 09:54:27 -0700904 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
905 DISPLAY_LIST_LOGD("%s%s %d %d", indent, "Save",
906 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
907 setViewProperties(renderer, level);
Romain Guy8a4ac612012-07-17 17:32:48 -0700908
909 if (renderer.quickRejectNoScissor(0, 0, mWidth, mHeight)) {
Chet Haaseb85967b2012-03-26 14:37:51 -0700910 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
911 renderer.restoreToCount(restoreTo);
912 renderer.endMark();
Chet Haase48659092012-05-31 15:21:51 -0700913 return drawGlStatus;
Chet Haaseb85967b2012-03-26 14:37:51 -0700914 }
Romain Guy13631f32012-01-30 17:41:55 -0800915
Chet Haase9c1e23b2011-03-24 10:51:31 -0700916 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800917 int saveCount = renderer.getSaveCount() - 1;
Romain Guy8a4ac612012-07-17 17:32:48 -0700918
Romain Guyb051e892010-09-28 19:09:36 -0700919 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700920 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800921 if (op & OP_MAY_BE_SKIPPED_MASK) {
Romain Guy390f8822012-03-13 18:00:10 -0700922 int32_t skip = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800923 if (CC_LIKELY(flags & kReplayFlag_ClipChildren)) {
924 mReader.skip(skip);
925 DISPLAY_LIST_LOGD("%s%s skipping %d bytes", (char*) indent,
926 OP_NAMES[op & ~OP_MAY_BE_SKIPPED_MASK], skip);
927 continue;
928 } else {
929 op &= ~OP_MAY_BE_SKIPPED_MASK;
Romain Guy33f6beb2012-02-16 19:24:51 -0800930 }
931 }
Chet Haase9c1e23b2011-03-24 10:51:31 -0700932 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800933
Romain Guy8a4ac612012-07-17 17:32:48 -0700934#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
935 Caches::getInstance().eventMark(strlen(OP_NAMES[op]), OP_NAMES[op]);
936#endif
937
Romain Guy5b3b3522010-10-27 18:57:51 -0700938 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800939 case DrawGLFunction: {
940 Functor *functor = (Functor *) getInt();
941 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guy13631f32012-01-30 17:41:55 -0800942 renderer.startMark("GL functor");
Romain Guy65549432012-03-26 16:45:05 -0700943 drawGlStatus |= renderer.callDrawGLFunction(functor, dirty);
Romain Guy13631f32012-01-30 17:41:55 -0800944 renderer.endMark();
Chet Haasedaf98e92011-01-10 14:10:36 -0800945 }
946 break;
Romain Guyb051e892010-09-28 19:09:36 -0700947 case Save: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800948 int32_t rendererNum = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800949 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
950 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700951 }
952 break;
953 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800954 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700955 renderer.restore();
956 }
957 break;
958 case RestoreToCount: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800959 int32_t restoreCount = saveCount + getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800960 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
961 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700962 }
963 break;
964 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800965 float f1 = getFloat();
966 float f2 = getFloat();
967 float f3 = getFloat();
968 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800969 SkPaint* paint = getPaint(renderer);
Romain Guy33f6beb2012-02-16 19:24:51 -0800970 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800971 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800972 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800973 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700974 }
975 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700976 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800977 float f1 = getFloat();
978 float f2 = getFloat();
979 float f3 = getFloat();
980 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800981 int32_t alpha = getInt();
982 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800983 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800984 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800985 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700986 }
987 break;
Romain Guyb051e892010-09-28 19:09:36 -0700988 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800989 float f1 = getFloat();
990 float f2 = getFloat();
991 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
992 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700993 }
994 break;
995 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800996 float rotation = getFloat();
997 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
998 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700999 }
1000 break;
1001 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001002 float sx = getFloat();
1003 float sy = getFloat();
1004 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
1005 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -07001006 }
1007 break;
Romain Guy807daf72011-01-18 11:19:19 -08001008 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001009 float sx = getFloat();
1010 float sy = getFloat();
1011 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
1012 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -08001013 }
1014 break;
Romain Guyb051e892010-09-28 19:09:36 -07001015 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001016 SkMatrix* matrix = getMatrix();
1017 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
1018 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -07001019 }
1020 break;
1021 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001022 SkMatrix* matrix = getMatrix();
Chet Haasea1cff502012-02-21 13:43:44 -08001023 DISPLAY_LIST_LOGD(
1024 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
1025 (char*) indent, OP_NAMES[op], matrix,
1026 matrix->get(0), matrix->get(1), matrix->get(2),
1027 matrix->get(3), matrix->get(4), matrix->get(5),
1028 matrix->get(6), matrix->get(7), matrix->get(8));
Chet Haasedaf98e92011-01-10 14:10:36 -08001029 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -07001030 }
1031 break;
1032 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001033 float f1 = getFloat();
1034 float f2 = getFloat();
1035 float f3 = getFloat();
1036 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001037 int32_t regionOp = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001038 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001039 f1, f2, f3, f4, regionOp);
Chet Haasedaf98e92011-01-10 14:10:36 -08001040 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -07001041 }
1042 break;
Romain Guy735738c2012-12-03 12:34:51 -08001043 case ClipPath: {
1044 SkPath* path = getPath();
1045 int32_t regionOp = getInt();
1046 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], regionOp);
1047 renderer.clipPath(path, (SkRegion::Op) regionOp);
1048 }
1049 break;
1050 case ClipRegion: {
1051 SkRegion* region = getRegion();
1052 int32_t regionOp = getInt();
1053 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], regionOp);
1054 renderer.clipRegion(region, (SkRegion::Op) regionOp);
1055 }
1056 break;
Romain Guy0fe478e2010-11-08 12:08:41 -08001057 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001058 DisplayList* displayList = getDisplayList();
Romain Guy33f6beb2012-02-16 19:24:51 -08001059 int32_t flags = getInt();
1060 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
Chet Haase1271e2c2012-04-20 09:54:27 -07001061 displayList, mWidth, mHeight, flags, level + 1);
1062 drawGlStatus |= renderer.drawDisplayList(displayList, dirty, flags, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -08001063 }
1064 break;
Romain Guy6c319ca2011-01-11 14:29:25 -08001065 case DrawLayer: {
Chet Haased15ebf22012-09-05 11:40:29 -07001066 int oldAlpha = -1;
Chet Haasedaf98e92011-01-10 14:10:36 -08001067 Layer* layer = (Layer*) getInt();
1068 float x = getFloat();
1069 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001070 SkPaint* paint = getPaint(renderer);
Chet Haased15ebf22012-09-05 11:40:29 -07001071 if (mCaching && mMultipliedAlpha < 255) {
1072 oldAlpha = layer->getAlpha();
1073 layer->setAlpha(mMultipliedAlpha);
Chet Haasea1cff502012-02-21 13:43:44 -08001074 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001075 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001076 layer, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001077 drawGlStatus |= renderer.drawLayer(layer, x, y, paint);
Chet Haased15ebf22012-09-05 11:40:29 -07001078 if (oldAlpha >= 0) {
1079 layer->setAlpha(oldAlpha);
1080 }
Romain Guy6c319ca2011-01-11 14:29:25 -08001081 }
1082 break;
Romain Guyb051e892010-09-28 19:09:36 -07001083 case DrawBitmap: {
Chet Haased15ebf22012-09-05 11:40:29 -07001084 int oldAlpha = -1;
Chet Haasedaf98e92011-01-10 14:10:36 -08001085 SkBitmap* bitmap = getBitmap();
1086 float x = getFloat();
1087 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001088 SkPaint* paint = getPaint(renderer);
Chet Haased15ebf22012-09-05 11:40:29 -07001089 if (mCaching && mMultipliedAlpha < 255) {
1090 oldAlpha = paint->getAlpha();
Chet Haaseb85967b2012-03-26 14:37:51 -07001091 paint->setAlpha(mMultipliedAlpha);
1092 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001093 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001094 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001095 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Chet Haased15ebf22012-09-05 11:40:29 -07001096 if (oldAlpha >= 0) {
1097 paint->setAlpha(oldAlpha);
1098 }
Romain Guyb051e892010-09-28 19:09:36 -07001099 }
1100 break;
1101 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001102 SkBitmap* bitmap = getBitmap();
1103 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -08001104 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001105 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001106 bitmap, matrix, paint);
Chet Haase48659092012-05-31 15:21:51 -07001107 drawGlStatus |= renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001108 }
1109 break;
1110 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001111 SkBitmap* bitmap = getBitmap();
1112 float f1 = getFloat();
1113 float f2 = getFloat();
1114 float f3 = getFloat();
1115 float f4 = getFloat();
1116 float f5 = getFloat();
1117 float f6 = getFloat();
1118 float f7 = getFloat();
1119 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001120 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001121 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001122 (char*) indent, OP_NAMES[op], bitmap,
1123 f1, f2, f3, f4, f5, f6, f7, f8,paint);
Chet Haase48659092012-05-31 15:21:51 -07001124 drawGlStatus |= renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001125 }
1126 break;
Romain Guye651cc62012-05-14 19:44:40 -07001127 case DrawBitmapData: {
1128 SkBitmap* bitmap = getBitmapData();
1129 float x = getFloat();
1130 float y = getFloat();
1131 SkPaint* paint = getPaint(renderer);
1132 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
1133 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001134 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Romain Guye651cc62012-05-14 19:44:40 -07001135 }
1136 break;
Romain Guy5a7b4662011-01-20 19:09:30 -08001137 case DrawBitmapMesh: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001138 int32_t verticesCount = 0;
Romain Guy5a7b4662011-01-20 19:09:30 -08001139 uint32_t colorsCount = 0;
1140
1141 SkBitmap* bitmap = getBitmap();
1142 uint32_t meshWidth = getInt();
1143 uint32_t meshHeight = getInt();
1144 float* vertices = getFloats(verticesCount);
1145 bool hasColors = getInt();
Romain Guy33f6beb2012-02-16 19:24:51 -08001146 int32_t* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -08001147 SkPaint* paint = getPaint(renderer);
Romain Guy5a7b4662011-01-20 19:09:30 -08001148
Chet Haasedaf98e92011-01-10 14:10:36 -08001149 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001150 drawGlStatus |= renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices,
1151 colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -08001152 }
Romain Guya566b7c2011-01-23 16:36:11 -08001153 break;
Romain Guyb051e892010-09-28 19:09:36 -07001154 case DrawPatch: {
1155 int32_t* xDivs = NULL;
1156 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -07001157 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -07001158 uint32_t xDivsCount = 0;
1159 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -07001160 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001161
1162 SkBitmap* bitmap = getBitmap();
1163
1164 xDivs = getInts(xDivsCount);
1165 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -07001166 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -07001167
Romain Guy9ff3cb52011-06-28 14:02:11 -07001168 float left = getFloat();
1169 float top = getFloat();
1170 float right = getFloat();
1171 float bottom = getFloat();
Romain Guybe6f9dc2012-07-16 12:41:17 -07001172
1173 int alpha = getInt();
1174 SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
Romain Guy9ff3cb52011-06-28 14:02:11 -07001175
Chet Haasedaf98e92011-01-10 14:10:36 -08001176 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001177 drawGlStatus |= renderer.drawPatch(bitmap, xDivs, yDivs, colors,
Romain Guybe6f9dc2012-07-16 12:41:17 -07001178 xDivsCount, yDivsCount, numColors, left, top, right, bottom,
1179 alpha, mode);
Romain Guyb051e892010-09-28 19:09:36 -07001180 }
1181 break;
1182 case DrawColor: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001183 int32_t color = getInt();
1184 int32_t xferMode = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001185 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haase48659092012-05-31 15:21:51 -07001186 drawGlStatus |= renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -07001187 }
1188 break;
1189 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001190 float f1 = getFloat();
1191 float f2 = getFloat();
1192 float f3 = getFloat();
1193 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001194 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001195 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001196 f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001197 drawGlStatus |= renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001198 }
1199 break;
Romain Guy01d58e42011-01-19 21:54:02 -08001200 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001201 float f1 = getFloat();
1202 float f2 = getFloat();
1203 float f3 = getFloat();
1204 float f4 = getFloat();
1205 float f5 = getFloat();
1206 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001207 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001208 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001209 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
Chet Haase48659092012-05-31 15:21:51 -07001210 drawGlStatus |= renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001211 }
1212 break;
1213 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001214 float f1 = getFloat();
1215 float f2 = getFloat();
1216 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001217 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001218 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001219 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
Chet Haase48659092012-05-31 15:21:51 -07001220 drawGlStatus |= renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001221 }
1222 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001223 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001224 float f1 = getFloat();
1225 float f2 = getFloat();
1226 float f3 = getFloat();
1227 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001228 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001229 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001230 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001231 drawGlStatus |= renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001232 }
1233 break;
Romain Guy8b2f5262011-01-23 16:15:02 -08001234 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001235 float f1 = getFloat();
1236 float f2 = getFloat();
1237 float f3 = getFloat();
1238 float f4 = getFloat();
1239 float f5 = getFloat();
1240 float f6 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001241 int32_t i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001242 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001243 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001244 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
Chet Haase48659092012-05-31 15:21:51 -07001245 drawGlStatus |= renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -08001246 }
1247 break;
Romain Guyb051e892010-09-28 19:09:36 -07001248 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001249 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -08001250 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001251 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haase48659092012-05-31 15:21:51 -07001252 drawGlStatus |= renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001253 }
1254 break;
1255 case DrawLines: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001256 int32_t count = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001257 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001258 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001259 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001260 drawGlStatus |= renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001261 }
1262 break;
Romain Guyed6fcb02011-03-21 13:11:28 -07001263 case DrawPoints: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001264 int32_t count = 0;
Romain Guyed6fcb02011-03-21 13:11:28 -07001265 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001266 SkPaint* paint = getPaint(renderer);
Romain Guyed6fcb02011-03-21 13:11:28 -07001267 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001268 drawGlStatus |= renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -07001269 }
1270 break;
Romain Guy325740f2012-02-24 16:48:34 -08001271 case DrawTextOnPath: {
1272 getText(&text);
1273 int32_t count = getInt();
1274 SkPath* path = getPath();
1275 float hOffset = getFloat();
1276 float vOffset = getFloat();
1277 SkPaint* paint = getPaint(renderer);
1278 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
1279 text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001280 drawGlStatus |= renderer.drawTextOnPath(text.text(), text.length(), count, path,
Romain Guy325740f2012-02-24 16:48:34 -08001281 hOffset, vOffset, paint);
1282 }
1283 break;
Romain Guyeb9a5362012-01-17 17:39:26 -08001284 case DrawPosText: {
1285 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -08001286 int32_t count = getInt();
1287 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -08001288 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -08001289 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -08001290 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
1291 OP_NAMES[op], text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001292 drawGlStatus |= renderer.drawPosText(text.text(), text.length(), count,
1293 positions, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -08001294 }
1295 break;
Romain Guyc2525952012-07-27 16:41:22 -07001296 case DrawText: {
Raph Levien996e57c2012-07-23 15:22:52 -07001297 getText(&text);
1298 int32_t count = getInt();
1299 float x = getFloat();
1300 float y = getFloat();
1301 int32_t positionsCount = 0;
1302 float* positions = getFloats(positionsCount);
1303 SkPaint* paint = getPaint(renderer);
1304 float length = getFloat();
1305 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
1306 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
Romain Guyc2525952012-07-27 16:41:22 -07001307 drawGlStatus |= renderer.drawText(text.text(), text.length(), count,
Raph Levien996e57c2012-07-23 15:22:52 -07001308 x, y, positions, paint, length);
1309 }
1310 break;
Romain Guy672433d2013-01-04 19:05:13 -08001311 case DrawRects: {
1312 int32_t count = 0;
1313 float* rects = getFloats(count);
1314 SkPaint* paint = getPaint(renderer);
1315 DISPLAY_LIST_LOGD("%s%s %d, %p", (char*) indent, OP_NAMES[op], count, paint);
1316 drawGlStatus |= renderer.drawRects(rects, count / 4, paint);
1317 }
1318 break;
Romain Guyb051e892010-09-28 19:09:36 -07001319 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001320 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001321 renderer.resetShader();
1322 }
1323 break;
1324 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001325 SkiaShader* shader = getShader();
1326 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
1327 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -07001328 }
1329 break;
1330 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001331 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001332 renderer.resetColorFilter();
1333 }
1334 break;
1335 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001336 SkiaColorFilter *colorFilter = getColorFilter();
1337 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
1338 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -07001339 }
1340 break;
1341 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001342 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001343 renderer.resetShadow();
1344 }
1345 break;
1346 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001347 float radius = getFloat();
1348 float dx = getFloat();
1349 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001350 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001351 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001352 radius, dx, dy, color);
Chet Haasedaf98e92011-01-10 14:10:36 -08001353 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -07001354 }
1355 break;
Romain Guy5ff9df62012-01-23 17:09:05 -08001356 case ResetPaintFilter: {
1357 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
1358 renderer.resetPaintFilter();
1359 }
1360 break;
1361 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001362 int32_t clearBits = getInt();
1363 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001364 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
1365 clearBits, setBits);
1366 renderer.setupPaintFilter(clearBits, setBits);
1367 }
1368 break;
Chet Haasedaf98e92011-01-10 14:10:36 -08001369 default:
1370 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -08001371 (char*) indent, OP_NAMES[op]);
Chet Haasedaf98e92011-01-10 14:10:36 -08001372 break;
Romain Guyb051e892010-09-28 19:09:36 -07001373 }
1374 }
Romain Guyffac7fc2011-01-13 17:21:49 -08001375
Chet Haase1271e2c2012-04-20 09:54:27 -07001376 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
1377 renderer.restoreToCount(restoreTo);
Romain Guy13631f32012-01-30 17:41:55 -08001378 renderer.endMark();
1379
Chet Haasea1cff502012-02-21 13:43:44 -08001380 DISPLAY_LIST_LOGD("%sDone (%p, %s), returning %d", (char*) indent + 2, this, mName.string(),
Romain Guy65549432012-03-26 16:45:05 -07001381 drawGlStatus);
1382 return drawGlStatus;
Romain Guyb051e892010-09-28 19:09:36 -07001383}
1384
1385///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -07001386// Base structure
1387///////////////////////////////////////////////////////////////////////////////
1388
Romain Guy58ecc202012-09-07 11:58:36 -07001389DisplayListRenderer::DisplayListRenderer():
1390 mCaches(Caches::getInstance()), mWriter(MIN_WRITER_SIZE),
Romain Guy54c1a642012-09-27 17:55:46 -07001391 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false),
1392 mHasDrawOps(false), mFunctorCount(0) {
Romain Guy4aa90572010-09-26 18:40:37 -07001393}
1394
1395DisplayListRenderer::~DisplayListRenderer() {
1396 reset();
1397}
1398
1399void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -07001400 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -07001401
Romain Guy58ecc202012-09-07 11:58:36 -07001402 mCaches.resourceCache.lock();
1403
Chet Haase5c13d892010-10-08 08:37:55 -07001404 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -07001405 mCaches.resourceCache.decrementRefcountLocked(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -07001406 }
Chet Haased98aa2d2010-10-25 15:47:32 -07001407
Romain Guy49c5fc02012-05-15 11:10:01 -07001408 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -07001409 mCaches.resourceCache.decrementRefcountLocked(mOwnedBitmapResources.itemAt(i));
Romain Guy49c5fc02012-05-15 11:10:01 -07001410 }
Romain Guy49c5fc02012-05-15 11:10:01 -07001411
Romain Guyd586ad92011-06-22 16:14:36 -07001412 for (size_t i = 0; i < mFilterResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -07001413 mCaches.resourceCache.decrementRefcountLocked(mFilterResources.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -07001414 }
Romain Guyd586ad92011-06-22 16:14:36 -07001415
Romain Guy43ccf462011-01-14 18:51:01 -08001416 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -07001417 mCaches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -08001418 }
Romain Guy43ccf462011-01-14 18:51:01 -08001419
Chet Haased34dd712012-05-02 18:50:34 -07001420 for (size_t i = 0; i < mSourcePaths.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -07001421 mCaches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
Chet Haased34dd712012-05-02 18:50:34 -07001422 }
Romain Guy58ecc202012-09-07 11:58:36 -07001423
Chet Haase603f6de2012-09-14 15:31:25 -07001424 for (size_t i = 0; i < mLayers.size(); i++) {
1425 mCaches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
1426 }
1427
Romain Guy58ecc202012-09-07 11:58:36 -07001428 mCaches.resourceCache.unlock();
1429
1430 mBitmapResources.clear();
1431 mOwnedBitmapResources.clear();
1432 mFilterResources.clear();
Chet Haased34dd712012-05-02 18:50:34 -07001433 mSourcePaths.clear();
1434
Romain Guy58ecc202012-09-07 11:58:36 -07001435 mShaders.clear();
1436 mShaderMap.clear();
1437
Romain Guy43ccf462011-01-14 18:51:01 -08001438 mPaints.clear();
1439 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001440
Romain Guy735738c2012-12-03 12:34:51 -08001441 mRegions.clear();
1442 mRegionMap.clear();
1443
Romain Guy2fc941e2011-02-03 15:06:05 -08001444 mPaths.clear();
1445 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001446
Chet Haased98aa2d2010-10-25 15:47:32 -07001447 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001448
Chet Haase603f6de2012-09-14 15:31:25 -07001449 mLayers.clear();
1450
Romain Guy04c9d8c2011-08-25 14:01:48 -07001451 mHasDrawOps = false;
Romain Guy54c1a642012-09-27 17:55:46 -07001452 mFunctorCount = 0;
Romain Guy4aa90572010-09-26 18:40:37 -07001453}
1454
1455///////////////////////////////////////////////////////////////////////////////
1456// Operations
1457///////////////////////////////////////////////////////////////////////////////
1458
Jeff Brown162a0212011-07-21 17:02:54 -07001459DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1460 if (!displayList) {
1461 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001462 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001463 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001464 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001465 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001466 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001467}
1468
Romain Guy49c5fc02012-05-15 11:10:01 -07001469bool DisplayListRenderer::isDeferred() {
1470 return true;
1471}
1472
Romain Guyb051e892010-09-28 19:09:36 -07001473void DisplayListRenderer::setViewport(int width, int height) {
1474 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1475
1476 mWidth = width;
1477 mHeight = height;
1478}
1479
Romain Guy7c25aab2012-10-18 15:05:02 -07001480status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -08001481 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001482 mSnapshot = new Snapshot(mFirstSnapshot,
1483 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1484 mSaveCount = 1;
Romain Guy45e4c3d2012-09-11 17:17:07 -07001485
Romain Guyb051e892010-09-28 19:09:36 -07001486 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy45e4c3d2012-09-11 17:17:07 -07001487 mDirtyClip = opaque;
1488
Romain Guy27454a42011-01-23 12:01:41 -08001489 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -07001490
Chet Haase44b2fe32012-06-06 19:03:58 -07001491 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -08001492}
1493
1494void DisplayListRenderer::finish() {
1495 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001496 insertTranlate();
Romain Guyb051e892010-09-28 19:09:36 -07001497}
1498
Chet Haasedaf98e92011-01-10 14:10:36 -08001499void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001500}
Romain Guy2b1847e2011-01-26 13:43:01 -08001501
Chet Haasedaf98e92011-01-10 14:10:36 -08001502void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001503}
1504
Romain Guy65549432012-03-26 16:45:05 -07001505status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -08001506 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001507 addOp(DisplayList::DrawGLFunction);
1508 addInt((int) functor);
Romain Guy54c1a642012-09-27 17:55:46 -07001509 mFunctorCount++;
Romain Guy65549432012-03-26 16:45:05 -07001510 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -08001511}
1512
Romain Guy4aa90572010-09-26 18:40:37 -07001513int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001514 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001515 addInt(flags);
1516 return OpenGLRenderer::save(flags);
1517}
1518
1519void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001520 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001521 restoreToCount(getSaveCount() - 1);
1522 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001523 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001524
1525 mRestoreSaveCount--;
1526 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001527 OpenGLRenderer::restore();
1528}
1529
1530void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001531 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001532 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001533 OpenGLRenderer::restoreToCount(saveCount);
1534}
1535
1536int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001537 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001538 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001539 addBounds(left, top, right, bottom);
1540 addPaint(p);
1541 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001542 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001543}
1544
Romain Guy5b3b3522010-10-27 18:57:51 -07001545int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1546 int alpha, int flags) {
1547 addOp(DisplayList::SaveLayerAlpha);
1548 addBounds(left, top, right, bottom);
1549 addInt(alpha);
1550 addInt(flags);
1551 return OpenGLRenderer::save(flags);
1552}
1553
Romain Guy4aa90572010-09-26 18:40:37 -07001554void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001555 mHasTranslate = true;
1556 mTranslateX += dx;
1557 mTranslateY += dy;
1558 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001559 OpenGLRenderer::translate(dx, dy);
1560}
1561
1562void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001563 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001564 addFloat(degrees);
1565 OpenGLRenderer::rotate(degrees);
1566}
1567
1568void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001569 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001570 addPoint(sx, sy);
1571 OpenGLRenderer::scale(sx, sy);
1572}
1573
Romain Guy807daf72011-01-18 11:19:19 -08001574void DisplayListRenderer::skew(float sx, float sy) {
1575 addOp(DisplayList::Skew);
1576 addPoint(sx, sy);
1577 OpenGLRenderer::skew(sx, sy);
1578}
1579
Romain Guy4aa90572010-09-26 18:40:37 -07001580void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001581 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001582 addMatrix(matrix);
1583 OpenGLRenderer::setMatrix(matrix);
1584}
1585
1586void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001587 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001588 addMatrix(matrix);
1589 OpenGLRenderer::concatMatrix(matrix);
1590}
1591
1592bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1593 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001594 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001595 addBounds(left, top, right, bottom);
1596 addInt(op);
1597 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1598}
1599
Romain Guy735738c2012-12-03 12:34:51 -08001600bool DisplayListRenderer::clipPath(SkPath* path, SkRegion::Op op) {
1601 addOp(DisplayList::ClipPath);
1602 addPath(path);
1603 addInt(op);
1604 return OpenGLRenderer::clipPath(path, op);
1605}
1606
1607bool DisplayListRenderer::clipRegion(SkRegion* region, SkRegion::Op op) {
1608 addOp(DisplayList::ClipRegion);
1609 addRegion(region);
1610 addInt(op);
1611 return OpenGLRenderer::clipRegion(region, op);
1612}
1613
Romain Guy65549432012-03-26 16:45:05 -07001614status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chet Haase1271e2c2012-04-20 09:54:27 -07001615 Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001616 // dirty is an out parameter and should not be recorded,
1617 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -07001618
1619 addOp(DisplayList::DrawDisplayList);
Romain Guy0fe478e2010-11-08 12:08:41 -08001620 addDisplayList(displayList);
Romain Guy33f6beb2012-02-16 19:24:51 -08001621 addInt(flags);
Romain Guy65549432012-03-26 16:45:05 -07001622 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -08001623}
1624
Chet Haase48659092012-05-31 15:21:51 -07001625status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001626 addOp(DisplayList::DrawLayer);
Chet Haase603f6de2012-09-14 15:31:25 -07001627 addLayer(layer);
Romain Guyada830f2011-01-13 12:13:20 -08001628 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001629 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001630 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -08001631}
1632
Chet Haase48659092012-05-31 15:21:51 -07001633status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Romain Guya3dc55f2012-09-28 13:55:44 -07001634 const bool reject = quickRejectNoScissor(left, top,
1635 left + bitmap->width(), top + bitmap->height());
Romain Guy33f6beb2012-02-16 19:24:51 -08001636 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001637 addBitmap(bitmap);
1638 addPoint(left, top);
1639 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001640 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001641 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001642}
1643
Chet Haase48659092012-05-31 15:21:51 -07001644status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001645 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1646 const mat4 transform(*matrix);
1647 transform.mapRect(r);
1648
Romain Guya3dc55f2012-09-28 13:55:44 -07001649 const bool reject = quickRejectNoScissor(r.left, r.top, r.right, r.bottom);
Romain Guy33f6beb2012-02-16 19:24:51 -08001650 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001651 addBitmap(bitmap);
1652 addMatrix(matrix);
1653 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001654 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001655 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001656}
1657
Chet Haase48659092012-05-31 15:21:51 -07001658status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -07001659 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001660 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guya3dc55f2012-09-28 13:55:44 -07001661 const bool reject = quickRejectNoScissor(dstLeft, dstTop, dstRight, dstBottom);
Romain Guy33f6beb2012-02-16 19:24:51 -08001662 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001663 addBitmap(bitmap);
1664 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1665 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1666 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001667 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001668 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001669}
1670
Chet Haase48659092012-05-31 15:21:51 -07001671status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
1672 SkPaint* paint) {
Romain Guya3dc55f2012-09-28 13:55:44 -07001673 const bool reject = quickRejectNoScissor(left, top,
1674 left + bitmap->width(), top + bitmap->height());
Romain Guye651cc62012-05-14 19:44:40 -07001675 uint32_t* location = addOp(DisplayList::DrawBitmapData, reject);
1676 addBitmapData(bitmap);
1677 addPoint(left, top);
1678 addPaint(paint);
1679 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001680 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -07001681}
1682
Chet Haase48659092012-05-31 15:21:51 -07001683status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -08001684 float* vertices, int* colors, SkPaint* paint) {
1685 addOp(DisplayList::DrawBitmapMesh);
1686 addBitmap(bitmap);
1687 addInt(meshWidth);
1688 addInt(meshHeight);
1689 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1690 if (colors) {
1691 addInt(1);
1692 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1693 } else {
1694 addInt(0);
1695 }
1696 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001697 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -08001698}
1699
Chet Haase48659092012-05-31 15:21:51 -07001700status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
1701 const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height,
1702 int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guybe6f9dc2012-07-16 12:41:17 -07001703 int alpha;
1704 SkXfermode::Mode mode;
1705 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
1706
Romain Guya3dc55f2012-09-28 13:55:44 -07001707 const bool reject = quickRejectNoScissor(left, top, right, bottom);
Romain Guy33f6beb2012-02-16 19:24:51 -08001708 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001709 addBitmap(bitmap);
1710 addInts(xDivs, width);
1711 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001712 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001713 addBounds(left, top, right, bottom);
Romain Guybe6f9dc2012-07-16 12:41:17 -07001714 addInt(alpha);
1715 addInt(mode);
Romain Guy33f6beb2012-02-16 19:24:51 -08001716 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001717 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001718}
1719
Chet Haase48659092012-05-31 15:21:51 -07001720status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001721 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001722 addInt(color);
1723 addInt(mode);
Chet Haase48659092012-05-31 15:21:51 -07001724 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001725}
1726
Chet Haase48659092012-05-31 15:21:51 -07001727status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001728 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001729 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
Romain Guya3dc55f2012-09-28 13:55:44 -07001730 quickRejectNoScissor(left, top, right, bottom);
Romain Guy33f6beb2012-02-16 19:24:51 -08001731 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001732 addBounds(left, top, right, bottom);
1733 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001734 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001735 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001736}
1737
Chet Haase48659092012-05-31 15:21:51 -07001738status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -08001739 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001740 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
Romain Guya3dc55f2012-09-28 13:55:44 -07001741 quickRejectNoScissor(left, top, right, bottom);
Romain Guy33f6beb2012-02-16 19:24:51 -08001742 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001743 addBounds(left, top, right, bottom);
1744 addPoint(rx, ry);
1745 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001746 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001747 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001748}
1749
Chet Haase48659092012-05-31 15:21:51 -07001750status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Romain Guy01d58e42011-01-19 21:54:02 -08001751 addOp(DisplayList::DrawCircle);
1752 addPoint(x, y);
1753 addFloat(radius);
1754 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001755 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001756}
1757
Chet Haase48659092012-05-31 15:21:51 -07001758status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001759 SkPaint* paint) {
1760 addOp(DisplayList::DrawOval);
1761 addBounds(left, top, right, bottom);
1762 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001763 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001764}
1765
Chet Haase48659092012-05-31 15:21:51 -07001766status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -08001767 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001768 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001769 addBounds(left, top, right, bottom);
1770 addPoint(startAngle, sweepAngle);
1771 addInt(useCenter ? 1 : 0);
1772 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001773 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -08001774}
1775
Chet Haase48659092012-05-31 15:21:51 -07001776status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001777 float left, top, offset;
1778 uint32_t width, height;
1779 computePathBounds(path, paint, left, top, offset, width, height);
1780
Romain Guy95c21d02012-07-17 17:46:03 -07001781 left -= offset;
1782 top -= offset;
1783
Romain Guya3dc55f2012-09-28 13:55:44 -07001784 const bool reject = quickRejectNoScissor(left, top, left + width, top + height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001785 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001786 addPath(path);
1787 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001788 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001789 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001790}
1791
Chet Haase48659092012-05-31 15:21:51 -07001792status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001793 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001794 addFloats(points, count);
1795 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001796 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001797}
1798
Chet Haase48659092012-05-31 15:21:51 -07001799status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Romain Guyed6fcb02011-03-21 13:11:28 -07001800 addOp(DisplayList::DrawPoints);
1801 addFloats(points, count);
1802 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001803 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -07001804}
1805
Chet Haase48659092012-05-31 15:21:51 -07001806status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -08001807 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001808 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001809 addOp(DisplayList::DrawTextOnPath);
1810 addText(text, bytesCount);
1811 addInt(count);
1812 addPath(path);
1813 addFloat(hOffset);
1814 addFloat(vOffset);
1815 paint->setAntiAlias(true);
Chet Haasee816bae2012-08-09 13:39:02 -07001816 SkPaint* addedPaint = addPaint(paint);
1817 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
Romain Guye3a9b242013-01-08 11:15:30 -08001818 fontRenderer.precache(addedPaint, text, count, *mSnapshot->transform);
Chet Haase48659092012-05-31 15:21:51 -07001819 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001820}
1821
Chet Haase48659092012-05-31 15:21:51 -07001822status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -08001823 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001824 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001825 addOp(DisplayList::DrawPosText);
1826 addText(text, bytesCount);
1827 addInt(count);
1828 addFloats(positions, count * 2);
1829 paint->setAntiAlias(true);
Chet Haasee816bae2012-08-09 13:39:02 -07001830 SkPaint* addedPaint = addPaint(paint);
1831 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
Romain Guye3a9b242013-01-08 11:15:30 -08001832 fontRenderer.precache(addedPaint, text, count, *mSnapshot->transform);
Chet Haase48659092012-05-31 15:21:51 -07001833 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001834}
1835
Romain Guyc2525952012-07-27 16:41:22 -07001836status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Raph Levien996e57c2012-07-23 15:22:52 -07001837 float x, float y, const float* positions, SkPaint* paint, float length) {
1838 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
1839
1840 // TODO: We should probably make a copy of the paint instead of modifying
1841 // it; modifying the paint will change its generationID the first
1842 // time, which might impact caches. More investigation needed to
1843 // see if it matters.
1844 // If we make a copy, then drawTextDecorations() should *not* make
1845 // its own copy as it does right now.
1846 // Beware: this needs Glyph encoding (already done on the Paint constructor)
1847 paint->setAntiAlias(true);
1848 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1849
1850 bool reject = false;
1851 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1852 SkPaint::FontMetrics metrics;
1853 paint->getFontMetrics(&metrics, 0.0f);
Romain Guya3dc55f2012-09-28 13:55:44 -07001854 reject = quickRejectNoScissor(x, y + metrics.fTop, x + length, y + metrics.fBottom);
Raph Levien996e57c2012-07-23 15:22:52 -07001855 }
1856
Romain Guyc2525952012-07-27 16:41:22 -07001857 uint32_t* location = addOp(DisplayList::DrawText, reject);
Raph Levien996e57c2012-07-23 15:22:52 -07001858 addText(text, bytesCount);
1859 addInt(count);
1860 addFloat(x);
1861 addFloat(y);
1862 addFloats(positions, count * 2);
Chet Haasee816bae2012-08-09 13:39:02 -07001863 SkPaint* addedPaint = addPaint(paint);
1864 if (!reject) {
1865 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
Romain Guye3a9b242013-01-08 11:15:30 -08001866 fontRenderer.precache(addedPaint, text, count, *mSnapshot->transform);
Chet Haasee816bae2012-08-09 13:39:02 -07001867 }
Raph Levien996e57c2012-07-23 15:22:52 -07001868 addFloat(length);
1869 addSkip(location);
1870 return DrawGlInfo::kStatusDone;
1871}
1872
Romain Guy672433d2013-01-04 19:05:13 -08001873status_t DisplayListRenderer::drawRects(const float* rects, int count, SkPaint* paint) {
1874 if (count <= 0) return DrawGlInfo::kStatusDone;
1875
1876 addOp(DisplayList::DrawRects);
1877 addFloats(rects, count * 4);
1878 addPaint(paint);
1879 return DrawGlInfo::kStatusDone;
1880}
1881
Romain Guy4aa90572010-09-26 18:40:37 -07001882void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001883 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001884}
1885
1886void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001887 addOp(DisplayList::SetupShader);
1888 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001889}
1890
1891void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001892 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001893}
1894
1895void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001896 addOp(DisplayList::SetupColorFilter);
1897 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001898}
1899
1900void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001901 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001902}
1903
1904void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001905 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001906 addFloat(radius);
1907 addPoint(dx, dy);
1908 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001909}
1910
Romain Guy5ff9df62012-01-23 17:09:05 -08001911void DisplayListRenderer::resetPaintFilter() {
1912 addOp(DisplayList::ResetPaintFilter);
1913}
1914
1915void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1916 addOp(DisplayList::SetupPaintFilter);
1917 addInt(clearBits);
1918 addInt(setBits);
1919}
1920
Romain Guy4aa90572010-09-26 18:40:37 -07001921}; // namespace uirenderer
1922}; // namespace android