blob: 2de70d462beaaf908ffc4fb16edd912e9ac7af30 [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 Guy325740f2012-02-24 16:48:34 -080064 "DrawTextOnPath",
Romain Guyeb9a5362012-01-17 17:39:26 -080065 "DrawPosText",
Romain Guyc2525952012-07-27 16:41:22 -070066 "DrawText",
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;
Romain Guy325740f2012-02-24 16:48:34 -0800575 case DrawTextOnPath: {
576 getText(&text);
577 int32_t count = getInt();
578 SkPath* path = getPath();
579 float hOffset = getFloat();
580 float vOffset = getFloat();
581 SkPaint* paint = getPaint(renderer);
582 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
583 text.text(), text.length(), count, paint);
584 }
585 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800586 case DrawPosText: {
587 getText(&text);
588 int count = getInt();
589 int positionsCount = 0;
590 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800591 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800592 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800593 text.text(), text.length(), count, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -0800594 }
Raph Levien996e57c2012-07-23 15:22:52 -0700595 break;
Romain Guyc2525952012-07-27 16:41:22 -0700596 case DrawText: {
Raph Levien996e57c2012-07-23 15:22:52 -0700597 getText(&text);
Romain Guy18edb812012-08-03 16:06:55 -0700598 int32_t count = getInt();
599 float x = getFloat();
600 float y = getFloat();
601 int32_t positionsCount = 0;
Raph Levien996e57c2012-07-23 15:22:52 -0700602 float* positions = getFloats(positionsCount);
603 SkPaint* paint = getPaint(renderer);
Romain Guy18edb812012-08-03 16:06:55 -0700604 float length = getFloat();
Raph Levien996e57c2012-07-23 15:22:52 -0700605 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
606 text.text(), text.length(), count, paint);
607 }
608 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700609 case ResetShader: {
Steve Block5baa3a62011-12-20 16:23:08 +0000610 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700611 }
612 break;
613 case SetupShader: {
614 SkiaShader* shader = getShader();
Steve Block5baa3a62011-12-20 16:23:08 +0000615 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
Chet Haaseed30fd82011-04-22 16:18:45 -0700616 }
617 break;
618 case ResetColorFilter: {
Steve Block5baa3a62011-12-20 16:23:08 +0000619 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700620 }
621 break;
622 case SetupColorFilter: {
623 SkiaColorFilter *colorFilter = getColorFilter();
Steve Block5baa3a62011-12-20 16:23:08 +0000624 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
Chet Haaseed30fd82011-04-22 16:18:45 -0700625 }
626 break;
627 case ResetShadow: {
Steve Block5baa3a62011-12-20 16:23:08 +0000628 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700629 }
630 break;
631 case SetupShadow: {
632 float radius = getFloat();
633 float dx = getFloat();
634 float dy = getFloat();
635 int color = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000636 ALOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800637 radius, dx, dy, color);
Chet Haaseed30fd82011-04-22 16:18:45 -0700638 }
639 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800640 case ResetPaintFilter: {
641 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
642 }
643 break;
644 case SetupPaintFilter: {
645 int clearBits = getInt();
646 int setBits = getInt();
647 ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
648 }
649 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700650 default:
Steve Block5baa3a62011-12-20 16:23:08 +0000651 ALOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -0800652 (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700653 break;
654 }
655 }
Chet Haasea1cff502012-02-21 13:43:44 -0800656 ALOGD("%sDone (%p, %s)", (char*) indent + 2, this, mName.string());
Chet Haaseed30fd82011-04-22 16:18:45 -0700657}
658
Chet Haasea1cff502012-02-21 13:43:44 -0800659void DisplayList::updateMatrix() {
660 if (mMatrixDirty) {
661 if (!mTransformMatrix) {
662 mTransformMatrix = new SkMatrix();
663 }
664 if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) {
665 mTransformMatrix->reset();
666 } else {
667 if (!mPivotExplicitlySet) {
668 if (mWidth != mPrevWidth || mHeight != mPrevHeight) {
669 mPrevWidth = mWidth;
670 mPrevHeight = mHeight;
671 mPivotX = mPrevWidth / 2;
672 mPivotY = mPrevHeight / 2;
673 }
674 }
675 if ((mMatrixFlags & ROTATION_3D) == 0) {
676 mTransformMatrix->setTranslate(mTranslationX, mTranslationY);
677 mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY);
678 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
679 } else {
680 if (!mTransformCamera) {
681 mTransformCamera = new Sk3DView();
682 mTransformMatrix3D = new SkMatrix();
683 }
684 mTransformMatrix->reset();
685 mTransformCamera->save();
686 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
687 mTransformCamera->rotateX(mRotationX);
688 mTransformCamera->rotateY(mRotationY);
689 mTransformCamera->rotateZ(-mRotation);
690 mTransformCamera->getMatrix(mTransformMatrix3D);
691 mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY);
692 mTransformMatrix3D->postTranslate(mPivotX + mTranslationX,
693 mPivotY + mTranslationY);
694 mTransformMatrix->postConcat(*mTransformMatrix3D);
695 mTransformCamera->restore();
696 }
697 }
698 mMatrixDirty = false;
699 }
700}
701
702void DisplayList::outputViewProperties(OpenGLRenderer& renderer, char* indent) {
Chet Haase1271e2c2012-04-20 09:54:27 -0700703 updateMatrix();
704 if (mLeft != 0 || mTop != 0) {
705 ALOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
706 }
707 if (mStaticMatrix) {
708 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
709 indent, "ConcatMatrix (static)", mStaticMatrix,
710 mStaticMatrix->get(0), mStaticMatrix->get(1),
711 mStaticMatrix->get(2), mStaticMatrix->get(3),
712 mStaticMatrix->get(4), mStaticMatrix->get(5),
713 mStaticMatrix->get(6), mStaticMatrix->get(7),
714 mStaticMatrix->get(8));
715 }
716 if (mAnimationMatrix) {
717 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
718 indent, "ConcatMatrix (animation)", mAnimationMatrix,
719 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
720 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
721 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
722 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
723 mAnimationMatrix->get(8));
724 }
725 if (mMatrixFlags != 0) {
726 if (mMatrixFlags == TRANSLATION) {
727 ALOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
728 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700729 ALOGD("%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700730 indent, "ConcatMatrix", mTransformMatrix,
731 mTransformMatrix->get(0), mTransformMatrix->get(1),
732 mTransformMatrix->get(2), mTransformMatrix->get(3),
733 mTransformMatrix->get(4), mTransformMatrix->get(5),
734 mTransformMatrix->get(6), mTransformMatrix->get(7),
735 mTransformMatrix->get(8));
Chet Haase9420abd2012-03-29 16:28:32 -0700736 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700737 }
738 if (mAlpha < 1 && !mCaching) {
739 // TODO: should be able to store the size of a DL at record time and not
740 // have to pass it into this call. In fact, this information might be in the
741 // location/size info that we store with the new native transform data.
742 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800743 if (mClipChildren) {
Chet Haase1271e2c2012-04-20 09:54:27 -0700744 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800745 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700746 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
747 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
748 mMultipliedAlpha, flags);
749 }
750 if (mClipChildren) {
751 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
752 (float) mRight - mLeft, (float) mBottom - mTop);
Chet Haasea1cff502012-02-21 13:43:44 -0800753 }
754}
755
Chet Haase1271e2c2012-04-20 09:54:27 -0700756void DisplayList::setViewProperties(OpenGLRenderer& renderer, uint32_t level) {
Chet Haasea1cff502012-02-21 13:43:44 -0800757#if DEBUG_DISPLAY_LIST
758 uint32_t count = (level + 1) * 2;
759 char indent[count + 1];
760 for (uint32_t i = 0; i < count; i++) {
761 indent[i] = ' ';
762 }
763 indent[count] = '\0';
764#endif
Chet Haase1271e2c2012-04-20 09:54:27 -0700765 updateMatrix();
766 if (mLeft != 0 || mTop != 0) {
767 DISPLAY_LIST_LOGD("%s%s %d, %d", indent, "Translate (left, top)", mLeft, mTop);
768 renderer.translate(mLeft, mTop);
769 }
770 if (mStaticMatrix) {
771 DISPLAY_LIST_LOGD(
772 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
773 indent, "ConcatMatrix (static)", mStaticMatrix,
774 mStaticMatrix->get(0), mStaticMatrix->get(1),
775 mStaticMatrix->get(2), mStaticMatrix->get(3),
776 mStaticMatrix->get(4), mStaticMatrix->get(5),
777 mStaticMatrix->get(6), mStaticMatrix->get(7),
778 mStaticMatrix->get(8));
779 renderer.concatMatrix(mStaticMatrix);
780 } else if (mAnimationMatrix) {
781 DISPLAY_LIST_LOGD(
782 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
783 indent, "ConcatMatrix (animation)", mAnimationMatrix,
784 mAnimationMatrix->get(0), mAnimationMatrix->get(1),
785 mAnimationMatrix->get(2), mAnimationMatrix->get(3),
786 mAnimationMatrix->get(4), mAnimationMatrix->get(5),
787 mAnimationMatrix->get(6), mAnimationMatrix->get(7),
788 mAnimationMatrix->get(8));
789 renderer.concatMatrix(mAnimationMatrix);
790 }
791 if (mMatrixFlags != 0) {
792 if (mMatrixFlags == TRANSLATION) {
793 DISPLAY_LIST_LOGD("%s%s %f, %f", indent, "Translate", mTranslationX, mTranslationY);
794 renderer.translate(mTranslationX, mTranslationY);
795 } else {
Chet Haase9420abd2012-03-29 16:28:32 -0700796 DISPLAY_LIST_LOGD(
797 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
Chet Haase1271e2c2012-04-20 09:54:27 -0700798 indent, "ConcatMatrix", mTransformMatrix,
799 mTransformMatrix->get(0), mTransformMatrix->get(1),
800 mTransformMatrix->get(2), mTransformMatrix->get(3),
801 mTransformMatrix->get(4), mTransformMatrix->get(5),
802 mTransformMatrix->get(6), mTransformMatrix->get(7),
803 mTransformMatrix->get(8));
804 renderer.concatMatrix(mTransformMatrix);
Chet Haasea1cff502012-02-21 13:43:44 -0800805 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700806 }
807 if (mAlpha < 1 && !mCaching) {
808 if (!mHasOverlappingRendering) {
809 DISPLAY_LIST_LOGD("%s%s %.2f", indent, "SetAlpha", mAlpha);
810 renderer.setAlpha(mAlpha);
811 } else {
812 // TODO: should be able to store the size of a DL at record time and not
813 // have to pass it into this call. In fact, this information might be in the
814 // location/size info that we store with the new native transform data.
815 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
816 if (mClipChildren) {
817 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chet Haasea1cff502012-02-21 13:43:44 -0800818 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700819 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", indent, "SaveLayerAlpha",
820 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
821 mMultipliedAlpha, flags);
822 renderer.saveLayerAlpha(0, 0, mRight - mLeft, mBottom - mTop,
823 mMultipliedAlpha, flags);
Chet Haasea1cff502012-02-21 13:43:44 -0800824 }
Chet Haase1271e2c2012-04-20 09:54:27 -0700825 }
826 if (mClipChildren) {
827 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f", indent, "ClipRect", 0.0f, 0.0f,
828 (float) mRight - mLeft, (float) mBottom - mTop);
829 renderer.clipRect(0, 0, mRight - mLeft, mBottom - mTop,
830 SkRegion::kIntersect_Op);
Chet Haasea1cff502012-02-21 13:43:44 -0800831 }
832}
833
Chet Haaseed30fd82011-04-22 16:18:45 -0700834/**
835 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
836 * in the output() function, since that function processes the same list of opcodes for the
837 * purposes of logging display list info for a given view.
838 */
Chet Haase1271e2c2012-04-20 09:54:27 -0700839status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level) {
Chet Haase48659092012-05-31 15:21:51 -0700840 status_t drawGlStatus = DrawGlInfo::kStatusDone;
Romain Guyb051e892010-09-28 19:09:36 -0700841 TextContainer text;
842 mReader.rewind();
843
Romain Guyffac7fc2011-01-13 17:21:49 -0800844#if DEBUG_DISPLAY_LIST
845 uint32_t count = (level + 1) * 2;
846 char indent[count + 1];
847 for (uint32_t i = 0; i < count; i++) {
848 indent[i] = ' ';
849 }
850 indent[count] = '\0';
Chet Haasea23eed82012-04-12 15:19:04 -0700851 Rect* clipRect = renderer.getClipRect();
852 DISPLAY_LIST_LOGD("%sStart display list (%p, %s), clipRect: %.0f, %.f, %.0f, %.0f",
853 (char*) indent + 2, this, mName.string(), clipRect->left, clipRect->top,
854 clipRect->right, clipRect->bottom);
Romain Guyffac7fc2011-01-13 17:21:49 -0800855#endif
Romain Guyb051e892010-09-28 19:09:36 -0700856
Romain Guy13631f32012-01-30 17:41:55 -0800857 renderer.startMark(mName.string());
Romain Guy8a4ac612012-07-17 17:32:48 -0700858
Chet Haase1271e2c2012-04-20 09:54:27 -0700859 int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
860 DISPLAY_LIST_LOGD("%s%s %d %d", indent, "Save",
861 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
862 setViewProperties(renderer, level);
Romain Guy8a4ac612012-07-17 17:32:48 -0700863
864 if (renderer.quickRejectNoScissor(0, 0, mWidth, mHeight)) {
Chet Haaseb85967b2012-03-26 14:37:51 -0700865 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
866 renderer.restoreToCount(restoreTo);
867 renderer.endMark();
Chet Haase48659092012-05-31 15:21:51 -0700868 return drawGlStatus;
Chet Haaseb85967b2012-03-26 14:37:51 -0700869 }
Romain Guy13631f32012-01-30 17:41:55 -0800870
Chet Haase9c1e23b2011-03-24 10:51:31 -0700871 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800872 int saveCount = renderer.getSaveCount() - 1;
Romain Guy8a4ac612012-07-17 17:32:48 -0700873
Romain Guyb051e892010-09-28 19:09:36 -0700874 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700875 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800876 if (op & OP_MAY_BE_SKIPPED_MASK) {
Romain Guy390f8822012-03-13 18:00:10 -0700877 int32_t skip = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800878 if (CC_LIKELY(flags & kReplayFlag_ClipChildren)) {
879 mReader.skip(skip);
880 DISPLAY_LIST_LOGD("%s%s skipping %d bytes", (char*) indent,
881 OP_NAMES[op & ~OP_MAY_BE_SKIPPED_MASK], skip);
882 continue;
883 } else {
884 op &= ~OP_MAY_BE_SKIPPED_MASK;
Romain Guy33f6beb2012-02-16 19:24:51 -0800885 }
886 }
Chet Haase9c1e23b2011-03-24 10:51:31 -0700887 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800888
Romain Guy8a4ac612012-07-17 17:32:48 -0700889#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
890 Caches::getInstance().eventMark(strlen(OP_NAMES[op]), OP_NAMES[op]);
891#endif
892
Romain Guy5b3b3522010-10-27 18:57:51 -0700893 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800894 case DrawGLFunction: {
895 Functor *functor = (Functor *) getInt();
896 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guy13631f32012-01-30 17:41:55 -0800897 renderer.startMark("GL functor");
Romain Guy65549432012-03-26 16:45:05 -0700898 drawGlStatus |= renderer.callDrawGLFunction(functor, dirty);
Romain Guy13631f32012-01-30 17:41:55 -0800899 renderer.endMark();
Chet Haasedaf98e92011-01-10 14:10:36 -0800900 }
901 break;
Romain Guyb051e892010-09-28 19:09:36 -0700902 case Save: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800903 int32_t rendererNum = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800904 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
905 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700906 }
907 break;
908 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800909 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700910 renderer.restore();
911 }
912 break;
913 case RestoreToCount: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800914 int32_t restoreCount = saveCount + getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800915 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
916 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700917 }
918 break;
919 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800920 float f1 = getFloat();
921 float f2 = getFloat();
922 float f3 = getFloat();
923 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800924 SkPaint* paint = getPaint(renderer);
Romain Guy33f6beb2012-02-16 19:24:51 -0800925 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800926 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800927 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800928 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700929 }
930 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700931 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800932 float f1 = getFloat();
933 float f2 = getFloat();
934 float f3 = getFloat();
935 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800936 int32_t alpha = getInt();
937 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800938 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haasea1cff502012-02-21 13:43:44 -0800939 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
Chet Haasedaf98e92011-01-10 14:10:36 -0800940 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700941 }
942 break;
Romain Guyb051e892010-09-28 19:09:36 -0700943 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800944 float f1 = getFloat();
945 float f2 = getFloat();
946 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
947 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700948 }
949 break;
950 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800951 float rotation = getFloat();
952 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
953 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700954 }
955 break;
956 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800957 float sx = getFloat();
958 float sy = getFloat();
959 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
960 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700961 }
962 break;
Romain Guy807daf72011-01-18 11:19:19 -0800963 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800964 float sx = getFloat();
965 float sy = getFloat();
966 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
967 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800968 }
969 break;
Romain Guyb051e892010-09-28 19:09:36 -0700970 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800971 SkMatrix* matrix = getMatrix();
972 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
973 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700974 }
975 break;
976 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800977 SkMatrix* matrix = getMatrix();
Chet Haasea1cff502012-02-21 13:43:44 -0800978 DISPLAY_LIST_LOGD(
979 "%s%s %p: [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f] [%.2f, %.2f, %.2f]",
980 (char*) indent, OP_NAMES[op], matrix,
981 matrix->get(0), matrix->get(1), matrix->get(2),
982 matrix->get(3), matrix->get(4), matrix->get(5),
983 matrix->get(6), matrix->get(7), matrix->get(8));
Chet Haasedaf98e92011-01-10 14:10:36 -0800984 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700985 }
986 break;
987 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800988 float f1 = getFloat();
989 float f2 = getFloat();
990 float f3 = getFloat();
991 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800992 int32_t regionOp = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800993 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -0800994 f1, f2, f3, f4, regionOp);
Chet Haasedaf98e92011-01-10 14:10:36 -0800995 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700996 }
997 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800998 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800999 DisplayList* displayList = getDisplayList();
Romain Guy33f6beb2012-02-16 19:24:51 -08001000 int32_t flags = getInt();
1001 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
Chet Haase1271e2c2012-04-20 09:54:27 -07001002 displayList, mWidth, mHeight, flags, level + 1);
1003 drawGlStatus |= renderer.drawDisplayList(displayList, dirty, flags, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -08001004 }
1005 break;
Romain Guy6c319ca2011-01-11 14:29:25 -08001006 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001007 Layer* layer = (Layer*) getInt();
1008 float x = getFloat();
1009 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001010 SkPaint* paint = getPaint(renderer);
Chet Haase6f9ad202012-05-01 10:05:13 -07001011 if (mCaching) {
Chet Haasea1cff502012-02-21 13:43:44 -08001012 paint->setAlpha(mMultipliedAlpha);
1013 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001014 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001015 layer, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001016 drawGlStatus |= renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -08001017 }
1018 break;
Romain Guyb051e892010-09-28 19:09:36 -07001019 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001020 SkBitmap* bitmap = getBitmap();
1021 float x = getFloat();
1022 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001023 SkPaint* paint = getPaint(renderer);
Chet Haase6f9ad202012-05-01 10:05:13 -07001024 if (mCaching) {
Chet Haaseb85967b2012-03-26 14:37:51 -07001025 paint->setAlpha(mMultipliedAlpha);
1026 }
Chet Haasedaf98e92011-01-10 14:10:36 -08001027 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001028 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001029 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001030 }
1031 break;
1032 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001033 SkBitmap* bitmap = getBitmap();
1034 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -08001035 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001036 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001037 bitmap, matrix, paint);
Chet Haase48659092012-05-31 15:21:51 -07001038 drawGlStatus |= renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001039 }
1040 break;
1041 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001042 SkBitmap* bitmap = getBitmap();
1043 float f1 = getFloat();
1044 float f2 = getFloat();
1045 float f3 = getFloat();
1046 float f4 = getFloat();
1047 float f5 = getFloat();
1048 float f6 = getFloat();
1049 float f7 = getFloat();
1050 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001051 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001052 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001053 (char*) indent, OP_NAMES[op], bitmap,
1054 f1, f2, f3, f4, f5, f6, f7, f8,paint);
Chet Haase48659092012-05-31 15:21:51 -07001055 drawGlStatus |= renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001056 }
1057 break;
Romain Guye651cc62012-05-14 19:44:40 -07001058 case DrawBitmapData: {
1059 SkBitmap* bitmap = getBitmapData();
1060 float x = getFloat();
1061 float y = getFloat();
1062 SkPaint* paint = getPaint(renderer);
1063 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
1064 bitmap, x, y, paint);
Chet Haase48659092012-05-31 15:21:51 -07001065 drawGlStatus |= renderer.drawBitmap(bitmap, x, y, paint);
Romain Guye651cc62012-05-14 19:44:40 -07001066 }
1067 break;
Romain Guy5a7b4662011-01-20 19:09:30 -08001068 case DrawBitmapMesh: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001069 int32_t verticesCount = 0;
Romain Guy5a7b4662011-01-20 19:09:30 -08001070 uint32_t colorsCount = 0;
1071
1072 SkBitmap* bitmap = getBitmap();
1073 uint32_t meshWidth = getInt();
1074 uint32_t meshHeight = getInt();
1075 float* vertices = getFloats(verticesCount);
1076 bool hasColors = getInt();
Romain Guy33f6beb2012-02-16 19:24:51 -08001077 int32_t* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -08001078 SkPaint* paint = getPaint(renderer);
Romain Guy5a7b4662011-01-20 19:09:30 -08001079
Chet Haasedaf98e92011-01-10 14:10:36 -08001080 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001081 drawGlStatus |= renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices,
1082 colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -08001083 }
Romain Guya566b7c2011-01-23 16:36:11 -08001084 break;
Romain Guyb051e892010-09-28 19:09:36 -07001085 case DrawPatch: {
1086 int32_t* xDivs = NULL;
1087 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -07001088 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -07001089 uint32_t xDivsCount = 0;
1090 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -07001091 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001092
1093 SkBitmap* bitmap = getBitmap();
1094
1095 xDivs = getInts(xDivsCount);
1096 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -07001097 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -07001098
Romain Guy9ff3cb52011-06-28 14:02:11 -07001099 float left = getFloat();
1100 float top = getFloat();
1101 float right = getFloat();
1102 float bottom = getFloat();
Romain Guybe6f9dc2012-07-16 12:41:17 -07001103
1104 int alpha = getInt();
1105 SkXfermode::Mode mode = (SkXfermode::Mode) getInt();
Romain Guy9ff3cb52011-06-28 14:02:11 -07001106
Chet Haasedaf98e92011-01-10 14:10:36 -08001107 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001108 drawGlStatus |= renderer.drawPatch(bitmap, xDivs, yDivs, colors,
Romain Guybe6f9dc2012-07-16 12:41:17 -07001109 xDivsCount, yDivsCount, numColors, left, top, right, bottom,
1110 alpha, mode);
Romain Guyb051e892010-09-28 19:09:36 -07001111 }
1112 break;
1113 case DrawColor: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001114 int32_t color = getInt();
1115 int32_t xferMode = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001116 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haase48659092012-05-31 15:21:51 -07001117 drawGlStatus |= renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -07001118 }
1119 break;
1120 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001121 float f1 = getFloat();
1122 float f2 = getFloat();
1123 float f3 = getFloat();
1124 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001125 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001126 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001127 f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001128 drawGlStatus |= renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001129 }
1130 break;
Romain Guy01d58e42011-01-19 21:54:02 -08001131 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001132 float f1 = getFloat();
1133 float f2 = getFloat();
1134 float f3 = getFloat();
1135 float f4 = getFloat();
1136 float f5 = getFloat();
1137 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001138 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001139 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001140 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
Chet Haase48659092012-05-31 15:21:51 -07001141 drawGlStatus |= renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001142 }
1143 break;
1144 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001145 float f1 = getFloat();
1146 float f2 = getFloat();
1147 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001148 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001149 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001150 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
Chet Haase48659092012-05-31 15:21:51 -07001151 drawGlStatus |= renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -08001152 }
1153 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001154 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001155 float f1 = getFloat();
1156 float f2 = getFloat();
1157 float f3 = getFloat();
1158 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -08001159 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001160 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001161 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
Chet Haase48659092012-05-31 15:21:51 -07001162 drawGlStatus |= renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001163 }
1164 break;
Romain Guy8b2f5262011-01-23 16:15:02 -08001165 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001166 float f1 = getFloat();
1167 float f2 = getFloat();
1168 float f3 = getFloat();
1169 float f4 = getFloat();
1170 float f5 = getFloat();
1171 float f6 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001172 int32_t i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001173 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001174 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haasea1cff502012-02-21 13:43:44 -08001175 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
Chet Haase48659092012-05-31 15:21:51 -07001176 drawGlStatus |= renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -08001177 }
1178 break;
Romain Guyb051e892010-09-28 19:09:36 -07001179 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001180 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -08001181 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001182 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haase48659092012-05-31 15:21:51 -07001183 drawGlStatus |= renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001184 }
1185 break;
1186 case DrawLines: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001187 int32_t count = 0;
Romain Guyb051e892010-09-28 19:09:36 -07001188 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001189 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -08001190 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001191 drawGlStatus |= renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -07001192 }
1193 break;
Romain Guyed6fcb02011-03-21 13:11:28 -07001194 case DrawPoints: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001195 int32_t count = 0;
Romain Guyed6fcb02011-03-21 13:11:28 -07001196 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -08001197 SkPaint* paint = getPaint(renderer);
Romain Guyed6fcb02011-03-21 13:11:28 -07001198 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haase48659092012-05-31 15:21:51 -07001199 drawGlStatus |= renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -07001200 }
1201 break;
Romain Guy325740f2012-02-24 16:48:34 -08001202 case DrawTextOnPath: {
1203 getText(&text);
1204 int32_t count = getInt();
1205 SkPath* path = getPath();
1206 float hOffset = getFloat();
1207 float vOffset = getFloat();
1208 SkPaint* paint = getPaint(renderer);
1209 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
1210 text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001211 drawGlStatus |= renderer.drawTextOnPath(text.text(), text.length(), count, path,
Romain Guy325740f2012-02-24 16:48:34 -08001212 hOffset, vOffset, paint);
1213 }
1214 break;
Romain Guyeb9a5362012-01-17 17:39:26 -08001215 case DrawPosText: {
1216 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -08001217 int32_t count = getInt();
1218 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -08001219 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -08001220 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -08001221 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
1222 OP_NAMES[op], text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001223 drawGlStatus |= renderer.drawPosText(text.text(), text.length(), count,
1224 positions, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -08001225 }
1226 break;
Romain Guyc2525952012-07-27 16:41:22 -07001227 case DrawText: {
Raph Levien996e57c2012-07-23 15:22:52 -07001228 getText(&text);
1229 int32_t count = getInt();
1230 float x = getFloat();
1231 float y = getFloat();
1232 int32_t positionsCount = 0;
1233 float* positions = getFloats(positionsCount);
1234 SkPaint* paint = getPaint(renderer);
1235 float length = getFloat();
1236 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
1237 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
Romain Guyc2525952012-07-27 16:41:22 -07001238 drawGlStatus |= renderer.drawText(text.text(), text.length(), count,
Raph Levien996e57c2012-07-23 15:22:52 -07001239 x, y, positions, paint, length);
1240 }
1241 break;
Romain Guyb051e892010-09-28 19:09:36 -07001242 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001243 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001244 renderer.resetShader();
1245 }
1246 break;
1247 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001248 SkiaShader* shader = getShader();
1249 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
1250 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -07001251 }
1252 break;
1253 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001254 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001255 renderer.resetColorFilter();
1256 }
1257 break;
1258 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001259 SkiaColorFilter *colorFilter = getColorFilter();
1260 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
1261 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -07001262 }
1263 break;
1264 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001265 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001266 renderer.resetShadow();
1267 }
1268 break;
1269 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001270 float radius = getFloat();
1271 float dx = getFloat();
1272 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001273 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001274 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001275 radius, dx, dy, color);
Chet Haasedaf98e92011-01-10 14:10:36 -08001276 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -07001277 }
1278 break;
Romain Guy5ff9df62012-01-23 17:09:05 -08001279 case ResetPaintFilter: {
1280 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
1281 renderer.resetPaintFilter();
1282 }
1283 break;
1284 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001285 int32_t clearBits = getInt();
1286 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001287 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
1288 clearBits, setBits);
1289 renderer.setupPaintFilter(clearBits, setBits);
1290 }
1291 break;
Chet Haasedaf98e92011-01-10 14:10:36 -08001292 default:
1293 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -08001294 (char*) indent, OP_NAMES[op]);
Chet Haasedaf98e92011-01-10 14:10:36 -08001295 break;
Romain Guyb051e892010-09-28 19:09:36 -07001296 }
1297 }
Romain Guyffac7fc2011-01-13 17:21:49 -08001298
Chet Haase1271e2c2012-04-20 09:54:27 -07001299 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
1300 renderer.restoreToCount(restoreTo);
Romain Guy13631f32012-01-30 17:41:55 -08001301 renderer.endMark();
1302
Chet Haasea1cff502012-02-21 13:43:44 -08001303 DISPLAY_LIST_LOGD("%sDone (%p, %s), returning %d", (char*) indent + 2, this, mName.string(),
Romain Guy65549432012-03-26 16:45:05 -07001304 drawGlStatus);
1305 return drawGlStatus;
Romain Guyb051e892010-09-28 19:09:36 -07001306}
1307
1308///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -07001309// Base structure
1310///////////////////////////////////////////////////////////////////////////////
1311
Chet Haasea1cff502012-02-21 13:43:44 -08001312DisplayListRenderer::DisplayListRenderer() : mWriter(MIN_WRITER_SIZE),
Romain Guy33f6beb2012-02-16 19:24:51 -08001313 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -07001314}
1315
1316DisplayListRenderer::~DisplayListRenderer() {
1317 reset();
1318}
1319
1320void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -07001321 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -07001322
1323 Caches& caches = Caches::getInstance();
1324 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001325 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -07001326 }
1327 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -07001328
Romain Guy49c5fc02012-05-15 11:10:01 -07001329 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
1330 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
1331 caches.resourceCache.decrementRefcount(bitmap);
1332 }
1333 mOwnedBitmapResources.clear();
1334
Romain Guyd586ad92011-06-22 16:14:36 -07001335 for (size_t i = 0; i < mFilterResources.size(); i++) {
1336 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
1337 }
1338 mFilterResources.clear();
1339
Romain Guy43ccf462011-01-14 18:51:01 -08001340 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001341 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -08001342 }
Romain Guy24c00212011-01-14 15:31:00 -08001343 mShaders.clear();
1344 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -08001345
Chet Haased34dd712012-05-02 18:50:34 -07001346 for (size_t i = 0; i < mSourcePaths.size(); i++) {
1347 caches.resourceCache.decrementRefcount(mSourcePaths.itemAt(i));
1348 }
1349 mSourcePaths.clear();
1350
Romain Guy43ccf462011-01-14 18:51:01 -08001351 mPaints.clear();
1352 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001353
Romain Guy2fc941e2011-02-03 15:06:05 -08001354 mPaths.clear();
1355 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001356
Chet Haased98aa2d2010-10-25 15:47:32 -07001357 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001358
1359 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -07001360}
1361
1362///////////////////////////////////////////////////////////////////////////////
1363// Operations
1364///////////////////////////////////////////////////////////////////////////////
1365
Jeff Brown162a0212011-07-21 17:02:54 -07001366DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1367 if (!displayList) {
1368 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001369 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001370 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001371 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001372 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001373 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001374}
1375
Romain Guy49c5fc02012-05-15 11:10:01 -07001376bool DisplayListRenderer::isDeferred() {
1377 return true;
1378}
1379
Romain Guyb051e892010-09-28 19:09:36 -07001380void DisplayListRenderer::setViewport(int width, int height) {
1381 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1382
1383 mWidth = width;
1384 mHeight = height;
1385}
1386
Chet Haase44b2fe32012-06-06 19:03:58 -07001387int DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -08001388 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001389 mSnapshot = new Snapshot(mFirstSnapshot,
1390 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1391 mSaveCount = 1;
1392 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -08001393 mRestoreSaveCount = -1;
Chet Haase44b2fe32012-06-06 19:03:58 -07001394 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -08001395}
1396
1397void DisplayListRenderer::finish() {
1398 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001399 insertTranlate();
Romain Guyb051e892010-09-28 19:09:36 -07001400}
1401
Chet Haasedaf98e92011-01-10 14:10:36 -08001402void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001403}
Romain Guy2b1847e2011-01-26 13:43:01 -08001404
Chet Haasedaf98e92011-01-10 14:10:36 -08001405void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001406}
1407
Romain Guy65549432012-03-26 16:45:05 -07001408status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -08001409 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001410 addOp(DisplayList::DrawGLFunction);
1411 addInt((int) functor);
Romain Guy65549432012-03-26 16:45:05 -07001412 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -08001413}
1414
Romain Guy4aa90572010-09-26 18:40:37 -07001415int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001416 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001417 addInt(flags);
1418 return OpenGLRenderer::save(flags);
1419}
1420
1421void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001422 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001423 restoreToCount(getSaveCount() - 1);
1424 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001425 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001426
1427 mRestoreSaveCount--;
1428 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001429 OpenGLRenderer::restore();
1430}
1431
1432void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001433 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001434 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001435 OpenGLRenderer::restoreToCount(saveCount);
1436}
1437
1438int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001439 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001440 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001441 addBounds(left, top, right, bottom);
1442 addPaint(p);
1443 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001444 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001445}
1446
Romain Guy5b3b3522010-10-27 18:57:51 -07001447int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1448 int alpha, int flags) {
1449 addOp(DisplayList::SaveLayerAlpha);
1450 addBounds(left, top, right, bottom);
1451 addInt(alpha);
1452 addInt(flags);
1453 return OpenGLRenderer::save(flags);
1454}
1455
Romain Guy4aa90572010-09-26 18:40:37 -07001456void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001457 mHasTranslate = true;
1458 mTranslateX += dx;
1459 mTranslateY += dy;
1460 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001461 OpenGLRenderer::translate(dx, dy);
1462}
1463
1464void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001465 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001466 addFloat(degrees);
1467 OpenGLRenderer::rotate(degrees);
1468}
1469
1470void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001471 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001472 addPoint(sx, sy);
1473 OpenGLRenderer::scale(sx, sy);
1474}
1475
Romain Guy807daf72011-01-18 11:19:19 -08001476void DisplayListRenderer::skew(float sx, float sy) {
1477 addOp(DisplayList::Skew);
1478 addPoint(sx, sy);
1479 OpenGLRenderer::skew(sx, sy);
1480}
1481
Romain Guy4aa90572010-09-26 18:40:37 -07001482void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001483 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001484 addMatrix(matrix);
1485 OpenGLRenderer::setMatrix(matrix);
1486}
1487
1488void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001489 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001490 addMatrix(matrix);
1491 OpenGLRenderer::concatMatrix(matrix);
1492}
1493
1494bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1495 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001496 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001497 addBounds(left, top, right, bottom);
1498 addInt(op);
1499 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1500}
1501
Romain Guy65549432012-03-26 16:45:05 -07001502status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chet Haase1271e2c2012-04-20 09:54:27 -07001503 Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001504 // dirty is an out parameter and should not be recorded,
1505 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -07001506
1507 addOp(DisplayList::DrawDisplayList);
Romain Guy0fe478e2010-11-08 12:08:41 -08001508 addDisplayList(displayList);
Romain Guy33f6beb2012-02-16 19:24:51 -08001509 addInt(flags);
Romain Guy65549432012-03-26 16:45:05 -07001510 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -08001511}
1512
Chet Haase48659092012-05-31 15:21:51 -07001513status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001514 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001515 addInt((int) layer);
1516 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001517 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001518 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -08001519}
1520
Chet Haase48659092012-05-31 15:21:51 -07001521status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001522 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
1523 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001524 addBitmap(bitmap);
1525 addPoint(left, top);
1526 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001527 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001528 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001529}
1530
Chet Haase48659092012-05-31 15:21:51 -07001531status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001532 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1533 const mat4 transform(*matrix);
1534 transform.mapRect(r);
1535
1536 const bool reject = quickReject(r.left, r.top, r.right, r.bottom);
1537 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001538 addBitmap(bitmap);
1539 addMatrix(matrix);
1540 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001541 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001542 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001543}
1544
Chet Haase48659092012-05-31 15:21:51 -07001545status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -07001546 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001547 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001548 const bool reject = quickReject(dstLeft, dstTop, dstRight, dstBottom);
1549 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001550 addBitmap(bitmap);
1551 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1552 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1553 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001554 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001555 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001556}
1557
Chet Haase48659092012-05-31 15:21:51 -07001558status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
1559 SkPaint* paint) {
Romain Guy95c21d02012-07-17 17:46:03 -07001560 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
Romain Guye651cc62012-05-14 19:44:40 -07001561 uint32_t* location = addOp(DisplayList::DrawBitmapData, reject);
1562 addBitmapData(bitmap);
1563 addPoint(left, top);
1564 addPaint(paint);
1565 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001566 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -07001567}
1568
Chet Haase48659092012-05-31 15:21:51 -07001569status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -08001570 float* vertices, int* colors, SkPaint* paint) {
1571 addOp(DisplayList::DrawBitmapMesh);
1572 addBitmap(bitmap);
1573 addInt(meshWidth);
1574 addInt(meshHeight);
1575 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1576 if (colors) {
1577 addInt(1);
1578 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1579 } else {
1580 addInt(0);
1581 }
1582 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001583 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -08001584}
1585
Chet Haase48659092012-05-31 15:21:51 -07001586status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
1587 const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height,
1588 int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guybe6f9dc2012-07-16 12:41:17 -07001589 int alpha;
1590 SkXfermode::Mode mode;
1591 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
1592
Romain Guy33f6beb2012-02-16 19:24:51 -08001593 const bool reject = quickReject(left, top, right, bottom);
1594 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001595 addBitmap(bitmap);
1596 addInts(xDivs, width);
1597 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001598 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001599 addBounds(left, top, right, bottom);
Romain Guybe6f9dc2012-07-16 12:41:17 -07001600 addInt(alpha);
1601 addInt(mode);
Romain Guy33f6beb2012-02-16 19:24:51 -08001602 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001603 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001604}
1605
Chet Haase48659092012-05-31 15:21:51 -07001606status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001607 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001608 addInt(color);
1609 addInt(mode);
Chet Haase48659092012-05-31 15:21:51 -07001610 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001611}
1612
Chet Haase48659092012-05-31 15:21:51 -07001613status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001614 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001615 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1616 quickReject(left, top, right, bottom);
1617 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001618 addBounds(left, top, right, bottom);
1619 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001620 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001621 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001622}
1623
Chet Haase48659092012-05-31 15:21:51 -07001624status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -08001625 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001626 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1627 quickReject(left, top, right, bottom);
1628 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001629 addBounds(left, top, right, bottom);
1630 addPoint(rx, ry);
1631 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001632 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001633 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001634}
1635
Chet Haase48659092012-05-31 15:21:51 -07001636status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Romain Guy01d58e42011-01-19 21:54:02 -08001637 addOp(DisplayList::DrawCircle);
1638 addPoint(x, y);
1639 addFloat(radius);
1640 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001641 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001642}
1643
Chet Haase48659092012-05-31 15:21:51 -07001644status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001645 SkPaint* paint) {
1646 addOp(DisplayList::DrawOval);
1647 addBounds(left, top, right, bottom);
1648 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001649 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001650}
1651
Chet Haase48659092012-05-31 15:21:51 -07001652status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -08001653 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001654 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001655 addBounds(left, top, right, bottom);
1656 addPoint(startAngle, sweepAngle);
1657 addInt(useCenter ? 1 : 0);
1658 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001659 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -08001660}
1661
Chet Haase48659092012-05-31 15:21:51 -07001662status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001663 float left, top, offset;
1664 uint32_t width, height;
1665 computePathBounds(path, paint, left, top, offset, width, height);
1666
Romain Guy95c21d02012-07-17 17:46:03 -07001667 left -= offset;
1668 top -= offset;
1669
1670 const bool reject = quickReject(left, top, left + width, top + height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001671 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001672 addPath(path);
1673 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001674 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001675 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001676}
1677
Chet Haase48659092012-05-31 15:21:51 -07001678status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001679 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001680 addFloats(points, count);
1681 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001682 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001683}
1684
Chet Haase48659092012-05-31 15:21:51 -07001685status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Romain Guyed6fcb02011-03-21 13:11:28 -07001686 addOp(DisplayList::DrawPoints);
1687 addFloats(points, count);
1688 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001689 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -07001690}
1691
Chet Haase48659092012-05-31 15:21:51 -07001692status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -08001693 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001694 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001695 addOp(DisplayList::DrawTextOnPath);
1696 addText(text, bytesCount);
1697 addInt(count);
1698 addPath(path);
1699 addFloat(hOffset);
1700 addFloat(vOffset);
1701 paint->setAntiAlias(true);
Chet Haasee816bae2012-08-09 13:39:02 -07001702 SkPaint* addedPaint = addPaint(paint);
1703 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
1704 fontRenderer.precache(addedPaint, text, count);
Chet Haase48659092012-05-31 15:21:51 -07001705 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001706}
1707
Chet Haase48659092012-05-31 15:21:51 -07001708status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -08001709 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001710 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001711 addOp(DisplayList::DrawPosText);
1712 addText(text, bytesCount);
1713 addInt(count);
1714 addFloats(positions, count * 2);
1715 paint->setAntiAlias(true);
Chet Haasee816bae2012-08-09 13:39:02 -07001716 SkPaint* addedPaint = addPaint(paint);
1717 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
1718 fontRenderer.precache(addedPaint, text, count);
Chet Haase48659092012-05-31 15:21:51 -07001719 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001720}
1721
Romain Guyc2525952012-07-27 16:41:22 -07001722status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Raph Levien996e57c2012-07-23 15:22:52 -07001723 float x, float y, const float* positions, SkPaint* paint, float length) {
1724 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
1725
1726 // TODO: We should probably make a copy of the paint instead of modifying
1727 // it; modifying the paint will change its generationID the first
1728 // time, which might impact caches. More investigation needed to
1729 // see if it matters.
1730 // If we make a copy, then drawTextDecorations() should *not* make
1731 // its own copy as it does right now.
1732 // Beware: this needs Glyph encoding (already done on the Paint constructor)
1733 paint->setAntiAlias(true);
1734 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1735
1736 bool reject = false;
1737 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1738 SkPaint::FontMetrics metrics;
1739 paint->getFontMetrics(&metrics, 0.0f);
1740 reject = quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom);
1741 }
1742
Romain Guyc2525952012-07-27 16:41:22 -07001743 uint32_t* location = addOp(DisplayList::DrawText, reject);
Raph Levien996e57c2012-07-23 15:22:52 -07001744 addText(text, bytesCount);
1745 addInt(count);
1746 addFloat(x);
1747 addFloat(y);
1748 addFloats(positions, count * 2);
Chet Haasee816bae2012-08-09 13:39:02 -07001749 SkPaint* addedPaint = addPaint(paint);
1750 if (!reject) {
1751 FontRenderer& fontRenderer = mCaches.fontRenderer->getFontRenderer(addedPaint);
1752 fontRenderer.precache(addedPaint, text, count);
1753 }
Raph Levien996e57c2012-07-23 15:22:52 -07001754 addFloat(length);
1755 addSkip(location);
1756 return DrawGlInfo::kStatusDone;
1757}
1758
Romain Guy4aa90572010-09-26 18:40:37 -07001759void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001760 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001761}
1762
1763void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001764 addOp(DisplayList::SetupShader);
1765 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001766}
1767
1768void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001769 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001770}
1771
1772void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001773 addOp(DisplayList::SetupColorFilter);
1774 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001775}
1776
1777void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001778 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001779}
1780
1781void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001782 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001783 addFloat(radius);
1784 addPoint(dx, dy);
1785 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001786}
1787
Romain Guy5ff9df62012-01-23 17:09:05 -08001788void DisplayListRenderer::resetPaintFilter() {
1789 addOp(DisplayList::ResetPaintFilter);
1790}
1791
1792void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1793 addOp(DisplayList::SetupPaintFilter);
1794 addInt(clearBits);
1795 addInt(setBits);
1796}
1797
Romain Guy4aa90572010-09-26 18:40:37 -07001798}; // namespace uirenderer
1799}; // namespace android