blob: f9088aca37186d289cd5c9eb16c74b53b76ccf2b [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
Chet Haase9c1e23b2011-03-24 10:51:31 -070019
20#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070021#include "DisplayListRenderer.h"
Chet Haase9c1e23b2011-03-24 10:51:31 -070022#include "Caches.h"
Romain Guy4aa90572010-09-26 18:40:37 -070023
Romain Guy13631f32012-01-30 17:41:55 -080024#include <utils/String8.h>
25
Romain Guy4aa90572010-09-26 18:40:37 -070026namespace android {
27namespace uirenderer {
28
Chet Haase9c1e23b2011-03-24 10:51:31 -070029
Romain Guy4aa90572010-09-26 18:40:37 -070030///////////////////////////////////////////////////////////////////////////////
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 Guy5a7b4662011-01-20 19:09:30 -080052 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -080053 "DrawPatch",
54 "DrawColor",
55 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -080056 "DrawRoundRect",
57 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -080058 "DrawOval",
Romain Guy8b2f5262011-01-23 16:15:02 -080059 "DrawArc",
Romain Guyffac7fc2011-01-13 17:21:49 -080060 "DrawPath",
61 "DrawLines",
Romain Guyed6fcb02011-03-21 13:11:28 -070062 "DrawPoints",
Romain Guyffac7fc2011-01-13 17:21:49 -080063 "DrawText",
Romain Guyeb9a5362012-01-17 17:39:26 -080064 "DrawPosText",
Romain Guyffac7fc2011-01-13 17:21:49 -080065 "ResetShader",
66 "SetupShader",
67 "ResetColorFilter",
68 "SetupColorFilter",
69 "ResetShadow",
Chet Haasedaf98e92011-01-10 14:10:36 -080070 "SetupShadow",
Romain Guy5ff9df62012-01-23 17:09:05 -080071 "ResetPaintFilter",
72 "SetupPaintFilter",
Chet Haasedaf98e92011-01-10 14:10:36 -080073 "DrawGLFunction"
Romain Guyffac7fc2011-01-13 17:21:49 -080074};
75
Chet Haase9c1e23b2011-03-24 10:51:31 -070076void DisplayList::outputLogBuffer(int fd) {
77 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
78 if (logBuffer.isEmpty()) {
79 return;
80 }
Romain Guy65b345f2011-07-27 18:51:50 -070081
Chet Haase9c1e23b2011-03-24 10:51:31 -070082 FILE *file = fdopen(fd, "a");
Romain Guy65b345f2011-07-27 18:51:50 -070083
Chet Haase9c1e23b2011-03-24 10:51:31 -070084 fprintf(file, "\nRecent DisplayList operations\n");
85 logBuffer.outputCommands(file, OP_NAMES);
Romain Guy65b345f2011-07-27 18:51:50 -070086
87 String8 cachesLog;
88 Caches::getInstance().dumpMemoryUsage(cachesLog);
89 fprintf(file, "\nCaches:\n%s", cachesLog.string());
90 fprintf(file, "\n");
91
Chet Haase9c1e23b2011-03-24 10:51:31 -070092 fflush(file);
93}
94
Romain Guyb051e892010-09-28 19:09:36 -070095DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -080096 initFromDisplayListRenderer(recorder);
97}
98
99DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -0800100 clearResources();
101}
102
103void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -0800104 sk_free((void*) mReader.base());
105
106 Caches& caches = Caches::getInstance();
107
108 for (size_t i = 0; i < mBitmapResources.size(); i++) {
109 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
110 }
111 mBitmapResources.clear();
112
Romain Guyd586ad92011-06-22 16:14:36 -0700113 for (size_t i = 0; i < mFilterResources.size(); i++) {
114 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
115 }
116 mFilterResources.clear();
117
Romain Guy24c00212011-01-14 15:31:00 -0800118 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800119 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700120 caches.resourceCache.destructor(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800121 }
Romain Guy24c00212011-01-14 15:31:00 -0800122 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800123
124 for (size_t i = 0; i < mPaints.size(); i++) {
125 delete mPaints.itemAt(i);
126 }
127 mPaints.clear();
128
Romain Guy2fc941e2011-02-03 15:06:05 -0800129 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700130 SkPath* path = mPaths.itemAt(i);
131 caches.pathCache.remove(path);
132 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800133 }
134 mPaths.clear();
135
Chet Haase5977baa2011-01-05 18:01:22 -0800136 for (size_t i = 0; i < mMatrices.size(); i++) {
137 delete mMatrices.itemAt(i);
138 }
139 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800140}
141
Chet Haased63cbd12011-02-03 16:32:46 -0800142void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700143 const SkWriter32& writer = recorder.writeStream();
144 init();
145
146 if (writer.size() == 0) {
147 return;
148 }
149
Chet Haased63cbd12011-02-03 16:32:46 -0800150 if (reusing) {
151 // re-using display list - clear out previous allocations
152 clearResources();
153 }
154
Romain Guy65b345f2011-07-27 18:51:50 -0700155 mSize = writer.size();
156 void* buffer = sk_malloc_throw(mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700157 writer.flatten(buffer);
Romain Guy65b345f2011-07-27 18:51:50 -0700158 mReader.setMemory(buffer, mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700159
Chet Haase5c13d892010-10-08 08:37:55 -0700160 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700161
Chet Haase5c13d892010-10-08 08:37:55 -0700162 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
163 for (size_t i = 0; i < bitmapResources.size(); i++) {
164 SkBitmap* resource = bitmapResources.itemAt(i);
165 mBitmapResources.add(resource);
166 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700167 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700168
Romain Guyd586ad92011-06-22 16:14:36 -0700169 const Vector<SkiaColorFilter*> &filterResources = recorder.getFilterResources();
170 for (size_t i = 0; i < filterResources.size(); i++) {
171 SkiaColorFilter* resource = filterResources.itemAt(i);
172 mFilterResources.add(resource);
173 caches.resourceCache.incrementRefcount(resource);
174 }
175
Romain Guy24c00212011-01-14 15:31:00 -0800176 const Vector<SkiaShader*> &shaders = recorder.getShaders();
177 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700178 SkiaShader* resource = shaders.itemAt(i);
179 mShaders.add(resource);
180 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700181 }
182
Chet Haased98aa2d2010-10-25 15:47:32 -0700183 const Vector<SkPaint*> &paints = recorder.getPaints();
184 for (size_t i = 0; i < paints.size(); i++) {
185 mPaints.add(paints.itemAt(i));
186 }
187
Romain Guy2fc941e2011-02-03 15:06:05 -0800188 const Vector<SkPath*> &paths = recorder.getPaths();
189 for (size_t i = 0; i < paths.size(); i++) {
190 mPaths.add(paths.itemAt(i));
191 }
192
Chet Haased98aa2d2010-10-25 15:47:32 -0700193 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
194 for (size_t i = 0; i < matrices.size(); i++) {
195 mMatrices.add(matrices.itemAt(i));
196 }
Romain Guyb051e892010-09-28 19:09:36 -0700197}
198
Romain Guyb051e892010-09-28 19:09:36 -0700199void DisplayList::init() {
Romain Guy65b345f2011-07-27 18:51:50 -0700200 mSize = 0;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700201 mIsRenderable = true;
Romain Guy65b345f2011-07-27 18:51:50 -0700202}
203
204size_t DisplayList::getSize() {
205 return mSize;
Romain Guyb051e892010-09-28 19:09:36 -0700206}
207
Chet Haaseed30fd82011-04-22 16:18:45 -0700208/**
209 * This function is a simplified version of replay(), where we simply retrieve and log the
210 * display list. This function should remain in sync with the replay() function.
211 */
212void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
213 TextContainer text;
214
215 uint32_t count = (level + 1) * 2;
216 char indent[count + 1];
217 for (uint32_t i = 0; i < count; i++) {
218 indent[i] = ' ';
219 }
220 indent[count] = '\0';
Romain Guy13631f32012-01-30 17:41:55 -0800221 ALOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
Chet Haaseed30fd82011-04-22 16:18:45 -0700222
223 int saveCount = renderer.getSaveCount() - 1;
224
225 mReader.rewind();
226
227 while (!mReader.eof()) {
228 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800229 if (op & OP_MAY_BE_SKIPPED_MASK) {
230 int skip = mReader.readInt();
231 ALOGD("%sSkip %d", (char*) indent, skip);
232 op &= ~OP_MAY_BE_SKIPPED_MASK;
233 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700234
235 switch (op) {
236 case DrawGLFunction: {
237 Functor *functor = (Functor *) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000238 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Chet Haaseed30fd82011-04-22 16:18:45 -0700239 }
240 break;
241 case Save: {
242 int rendererNum = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000243 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
Chet Haaseed30fd82011-04-22 16:18:45 -0700244 }
245 break;
246 case Restore: {
Steve Block5baa3a62011-12-20 16:23:08 +0000247 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700248 }
249 break;
250 case RestoreToCount: {
251 int restoreCount = saveCount + getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000252 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
Chet Haaseed30fd82011-04-22 16:18:45 -0700253 }
254 break;
255 case SaveLayer: {
256 float f1 = getFloat();
257 float f2 = getFloat();
258 float f3 = getFloat();
259 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800260 SkPaint* paint = getPaint(renderer);
Chet Haaseed30fd82011-04-22 16:18:45 -0700261 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000262 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haaseed30fd82011-04-22 16:18:45 -0700263 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
264 }
265 break;
266 case SaveLayerAlpha: {
267 float f1 = getFloat();
268 float f2 = getFloat();
269 float f3 = getFloat();
270 float f4 = getFloat();
271 int alpha = getInt();
272 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000273 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haaseed30fd82011-04-22 16:18:45 -0700274 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
275 }
276 break;
277 case Translate: {
278 float f1 = getFloat();
279 float f2 = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000280 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700281 }
282 break;
283 case Rotate: {
284 float rotation = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000285 ALOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
Chet Haaseed30fd82011-04-22 16:18:45 -0700286 }
287 break;
288 case Scale: {
289 float sx = getFloat();
290 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000291 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700292 }
293 break;
294 case Skew: {
295 float sx = getFloat();
296 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000297 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700298 }
299 break;
300 case SetMatrix: {
301 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000302 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700303 }
304 break;
305 case ConcatMatrix: {
306 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000307 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700308 }
309 break;
310 case ClipRect: {
311 float f1 = getFloat();
312 float f2 = getFloat();
313 float f3 = getFloat();
314 float f4 = getFloat();
315 int regionOp = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000316 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700317 f1, f2, f3, f4, regionOp);
318 }
319 break;
320 case DrawDisplayList: {
321 DisplayList* displayList = getDisplayList();
322 uint32_t width = getUInt();
323 uint32_t height = getUInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800324 int32_t flags = getInt();
325 ALOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
326 displayList, width, height, flags, level + 1);
Chet Haaseed30fd82011-04-22 16:18:45 -0700327 renderer.outputDisplayList(displayList, level + 1);
328 }
329 break;
330 case DrawLayer: {
331 Layer* layer = (Layer*) getInt();
332 float x = getFloat();
333 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800334 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000335 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700336 layer, x, y, paint);
337 }
338 break;
339 case DrawBitmap: {
340 SkBitmap* bitmap = getBitmap();
341 float x = getFloat();
342 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800343 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000344 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700345 bitmap, x, y, paint);
346 }
347 break;
348 case DrawBitmapMatrix: {
349 SkBitmap* bitmap = getBitmap();
350 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800351 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000352 ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700353 bitmap, matrix, paint);
354 }
355 break;
356 case DrawBitmapRect: {
357 SkBitmap* bitmap = getBitmap();
358 float f1 = getFloat();
359 float f2 = getFloat();
360 float f3 = getFloat();
361 float f4 = getFloat();
362 float f5 = getFloat();
363 float f6 = getFloat();
364 float f7 = getFloat();
365 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800366 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000367 ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700368 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
369 }
370 break;
371 case DrawBitmapMesh: {
372 int verticesCount = 0;
373 uint32_t colorsCount = 0;
374 SkBitmap* bitmap = getBitmap();
375 uint32_t meshWidth = getInt();
376 uint32_t meshHeight = getInt();
377 float* vertices = getFloats(verticesCount);
378 bool hasColors = getInt();
379 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800380 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000381 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700382 }
383 break;
384 case DrawPatch: {
385 int32_t* xDivs = NULL;
386 int32_t* yDivs = NULL;
387 uint32_t* colors = NULL;
388 uint32_t xDivsCount = 0;
389 uint32_t yDivsCount = 0;
390 int8_t numColors = 0;
391 SkBitmap* bitmap = getBitmap();
392 xDivs = getInts(xDivsCount);
393 yDivs = getInts(yDivsCount);
394 colors = getUInts(numColors);
Romain Guya62f1722011-10-19 17:06:19 -0700395 float left = getFloat();
396 float top = getFloat();
397 float right = getFloat();
398 float bottom = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800399 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000400 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
Romain Guya62f1722011-10-19 17:06:19 -0700401 left, top, right, bottom);
Chet Haaseed30fd82011-04-22 16:18:45 -0700402 }
403 break;
404 case DrawColor: {
405 int color = getInt();
406 int xferMode = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000407 ALOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haaseed30fd82011-04-22 16:18:45 -0700408 }
409 break;
410 case DrawRect: {
411 float f1 = getFloat();
412 float f2 = getFloat();
413 float f3 = getFloat();
414 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800415 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000416 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700417 f1, f2, f3, f4, paint);
418 }
419 break;
420 case DrawRoundRect: {
421 float f1 = getFloat();
422 float f2 = getFloat();
423 float f3 = getFloat();
424 float f4 = getFloat();
425 float f5 = getFloat();
426 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800427 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000428 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700429 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
430 }
431 break;
432 case DrawCircle: {
433 float f1 = getFloat();
434 float f2 = getFloat();
435 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800436 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000437 ALOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700438 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
439 }
440 break;
441 case DrawOval: {
442 float f1 = getFloat();
443 float f2 = getFloat();
444 float f3 = getFloat();
445 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800446 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000447 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700448 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
449 }
450 break;
451 case DrawArc: {
452 float f1 = getFloat();
453 float f2 = getFloat();
454 float f3 = getFloat();
455 float f4 = getFloat();
456 float f5 = getFloat();
457 float f6 = getFloat();
458 int i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800459 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000460 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700461 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
462 }
463 break;
464 case DrawPath: {
465 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800466 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000467 ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700468 }
469 break;
470 case DrawLines: {
471 int count = 0;
472 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800473 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000474 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700475 }
476 break;
477 case DrawPoints: {
478 int count = 0;
479 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800480 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000481 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700482 }
483 break;
484 case DrawText: {
485 getText(&text);
486 int count = getInt();
487 float x = getFloat();
488 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800489 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -0800490 float length = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000491 ALOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
Romain Guycac5fd32011-12-01 20:08:50 -0800492 text.text(), text.length(), count, x, y, paint, length);
Chet Haaseed30fd82011-04-22 16:18:45 -0700493 }
494 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800495 case DrawPosText: {
496 getText(&text);
497 int count = getInt();
498 int positionsCount = 0;
499 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800500 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800501 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
502 text.text(), text.length(), count, paint);
503 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700504 case ResetShader: {
Steve Block5baa3a62011-12-20 16:23:08 +0000505 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700506 }
507 break;
508 case SetupShader: {
509 SkiaShader* shader = getShader();
Steve Block5baa3a62011-12-20 16:23:08 +0000510 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
Chet Haaseed30fd82011-04-22 16:18:45 -0700511 }
512 break;
513 case ResetColorFilter: {
Steve Block5baa3a62011-12-20 16:23:08 +0000514 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700515 }
516 break;
517 case SetupColorFilter: {
518 SkiaColorFilter *colorFilter = getColorFilter();
Steve Block5baa3a62011-12-20 16:23:08 +0000519 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
Chet Haaseed30fd82011-04-22 16:18:45 -0700520 }
521 break;
522 case ResetShadow: {
Steve Block5baa3a62011-12-20 16:23:08 +0000523 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700524 }
525 break;
526 case SetupShadow: {
527 float radius = getFloat();
528 float dx = getFloat();
529 float dy = getFloat();
530 int color = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000531 ALOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700532 radius, dx, dy, color);
533 }
534 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800535 case ResetPaintFilter: {
536 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
537 }
538 break;
539 case SetupPaintFilter: {
540 int clearBits = getInt();
541 int setBits = getInt();
542 ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
543 }
544 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700545 default:
Steve Block5baa3a62011-12-20 16:23:08 +0000546 ALOGD("Display List error: op not handled: %s%s",
Chet Haaseed30fd82011-04-22 16:18:45 -0700547 (char*) indent, OP_NAMES[op]);
548 break;
549 }
550 }
551
Steve Block5baa3a62011-12-20 16:23:08 +0000552 ALOGD("%sDone", (char*) indent + 2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700553}
554
555/**
556 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
557 * in the output() function, since that function processes the same list of opcodes for the
558 * purposes of logging display list info for a given view.
559 */
Romain Guy33f6beb2012-02-16 19:24:51 -0800560bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800561 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700562 TextContainer text;
563 mReader.rewind();
564
Romain Guyffac7fc2011-01-13 17:21:49 -0800565#if DEBUG_DISPLAY_LIST
566 uint32_t count = (level + 1) * 2;
567 char indent[count + 1];
568 for (uint32_t i = 0; i < count; i++) {
569 indent[i] = ' ';
570 }
571 indent[count] = '\0';
Romain Guy13631f32012-01-30 17:41:55 -0800572 DISPLAY_LIST_LOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
Romain Guyffac7fc2011-01-13 17:21:49 -0800573#endif
Romain Guyb051e892010-09-28 19:09:36 -0700574
Romain Guy13631f32012-01-30 17:41:55 -0800575 renderer.startMark(mName.string());
576
Chet Haase9c1e23b2011-03-24 10:51:31 -0700577 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800578 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700579 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700580 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800581 if (op & OP_MAY_BE_SKIPPED_MASK) {
582 int32_t skip = mReader.readInt() * 4;
583 if (CC_LIKELY(flags & kReplayFlag_ClipChildren)) {
584 mReader.skip(skip);
585 DISPLAY_LIST_LOGD("%s%s skipping %d bytes", (char*) indent,
586 OP_NAMES[op & ~OP_MAY_BE_SKIPPED_MASK], skip);
587 continue;
588 } else {
589 op &= ~OP_MAY_BE_SKIPPED_MASK;
590 ALOGD("%s", OP_NAMES[op]);
591 }
592 }
Chet Haase9c1e23b2011-03-24 10:51:31 -0700593 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800594
Romain Guy5b3b3522010-10-27 18:57:51 -0700595 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800596 case DrawGLFunction: {
597 Functor *functor = (Functor *) getInt();
598 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guy13631f32012-01-30 17:41:55 -0800599 renderer.startMark("GL functor");
Romain Guycabfcc12011-03-07 18:06:46 -0800600 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Romain Guy13631f32012-01-30 17:41:55 -0800601 renderer.endMark();
Chet Haasedaf98e92011-01-10 14:10:36 -0800602 }
603 break;
Romain Guyb051e892010-09-28 19:09:36 -0700604 case Save: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800605 int32_t rendererNum = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800606 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
607 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700608 }
609 break;
610 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800611 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700612 renderer.restore();
613 }
614 break;
615 case RestoreToCount: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800616 int32_t restoreCount = saveCount + getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800617 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
618 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700619 }
620 break;
621 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800622 float f1 = getFloat();
623 float f2 = getFloat();
624 float f3 = getFloat();
625 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800626 SkPaint* paint = getPaint(renderer);
Romain Guy33f6beb2012-02-16 19:24:51 -0800627 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800628 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
629 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
630 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700631 }
632 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700633 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800634 float f1 = getFloat();
635 float f2 = getFloat();
636 float f3 = getFloat();
637 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800638 int32_t alpha = getInt();
639 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800640 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
641 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
642 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700643 }
644 break;
Romain Guyb051e892010-09-28 19:09:36 -0700645 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800646 float f1 = getFloat();
647 float f2 = getFloat();
648 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
649 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700650 }
651 break;
652 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800653 float rotation = getFloat();
654 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
655 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700656 }
657 break;
658 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800659 float sx = getFloat();
660 float sy = getFloat();
661 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
662 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700663 }
664 break;
Romain Guy807daf72011-01-18 11:19:19 -0800665 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800666 float sx = getFloat();
667 float sy = getFloat();
668 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
669 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800670 }
671 break;
Romain Guyb051e892010-09-28 19:09:36 -0700672 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800673 SkMatrix* matrix = getMatrix();
674 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
675 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700676 }
677 break;
678 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800679 SkMatrix* matrix = getMatrix();
680 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
681 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700682 }
683 break;
684 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800685 float f1 = getFloat();
686 float f2 = getFloat();
687 float f3 = getFloat();
688 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800689 int32_t regionOp = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800690 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
691 f1, f2, f3, f4, regionOp);
692 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700693 }
694 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800695 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800696 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700697 uint32_t width = getUInt();
698 uint32_t height = getUInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800699 int32_t flags = getInt();
700 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
701 displayList, width, height, flags, level + 1);
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700702 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
Romain Guy33f6beb2012-02-16 19:24:51 -0800703 dirty, flags, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800704 }
705 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800706 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800707 Layer* layer = (Layer*) getInt();
708 float x = getFloat();
709 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800710 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800711 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
712 layer, x, y, paint);
713 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800714 }
715 break;
Romain Guyb051e892010-09-28 19:09:36 -0700716 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800717 SkBitmap* bitmap = getBitmap();
718 float x = getFloat();
719 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800720 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800721 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
722 bitmap, x, y, paint);
723 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700724 }
725 break;
726 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800727 SkBitmap* bitmap = getBitmap();
728 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800729 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800730 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
731 bitmap, matrix, paint);
732 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700733 }
734 break;
735 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800736 SkBitmap* bitmap = getBitmap();
737 float f1 = getFloat();
738 float f2 = getFloat();
739 float f3 = getFloat();
740 float f4 = getFloat();
741 float f5 = getFloat();
742 float f6 = getFloat();
743 float f7 = getFloat();
744 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800745 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800746 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
747 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
748 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700749 }
750 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800751 case DrawBitmapMesh: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800752 int32_t verticesCount = 0;
Romain Guy5a7b4662011-01-20 19:09:30 -0800753 uint32_t colorsCount = 0;
754
755 SkBitmap* bitmap = getBitmap();
756 uint32_t meshWidth = getInt();
757 uint32_t meshHeight = getInt();
758 float* vertices = getFloats(verticesCount);
759 bool hasColors = getInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800760 int32_t* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800761 SkPaint* paint = getPaint(renderer);
Romain Guy5a7b4662011-01-20 19:09:30 -0800762
Chet Haasedaf98e92011-01-10 14:10:36 -0800763 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700764 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -0800765 }
Romain Guya566b7c2011-01-23 16:36:11 -0800766 break;
Romain Guyb051e892010-09-28 19:09:36 -0700767 case DrawPatch: {
768 int32_t* xDivs = NULL;
769 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700770 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700771 uint32_t xDivsCount = 0;
772 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700773 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700774
775 SkBitmap* bitmap = getBitmap();
776
777 xDivs = getInts(xDivsCount);
778 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700779 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700780
Romain Guy9ff3cb52011-06-28 14:02:11 -0700781 float left = getFloat();
782 float top = getFloat();
783 float right = getFloat();
784 float bottom = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800785 SkPaint* paint = getPaint(renderer);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700786
Chet Haasedaf98e92011-01-10 14:10:36 -0800787 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700788 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
Romain Guy9ff3cb52011-06-28 14:02:11 -0700789 numColors, left, top, right, bottom, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700790 }
791 break;
792 case DrawColor: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800793 int32_t color = getInt();
794 int32_t xferMode = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800795 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
796 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700797 }
798 break;
799 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800800 float f1 = getFloat();
801 float f2 = getFloat();
802 float f3 = getFloat();
803 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800804 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800805 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
806 f1, f2, f3, f4, paint);
807 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700808 }
809 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800810 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800811 float f1 = getFloat();
812 float f2 = getFloat();
813 float f3 = getFloat();
814 float f4 = getFloat();
815 float f5 = getFloat();
816 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800817 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800818 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
819 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
820 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800821 }
822 break;
823 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800824 float f1 = getFloat();
825 float f2 = getFloat();
826 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800827 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800828 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
829 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
830 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800831 }
832 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800833 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800834 float f1 = getFloat();
835 float f2 = getFloat();
836 float f3 = getFloat();
837 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800838 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800839 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
840 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
841 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800842 }
843 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800844 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800845 float f1 = getFloat();
846 float f2 = getFloat();
847 float f3 = getFloat();
848 float f4 = getFloat();
849 float f5 = getFloat();
850 float f6 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800851 int32_t i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800852 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800853 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
854 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
855 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800856 }
857 break;
Romain Guyb051e892010-09-28 19:09:36 -0700858 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800859 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800860 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800861 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
862 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700863 }
864 break;
865 case DrawLines: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800866 int32_t count = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700867 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800868 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800869 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700870 renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700871 }
872 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700873 case DrawPoints: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800874 int32_t count = 0;
Romain Guyed6fcb02011-03-21 13:11:28 -0700875 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800876 SkPaint* paint = getPaint(renderer);
Romain Guyed6fcb02011-03-21 13:11:28 -0700877 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700878 renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700879 }
880 break;
Romain Guyb051e892010-09-28 19:09:36 -0700881 case DrawText: {
882 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -0800883 int32_t count = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800884 float x = getFloat();
885 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800886 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -0800887 float length = getFloat();
888 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
889 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
890 renderer.drawText(text.text(), text.length(), count, x, y, paint, length);
Romain Guyb051e892010-09-28 19:09:36 -0700891 }
892 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800893 case DrawPosText: {
894 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -0800895 int32_t count = getInt();
896 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -0800897 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800898 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800899 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
900 OP_NAMES[op], text.text(), text.length(), count, paint);
901 renderer.drawPosText(text.text(), text.length(), count, positions, paint);
902 }
903 break;
Romain Guyb051e892010-09-28 19:09:36 -0700904 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800905 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700906 renderer.resetShader();
907 }
908 break;
909 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800910 SkiaShader* shader = getShader();
911 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
912 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700913 }
914 break;
915 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800916 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700917 renderer.resetColorFilter();
918 }
919 break;
920 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800921 SkiaColorFilter *colorFilter = getColorFilter();
922 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
923 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700924 }
925 break;
926 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800927 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700928 renderer.resetShadow();
929 }
930 break;
931 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800932 float radius = getFloat();
933 float dx = getFloat();
934 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800935 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800936 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
937 radius, dx, dy, color);
938 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700939 }
940 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800941 case ResetPaintFilter: {
942 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
943 renderer.resetPaintFilter();
944 }
945 break;
946 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800947 int32_t clearBits = getInt();
948 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800949 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
950 clearBits, setBits);
951 renderer.setupPaintFilter(clearBits, setBits);
952 }
953 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800954 default:
955 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
956 (char*) indent, OP_NAMES[op]);
957 break;
Romain Guyb051e892010-09-28 19:09:36 -0700958 }
959 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800960
Romain Guy13631f32012-01-30 17:41:55 -0800961 renderer.endMark();
962
Chet Haasedaf98e92011-01-10 14:10:36 -0800963 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
964 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700965}
966
967///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700968// Base structure
969///////////////////////////////////////////////////////////////////////////////
970
Romain Guy33f6beb2012-02-16 19:24:51 -0800971DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE),
972 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -0700973}
974
975DisplayListRenderer::~DisplayListRenderer() {
976 reset();
977}
978
979void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -0700980 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700981
982 Caches& caches = Caches::getInstance();
983 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700984 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -0700985 }
986 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700987
Romain Guyd586ad92011-06-22 16:14:36 -0700988 for (size_t i = 0; i < mFilterResources.size(); i++) {
989 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
990 }
991 mFilterResources.clear();
992
Romain Guy43ccf462011-01-14 18:51:01 -0800993 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700994 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -0800995 }
Romain Guy24c00212011-01-14 15:31:00 -0800996 mShaders.clear();
997 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800998
999 mPaints.clear();
1000 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001001
Romain Guy2fc941e2011-02-03 15:06:05 -08001002 mPaths.clear();
1003 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001004
Chet Haased98aa2d2010-10-25 15:47:32 -07001005 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001006
1007 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -07001008}
1009
1010///////////////////////////////////////////////////////////////////////////////
1011// Operations
1012///////////////////////////////////////////////////////////////////////////////
1013
Jeff Brown162a0212011-07-21 17:02:54 -07001014DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1015 if (!displayList) {
1016 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001017 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001018 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001019 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001020 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001021 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001022}
1023
Romain Guyb051e892010-09-28 19:09:36 -07001024void DisplayListRenderer::setViewport(int width, int height) {
1025 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1026
1027 mWidth = width;
1028 mHeight = height;
1029}
1030
Romain Guy7d7b5492011-01-24 16:33:45 -08001031void DisplayListRenderer::prepareDirty(float left, float top,
1032 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001033 mSnapshot = new Snapshot(mFirstSnapshot,
1034 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1035 mSaveCount = 1;
1036 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -08001037 mRestoreSaveCount = -1;
1038}
1039
1040void DisplayListRenderer::finish() {
1041 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001042 insertTranlate();
Romain Guy27454a42011-01-23 12:01:41 -08001043 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -07001044}
1045
Chet Haasedaf98e92011-01-10 14:10:36 -08001046void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001047}
Romain Guy2b1847e2011-01-26 13:43:01 -08001048
Chet Haasedaf98e92011-01-10 14:10:36 -08001049void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001050}
1051
Romain Guycabfcc12011-03-07 18:06:46 -08001052bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
1053 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001054 addOp(DisplayList::DrawGLFunction);
1055 addInt((int) functor);
1056 return false; // No invalidate needed at record-time
1057}
1058
Romain Guy4aa90572010-09-26 18:40:37 -07001059int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001060 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001061 addInt(flags);
1062 return OpenGLRenderer::save(flags);
1063}
1064
1065void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001066 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001067 restoreToCount(getSaveCount() - 1);
1068 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001069 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001070
1071 mRestoreSaveCount--;
1072 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001073 OpenGLRenderer::restore();
1074}
1075
1076void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001077 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001078 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001079 OpenGLRenderer::restoreToCount(saveCount);
1080}
1081
1082int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001083 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001084 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001085 addBounds(left, top, right, bottom);
1086 addPaint(p);
1087 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001088 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001089}
1090
Romain Guy5b3b3522010-10-27 18:57:51 -07001091int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1092 int alpha, int flags) {
1093 addOp(DisplayList::SaveLayerAlpha);
1094 addBounds(left, top, right, bottom);
1095 addInt(alpha);
1096 addInt(flags);
1097 return OpenGLRenderer::save(flags);
1098}
1099
Romain Guy4aa90572010-09-26 18:40:37 -07001100void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001101 mHasTranslate = true;
1102 mTranslateX += dx;
1103 mTranslateY += dy;
1104 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001105 OpenGLRenderer::translate(dx, dy);
1106}
1107
1108void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001109 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001110 addFloat(degrees);
1111 OpenGLRenderer::rotate(degrees);
1112}
1113
1114void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001115 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001116 addPoint(sx, sy);
1117 OpenGLRenderer::scale(sx, sy);
1118}
1119
Romain Guy807daf72011-01-18 11:19:19 -08001120void DisplayListRenderer::skew(float sx, float sy) {
1121 addOp(DisplayList::Skew);
1122 addPoint(sx, sy);
1123 OpenGLRenderer::skew(sx, sy);
1124}
1125
Romain Guy4aa90572010-09-26 18:40:37 -07001126void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001127 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001128 addMatrix(matrix);
1129 OpenGLRenderer::setMatrix(matrix);
1130}
1131
1132void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001133 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001134 addMatrix(matrix);
1135 OpenGLRenderer::concatMatrix(matrix);
1136}
1137
1138bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1139 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001140 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001141 addBounds(left, top, right, bottom);
1142 addInt(op);
1143 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1144}
1145
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001146bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Romain Guy33f6beb2012-02-16 19:24:51 -08001147 uint32_t width, uint32_t height, Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001148 // dirty is an out parameter and should not be recorded,
1149 // it matters only when replaying the display list
Romain Guy33f6beb2012-02-16 19:24:51 -08001150 const bool reject = quickReject(0.0f, 0.0f, width, height);
1151 uint32_t* location = addOp(DisplayList::DrawDisplayList, reject);
Romain Guy0fe478e2010-11-08 12:08:41 -08001152 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001153 addSize(width, height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001154 addInt(flags);
1155 addSkip(location);
Chet Haasedaf98e92011-01-10 14:10:36 -08001156 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001157}
1158
Romain Guyada830f2011-01-13 12:13:20 -08001159void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001160 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001161 addInt((int) layer);
1162 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001163 addPaint(paint);
1164}
1165
Romain Guy33f6beb2012-02-16 19:24:51 -08001166void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
1167 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
1168 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001169 addBitmap(bitmap);
1170 addPoint(left, top);
1171 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001172 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001173}
1174
Romain Guy33f6beb2012-02-16 19:24:51 -08001175void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
1176 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1177 const mat4 transform(*matrix);
1178 transform.mapRect(r);
1179
1180 const bool reject = quickReject(r.left, r.top, r.right, r.bottom);
1181 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001182 addBitmap(bitmap);
1183 addMatrix(matrix);
1184 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001185 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001186}
1187
1188void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1189 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001190 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001191 const bool reject = quickReject(dstLeft, dstTop, dstRight, dstBottom);
1192 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001193 addBitmap(bitmap);
1194 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1195 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1196 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001197 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001198}
1199
Romain Guy5a7b4662011-01-20 19:09:30 -08001200void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1201 float* vertices, int* colors, SkPaint* paint) {
1202 addOp(DisplayList::DrawBitmapMesh);
1203 addBitmap(bitmap);
1204 addInt(meshWidth);
1205 addInt(meshHeight);
1206 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1207 if (colors) {
1208 addInt(1);
1209 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1210 } else {
1211 addInt(0);
1212 }
1213 addPaint(paint);
1214}
1215
Romain Guy4aa90572010-09-26 18:40:37 -07001216void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001217 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001218 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001219 const bool reject = quickReject(left, top, right, bottom);
1220 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001221 addBitmap(bitmap);
1222 addInts(xDivs, width);
1223 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001224 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001225 addBounds(left, top, right, bottom);
1226 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001227 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001228}
1229
1230void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001231 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001232 addInt(color);
1233 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001234}
1235
1236void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001237 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001238 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1239 quickReject(left, top, right, bottom);
1240 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001241 addBounds(left, top, right, bottom);
1242 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001243 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001244}
1245
Romain Guy01d58e42011-01-19 21:54:02 -08001246void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1247 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001248 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1249 quickReject(left, top, right, bottom);
1250 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001251 addBounds(left, top, right, bottom);
1252 addPoint(rx, ry);
1253 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001254 addSkip(location);
Romain Guy01d58e42011-01-19 21:54:02 -08001255}
1256
1257void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1258 addOp(DisplayList::DrawCircle);
1259 addPoint(x, y);
1260 addFloat(radius);
1261 addPaint(paint);
1262}
1263
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001264void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1265 SkPaint* paint) {
1266 addOp(DisplayList::DrawOval);
1267 addBounds(left, top, right, bottom);
1268 addPaint(paint);
1269}
1270
Romain Guy8b2f5262011-01-23 16:15:02 -08001271void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1272 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001273 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001274 addBounds(left, top, right, bottom);
1275 addPoint(startAngle, sweepAngle);
1276 addInt(useCenter ? 1 : 0);
1277 addPaint(paint);
1278}
1279
Romain Guy4aa90572010-09-26 18:40:37 -07001280void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001281 float left, top, offset;
1282 uint32_t width, height;
1283 computePathBounds(path, paint, left, top, offset, width, height);
1284
1285 const bool reject = quickReject(left - offset, top - offset, width, height);
1286 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001287 addPath(path);
1288 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001289 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001290}
1291
Chet Haase5c13d892010-10-08 08:37:55 -07001292void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001293 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001294 addFloats(points, count);
1295 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001296}
1297
Romain Guyed6fcb02011-03-21 13:11:28 -07001298void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1299 addOp(DisplayList::DrawPoints);
1300 addFloats(points, count);
1301 addPaint(paint);
1302}
1303
Romain Guy4aa90572010-09-26 18:40:37 -07001304void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Romain Guycac5fd32011-12-01 20:08:50 -08001305 float x, float y, SkPaint* paint, float length) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001306 if (!text || count <= 0) return;
1307
Romain Guy8f9a9f62011-12-05 11:53:26 -08001308 // TODO: We should probably make a copy of the paint instead of modifying
1309 // it; modifying the paint will change its generationID the first
1310 // time, which might impact caches. More investigation needed to
1311 // see if it matters.
1312 // If we make a copy, then drawTextDecorations() should *not* make
1313 // its own copy as it does right now.
Fabrice Di Meglioc511bee82012-01-05 13:30:54 -08001314 // Beware: this needs Glyph encoding (already done on the Paint constructor)
Romain Guy8f9a9f62011-12-05 11:53:26 -08001315 paint->setAntiAlias(true);
Romain Guy33f6beb2012-02-16 19:24:51 -08001316 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1317
1318 bool reject = false;
1319 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1320 SkPaint::FontMetrics metrics;
1321 paint->getFontMetrics(&metrics, 0.0f);
1322 reject = quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom);
1323 }
1324
1325 uint32_t* location = addOp(DisplayList::DrawText, reject);
1326 addText(text, bytesCount);
1327 addInt(count);
1328 addPoint(x, y);
Romain Guy4aa90572010-09-26 18:40:37 -07001329 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001330 addFloat(length);
1331 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001332}
1333
Romain Guyeb9a5362012-01-17 17:39:26 -08001334void DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
1335 const float* positions, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001336 if (!text || count <= 0) return;
Romain Guyeb9a5362012-01-17 17:39:26 -08001337 addOp(DisplayList::DrawPosText);
1338 addText(text, bytesCount);
1339 addInt(count);
1340 addFloats(positions, count * 2);
1341 paint->setAntiAlias(true);
1342 addPaint(paint);
1343}
1344
Romain Guy4aa90572010-09-26 18:40:37 -07001345void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001346 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001347}
1348
1349void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001350 addOp(DisplayList::SetupShader);
1351 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001352}
1353
1354void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001355 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001356}
1357
1358void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001359 addOp(DisplayList::SetupColorFilter);
1360 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001361}
1362
1363void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001364 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001365}
1366
1367void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001368 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001369 addFloat(radius);
1370 addPoint(dx, dy);
1371 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001372}
1373
Romain Guy5ff9df62012-01-23 17:09:05 -08001374void DisplayListRenderer::resetPaintFilter() {
1375 addOp(DisplayList::ResetPaintFilter);
1376}
1377
1378void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1379 addOp(DisplayList::SetupPaintFilter);
1380 addInt(clearBits);
1381 addInt(setBits);
1382}
1383
Romain Guy4aa90572010-09-26 18:40:37 -07001384}; // namespace uirenderer
1385}; // namespace android