blob: 133f63f249c346268d73648d64d6f12682a91b6d [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",
47 "DrawDisplayList",
48 "DrawLayer",
49 "DrawBitmap",
50 "DrawBitmapMatrix",
51 "DrawBitmapRect",
Romain Guye651cc62012-05-14 19:44:40 -070052 "DrawBitmapData",
Romain Guy5a7b4662011-01-20 19:09:30 -080053 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -080054 "DrawPatch",
55 "DrawColor",
56 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -080057 "DrawRoundRect",
58 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -080059 "DrawOval",
Romain Guy8b2f5262011-01-23 16:15:02 -080060 "DrawArc",
Romain Guyffac7fc2011-01-13 17:21:49 -080061 "DrawPath",
62 "DrawLines",
Romain Guyed6fcb02011-03-21 13:11:28 -070063 "DrawPoints",
Romain Guyffac7fc2011-01-13 17:21:49 -080064 "DrawText",
Romain Guy325740f2012-02-24 16:48:34 -080065 "DrawTextOnPath",
Romain Guyeb9a5362012-01-17 17:39:26 -080066 "DrawPosText",
Romain Guyffac7fc2011-01-13 17:21:49 -080067 "ResetShader",
68 "SetupShader",
69 "ResetColorFilter",
70 "SetupColorFilter",
71 "ResetShadow",
Chet Haasedaf98e92011-01-10 14:10:36 -080072 "SetupShadow",
Romain Guy5ff9df62012-01-23 17:09:05 -080073 "ResetPaintFilter",
74 "SetupPaintFilter",
Chet Haasedaf98e92011-01-10 14:10:36 -080075 "DrawGLFunction"
Romain Guyffac7fc2011-01-13 17:21:49 -080076};
77
Chet Haase9c1e23b2011-03-24 10:51:31 -070078void DisplayList::outputLogBuffer(int fd) {
79 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
80 if (logBuffer.isEmpty()) {
81 return;
82 }
Romain Guy65b345f2011-07-27 18:51:50 -070083
Chet Haase9c1e23b2011-03-24 10:51:31 -070084 FILE *file = fdopen(fd, "a");
Romain Guy65b345f2011-07-27 18:51:50 -070085
Chet Haase9c1e23b2011-03-24 10:51:31 -070086 fprintf(file, "\nRecent DisplayList operations\n");
87 logBuffer.outputCommands(file, OP_NAMES);
Romain Guy65b345f2011-07-27 18:51:50 -070088
89 String8 cachesLog;
90 Caches::getInstance().dumpMemoryUsage(cachesLog);
91 fprintf(file, "\nCaches:\n%s", cachesLog.string());
92 fprintf(file, "\n");
93
Chet Haase9c1e23b2011-03-24 10:51:31 -070094 fflush(file);
95}
96
Chet Haase491189f2012-03-13 11:42:34 -070097DisplayList::DisplayList(const DisplayListRenderer& recorder) :
Chet Haase9420abd2012-03-29 16:28:32 -070098 mTransformMatrix(NULL), mTransformCamera(NULL), mTransformMatrix3D(NULL),
99 mStaticMatrix(NULL), mAnimationMatrix(NULL) {
Chet Haase491189f2012-03-13 11:42:34 -0700100
Chet Haase5977baa2011-01-05 18:01:22 -0800101 initFromDisplayListRenderer(recorder);
102}
103
104DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -0800105 clearResources();
106}
107
Chet Haasea1cff502012-02-21 13:43:44 -0800108void DisplayList::initProperties() {
109 mLeft = 0;
110 mTop = 0;
Chet Haaseb85967b2012-03-26 14:37:51 -0700111 mRight = 0;
Chet Haasea1cff502012-02-21 13:43:44 -0800112 mBottom = 0;
Chet Haasea1cff502012-02-21 13:43:44 -0800113 mClipChildren = true;
114 mAlpha = 1;
115 mMultipliedAlpha = 255;
Chet Haasedb8c9a62012-03-21 18:54:18 -0700116 mHasOverlappingRendering = true;
Chet Haasea1cff502012-02-21 13:43:44 -0800117 mTranslationX = 0;
118 mTranslationY = 0;
119 mRotation = 0;
120 mRotationX = 0;
121 mRotationY= 0;
122 mScaleX = 1;
123 mScaleY = 1;
124 mPivotX = 0;
125 mPivotY = 0;
Chet Haaseb85967b2012-03-26 14:37:51 -0700126 mCameraDistance = 0;
Chet Haasea1cff502012-02-21 13:43:44 -0800127 mMatrixDirty = false;
128 mMatrixFlags = 0;
129 mPrevWidth = -1;
130 mPrevHeight = -1;
131 mWidth = 0;
132 mHeight = 0;
133 mPivotExplicitlySet = false;
Chet Haasea1cff502012-02-21 13:43:44 -0800134 mCaching = false;
135}
136
Romain Guybb0acdf2012-03-05 13:44:35 -0800137void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {
138 if (displayList) {
139 DISPLAY_LIST_LOGD("Deferring display list destruction");
140 Caches::getInstance().deleteDisplayListDeferred(displayList);
141 }
142}
143
Chet Haased63cbd12011-02-03 16:32:46 -0800144void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -0800145 sk_free((void*) mReader.base());
146
Chet Haase1271e2c2012-04-20 09:54:27 -0700147 delete mTransformMatrix;
148 delete mTransformCamera;
149 delete mTransformMatrix3D;
150 delete mStaticMatrix;
151 delete mAnimationMatrix;
152 mTransformMatrix = NULL;
153 mTransformCamera = NULL;
154 mTransformMatrix3D = NULL;
155 mStaticMatrix = NULL;
156 mAnimationMatrix = NULL;
Chet Haasea1cff502012-02-21 13:43:44 -0800157
Chet Haase5977baa2011-01-05 18:01:22 -0800158 Caches& caches = Caches::getInstance();
159
160 for (size_t i = 0; i < mBitmapResources.size(); i++) {
161 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
162 }
163 mBitmapResources.clear();
164
Romain Guy49c5fc02012-05-15 11:10:01 -0700165 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
166 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
167 caches.resourceCache.decrementRefcount(bitmap);
168 caches.resourceCache.destructor(bitmap);
169 }
170 mOwnedBitmapResources.clear();
171
Romain Guyd586ad92011-06-22 16:14:36 -0700172 for (size_t i = 0; i < mFilterResources.size(); i++) {
173 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
174 }
175 mFilterResources.clear();
176
Romain Guy24c00212011-01-14 15:31:00 -0800177 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800178 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700179 caches.resourceCache.destructor(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800180 }
Romain Guy24c00212011-01-14 15:31:00 -0800181 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800182
183 for (size_t i = 0; i < mPaints.size(); i++) {
184 delete mPaints.itemAt(i);
185 }
186 mPaints.clear();
187
Romain Guy2fc941e2011-02-03 15:06:05 -0800188 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700189 SkPath* path = mPaths.itemAt(i);
190 caches.pathCache.remove(path);
191 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800192 }
193 mPaths.clear();
194
Chet Haased34dd712012-05-02 18:50:34 -0700195 for (size_t i = 0; i < mSourcePaths.size(); i++) {
196 caches.resourceCache.decrementRefcount(mSourcePaths.itemAt(i));
197 }
198 mSourcePaths.clear();
199
Chet Haase5977baa2011-01-05 18:01:22 -0800200 for (size_t i = 0; i < mMatrices.size(); i++) {
201 delete mMatrices.itemAt(i);
202 }
203 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800204}
205
Chet Haased63cbd12011-02-03 16:32:46 -0800206void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700207 const SkWriter32& writer = recorder.writeStream();
208 init();
209
210 if (writer.size() == 0) {
211 return;
212 }
213
Chet Haased63cbd12011-02-03 16:32:46 -0800214 if (reusing) {
215 // re-using display list - clear out previous allocations
216 clearResources();
217 }
Chet Haasea1cff502012-02-21 13:43:44 -0800218 initProperties();
Chet Haased63cbd12011-02-03 16:32:46 -0800219
Romain Guy65b345f2011-07-27 18:51:50 -0700220 mSize = writer.size();
221 void* buffer = sk_malloc_throw(mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700222 writer.flatten(buffer);
Romain Guy65b345f2011-07-27 18:51:50 -0700223 mReader.setMemory(buffer, mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700224
Chet Haase5c13d892010-10-08 08:37:55 -0700225 Caches& caches = Caches::getInstance();
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);
231 caches.resourceCache.incrementRefcount(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);
238 caches.resourceCache.incrementRefcount(resource);
239 }
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);
245 caches.resourceCache.incrementRefcount(resource);
246 }
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);
252 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700253 }
254
Romain Guy49c5fc02012-05-15 11:10:01 -0700255 const Vector<SkPaint*>& paints = recorder.getPaints();
Chet Haased98aa2d2010-10-25 15:47:32 -0700256 for (size_t i = 0; i < paints.size(); i++) {
257 mPaints.add(paints.itemAt(i));
258 }
259
Romain Guy49c5fc02012-05-15 11:10:01 -0700260 const Vector<SkPath*>& paths = recorder.getPaths();
Romain Guy2fc941e2011-02-03 15:06:05 -0800261 for (size_t i = 0; i < paths.size(); i++) {
262 mPaths.add(paths.itemAt(i));
263 }
264
Romain Guy49c5fc02012-05-15 11:10:01 -0700265 const SortedVector<SkPath*>& sourcePaths = recorder.getSourcePaths();
Chet Haased34dd712012-05-02 18:50:34 -0700266 for (size_t i = 0; i < sourcePaths.size(); i++) {
267 mSourcePaths.add(sourcePaths.itemAt(i));
268 caches.resourceCache.incrementRefcount(sourcePaths.itemAt(i));
269 }
270
Romain Guy49c5fc02012-05-15 11:10:01 -0700271 const Vector<SkMatrix*>& matrices = recorder.getMatrices();
Chet Haased98aa2d2010-10-25 15:47:32 -0700272 for (size_t i = 0; i < matrices.size(); i++) {
273 mMatrices.add(matrices.itemAt(i));
274 }
Romain Guyb051e892010-09-28 19:09:36 -0700275}
276
Romain Guyb051e892010-09-28 19:09:36 -0700277void DisplayList::init() {
Romain Guy65b345f2011-07-27 18:51:50 -0700278 mSize = 0;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700279 mIsRenderable = true;
Romain Guy65b345f2011-07-27 18:51:50 -0700280}
281
282size_t DisplayList::getSize() {
283 return mSize;
Romain Guyb051e892010-09-28 19:09:36 -0700284}
285
Chet Haaseed30fd82011-04-22 16:18:45 -0700286/**
287 * This function is a simplified version of replay(), where we simply retrieve and log the
288 * display list. This function should remain in sync with the replay() function.
289 */
290void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
291 TextContainer text;
292
293 uint32_t count = (level + 1) * 2;
294 char indent[count + 1];
295 for (uint32_t i = 0; i < count; i++) {
296 indent[i] = ' ';
297 }
298 indent[count] = '\0';
Romain Guyddf74372012-05-22 14:07:07 -0700299 ALOGD("%sStart display list (%p, %s, render=%d)", (char*) indent + 2, this,
300 mName.string(), isRenderable());
Chet Haaseed30fd82011-04-22 16:18:45 -0700301
Chet Haase1271e2c2012-04-20 09:54:27 -0700302 ALOGD("%s%s %d", indent, "Save", SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
Chet Haaseed30fd82011-04-22 16:18:45 -0700303 int saveCount = renderer.getSaveCount() - 1;
304
Chet Haasea1cff502012-02-21 13:43:44 -0800305 outputViewProperties(renderer, (char*) indent);
Chet Haaseed30fd82011-04-22 16:18:45 -0700306 mReader.rewind();
307
308 while (!mReader.eof()) {
309 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800310 if (op & OP_MAY_BE_SKIPPED_MASK) {
311 int skip = mReader.readInt();
312 ALOGD("%sSkip %d", (char*) indent, skip);
313 op &= ~OP_MAY_BE_SKIPPED_MASK;
Chet Haasea1cff502012-02-21 13:43:44 -0800314 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700315
316 switch (op) {
317 case DrawGLFunction: {
318 Functor *functor = (Functor *) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000319 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Chet Haaseed30fd82011-04-22 16:18:45 -0700320 }
321 break;
322 case Save: {
323 int rendererNum = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000324 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
Chet Haaseed30fd82011-04-22 16:18:45 -0700325 }
326 break;
327 case Restore: {
Steve Block5baa3a62011-12-20 16:23:08 +0000328 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700329 }
330 break;
331 case RestoreToCount: {
332 int restoreCount = saveCount + getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000333 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
Chet Haaseed30fd82011-04-22 16:18:45 -0700334 }
335 break;
336 case SaveLayer: {
337 float f1 = getFloat();
338 float f2 = getFloat();
339 float f3 = getFloat();
340 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800341 SkPaint* paint = getPaint(renderer);
Chet Haaseed30fd82011-04-22 16:18:45 -0700342 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000343 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800344 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
Chet Haaseed30fd82011-04-22 16:18:45 -0700345 }
346 break;
347 case SaveLayerAlpha: {
348 float f1 = getFloat();
349 float f2 = getFloat();
350 float f3 = getFloat();
351 float f4 = getFloat();
352 int alpha = getInt();
353 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000354 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800355 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
Chet Haaseed30fd82011-04-22 16:18:45 -0700356 }
357 break;
358 case Translate: {
359 float f1 = getFloat();
360 float f2 = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000361 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700362 }
363 break;
364 case Rotate: {
365 float rotation = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000366 ALOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
Chet Haaseed30fd82011-04-22 16:18:45 -0700367 }
368 break;
369 case Scale: {
370 float sx = getFloat();
371 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000372 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700373 }
374 break;
375 case Skew: {
376 float sx = getFloat();
377 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000378 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700379 }
380 break;
381 case SetMatrix: {
382 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000383 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700384 }
385 break;
386 case ConcatMatrix: {
387 SkMatrix* matrix = getMatrix();
Chet Haasea1cff502012-02-21 13:43:44 -0800388 ALOGD("%s%s new concat %p: [%f, %f, %f] [%f, %f, %f] [%f, %f, %f]",
389 (char*) indent, OP_NAMES[op], matrix, matrix->get(0), matrix->get(1),
390 matrix->get(2), matrix->get(3), matrix->get(4), matrix->get(5),
391 matrix->get(6), matrix->get(7), matrix->get(8));
Chet Haaseed30fd82011-04-22 16:18:45 -0700392 }
393 break;
394 case ClipRect: {
395 float f1 = getFloat();
396 float f2 = getFloat();
397 float f3 = getFloat();
398 float f4 = getFloat();
399 int regionOp = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000400 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800401 f1, f2, f3, f4, regionOp);
Chet Haaseed30fd82011-04-22 16:18:45 -0700402 }
403 break;
404 case DrawDisplayList: {
405 DisplayList* displayList = getDisplayList();
Romain Guy33f6beb2012-02-16 19:24:51 -0800406 int32_t flags = getInt();
407 ALOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
Chet Haase1271e2c2012-04-20 09:54:27 -0700408 displayList, mWidth, mHeight, flags, level + 1);
Chet Haaseed30fd82011-04-22 16:18:45 -0700409 renderer.outputDisplayList(displayList, level + 1);
410 }
411 break;
412 case DrawLayer: {
413 Layer* layer = (Layer*) getInt();
414 float x = getFloat();
415 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800416 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000417 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800418 layer, x, y, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700419 }
420 break;
421 case DrawBitmap: {
422 SkBitmap* bitmap = getBitmap();
423 float x = getFloat();
424 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800425 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000426 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800427 bitmap, x, y, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700428 }
429 break;
430 case DrawBitmapMatrix: {
431 SkBitmap* bitmap = getBitmap();
432 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800433 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000434 ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800435 bitmap, matrix, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700436 }
437 break;
438 case DrawBitmapRect: {
439 SkBitmap* bitmap = getBitmap();
440 float f1 = getFloat();
441 float f2 = getFloat();
442 float f3 = getFloat();
443 float f4 = getFloat();
444 float f5 = getFloat();
445 float f6 = getFloat();
446 float f7 = getFloat();
447 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800448 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000449 ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800450 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700451 }
452 break;
Romain Guye651cc62012-05-14 19:44:40 -0700453 case DrawBitmapData: {
454 SkBitmap* bitmap = getBitmapData();
455 float x = getFloat();
456 float y = getFloat();
457 SkPaint* paint = getPaint(renderer);
458 ALOGD("%s%s %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], x, y, paint);
459 }
460 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700461 case DrawBitmapMesh: {
462 int verticesCount = 0;
463 uint32_t colorsCount = 0;
464 SkBitmap* bitmap = getBitmap();
465 uint32_t meshWidth = getInt();
466 uint32_t meshHeight = getInt();
467 float* vertices = getFloats(verticesCount);
468 bool hasColors = getInt();
469 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800470 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000471 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700472 }
473 break;
474 case DrawPatch: {
475 int32_t* xDivs = NULL;
476 int32_t* yDivs = NULL;
477 uint32_t* colors = NULL;
478 uint32_t xDivsCount = 0;
479 uint32_t yDivsCount = 0;
480 int8_t numColors = 0;
481 SkBitmap* bitmap = getBitmap();
482 xDivs = getInts(xDivsCount);
483 yDivs = getInts(yDivsCount);
484 colors = getUInts(numColors);
Romain Guya62f1722011-10-19 17:06:19 -0700485 float left = getFloat();
486 float top = getFloat();
487 float right = getFloat();
488 float bottom = getFloat();
Romain Guybe6f9dc2012-07-16 12:41:17 -0700489 int alpha = getInt();
490 SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000491 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
Romain Guya62f1722011-10-19 17:06:19 -0700492 left, top, right, bottom);
Chet Haaseed30fd82011-04-22 16:18:45 -0700493 }
494 break;
495 case DrawColor: {
496 int color = getInt();
497 int xferMode = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000498 ALOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haaseed30fd82011-04-22 16:18:45 -0700499 }
500 break;
501 case DrawRect: {
502 float f1 = getFloat();
503 float f2 = getFloat();
504 float f3 = getFloat();
505 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800506 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000507 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800508 f1, f2, f3, f4, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700509 }
510 break;
511 case DrawRoundRect: {
512 float f1 = getFloat();
513 float f2 = getFloat();
514 float f3 = getFloat();
515 float f4 = getFloat();
516 float f5 = getFloat();
517 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800518 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000519 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800520 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700521 }
522 break;
523 case DrawCircle: {
524 float f1 = getFloat();
525 float f2 = getFloat();
526 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800527 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000528 ALOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800529 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700530 }
531 break;
532 case DrawOval: {
533 float f1 = getFloat();
534 float f2 = getFloat();
535 float f3 = getFloat();
536 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800537 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000538 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800539 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700540 }
541 break;
542 case DrawArc: {
543 float f1 = getFloat();
544 float f2 = getFloat();
545 float f3 = getFloat();
546 float f4 = getFloat();
547 float f5 = getFloat();
548 float f6 = getFloat();
549 int i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800550 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000551 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haasea1cff502012-02-21 13:43:44 -0800552 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700553 }
554 break;
555 case DrawPath: {
556 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800557 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000558 ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700559 }
560 break;
561 case DrawLines: {
562 int count = 0;
563 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800564 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000565 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700566 }
567 break;
568 case DrawPoints: {
569 int count = 0;
570 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800571 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000572 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700573 }
574 break;
575 case DrawText: {
576 getText(&text);
Romain Guy325740f2012-02-24 16:48:34 -0800577 int32_t count = getInt();
Chet Haaseed30fd82011-04-22 16:18:45 -0700578 float x = getFloat();
579 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800580 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -0800581 float length = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000582 ALOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800583 text.text(), text.length(), count, x, y, paint, length);
Chet Haaseed30fd82011-04-22 16:18:45 -0700584 }
585 break;
Romain Guy325740f2012-02-24 16:48:34 -0800586 case DrawTextOnPath: {
587 getText(&text);
588 int32_t count = getInt();
589 SkPath* path = getPath();
590 float hOffset = getFloat();
591 float vOffset = getFloat();
592 SkPaint* paint = getPaint(renderer);
593 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
594 text.text(), text.length(), count, paint);
595 }
596 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800597 case DrawPosText: {
598 getText(&text);
599 int count = getInt();
600 int positionsCount = 0;
601 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800602 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800603 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800604 text.text(), text.length(), count, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -0800605 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700606 case ResetShader: {
Steve Block5baa3a62011-12-20 16:23:08 +0000607 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700608 }
609 break;
610 case SetupShader: {
611 SkiaShader* shader = getShader();
Steve Block5baa3a62011-12-20 16:23:08 +0000612 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
Chet Haaseed30fd82011-04-22 16:18:45 -0700613 }
614 break;
615 case ResetColorFilter: {
Steve Block5baa3a62011-12-20 16:23:08 +0000616 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700617 }
618 break;
619 case SetupColorFilter: {
620 SkiaColorFilter *colorFilter = getColorFilter();
Steve Block5baa3a62011-12-20 16:23:08 +0000621 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
Chet Haaseed30fd82011-04-22 16:18:45 -0700622 }
623 break;
624 case ResetShadow: {
Steve Block5baa3a62011-12-20 16:23:08 +0000625 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700626 }
627 break;
628 case SetupShadow: {
629 float radius = getFloat();
630 float dx = getFloat();
631 float dy = getFloat();
632 int color = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000633 ALOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800634 radius, dx, dy, color);
Chet Haaseed30fd82011-04-22 16:18:45 -0700635 }
636 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800637 case ResetPaintFilter: {
638 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
639 }
640 break;
641 case SetupPaintFilter: {
642 int clearBits = getInt();
643 int setBits = getInt();
644 ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
645 }
646 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700647 default:
Steve Block5baa3a62011-12-20 16:23:08 +0000648 ALOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -0800649 (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700650 break;
651 }
652 }
Chet Haasea1cff502012-02-21 13:43:44 -0800653 ALOGD("%sDone (%p, %s)", (char*) indent + 2, this, mName.string());
Chet Haaseed30fd82011-04-22 16:18:45 -0700654}
655
Chet Haasea1cff502012-02-21 13:43:44 -0800656void DisplayList::updateMatrix() {
657 if (mMatrixDirty) {
658 if (!mTransformMatrix) {
659 mTransformMatrix = new SkMatrix();
660 }
661 if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) {
662 mTransformMatrix->reset();
663 } else {
664 if (!mPivotExplicitlySet) {
665 if (mWidth != mPrevWidth || mHeight != mPrevHeight) {
666 mPrevWidth = mWidth;
667 mPrevHeight = mHeight;
668 mPivotX = mPrevWidth / 2;
669 mPivotY = mPrevHeight / 2;
670 }
671 }
672 if ((mMatrixFlags & ROTATION_3D) == 0) {
673 mTransformMatrix->setTranslate(mTranslationX, mTranslationY);
674 mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY);
675 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
676 } else {
677 if (!mTransformCamera) {
678 mTransformCamera = new Sk3DView();
679 mTransformMatrix3D = new SkMatrix();
680 }
681 mTransformMatrix->reset();
682 mTransformCamera->save();
683 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
684 mTransformCamera->rotateX(mRotationX);
685 mTransformCamera->rotateY(mRotationY);
686 mTransformCamera->rotateZ(-mRotation);
687 mTransformCamera->getMatrix(mTransformMatrix3D);
688 mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY);
689 mTransformMatrix3D->postTranslate(mPivotX + mTranslationX,
690 mPivotY + mTranslationY);
691 mTransformMatrix->postConcat(*mTransformMatrix3D);
692 mTransformCamera->restore();
693 }
694 }
695 mMatrixDirty = false;
696 }
697}
698
699void DisplayList::outputViewProperties(OpenGLRenderer& renderer, char* indent) {
Chet Haase1271e2c2012-04-20 09:54:27 -0700700 updateMatrix();
701 if (mLeft != 0 || mTop != 0) {
702 ALOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
703 }
704 if (mStaticMatrix) {
705 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
706 indent, "ConcatMatrix (static)", mStaticMatrix,
707 mStaticMatrix->get(0), mStaticMatrix->get(1),
708 mStaticMatrix->get(2), mStaticMatrix->get(3),
709 mStaticMatrix->get(4), mStaticMatrix->get(5),
710 mStaticMatrix->get(6), mStaticMatrix->get(7),
711 mStaticMatrix->get(8));
712 }
713 if (mAnimationMatrix) {
714 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
715 indent, "ConcatMatrix (animation)", mAnimationMatrix,
716 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
717 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
718 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
719 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
720 mAnimationMatrix->get(8));
721 }
722 if (mMatrixFlags != 0) {
723 if (mMatrixFlags == TRANSLATION) {
724 ALOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
725 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700726 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700727 indent, "ConcatMatrix", mTransformMatrix,
728 mTransformMatrix->get(0), mTransformMatrix->get(1),
729 mTransformMatrix->get(2), mTransformMatrix->get(3),
730 mTransformMatrix->get(4), mTransformMatrix->get(5),
731 mTransformMatrix->get(6), mTransformMatrix->get(7),
732 mTransformMatrix->get(8));
Chet Haase9420abd2012-03-29 16:28:32 -0700733 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700734 }
735 if (mAlpha < 1 && !mCaching) {
736 // TODO: should be able to store the size of a DL at record time and not
737 // have to pass it into this call. In fact, this information might be in the
738 // location/size info that we store with the new native transform data.
739 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800740 if (mClipChildren) {
Chet Haase1271e2c2012-04-20 09:54:27 -0700741 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800742 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700743 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
744 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
745 mMultipliedAlpha, flags);
746 }
747 if (mClipChildren) {
748 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
749 (float) mRight - mLeft, (float) mBottom - mTop);
Chet Haasea1cff502012-02-21 13:43:44 -0800750 }
751}
752
Chet Haase1271e2c2012-04-20 09:54:27 -0700753void DisplayList::setViewProperties(OpenGLRenderer& renderer, uint32_t level) {
Chet Haasea1cff502012-02-21 13:43:44 -0800754#if DEBUG_DISPLAY_LIST
755 uint32_t count = (level + 1) * 2;
756 char indent[count + 1];
757 for (uint32_t i = 0; i < count; i++) {
758 indent[i] = ' ';
759 }
760 indent[count] = '\0';
761#endif
Chet Haase1271e2c2012-04-20 09:54:27 -0700762 updateMatrix();
763 if (mLeft != 0 || mTop != 0) {
764 DISPLAY_LIST_LOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
765 renderer.translate(mLeft, mTop);
766 }
767 if (mStaticMatrix) {
768 DISPLAY_LIST_LOGD(
769 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
770 indent, "ConcatMatrix (static)", mStaticMatrix,
771 mStaticMatrix->get(0), mStaticMatrix->get(1),
772 mStaticMatrix->get(2), mStaticMatrix->get(3),
773 mStaticMatrix->get(4), mStaticMatrix->get(5),
774 mStaticMatrix->get(6), mStaticMatrix->get(7),
775 mStaticMatrix->get(8));
776 renderer.concatMatrix(mStaticMatrix);
777 } else if (mAnimationMatrix) {
778 DISPLAY_LIST_LOGD(
779 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
780 indent, "ConcatMatrix (animation)", mAnimationMatrix,
781 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
782 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
783 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
784 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
785 mAnimationMatrix->get(8));
786 renderer.concatMatrix(mAnimationMatrix);
787 }
788 if (mMatrixFlags != 0) {
789 if (mMatrixFlags == TRANSLATION) {
790 DISPLAY_LIST_LOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
791 renderer.translate(mTranslationX, mTranslationY);
792 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700793 DISPLAY_LIST_LOGD(
794 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700795 indent, "ConcatMatrix", mTransformMatrix,
796 mTransformMatrix->get(0), mTransformMatrix->get(1),
797 mTransformMatrix->get(2), mTransformMatrix->get(3),
798 mTransformMatrix->get(4), mTransformMatrix->get(5),
799 mTransformMatrix->get(6), mTransformMatrix->get(7),
800 mTransformMatrix->get(8));
801 renderer.concatMatrix(mTransformMatrix);
Chet Haasea1cff502012-02-21 13:43:44 -0800802 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700803 }
804 if (mAlpha < 1 && !mCaching) {
805 if (!mHasOverlappingRendering) {
806 DISPLAY_LIST_LOGD("%s%s %.2f", indent, "SetAlpha", mAlpha);
807 renderer.setAlpha(mAlpha);
808 } else {
809 // TODO: should be able to store the size of a DL at record time and not
810 // have to pass it into this call. In fact, this information might be in the
811 // location/size info that we store with the new native transform data.
812 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
813 if (mClipChildren) {
814 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800815 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700816 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
817 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
818 mMultipliedAlpha, flags);
819 renderer.saveLayerAlpha(0, 0, mRight - mLeft, mBottom - mTop,
820 mMultipliedAlpha, flags);
Chet Haasea1cff502012-02-21 13:43:44 -0800821 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700822 }
823 if (mClipChildren) {
824 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
825 (float) mRight - mLeft, (float) mBottom - mTop);
826 renderer.clipRect(0, 0, mRight - mLeft, mBottom - mTop,
827 SkRegion::kIntersect_Op);
Chet Haasea1cff502012-02-21 13:43:44 -0800828 }
829}
830
Chet Haaseed30fd82011-04-22 16:18:45 -0700831/**
832 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
833 * in the output() function, since that function processes the same list of opcodes for the
834 * purposes of logging display list info for a given view.
835 */
Chet Haase1271e2c2012-04-20 09:54:27 -0700836status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level) {
Chet Haase48659092012-05-31 15:21:51 -0700837 status_t drawGlStatus = DrawGlInfo::kStatusDone;
Romain Guyb051e892010-09-28 19:09:36 -0700838 TextContainer text;
839 mReader.rewind();
840
Romain Guyffac7fc2011-01-13 17:21:49 -0800841#if DEBUG_DISPLAY_LIST
842 uint32_t count = (level + 1) * 2;
843 char indent[count + 1];
844 for (uint32_t i = 0; i < count; i++) {
845 indent[i] = ' ';
846 }
847 indent[count] = '\0';
Chet Haasea23eed82012-04-12 15:19:04 -0700848 Rect* clipRect = renderer.getClipRect();
849 DISPLAY_LIST_LOGD("%sStart display list (%p, %s), clipRect: %.0f, %.f, %.0f, %.0f",
850 (char*) indent + 2, this, mName.string(), clipRect->left, clipRect->top,
851 clipRect->right, clipRect->bottom);
Romain Guyffac7fc2011-01-13 17:21:49 -0800852#endif
Romain Guyb051e892010-09-28 19:09:36 -0700853
Romain Guy13631f32012-01-30 17:41:55 -0800854 renderer.startMark(mName.string());
Romain Guy8a4ac612012-07-17 17:32:48 -0700855
Chet Haase1271e2c2012-04-20 09:54:27 -0700856 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
857 DISPLAY_LIST_LOGD("%s%s %d %d", indent, "Save",
858 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
859 setViewProperties(renderer, level);
Romain Guy8a4ac612012-07-17 17:32:48 -0700860
861 if (renderer.quickRejectNoScissor(0, 0, mWidth, mHeight)) {
Chet Haaseb85967b2012-03-26 14:37:51 -0700862 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
863 renderer.restoreToCount(restoreTo);
864 renderer.endMark();
Chet Haase48659092012-05-31 15:21:51 -0700865 return drawGlStatus;
Chet Haaseb85967b2012-03-26 14:37:51 -0700866 }
Romain Guy13631f32012-01-30 17:41:55 -0800867
Chet Haase9c1e23b2011-03-24 10:51:31 -0700868 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800869 int saveCount = renderer.getSaveCount() - 1;
Romain Guy8a4ac612012-07-17 17:32:48 -0700870
Romain Guyb051e892010-09-28 19:09:36 -0700871 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700872 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800873 if (op & OP_MAY_BE_SKIPPED_MASK) {
Romain Guy390f8822012-03-13 18:00:10 -0700874 int32_t skip = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800875 if (CC_LIKELY(flags & kReplayFlag_ClipChildren)) {
876 mReader.skip(skip);
877 DISPLAY_LIST_LOGD("%s%s skipping %d bytes", (char*) indent,
878 OP_NAMES[op & ~OP_MAY_BE_SKIPPED_MASK], skip);
879 continue;
880 } else {
881 op &= ~OP_MAY_BE_SKIPPED_MASK;
Romain Guy33f6beb2012-02-16 19:24:51 -0800882 }
883 }
Chet Haase9c1e23b2011-03-24 10:51:31 -0700884 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800885
Romain Guy8a4ac612012-07-17 17:32:48 -0700886#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
887 Caches::getInstance().eventMark(strlen(OP_NAMES[op]), OP_NAMES[op]);
888#endif
889
Romain Guy5b3b3522010-10-27 18:57:51 -0700890 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800891 case DrawGLFunction: {
892 Functor *functor = (Functor *) getInt();
893 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guy13631f32012-01-30 17:41:55 -0800894 renderer.startMark("GL functor");
Romain Guy65549432012-03-26 16:45:05 -0700895 drawGlStatus |= renderer.callDrawGLFunction(functor, dirty);
Romain Guy13631f32012-01-30 17:41:55 -0800896 renderer.endMark();
Chet Haasedaf98e92011-01-10 14:10:36 -0800897 }
898 break;
Romain Guyb051e892010-09-28 19:09:36 -0700899 case Save: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800900 int32_t rendererNum = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800901 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
902 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700903 }
904 break;
905 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800906 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700907 renderer.restore();
908 }
909 break;
910 case RestoreToCount: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800911 int32_t restoreCount = saveCount + getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800912 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
913 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700914 }
915 break;
916 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800917 float f1 = getFloat();
918 float f2 = getFloat();
919 float f3 = getFloat();
920 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800921 SkPaint* paint = getPaint(renderer);
Romain Guy33f6beb2012-02-16 19:24:51 -0800922 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800923 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800924 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800925 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700926 }
927 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700928 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800929 float f1 = getFloat();
930 float f2 = getFloat();
931 float f3 = getFloat();
932 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800933 int32_t alpha = getInt();
934 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800935 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800936 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800937 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700938 }
939 break;
Romain Guyb051e892010-09-28 19:09:36 -0700940 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800941 float f1 = getFloat();
942 float f2 = getFloat();
943 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
944 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700945 }
946 break;
947 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800948 float rotation = getFloat();
949 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
950 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700951 }
952 break;
953 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800954 float sx = getFloat();
955 float sy = getFloat();
956 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
957 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700958 }
959 break;
Romain Guy807daf72011-01-18 11:19:19 -0800960 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800961 float sx = getFloat();
962 float sy = getFloat();
963 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
964 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800965 }
966 break;
Romain Guyb051e892010-09-28 19:09:36 -0700967 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800968 SkMatrix* matrix = getMatrix();
969 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
970 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700971 }
972 break;
973 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800974 SkMatrix* matrix = getMatrix();
Chet Haasea1cff502012-02-21 13:43:44 -0800975 DISPLAY_LIST_LOGD(
976 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
977 (char*) indent, OP_NAMES[op], matrix,
978 matrix->get(0), matrix->get(1), matrix->get(2),
979 matrix->get(3), matrix->get(4), matrix->get(5),
980 matrix->get(6), matrix->get(7), matrix->get(8));
Chet Haasedaf98e92011-01-10 14:10:36 -0800981 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700982 }
983 break;
984 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800985 float f1 = getFloat();
986 float f2 = getFloat();
987 float f3 = getFloat();
988 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800989 int32_t regionOp = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800990 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800991 f1, f2, f3, f4, regionOp);
Chet Haasedaf98e92011-01-10 14:10:36 -0800992 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700993 }
994 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800995 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800996 DisplayList* displayList = getDisplayList();
Romain Guy33f6beb2012-02-16 19:24:51 -0800997 int32_t flags = getInt();
998 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
Chet Haase1271e2c2012-04-20 09:54:27 -0700999 displayList, mWidth, mHeight, flags, level + 1);
1000 drawGlStatus |= renderer.drawDisplayList(displayList, dirty, flags, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -08001001 }
1002 break;
Romain Guy6c319ca2011-01-11 14:29:25 -08001003 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001004 Layer* layer = (Layer*) getInt();
1005 float x = getFloat();
1006 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001007 SkPaint* paint = getPaint(renderer);
Chet Haase6f9ad202012-05-01 10:05:13 -07001008 if (mCaching) {
Chet Haasea1cff502012-02-21 13:43:44 -08001009 paint->setAlpha(mMultipliedAlpha);
1010 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001011 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001012 layer, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001013 drawGlStatus |= renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -08001014 }
1015 break;
Romain Guyb051e892010-09-28 19:09:36 -07001016 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001017 SkBitmap* bitmap = getBitmap();
1018 float x = getFloat();
1019 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001020 SkPaint* paint = getPaint(renderer);
Chet Haase6f9ad202012-05-01 10:05:13 -07001021 if (mCaching) {
Chet Haaseb85967b2012-03-26 14:37:51 -07001022 paint->setAlpha(mMultipliedAlpha);
1023 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001024 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001025 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001026 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001027 }
1028 break;
1029 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001030 SkBitmap* bitmap = getBitmap();
1031 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -08001032 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001033 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001034 bitmap, matrix, paint);
Chet Haase48659092012-05-31 15:21:51 -07001035 drawGlStatus |= renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001036 }
1037 break;
1038 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001039 SkBitmap* bitmap = getBitmap();
1040 float f1 = getFloat();
1041 float f2 = getFloat();
1042 float f3 = getFloat();
1043 float f4 = getFloat();
1044 float f5 = getFloat();
1045 float f6 = getFloat();
1046 float f7 = getFloat();
1047 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001048 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001049 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001050 (char*) indent, OP_NAMES[op], bitmap,
1051 f1, f2, f3, f4, f5, f6, f7, f8,paint);
Chet Haase48659092012-05-31 15:21:51 -07001052 drawGlStatus |= renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001053 }
1054 break;
Romain Guye651cc62012-05-14 19:44:40 -07001055 case DrawBitmapData: {
1056 SkBitmap* bitmap = getBitmapData();
1057 float x = getFloat();
1058 float y = getFloat();
1059 SkPaint* paint = getPaint(renderer);
1060 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
1061 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001062 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Romain Guye651cc62012-05-14 19:44:40 -07001063 }
1064 break;
Romain Guy5a7b4662011-01-20 19:09:30 -08001065 case DrawBitmapMesh: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001066 int32_t verticesCount = 0;
Romain Guy5a7b4662011-01-20 19:09:30 -08001067 uint32_t colorsCount = 0;
1068
1069 SkBitmap* bitmap = getBitmap();
1070 uint32_t meshWidth = getInt();
1071 uint32_t meshHeight = getInt();
1072 float* vertices = getFloats(verticesCount);
1073 bool hasColors = getInt();
Romain Guy33f6beb2012-02-16 19:24:51 -08001074 int32_t* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -08001075 SkPaint* paint = getPaint(renderer);
Romain Guy5a7b4662011-01-20 19:09:30 -08001076
Chet Haasedaf98e92011-01-10 14:10:36 -08001077 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001078 drawGlStatus |= renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices,
1079 colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -08001080 }
Romain Guya566b7c2011-01-23 16:36:11 -08001081 break;
Romain Guyb051e892010-09-28 19:09:36 -07001082 case DrawPatch: {
1083 int32_t* xDivs = NULL;
1084 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -07001085 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -07001086 uint32_t xDivsCount = 0;
1087 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -07001088 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001089
1090 SkBitmap* bitmap = getBitmap();
1091
1092 xDivs = getInts(xDivsCount);
1093 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -07001094 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -07001095
Romain Guy9ff3cb52011-06-28 14:02:11 -07001096 float left = getFloat();
1097 float top = getFloat();
1098 float right = getFloat();
1099 float bottom = getFloat();
Romain Guybe6f9dc2012-07-16 12:41:17 -07001100
1101 int alpha = getInt();
1102 SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
Romain Guy9ff3cb52011-06-28 14:02:11 -07001103
Chet Haasedaf98e92011-01-10 14:10:36 -08001104 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001105 drawGlStatus |= renderer.drawPatch(bitmap, xDivs, yDivs, colors,
Romain Guybe6f9dc2012-07-16 12:41:17 -07001106 xDivsCount, yDivsCount, numColors, left, top, right, bottom,
1107 alpha, mode);
Romain Guyb051e892010-09-28 19:09:36 -07001108 }
1109 break;
1110 case DrawColor: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001111 int32_t color = getInt();
1112 int32_t xferMode = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001113 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haase48659092012-05-31 15:21:51 -07001114 drawGlStatus |= renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -07001115 }
1116 break;
1117 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001118 float f1 = getFloat();
1119 float f2 = getFloat();
1120 float f3 = getFloat();
1121 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001122 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001123 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001124 f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001125 drawGlStatus |= renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001126 }
1127 break;
Romain Guy01d58e42011-01-19 21:54:02 -08001128 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001129 float f1 = getFloat();
1130 float f2 = getFloat();
1131 float f3 = getFloat();
1132 float f4 = getFloat();
1133 float f5 = getFloat();
1134 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001135 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001136 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001137 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
Chet Haase48659092012-05-31 15:21:51 -07001138 drawGlStatus |= renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001139 }
1140 break;
1141 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001142 float f1 = getFloat();
1143 float f2 = getFloat();
1144 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001145 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001146 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001147 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
Chet Haase48659092012-05-31 15:21:51 -07001148 drawGlStatus |= renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001149 }
1150 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001151 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001152 float f1 = getFloat();
1153 float f2 = getFloat();
1154 float f3 = getFloat();
1155 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001156 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001157 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001158 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001159 drawGlStatus |= renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001160 }
1161 break;
Romain Guy8b2f5262011-01-23 16:15:02 -08001162 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001163 float f1 = getFloat();
1164 float f2 = getFloat();
1165 float f3 = getFloat();
1166 float f4 = getFloat();
1167 float f5 = getFloat();
1168 float f6 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001169 int32_t i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001170 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001171 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001172 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
Chet Haase48659092012-05-31 15:21:51 -07001173 drawGlStatus |= renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -08001174 }
1175 break;
Romain Guyb051e892010-09-28 19:09:36 -07001176 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001177 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -08001178 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001179 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haase48659092012-05-31 15:21:51 -07001180 drawGlStatus |= renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001181 }
1182 break;
1183 case DrawLines: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001184 int32_t count = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001185 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001186 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001187 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001188 drawGlStatus |= renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001189 }
1190 break;
Romain Guyed6fcb02011-03-21 13:11:28 -07001191 case DrawPoints: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001192 int32_t count = 0;
Romain Guyed6fcb02011-03-21 13:11:28 -07001193 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001194 SkPaint* paint = getPaint(renderer);
Romain Guyed6fcb02011-03-21 13:11:28 -07001195 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001196 drawGlStatus |= renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -07001197 }
1198 break;
Romain Guyb051e892010-09-28 19:09:36 -07001199 case DrawText: {
1200 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -08001201 int32_t count = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001202 float x = getFloat();
1203 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001204 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -08001205 float length = getFloat();
1206 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
1207 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
Chet Haase48659092012-05-31 15:21:51 -07001208 drawGlStatus |= renderer.drawText(text.text(), text.length(), count, x, y,
1209 paint, length);
Romain Guyb051e892010-09-28 19:09:36 -07001210 }
1211 break;
Romain Guy325740f2012-02-24 16:48:34 -08001212 case DrawTextOnPath: {
1213 getText(&text);
1214 int32_t count = getInt();
1215 SkPath* path = getPath();
1216 float hOffset = getFloat();
1217 float vOffset = getFloat();
1218 SkPaint* paint = getPaint(renderer);
1219 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
1220 text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001221 drawGlStatus |= renderer.drawTextOnPath(text.text(), text.length(), count, path,
Romain Guy325740f2012-02-24 16:48:34 -08001222 hOffset, vOffset, paint);
1223 }
1224 break;
Romain Guyeb9a5362012-01-17 17:39:26 -08001225 case DrawPosText: {
1226 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -08001227 int32_t count = getInt();
1228 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -08001229 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -08001230 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -08001231 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
1232 OP_NAMES[op], text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001233 drawGlStatus |= renderer.drawPosText(text.text(), text.length(), count,
1234 positions, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -08001235 }
1236 break;
Romain Guyb051e892010-09-28 19:09:36 -07001237 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001238 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001239 renderer.resetShader();
1240 }
1241 break;
1242 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001243 SkiaShader* shader = getShader();
1244 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
1245 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -07001246 }
1247 break;
1248 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001249 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001250 renderer.resetColorFilter();
1251 }
1252 break;
1253 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001254 SkiaColorFilter *colorFilter = getColorFilter();
1255 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
1256 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -07001257 }
1258 break;
1259 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001260 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001261 renderer.resetShadow();
1262 }
1263 break;
1264 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001265 float radius = getFloat();
1266 float dx = getFloat();
1267 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001268 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001269 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001270 radius, dx, dy, color);
Chet Haasedaf98e92011-01-10 14:10:36 -08001271 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -07001272 }
1273 break;
Romain Guy5ff9df62012-01-23 17:09:05 -08001274 case ResetPaintFilter: {
1275 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
1276 renderer.resetPaintFilter();
1277 }
1278 break;
1279 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001280 int32_t clearBits = getInt();
1281 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001282 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
1283 clearBits, setBits);
1284 renderer.setupPaintFilter(clearBits, setBits);
1285 }
1286 break;
Chet Haasedaf98e92011-01-10 14:10:36 -08001287 default:
1288 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -08001289 (char*) indent, OP_NAMES[op]);
Chet Haasedaf98e92011-01-10 14:10:36 -08001290 break;
Romain Guyb051e892010-09-28 19:09:36 -07001291 }
1292 }
Romain Guyffac7fc2011-01-13 17:21:49 -08001293
Chet Haase1271e2c2012-04-20 09:54:27 -07001294 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
1295 renderer.restoreToCount(restoreTo);
Romain Guy13631f32012-01-30 17:41:55 -08001296 renderer.endMark();
1297
Chet Haasea1cff502012-02-21 13:43:44 -08001298 DISPLAY_LIST_LOGD("%sDone (%p, %s), returning %d", (char*) indent + 2, this, mName.string(),
Romain Guy65549432012-03-26 16:45:05 -07001299 drawGlStatus);
1300 return drawGlStatus;
Romain Guyb051e892010-09-28 19:09:36 -07001301}
1302
1303///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -07001304// Base structure
1305///////////////////////////////////////////////////////////////////////////////
1306
Chet Haasea1cff502012-02-21 13:43:44 -08001307DisplayListRenderer::DisplayListRenderer() : mWriter(MIN_WRITER_SIZE),
Romain Guy33f6beb2012-02-16 19:24:51 -08001308 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -07001309}
1310
1311DisplayListRenderer::~DisplayListRenderer() {
1312 reset();
1313}
1314
1315void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -07001316 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -07001317
1318 Caches& caches = Caches::getInstance();
1319 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001320 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -07001321 }
1322 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -07001323
Romain Guy49c5fc02012-05-15 11:10:01 -07001324 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
1325 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
1326 caches.resourceCache.decrementRefcount(bitmap);
1327 }
1328 mOwnedBitmapResources.clear();
1329
Romain Guyd586ad92011-06-22 16:14:36 -07001330 for (size_t i = 0; i < mFilterResources.size(); i++) {
1331 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
1332 }
1333 mFilterResources.clear();
1334
Romain Guy43ccf462011-01-14 18:51:01 -08001335 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001336 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -08001337 }
Romain Guy24c00212011-01-14 15:31:00 -08001338 mShaders.clear();
1339 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -08001340
Chet Haased34dd712012-05-02 18:50:34 -07001341 for (size_t i = 0; i < mSourcePaths.size(); i++) {
1342 caches.resourceCache.decrementRefcount(mSourcePaths.itemAt(i));
1343 }
1344 mSourcePaths.clear();
1345
Romain Guy43ccf462011-01-14 18:51:01 -08001346 mPaints.clear();
1347 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001348
Romain Guy2fc941e2011-02-03 15:06:05 -08001349 mPaths.clear();
1350 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001351
Chet Haased98aa2d2010-10-25 15:47:32 -07001352 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001353
1354 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -07001355}
1356
1357///////////////////////////////////////////////////////////////////////////////
1358// Operations
1359///////////////////////////////////////////////////////////////////////////////
1360
Jeff Brown162a0212011-07-21 17:02:54 -07001361DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1362 if (!displayList) {
1363 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001364 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001365 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001366 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001367 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001368 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001369}
1370
Romain Guy49c5fc02012-05-15 11:10:01 -07001371bool DisplayListRenderer::isDeferred() {
1372 return true;
1373}
1374
Romain Guyb051e892010-09-28 19:09:36 -07001375void DisplayListRenderer::setViewport(int width, int height) {
1376 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1377
1378 mWidth = width;
1379 mHeight = height;
1380}
1381
Chet Haase44b2fe32012-06-06 19:03:58 -07001382int DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -08001383 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001384 mSnapshot = new Snapshot(mFirstSnapshot,
1385 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1386 mSaveCount = 1;
1387 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -08001388 mRestoreSaveCount = -1;
Chet Haase44b2fe32012-06-06 19:03:58 -07001389 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -08001390}
1391
1392void DisplayListRenderer::finish() {
1393 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001394 insertTranlate();
Romain Guyb051e892010-09-28 19:09:36 -07001395}
1396
Chet Haasedaf98e92011-01-10 14:10:36 -08001397void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001398}
Romain Guy2b1847e2011-01-26 13:43:01 -08001399
Chet Haasedaf98e92011-01-10 14:10:36 -08001400void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001401}
1402
Romain Guy65549432012-03-26 16:45:05 -07001403status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -08001404 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001405 addOp(DisplayList::DrawGLFunction);
1406 addInt((int) functor);
Romain Guy65549432012-03-26 16:45:05 -07001407 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -08001408}
1409
Romain Guy4aa90572010-09-26 18:40:37 -07001410int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001411 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001412 addInt(flags);
1413 return OpenGLRenderer::save(flags);
1414}
1415
1416void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001417 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001418 restoreToCount(getSaveCount() - 1);
1419 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001420 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001421
1422 mRestoreSaveCount--;
1423 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001424 OpenGLRenderer::restore();
1425}
1426
1427void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001428 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001429 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001430 OpenGLRenderer::restoreToCount(saveCount);
1431}
1432
1433int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001434 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001435 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001436 addBounds(left, top, right, bottom);
1437 addPaint(p);
1438 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001439 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001440}
1441
Romain Guy5b3b3522010-10-27 18:57:51 -07001442int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1443 int alpha, int flags) {
1444 addOp(DisplayList::SaveLayerAlpha);
1445 addBounds(left, top, right, bottom);
1446 addInt(alpha);
1447 addInt(flags);
1448 return OpenGLRenderer::save(flags);
1449}
1450
Romain Guy4aa90572010-09-26 18:40:37 -07001451void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001452 mHasTranslate = true;
1453 mTranslateX += dx;
1454 mTranslateY += dy;
1455 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001456 OpenGLRenderer::translate(dx, dy);
1457}
1458
1459void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001460 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001461 addFloat(degrees);
1462 OpenGLRenderer::rotate(degrees);
1463}
1464
1465void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001466 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001467 addPoint(sx, sy);
1468 OpenGLRenderer::scale(sx, sy);
1469}
1470
Romain Guy807daf72011-01-18 11:19:19 -08001471void DisplayListRenderer::skew(float sx, float sy) {
1472 addOp(DisplayList::Skew);
1473 addPoint(sx, sy);
1474 OpenGLRenderer::skew(sx, sy);
1475}
1476
Romain Guy4aa90572010-09-26 18:40:37 -07001477void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001478 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001479 addMatrix(matrix);
1480 OpenGLRenderer::setMatrix(matrix);
1481}
1482
1483void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001484 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001485 addMatrix(matrix);
1486 OpenGLRenderer::concatMatrix(matrix);
1487}
1488
1489bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1490 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001491 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001492 addBounds(left, top, right, bottom);
1493 addInt(op);
1494 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1495}
1496
Romain Guy65549432012-03-26 16:45:05 -07001497status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chet Haase1271e2c2012-04-20 09:54:27 -07001498 Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001499 // dirty is an out parameter and should not be recorded,
1500 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -07001501
1502 addOp(DisplayList::DrawDisplayList);
Romain Guy0fe478e2010-11-08 12:08:41 -08001503 addDisplayList(displayList);
Romain Guy33f6beb2012-02-16 19:24:51 -08001504 addInt(flags);
Romain Guy65549432012-03-26 16:45:05 -07001505 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -08001506}
1507
Chet Haase48659092012-05-31 15:21:51 -07001508status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001509 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001510 addInt((int) layer);
1511 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001512 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001513 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -08001514}
1515
Chet Haase48659092012-05-31 15:21:51 -07001516status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001517 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
1518 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001519 addBitmap(bitmap);
1520 addPoint(left, top);
1521 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001522 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001523 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001524}
1525
Chet Haase48659092012-05-31 15:21:51 -07001526status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001527 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1528 const mat4 transform(*matrix);
1529 transform.mapRect(r);
1530
1531 const bool reject = quickReject(r.left, r.top, r.right, r.bottom);
1532 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001533 addBitmap(bitmap);
1534 addMatrix(matrix);
1535 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001536 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001537 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001538}
1539
Chet Haase48659092012-05-31 15:21:51 -07001540status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -07001541 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001542 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001543 const bool reject = quickReject(dstLeft, dstTop, dstRight, dstBottom);
1544 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001545 addBitmap(bitmap);
1546 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1547 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1548 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001549 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001550 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001551}
1552
Chet Haase48659092012-05-31 15:21:51 -07001553status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
1554 SkPaint* paint) {
Romain Guy95c21d02012-07-17 17:46:03 -07001555 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
Romain Guye651cc62012-05-14 19:44:40 -07001556 uint32_t* location = addOp(DisplayList::DrawBitmapData, reject);
1557 addBitmapData(bitmap);
1558 addPoint(left, top);
1559 addPaint(paint);
1560 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001561 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -07001562}
1563
Chet Haase48659092012-05-31 15:21:51 -07001564status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -08001565 float* vertices, int* colors, SkPaint* paint) {
1566 addOp(DisplayList::DrawBitmapMesh);
1567 addBitmap(bitmap);
1568 addInt(meshWidth);
1569 addInt(meshHeight);
1570 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1571 if (colors) {
1572 addInt(1);
1573 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1574 } else {
1575 addInt(0);
1576 }
1577 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001578 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -08001579}
1580
Chet Haase48659092012-05-31 15:21:51 -07001581status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
1582 const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height,
1583 int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guybe6f9dc2012-07-16 12:41:17 -07001584 int alpha;
1585 SkXfermode::Mode mode;
1586 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
1587
Romain Guy33f6beb2012-02-16 19:24:51 -08001588 const bool reject = quickReject(left, top, right, bottom);
1589 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001590 addBitmap(bitmap);
1591 addInts(xDivs, width);
1592 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001593 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001594 addBounds(left, top, right, bottom);
Romain Guybe6f9dc2012-07-16 12:41:17 -07001595 addInt(alpha);
1596 addInt(mode);
Romain Guy33f6beb2012-02-16 19:24:51 -08001597 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001598 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001599}
1600
Chet Haase48659092012-05-31 15:21:51 -07001601status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001602 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001603 addInt(color);
1604 addInt(mode);
Chet Haase48659092012-05-31 15:21:51 -07001605 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001606}
1607
Chet Haase48659092012-05-31 15:21:51 -07001608status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001609 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001610 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1611 quickReject(left, top, right, bottom);
1612 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001613 addBounds(left, top, right, bottom);
1614 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001615 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001616 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001617}
1618
Chet Haase48659092012-05-31 15:21:51 -07001619status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -08001620 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001621 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1622 quickReject(left, top, right, bottom);
1623 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001624 addBounds(left, top, right, bottom);
1625 addPoint(rx, ry);
1626 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001627 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001628 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001629}
1630
Chet Haase48659092012-05-31 15:21:51 -07001631status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Romain Guy01d58e42011-01-19 21:54:02 -08001632 addOp(DisplayList::DrawCircle);
1633 addPoint(x, y);
1634 addFloat(radius);
1635 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001636 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001637}
1638
Chet Haase48659092012-05-31 15:21:51 -07001639status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001640 SkPaint* paint) {
1641 addOp(DisplayList::DrawOval);
1642 addBounds(left, top, right, bottom);
1643 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001644 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001645}
1646
Chet Haase48659092012-05-31 15:21:51 -07001647status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -08001648 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001649 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001650 addBounds(left, top, right, bottom);
1651 addPoint(startAngle, sweepAngle);
1652 addInt(useCenter ? 1 : 0);
1653 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001654 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -08001655}
1656
Chet Haase48659092012-05-31 15:21:51 -07001657status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001658 float left, top, offset;
1659 uint32_t width, height;
1660 computePathBounds(path, paint, left, top, offset, width, height);
1661
Romain Guy95c21d02012-07-17 17:46:03 -07001662 left -= offset;
1663 top -= offset;
1664
1665 const bool reject = quickReject(left, top, left + width, top + height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001666 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001667 addPath(path);
1668 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001669 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001670 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001671}
1672
Chet Haase48659092012-05-31 15:21:51 -07001673status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001674 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001675 addFloats(points, count);
1676 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001677 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001678}
1679
Chet Haase48659092012-05-31 15:21:51 -07001680status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Romain Guyed6fcb02011-03-21 13:11:28 -07001681 addOp(DisplayList::DrawPoints);
1682 addFloats(points, count);
1683 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001684 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -07001685}
1686
Chet Haase48659092012-05-31 15:21:51 -07001687status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Romain Guycac5fd32011-12-01 20:08:50 -08001688 float x, float y, SkPaint* paint, float length) {
Chet Haase48659092012-05-31 15:21:51 -07001689 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guy33f6beb2012-02-16 19:24:51 -08001690
Romain Guy8f9a9f62011-12-05 11:53:26 -08001691 // TODO: We should probably make a copy of the paint instead of modifying
1692 // it; modifying the paint will change its generationID the first
1693 // time, which might impact caches. More investigation needed to
1694 // see if it matters.
1695 // If we make a copy, then drawTextDecorations() should *not* make
1696 // its own copy as it does right now.
Fabrice Di Meglioc511bee82012-01-05 13:30:54 -08001697 // Beware: this needs Glyph encoding (already done on the Paint constructor)
Romain Guy8f9a9f62011-12-05 11:53:26 -08001698 paint->setAntiAlias(true);
Romain Guy33f6beb2012-02-16 19:24:51 -08001699 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1700
1701 bool reject = false;
1702 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1703 SkPaint::FontMetrics metrics;
1704 paint->getFontMetrics(&metrics, 0.0f);
1705 reject = quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom);
1706 }
1707
1708 uint32_t* location = addOp(DisplayList::DrawText, reject);
1709 addText(text, bytesCount);
1710 addInt(count);
1711 addPoint(x, y);
Romain Guy4aa90572010-09-26 18:40:37 -07001712 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001713 addFloat(length);
1714 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001715 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001716}
1717
Chet Haase48659092012-05-31 15:21:51 -07001718status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -08001719 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001720 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001721 addOp(DisplayList::DrawTextOnPath);
1722 addText(text, bytesCount);
1723 addInt(count);
1724 addPath(path);
1725 addFloat(hOffset);
1726 addFloat(vOffset);
1727 paint->setAntiAlias(true);
1728 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001729 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001730}
1731
Chet Haase48659092012-05-31 15:21:51 -07001732status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -08001733 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001734 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001735 addOp(DisplayList::DrawPosText);
1736 addText(text, bytesCount);
1737 addInt(count);
1738 addFloats(positions, count * 2);
1739 paint->setAntiAlias(true);
1740 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001741 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001742}
1743
Romain Guy4aa90572010-09-26 18:40:37 -07001744void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001745 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001746}
1747
1748void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001749 addOp(DisplayList::SetupShader);
1750 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001751}
1752
1753void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001754 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001755}
1756
1757void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001758 addOp(DisplayList::SetupColorFilter);
1759 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001760}
1761
1762void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001763 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001764}
1765
1766void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001767 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001768 addFloat(radius);
1769 addPoint(dx, dy);
1770 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001771}
1772
Romain Guy5ff9df62012-01-23 17:09:05 -08001773void DisplayListRenderer::resetPaintFilter() {
1774 addOp(DisplayList::ResetPaintFilter);
1775}
1776
1777void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1778 addOp(DisplayList::SetupPaintFilter);
1779 addInt(clearBits);
1780 addInt(setBits);
1781}
1782
Romain Guy4aa90572010-09-26 18:40:37 -07001783}; // namespace uirenderer
1784}; // namespace android