blob: 7161c589b19119b04ab821e22c47b5ae15cf38ec [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",
Raph Levien996e57c2012-07-23 15:22:52 -070066 "DrawGeneralText",
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;
596 case DrawGeneralText: {
597 getText(&text);
598 int count = getInt();
599 int positionsCount = 0;
600 float* positions = getFloats(positionsCount);
601 SkPaint* paint = getPaint(renderer);
602 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
603 text.text(), text.length(), count, paint);
604 }
605 break;
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 Guy325740f2012-02-24 16:48:34 -08001199 case DrawTextOnPath: {
1200 getText(&text);
1201 int32_t count = getInt();
1202 SkPath* path = getPath();
1203 float hOffset = getFloat();
1204 float vOffset = getFloat();
1205 SkPaint* paint = getPaint(renderer);
1206 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
1207 text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001208 drawGlStatus |= renderer.drawTextOnPath(text.text(), text.length(), count, path,
Romain Guy325740f2012-02-24 16:48:34 -08001209 hOffset, vOffset, paint);
1210 }
1211 break;
Romain Guyeb9a5362012-01-17 17:39:26 -08001212 case DrawPosText: {
1213 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -08001214 int32_t count = getInt();
1215 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -08001216 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -08001217 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -08001218 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
1219 OP_NAMES[op], text.text(), text.length(), count, paint);
Chet Haase48659092012-05-31 15:21:51 -07001220 drawGlStatus |= renderer.drawPosText(text.text(), text.length(), count,
1221 positions, paint);
Romain Guyeb9a5362012-01-17 17:39:26 -08001222 }
1223 break;
Raph Levien996e57c2012-07-23 15:22:52 -07001224 case DrawGeneralText: {
1225 getText(&text);
1226 int32_t count = getInt();
1227 float x = getFloat();
1228 float y = getFloat();
1229 int32_t positionsCount = 0;
1230 float* positions = getFloats(positionsCount);
1231 SkPaint* paint = getPaint(renderer);
1232 float length = getFloat();
1233 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
1234 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
1235 drawGlStatus |= renderer.drawGeneralText(text.text(), text.length(), count,
1236 x, y, positions, paint, length);
1237 }
1238 break;
Romain Guyb051e892010-09-28 19:09:36 -07001239 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001240 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001241 renderer.resetShader();
1242 }
1243 break;
1244 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001245 SkiaShader* shader = getShader();
1246 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
1247 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -07001248 }
1249 break;
1250 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001251 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001252 renderer.resetColorFilter();
1253 }
1254 break;
1255 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001256 SkiaColorFilter *colorFilter = getColorFilter();
1257 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
1258 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -07001259 }
1260 break;
1261 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001262 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -07001263 renderer.resetShadow();
1264 }
1265 break;
1266 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -08001267 float radius = getFloat();
1268 float dx = getFloat();
1269 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -08001270 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -08001271 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haasea1cff502012-02-21 13:43:44 -08001272 radius, dx, dy, color);
Chet Haasedaf98e92011-01-10 14:10:36 -08001273 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -07001274 }
1275 break;
Romain Guy5ff9df62012-01-23 17:09:05 -08001276 case ResetPaintFilter: {
1277 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
1278 renderer.resetPaintFilter();
1279 }
1280 break;
1281 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -08001282 int32_t clearBits = getInt();
1283 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -08001284 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
1285 clearBits, setBits);
1286 renderer.setupPaintFilter(clearBits, setBits);
1287 }
1288 break;
Chet Haasedaf98e92011-01-10 14:10:36 -08001289 default:
1290 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
Chet Haasea1cff502012-02-21 13:43:44 -08001291 (char*) indent, OP_NAMES[op]);
Chet Haasedaf98e92011-01-10 14:10:36 -08001292 break;
Romain Guyb051e892010-09-28 19:09:36 -07001293 }
1294 }
Romain Guyffac7fc2011-01-13 17:21:49 -08001295
Chet Haase1271e2c2012-04-20 09:54:27 -07001296 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
1297 renderer.restoreToCount(restoreTo);
Romain Guy13631f32012-01-30 17:41:55 -08001298 renderer.endMark();
1299
Chet Haasea1cff502012-02-21 13:43:44 -08001300 DISPLAY_LIST_LOGD("%sDone (%p, %s), returning %d", (char*) indent + 2, this, mName.string(),
Romain Guy65549432012-03-26 16:45:05 -07001301 drawGlStatus);
1302 return drawGlStatus;
Romain Guyb051e892010-09-28 19:09:36 -07001303}
1304
1305///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -07001306// Base structure
1307///////////////////////////////////////////////////////////////////////////////
1308
Chet Haasea1cff502012-02-21 13:43:44 -08001309DisplayListRenderer::DisplayListRenderer() : mWriter(MIN_WRITER_SIZE),
Romain Guy33f6beb2012-02-16 19:24:51 -08001310 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -07001311}
1312
1313DisplayListRenderer::~DisplayListRenderer() {
1314 reset();
1315}
1316
1317void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -07001318 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -07001319
1320 Caches& caches = Caches::getInstance();
1321 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001322 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -07001323 }
1324 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -07001325
Romain Guy49c5fc02012-05-15 11:10:01 -07001326 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
1327 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
1328 caches.resourceCache.decrementRefcount(bitmap);
1329 }
1330 mOwnedBitmapResources.clear();
1331
Romain Guyd586ad92011-06-22 16:14:36 -07001332 for (size_t i = 0; i < mFilterResources.size(); i++) {
1333 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
1334 }
1335 mFilterResources.clear();
1336
Romain Guy43ccf462011-01-14 18:51:01 -08001337 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001338 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -08001339 }
Romain Guy24c00212011-01-14 15:31:00 -08001340 mShaders.clear();
1341 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -08001342
Chet Haased34dd712012-05-02 18:50:34 -07001343 for (size_t i = 0; i < mSourcePaths.size(); i++) {
1344 caches.resourceCache.decrementRefcount(mSourcePaths.itemAt(i));
1345 }
1346 mSourcePaths.clear();
1347
Romain Guy43ccf462011-01-14 18:51:01 -08001348 mPaints.clear();
1349 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001350
Romain Guy2fc941e2011-02-03 15:06:05 -08001351 mPaths.clear();
1352 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001353
Chet Haased98aa2d2010-10-25 15:47:32 -07001354 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001355
1356 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -07001357}
1358
1359///////////////////////////////////////////////////////////////////////////////
1360// Operations
1361///////////////////////////////////////////////////////////////////////////////
1362
Jeff Brown162a0212011-07-21 17:02:54 -07001363DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1364 if (!displayList) {
1365 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001366 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001367 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001368 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001369 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001370 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001371}
1372
Romain Guy49c5fc02012-05-15 11:10:01 -07001373bool DisplayListRenderer::isDeferred() {
1374 return true;
1375}
1376
Romain Guyb051e892010-09-28 19:09:36 -07001377void DisplayListRenderer::setViewport(int width, int height) {
1378 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1379
1380 mWidth = width;
1381 mHeight = height;
1382}
1383
Chet Haase44b2fe32012-06-06 19:03:58 -07001384int DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -08001385 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001386 mSnapshot = new Snapshot(mFirstSnapshot,
1387 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1388 mSaveCount = 1;
1389 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -08001390 mRestoreSaveCount = -1;
Chet Haase44b2fe32012-06-06 19:03:58 -07001391 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -08001392}
1393
1394void DisplayListRenderer::finish() {
1395 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001396 insertTranlate();
Romain Guyb051e892010-09-28 19:09:36 -07001397}
1398
Chet Haasedaf98e92011-01-10 14:10:36 -08001399void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001400}
Romain Guy2b1847e2011-01-26 13:43:01 -08001401
Chet Haasedaf98e92011-01-10 14:10:36 -08001402void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001403}
1404
Romain Guy65549432012-03-26 16:45:05 -07001405status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -08001406 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001407 addOp(DisplayList::DrawGLFunction);
1408 addInt((int) functor);
Romain Guy65549432012-03-26 16:45:05 -07001409 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -08001410}
1411
Romain Guy4aa90572010-09-26 18:40:37 -07001412int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001413 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001414 addInt(flags);
1415 return OpenGLRenderer::save(flags);
1416}
1417
1418void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001419 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001420 restoreToCount(getSaveCount() - 1);
1421 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001422 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001423
1424 mRestoreSaveCount--;
1425 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001426 OpenGLRenderer::restore();
1427}
1428
1429void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001430 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001431 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001432 OpenGLRenderer::restoreToCount(saveCount);
1433}
1434
1435int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001436 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001437 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001438 addBounds(left, top, right, bottom);
1439 addPaint(p);
1440 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001441 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001442}
1443
Romain Guy5b3b3522010-10-27 18:57:51 -07001444int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1445 int alpha, int flags) {
1446 addOp(DisplayList::SaveLayerAlpha);
1447 addBounds(left, top, right, bottom);
1448 addInt(alpha);
1449 addInt(flags);
1450 return OpenGLRenderer::save(flags);
1451}
1452
Romain Guy4aa90572010-09-26 18:40:37 -07001453void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001454 mHasTranslate = true;
1455 mTranslateX += dx;
1456 mTranslateY += dy;
1457 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001458 OpenGLRenderer::translate(dx, dy);
1459}
1460
1461void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001462 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001463 addFloat(degrees);
1464 OpenGLRenderer::rotate(degrees);
1465}
1466
1467void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001468 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001469 addPoint(sx, sy);
1470 OpenGLRenderer::scale(sx, sy);
1471}
1472
Romain Guy807daf72011-01-18 11:19:19 -08001473void DisplayListRenderer::skew(float sx, float sy) {
1474 addOp(DisplayList::Skew);
1475 addPoint(sx, sy);
1476 OpenGLRenderer::skew(sx, sy);
1477}
1478
Romain Guy4aa90572010-09-26 18:40:37 -07001479void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001480 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001481 addMatrix(matrix);
1482 OpenGLRenderer::setMatrix(matrix);
1483}
1484
1485void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001486 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001487 addMatrix(matrix);
1488 OpenGLRenderer::concatMatrix(matrix);
1489}
1490
1491bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1492 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001493 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001494 addBounds(left, top, right, bottom);
1495 addInt(op);
1496 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1497}
1498
Romain Guy65549432012-03-26 16:45:05 -07001499status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chet Haase1271e2c2012-04-20 09:54:27 -07001500 Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001501 // dirty is an out parameter and should not be recorded,
1502 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -07001503
1504 addOp(DisplayList::DrawDisplayList);
Romain Guy0fe478e2010-11-08 12:08:41 -08001505 addDisplayList(displayList);
Romain Guy33f6beb2012-02-16 19:24:51 -08001506 addInt(flags);
Romain Guy65549432012-03-26 16:45:05 -07001507 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -08001508}
1509
Chet Haase48659092012-05-31 15:21:51 -07001510status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001511 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001512 addInt((int) layer);
1513 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001514 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001515 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -08001516}
1517
Chet Haase48659092012-05-31 15:21:51 -07001518status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001519 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
1520 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001521 addBitmap(bitmap);
1522 addPoint(left, top);
1523 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001524 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001525 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001526}
1527
Chet Haase48659092012-05-31 15:21:51 -07001528status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001529 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1530 const mat4 transform(*matrix);
1531 transform.mapRect(r);
1532
1533 const bool reject = quickReject(r.left, r.top, r.right, r.bottom);
1534 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001535 addBitmap(bitmap);
1536 addMatrix(matrix);
1537 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001538 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001539 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001540}
1541
Chet Haase48659092012-05-31 15:21:51 -07001542status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -07001543 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001544 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001545 const bool reject = quickReject(dstLeft, dstTop, dstRight, dstBottom);
1546 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001547 addBitmap(bitmap);
1548 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1549 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1550 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001551 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001552 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001553}
1554
Chet Haase48659092012-05-31 15:21:51 -07001555status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
1556 SkPaint* paint) {
Romain Guy95c21d02012-07-17 17:46:03 -07001557 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
Romain Guye651cc62012-05-14 19:44:40 -07001558 uint32_t* location = addOp(DisplayList::DrawBitmapData, reject);
1559 addBitmapData(bitmap);
1560 addPoint(left, top);
1561 addPaint(paint);
1562 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001563 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -07001564}
1565
Chet Haase48659092012-05-31 15:21:51 -07001566status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -08001567 float* vertices, int* colors, SkPaint* paint) {
1568 addOp(DisplayList::DrawBitmapMesh);
1569 addBitmap(bitmap);
1570 addInt(meshWidth);
1571 addInt(meshHeight);
1572 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1573 if (colors) {
1574 addInt(1);
1575 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1576 } else {
1577 addInt(0);
1578 }
1579 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001580 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -08001581}
1582
Chet Haase48659092012-05-31 15:21:51 -07001583status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs,
1584 const int32_t* yDivs, const uint32_t* colors, uint32_t width, uint32_t height,
1585 int8_t numColors, float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guybe6f9dc2012-07-16 12:41:17 -07001586 int alpha;
1587 SkXfermode::Mode mode;
1588 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
1589
Romain Guy33f6beb2012-02-16 19:24:51 -08001590 const bool reject = quickReject(left, top, right, bottom);
1591 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001592 addBitmap(bitmap);
1593 addInts(xDivs, width);
1594 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001595 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001596 addBounds(left, top, right, bottom);
Romain Guybe6f9dc2012-07-16 12:41:17 -07001597 addInt(alpha);
1598 addInt(mode);
Romain Guy33f6beb2012-02-16 19:24:51 -08001599 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001600 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001601}
1602
Chet Haase48659092012-05-31 15:21:51 -07001603status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001604 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001605 addInt(color);
1606 addInt(mode);
Chet Haase48659092012-05-31 15:21:51 -07001607 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001608}
1609
Chet Haase48659092012-05-31 15:21:51 -07001610status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001611 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001612 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1613 quickReject(left, top, right, bottom);
1614 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001615 addBounds(left, top, right, bottom);
1616 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001617 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001618 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001619}
1620
Chet Haase48659092012-05-31 15:21:51 -07001621status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -08001622 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001623 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1624 quickReject(left, top, right, bottom);
1625 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001626 addBounds(left, top, right, bottom);
1627 addPoint(rx, ry);
1628 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001629 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001630 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001631}
1632
Chet Haase48659092012-05-31 15:21:51 -07001633status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Romain Guy01d58e42011-01-19 21:54:02 -08001634 addOp(DisplayList::DrawCircle);
1635 addPoint(x, y);
1636 addFloat(radius);
1637 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001638 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -08001639}
1640
Chet Haase48659092012-05-31 15:21:51 -07001641status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001642 SkPaint* paint) {
1643 addOp(DisplayList::DrawOval);
1644 addBounds(left, top, right, bottom);
1645 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001646 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001647}
1648
Chet Haase48659092012-05-31 15:21:51 -07001649status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -08001650 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001651 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001652 addBounds(left, top, right, bottom);
1653 addPoint(startAngle, sweepAngle);
1654 addInt(useCenter ? 1 : 0);
1655 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001656 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -08001657}
1658
Chet Haase48659092012-05-31 15:21:51 -07001659status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001660 float left, top, offset;
1661 uint32_t width, height;
1662 computePathBounds(path, paint, left, top, offset, width, height);
1663
Romain Guy95c21d02012-07-17 17:46:03 -07001664 left -= offset;
1665 top -= offset;
1666
1667 const bool reject = quickReject(left, top, left + width, top + height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001668 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001669 addPath(path);
1670 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001671 addSkip(location);
Chet Haase48659092012-05-31 15:21:51 -07001672 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001673}
1674
Chet Haase48659092012-05-31 15:21:51 -07001675status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001676 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001677 addFloats(points, count);
1678 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001679 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -07001680}
1681
Chet Haase48659092012-05-31 15:21:51 -07001682status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Romain Guyed6fcb02011-03-21 13:11:28 -07001683 addOp(DisplayList::DrawPoints);
1684 addFloats(points, count);
1685 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001686 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -07001687}
1688
Chet Haase48659092012-05-31 15:21:51 -07001689status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -08001690 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001691 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001692 addOp(DisplayList::DrawTextOnPath);
1693 addText(text, bytesCount);
1694 addInt(count);
1695 addPath(path);
1696 addFloat(hOffset);
1697 addFloat(vOffset);
1698 paint->setAntiAlias(true);
1699 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001700 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -08001701}
1702
Chet Haase48659092012-05-31 15:21:51 -07001703status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -08001704 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -07001705 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001706 addOp(DisplayList::DrawPosText);
1707 addText(text, bytesCount);
1708 addInt(count);
1709 addFloats(positions, count * 2);
1710 paint->setAntiAlias(true);
1711 addPaint(paint);
Chet Haase48659092012-05-31 15:21:51 -07001712 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -08001713}
1714
Raph Levien996e57c2012-07-23 15:22:52 -07001715status_t DisplayListRenderer::drawGeneralText(const char* text, int bytesCount, int count,
1716 float x, float y, const float* positions, SkPaint* paint, float length) {
1717 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
1718
1719 // TODO: We should probably make a copy of the paint instead of modifying
1720 // it; modifying the paint will change its generationID the first
1721 // time, which might impact caches. More investigation needed to
1722 // see if it matters.
1723 // If we make a copy, then drawTextDecorations() should *not* make
1724 // its own copy as it does right now.
1725 // Beware: this needs Glyph encoding (already done on the Paint constructor)
1726 paint->setAntiAlias(true);
1727 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1728
1729 bool reject = false;
1730 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1731 SkPaint::FontMetrics metrics;
1732 paint->getFontMetrics(&metrics, 0.0f);
1733 reject = quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom);
1734 }
1735
1736 uint32_t* location = addOp(DisplayList::DrawGeneralText, reject);
1737 addText(text, bytesCount);
1738 addInt(count);
1739 addFloat(x);
1740 addFloat(y);
1741 addFloats(positions, count * 2);
1742 addPaint(paint);
1743 addFloat(length);
1744 addSkip(location);
1745 return DrawGlInfo::kStatusDone;
1746}
1747
Romain Guy4aa90572010-09-26 18:40:37 -07001748void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001749 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001750}
1751
1752void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001753 addOp(DisplayList::SetupShader);
1754 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001755}
1756
1757void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001758 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001759}
1760
1761void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001762 addOp(DisplayList::SetupColorFilter);
1763 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001764}
1765
1766void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001767 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001768}
1769
1770void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001771 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001772 addFloat(radius);
1773 addPoint(dx, dy);
1774 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001775}
1776
Romain Guy5ff9df62012-01-23 17:09:05 -08001777void DisplayListRenderer::resetPaintFilter() {
1778 addOp(DisplayList::ResetPaintFilter);
1779}
1780
1781void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1782 addOp(DisplayList::SetupPaintFilter);
1783 addInt(clearBits);
1784 addInt(setBits);
1785}
1786
Romain Guy4aa90572010-09-26 18:40:37 -07001787}; // namespace uirenderer
1788}; // namespace android