blob: 5a52464a54fb1e4675ca48cb716aa7b7ac1136ee [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 <utils/String8.h>
23#include "Caches.h"
Romain Guy4aa90572010-09-26 18:40:37 -070024
25namespace android {
26namespace uirenderer {
27
Chet Haase9c1e23b2011-03-24 10:51:31 -070028
Romain Guy4aa90572010-09-26 18:40:37 -070029///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070030// Display list
31///////////////////////////////////////////////////////////////////////////////
32
Romain Guyffac7fc2011-01-13 17:21:49 -080033const char* DisplayList::OP_NAMES[] = {
Romain Guyffac7fc2011-01-13 17:21:49 -080034 "Save",
35 "Restore",
36 "RestoreToCount",
37 "SaveLayer",
38 "SaveLayerAlpha",
39 "Translate",
40 "Rotate",
41 "Scale",
Romain Guy4cf6e2f2011-01-23 11:35:13 -080042 "Skew",
Romain Guyffac7fc2011-01-13 17:21:49 -080043 "SetMatrix",
44 "ConcatMatrix",
45 "ClipRect",
46 "DrawDisplayList",
47 "DrawLayer",
48 "DrawBitmap",
49 "DrawBitmapMatrix",
50 "DrawBitmapRect",
Romain Guy5a7b4662011-01-20 19:09:30 -080051 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -080052 "DrawPatch",
53 "DrawColor",
54 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -080055 "DrawRoundRect",
56 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -080057 "DrawOval",
Romain Guy8b2f5262011-01-23 16:15:02 -080058 "DrawArc",
Romain Guyffac7fc2011-01-13 17:21:49 -080059 "DrawPath",
60 "DrawLines",
Romain Guyed6fcb02011-03-21 13:11:28 -070061 "DrawPoints",
Romain Guyffac7fc2011-01-13 17:21:49 -080062 "DrawText",
63 "ResetShader",
64 "SetupShader",
65 "ResetColorFilter",
66 "SetupColorFilter",
67 "ResetShadow",
Chet Haasedaf98e92011-01-10 14:10:36 -080068 "SetupShadow",
69 "DrawGLFunction"
Romain Guyffac7fc2011-01-13 17:21:49 -080070};
71
Chet Haase9c1e23b2011-03-24 10:51:31 -070072void DisplayList::outputLogBuffer(int fd) {
73 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
74 if (logBuffer.isEmpty()) {
75 return;
76 }
Romain Guy65b345f2011-07-27 18:51:50 -070077
Chet Haase9c1e23b2011-03-24 10:51:31 -070078 FILE *file = fdopen(fd, "a");
Romain Guy65b345f2011-07-27 18:51:50 -070079
Chet Haase9c1e23b2011-03-24 10:51:31 -070080 fprintf(file, "\nRecent DisplayList operations\n");
81 logBuffer.outputCommands(file, OP_NAMES);
Romain Guy65b345f2011-07-27 18:51:50 -070082
83 String8 cachesLog;
84 Caches::getInstance().dumpMemoryUsage(cachesLog);
85 fprintf(file, "\nCaches:\n%s", cachesLog.string());
86 fprintf(file, "\n");
87
Chet Haase9c1e23b2011-03-24 10:51:31 -070088 fflush(file);
89}
90
Romain Guyb051e892010-09-28 19:09:36 -070091DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -080092 initFromDisplayListRenderer(recorder);
93}
94
95DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -080096 clearResources();
97}
98
99void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -0800100 sk_free((void*) mReader.base());
101
102 Caches& caches = Caches::getInstance();
103
104 for (size_t i = 0; i < mBitmapResources.size(); i++) {
105 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
106 }
107 mBitmapResources.clear();
108
Romain Guyd586ad92011-06-22 16:14:36 -0700109 for (size_t i = 0; i < mFilterResources.size(); i++) {
110 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
111 }
112 mFilterResources.clear();
113
Romain Guy24c00212011-01-14 15:31:00 -0800114 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800115 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700116 caches.resourceCache.destructor(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800117 }
Romain Guy24c00212011-01-14 15:31:00 -0800118 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800119
120 for (size_t i = 0; i < mPaints.size(); i++) {
121 delete mPaints.itemAt(i);
122 }
123 mPaints.clear();
124
Romain Guy2fc941e2011-02-03 15:06:05 -0800125 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700126 SkPath* path = mPaths.itemAt(i);
127 caches.pathCache.remove(path);
128 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800129 }
130 mPaths.clear();
131
Chet Haase5977baa2011-01-05 18:01:22 -0800132 for (size_t i = 0; i < mMatrices.size(); i++) {
133 delete mMatrices.itemAt(i);
134 }
135 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800136}
137
Chet Haased63cbd12011-02-03 16:32:46 -0800138void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700139 const SkWriter32& writer = recorder.writeStream();
140 init();
141
142 if (writer.size() == 0) {
143 return;
144 }
145
Chet Haased63cbd12011-02-03 16:32:46 -0800146 if (reusing) {
147 // re-using display list - clear out previous allocations
148 clearResources();
149 }
150
Romain Guy65b345f2011-07-27 18:51:50 -0700151 mSize = writer.size();
152 void* buffer = sk_malloc_throw(mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700153 writer.flatten(buffer);
Romain Guy65b345f2011-07-27 18:51:50 -0700154 mReader.setMemory(buffer, mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700155
Chet Haase5c13d892010-10-08 08:37:55 -0700156 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700157
Chet Haase5c13d892010-10-08 08:37:55 -0700158 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
159 for (size_t i = 0; i < bitmapResources.size(); i++) {
160 SkBitmap* resource = bitmapResources.itemAt(i);
161 mBitmapResources.add(resource);
162 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700163 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700164
Romain Guyd586ad92011-06-22 16:14:36 -0700165 const Vector<SkiaColorFilter*> &filterResources = recorder.getFilterResources();
166 for (size_t i = 0; i < filterResources.size(); i++) {
167 SkiaColorFilter* resource = filterResources.itemAt(i);
168 mFilterResources.add(resource);
169 caches.resourceCache.incrementRefcount(resource);
170 }
171
Romain Guy24c00212011-01-14 15:31:00 -0800172 const Vector<SkiaShader*> &shaders = recorder.getShaders();
173 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700174 SkiaShader* resource = shaders.itemAt(i);
175 mShaders.add(resource);
176 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700177 }
178
Chet Haased98aa2d2010-10-25 15:47:32 -0700179 const Vector<SkPaint*> &paints = recorder.getPaints();
180 for (size_t i = 0; i < paints.size(); i++) {
181 mPaints.add(paints.itemAt(i));
182 }
183
Romain Guy2fc941e2011-02-03 15:06:05 -0800184 const Vector<SkPath*> &paths = recorder.getPaths();
185 for (size_t i = 0; i < paths.size(); i++) {
186 mPaths.add(paths.itemAt(i));
187 }
188
Chet Haased98aa2d2010-10-25 15:47:32 -0700189 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
190 for (size_t i = 0; i < matrices.size(); i++) {
191 mMatrices.add(matrices.itemAt(i));
192 }
Romain Guyb051e892010-09-28 19:09:36 -0700193}
194
Romain Guyb051e892010-09-28 19:09:36 -0700195void DisplayList::init() {
Romain Guy65b345f2011-07-27 18:51:50 -0700196 mSize = 0;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700197 mIsRenderable = true;
Romain Guy65b345f2011-07-27 18:51:50 -0700198}
199
200size_t DisplayList::getSize() {
201 return mSize;
Romain Guyb051e892010-09-28 19:09:36 -0700202}
203
Chet Haaseed30fd82011-04-22 16:18:45 -0700204/**
205 * This function is a simplified version of replay(), where we simply retrieve and log the
206 * display list. This function should remain in sync with the replay() function.
207 */
208void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
209 TextContainer text;
210
211 uint32_t count = (level + 1) * 2;
212 char indent[count + 1];
213 for (uint32_t i = 0; i < count; i++) {
214 indent[i] = ' ';
215 }
216 indent[count] = '\0';
217 LOGD("%sStart display list (%p)", (char*) indent + 2, this);
218
219 int saveCount = renderer.getSaveCount() - 1;
220
221 mReader.rewind();
222
223 while (!mReader.eof()) {
224 int op = mReader.readInt();
225
226 switch (op) {
227 case DrawGLFunction: {
228 Functor *functor = (Functor *) getInt();
229 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
230 }
231 break;
232 case Save: {
233 int rendererNum = getInt();
234 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
235 }
236 break;
237 case Restore: {
238 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
239 }
240 break;
241 case RestoreToCount: {
242 int restoreCount = saveCount + getInt();
243 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
244 }
245 break;
246 case SaveLayer: {
247 float f1 = getFloat();
248 float f2 = getFloat();
249 float f3 = getFloat();
250 float f4 = getFloat();
251 SkPaint* paint = getPaint();
252 int flags = getInt();
253 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
254 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
255 }
256 break;
257 case SaveLayerAlpha: {
258 float f1 = getFloat();
259 float f2 = getFloat();
260 float f3 = getFloat();
261 float f4 = getFloat();
262 int alpha = getInt();
263 int flags = getInt();
264 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
265 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
266 }
267 break;
268 case Translate: {
269 float f1 = getFloat();
270 float f2 = getFloat();
271 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
272 }
273 break;
274 case Rotate: {
275 float rotation = getFloat();
276 LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
277 }
278 break;
279 case Scale: {
280 float sx = getFloat();
281 float sy = getFloat();
282 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
283 }
284 break;
285 case Skew: {
286 float sx = getFloat();
287 float sy = getFloat();
288 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
289 }
290 break;
291 case SetMatrix: {
292 SkMatrix* matrix = getMatrix();
293 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
294 }
295 break;
296 case ConcatMatrix: {
297 SkMatrix* matrix = getMatrix();
298 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
299 }
300 break;
301 case ClipRect: {
302 float f1 = getFloat();
303 float f2 = getFloat();
304 float f3 = getFloat();
305 float f4 = getFloat();
306 int regionOp = getInt();
307 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
308 f1, f2, f3, f4, regionOp);
309 }
310 break;
311 case DrawDisplayList: {
312 DisplayList* displayList = getDisplayList();
313 uint32_t width = getUInt();
314 uint32_t height = getUInt();
315 LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
316 displayList, width, height, level + 1);
317 renderer.outputDisplayList(displayList, level + 1);
318 }
319 break;
320 case DrawLayer: {
321 Layer* layer = (Layer*) getInt();
322 float x = getFloat();
323 float y = getFloat();
324 SkPaint* paint = getPaint();
325 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
326 layer, x, y, paint);
327 }
328 break;
329 case DrawBitmap: {
330 SkBitmap* bitmap = getBitmap();
331 float x = getFloat();
332 float y = getFloat();
333 SkPaint* paint = getPaint();
334 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
335 bitmap, x, y, paint);
336 }
337 break;
338 case DrawBitmapMatrix: {
339 SkBitmap* bitmap = getBitmap();
340 SkMatrix* matrix = getMatrix();
341 SkPaint* paint = getPaint();
342 LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
343 bitmap, matrix, paint);
344 }
345 break;
346 case DrawBitmapRect: {
347 SkBitmap* bitmap = getBitmap();
348 float f1 = getFloat();
349 float f2 = getFloat();
350 float f3 = getFloat();
351 float f4 = getFloat();
352 float f5 = getFloat();
353 float f6 = getFloat();
354 float f7 = getFloat();
355 float f8 = getFloat();
356 SkPaint* paint = getPaint();
357 LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
358 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
359 }
360 break;
361 case DrawBitmapMesh: {
362 int verticesCount = 0;
363 uint32_t colorsCount = 0;
364 SkBitmap* bitmap = getBitmap();
365 uint32_t meshWidth = getInt();
366 uint32_t meshHeight = getInt();
367 float* vertices = getFloats(verticesCount);
368 bool hasColors = getInt();
369 int* colors = hasColors ? getInts(colorsCount) : NULL;
370 SkPaint* paint = getPaint();
371 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
372 }
373 break;
374 case DrawPatch: {
375 int32_t* xDivs = NULL;
376 int32_t* yDivs = NULL;
377 uint32_t* colors = NULL;
378 uint32_t xDivsCount = 0;
379 uint32_t yDivsCount = 0;
380 int8_t numColors = 0;
381 SkBitmap* bitmap = getBitmap();
382 xDivs = getInts(xDivsCount);
383 yDivs = getInts(yDivsCount);
384 colors = getUInts(numColors);
Romain Guya62f1722011-10-19 17:06:19 -0700385 float left = getFloat();
386 float top = getFloat();
387 float right = getFloat();
388 float bottom = getFloat();
389 SkPaint* paint = getPaint();
390 LOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
391 left, top, right, bottom);
Chet Haaseed30fd82011-04-22 16:18:45 -0700392 }
393 break;
394 case DrawColor: {
395 int color = getInt();
396 int xferMode = getInt();
397 LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
398 }
399 break;
400 case DrawRect: {
401 float f1 = getFloat();
402 float f2 = getFloat();
403 float f3 = getFloat();
404 float f4 = getFloat();
405 SkPaint* paint = getPaint();
406 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
407 f1, f2, f3, f4, paint);
408 }
409 break;
410 case DrawRoundRect: {
411 float f1 = getFloat();
412 float f2 = getFloat();
413 float f3 = getFloat();
414 float f4 = getFloat();
415 float f5 = getFloat();
416 float f6 = getFloat();
417 SkPaint* paint = getPaint();
418 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
419 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
420 }
421 break;
422 case DrawCircle: {
423 float f1 = getFloat();
424 float f2 = getFloat();
425 float f3 = getFloat();
426 SkPaint* paint = getPaint();
427 LOGD("%s%s %.2f, %.2f, %.2f, %p",
428 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
429 }
430 break;
431 case DrawOval: {
432 float f1 = getFloat();
433 float f2 = getFloat();
434 float f3 = getFloat();
435 float f4 = getFloat();
436 SkPaint* paint = getPaint();
437 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
438 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
439 }
440 break;
441 case DrawArc: {
442 float f1 = getFloat();
443 float f2 = getFloat();
444 float f3 = getFloat();
445 float f4 = getFloat();
446 float f5 = getFloat();
447 float f6 = getFloat();
448 int i1 = getInt();
449 SkPaint* paint = getPaint();
450 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
451 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
452 }
453 break;
454 case DrawPath: {
455 SkPath* path = getPath();
456 SkPaint* paint = getPaint();
457 LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
458 }
459 break;
460 case DrawLines: {
461 int count = 0;
462 float* points = getFloats(count);
463 SkPaint* paint = getPaint();
464 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
465 }
466 break;
467 case DrawPoints: {
468 int count = 0;
469 float* points = getFloats(count);
470 SkPaint* paint = getPaint();
471 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
472 }
473 break;
474 case DrawText: {
475 getText(&text);
476 int count = getInt();
477 float x = getFloat();
478 float y = getFloat();
479 SkPaint* paint = getPaint();
Romain Guycac5fd32011-12-01 20:08:50 -0800480 float length = getFloat();
481 LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
482 text.text(), text.length(), count, x, y, paint, length);
Chet Haaseed30fd82011-04-22 16:18:45 -0700483 }
484 break;
485 case ResetShader: {
486 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
487 }
488 break;
489 case SetupShader: {
490 SkiaShader* shader = getShader();
491 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
492 }
493 break;
494 case ResetColorFilter: {
495 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
496 }
497 break;
498 case SetupColorFilter: {
499 SkiaColorFilter *colorFilter = getColorFilter();
500 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
501 }
502 break;
503 case ResetShadow: {
504 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
505 }
506 break;
507 case SetupShadow: {
508 float radius = getFloat();
509 float dx = getFloat();
510 float dy = getFloat();
511 int color = getInt();
512 LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
513 radius, dx, dy, color);
514 }
515 break;
516 default:
517 LOGD("Display List error: op not handled: %s%s",
518 (char*) indent, OP_NAMES[op]);
519 break;
520 }
521 }
522
523 LOGD("%sDone", (char*) indent + 2);
524}
525
526/**
527 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
528 * in the output() function, since that function processes the same list of opcodes for the
529 * purposes of logging display list info for a given view.
530 */
Romain Guycabfcc12011-03-07 18:06:46 -0800531bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800532 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700533 TextContainer text;
534 mReader.rewind();
535
Romain Guyffac7fc2011-01-13 17:21:49 -0800536#if DEBUG_DISPLAY_LIST
537 uint32_t count = (level + 1) * 2;
538 char indent[count + 1];
539 for (uint32_t i = 0; i < count; i++) {
540 indent[i] = ' ';
541 }
542 indent[count] = '\0';
543 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
544#endif
Romain Guyb051e892010-09-28 19:09:36 -0700545
Chet Haase9c1e23b2011-03-24 10:51:31 -0700546 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800547 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700548 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700549 int op = mReader.readInt();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700550 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800551
Romain Guy5b3b3522010-10-27 18:57:51 -0700552 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800553 case DrawGLFunction: {
554 Functor *functor = (Functor *) getInt();
555 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guycabfcc12011-03-07 18:06:46 -0800556 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Chet Haasedaf98e92011-01-10 14:10:36 -0800557 }
558 break;
Romain Guyb051e892010-09-28 19:09:36 -0700559 case Save: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800560 int rendererNum = getInt();
561 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
562 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700563 }
564 break;
565 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800566 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700567 renderer.restore();
568 }
569 break;
570 case RestoreToCount: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800571 int restoreCount = saveCount + getInt();
572 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
573 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700574 }
575 break;
576 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800577 float f1 = getFloat();
578 float f2 = getFloat();
579 float f3 = getFloat();
580 float f4 = getFloat();
581 SkPaint* paint = getPaint();
582 int flags = getInt();
583 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
584 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
585 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700586 }
587 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700588 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800589 float f1 = getFloat();
590 float f2 = getFloat();
591 float f3 = getFloat();
592 float f4 = getFloat();
593 int alpha = getInt();
594 int flags = getInt();
595 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
596 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
597 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700598 }
599 break;
Romain Guyb051e892010-09-28 19:09:36 -0700600 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800601 float f1 = getFloat();
602 float f2 = getFloat();
603 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
604 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700605 }
606 break;
607 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800608 float rotation = getFloat();
609 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
610 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700611 }
612 break;
613 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800614 float sx = getFloat();
615 float sy = getFloat();
616 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
617 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700618 }
619 break;
Romain Guy807daf72011-01-18 11:19:19 -0800620 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800621 float sx = getFloat();
622 float sy = getFloat();
623 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
624 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800625 }
626 break;
Romain Guyb051e892010-09-28 19:09:36 -0700627 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800628 SkMatrix* matrix = getMatrix();
629 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
630 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700631 }
632 break;
633 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800634 SkMatrix* matrix = getMatrix();
635 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
636 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700637 }
638 break;
639 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800640 float f1 = getFloat();
641 float f2 = getFloat();
642 float f3 = getFloat();
643 float f4 = getFloat();
644 int regionOp = getInt();
645 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
646 f1, f2, f3, f4, regionOp);
647 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700648 }
649 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800650 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800651 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700652 uint32_t width = getUInt();
653 uint32_t height = getUInt();
654 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
655 displayList, width, height, level + 1);
656 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
657 dirty, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800658 }
659 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800660 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800661 Layer* layer = (Layer*) getInt();
662 float x = getFloat();
663 float y = getFloat();
664 SkPaint* paint = getPaint();
665 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
666 layer, x, y, paint);
667 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800668 }
669 break;
Romain Guyb051e892010-09-28 19:09:36 -0700670 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800671 SkBitmap* bitmap = getBitmap();
672 float x = getFloat();
673 float y = getFloat();
674 SkPaint* paint = getPaint();
675 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
676 bitmap, x, y, paint);
677 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700678 }
679 break;
680 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800681 SkBitmap* bitmap = getBitmap();
682 SkMatrix* matrix = getMatrix();
683 SkPaint* paint = getPaint();
684 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
685 bitmap, matrix, paint);
686 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700687 }
688 break;
689 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800690 SkBitmap* bitmap = getBitmap();
691 float f1 = getFloat();
692 float f2 = getFloat();
693 float f3 = getFloat();
694 float f4 = getFloat();
695 float f5 = getFloat();
696 float f6 = getFloat();
697 float f7 = getFloat();
698 float f8 = getFloat();
699 SkPaint* paint = getPaint();
700 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
701 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
702 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700703 }
704 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800705 case DrawBitmapMesh: {
706 int verticesCount = 0;
707 uint32_t colorsCount = 0;
708
709 SkBitmap* bitmap = getBitmap();
710 uint32_t meshWidth = getInt();
711 uint32_t meshHeight = getInt();
712 float* vertices = getFloats(verticesCount);
713 bool hasColors = getInt();
714 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy9ff3cb52011-06-28 14:02:11 -0700715 SkPaint* paint = getPaint();
Romain Guy5a7b4662011-01-20 19:09:30 -0800716
Chet Haasedaf98e92011-01-10 14:10:36 -0800717 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700718 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -0800719 }
Romain Guya566b7c2011-01-23 16:36:11 -0800720 break;
Romain Guyb051e892010-09-28 19:09:36 -0700721 case DrawPatch: {
722 int32_t* xDivs = NULL;
723 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700724 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700725 uint32_t xDivsCount = 0;
726 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700727 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700728
729 SkBitmap* bitmap = getBitmap();
730
731 xDivs = getInts(xDivsCount);
732 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700733 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700734
Romain Guy9ff3cb52011-06-28 14:02:11 -0700735 float left = getFloat();
736 float top = getFloat();
737 float right = getFloat();
738 float bottom = getFloat();
739 SkPaint* paint = getPaint();
740
Chet Haasedaf98e92011-01-10 14:10:36 -0800741 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700742 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
Romain Guy9ff3cb52011-06-28 14:02:11 -0700743 numColors, left, top, right, bottom, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700744 }
745 break;
746 case DrawColor: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800747 int color = getInt();
748 int xferMode = getInt();
749 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
750 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700751 }
752 break;
753 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800754 float f1 = getFloat();
755 float f2 = getFloat();
756 float f3 = getFloat();
757 float f4 = getFloat();
758 SkPaint* paint = getPaint();
759 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
760 f1, f2, f3, f4, paint);
761 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700762 }
763 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800764 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800765 float f1 = getFloat();
766 float f2 = getFloat();
767 float f3 = getFloat();
768 float f4 = getFloat();
769 float f5 = getFloat();
770 float f6 = getFloat();
771 SkPaint* paint = getPaint();
772 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
773 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
774 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800775 }
776 break;
777 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800778 float f1 = getFloat();
779 float f2 = getFloat();
780 float f3 = getFloat();
781 SkPaint* paint = getPaint();
782 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
783 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
784 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800785 }
786 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800787 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800788 float f1 = getFloat();
789 float f2 = getFloat();
790 float f3 = getFloat();
791 float f4 = getFloat();
792 SkPaint* paint = getPaint();
793 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
794 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
795 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800796 }
797 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800798 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800799 float f1 = getFloat();
800 float f2 = getFloat();
801 float f3 = getFloat();
802 float f4 = getFloat();
803 float f5 = getFloat();
804 float f6 = getFloat();
805 int i1 = getInt();
806 SkPaint* paint = getPaint();
807 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
808 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
809 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800810 }
811 break;
Romain Guyb051e892010-09-28 19:09:36 -0700812 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800813 SkPath* path = getPath();
814 SkPaint* paint = getPaint();
815 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
816 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700817 }
818 break;
819 case DrawLines: {
820 int count = 0;
821 float* points = getFloats(count);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700822 SkPaint* paint = getPaint();
Chet Haasedaf98e92011-01-10 14:10:36 -0800823 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700824 renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700825 }
826 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700827 case DrawPoints: {
828 int count = 0;
829 float* points = getFloats(count);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700830 SkPaint* paint = getPaint();
Romain Guyed6fcb02011-03-21 13:11:28 -0700831 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700832 renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700833 }
834 break;
Romain Guyb051e892010-09-28 19:09:36 -0700835 case DrawText: {
836 getText(&text);
Chet Haasedaf98e92011-01-10 14:10:36 -0800837 int count = getInt();
838 float x = getFloat();
839 float y = getFloat();
840 SkPaint* paint = getPaint();
Romain Guycac5fd32011-12-01 20:08:50 -0800841 float length = getFloat();
842 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
843 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
844 renderer.drawText(text.text(), text.length(), count, x, y, paint, length);
Romain Guyb051e892010-09-28 19:09:36 -0700845 }
846 break;
847 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800848 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700849 renderer.resetShader();
850 }
851 break;
852 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800853 SkiaShader* shader = getShader();
854 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
855 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700856 }
857 break;
858 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800859 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700860 renderer.resetColorFilter();
861 }
862 break;
863 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800864 SkiaColorFilter *colorFilter = getColorFilter();
865 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
866 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700867 }
868 break;
869 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800870 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700871 renderer.resetShadow();
872 }
873 break;
874 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800875 float radius = getFloat();
876 float dx = getFloat();
877 float dy = getFloat();
878 int color = getInt();
879 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
880 radius, dx, dy, color);
881 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700882 }
883 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800884 default:
885 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
886 (char*) indent, OP_NAMES[op]);
887 break;
Romain Guyb051e892010-09-28 19:09:36 -0700888 }
889 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800890
Chet Haasedaf98e92011-01-10 14:10:36 -0800891 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
892 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700893}
894
895///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700896// Base structure
897///////////////////////////////////////////////////////////////////////////////
898
Romain Guy04c9d8c2011-08-25 14:01:48 -0700899DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -0700900}
901
902DisplayListRenderer::~DisplayListRenderer() {
903 reset();
904}
905
906void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -0700907 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700908
909 Caches& caches = Caches::getInstance();
910 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700911 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -0700912 }
913 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700914
Romain Guyd586ad92011-06-22 16:14:36 -0700915 for (size_t i = 0; i < mFilterResources.size(); i++) {
916 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
917 }
918 mFilterResources.clear();
919
Romain Guy43ccf462011-01-14 18:51:01 -0800920 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700921 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -0800922 }
Romain Guy24c00212011-01-14 15:31:00 -0800923 mShaders.clear();
924 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800925
926 mPaints.clear();
927 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700928
Romain Guy2fc941e2011-02-03 15:06:05 -0800929 mPaths.clear();
930 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700931
Chet Haased98aa2d2010-10-25 15:47:32 -0700932 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -0700933
934 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -0700935}
936
937///////////////////////////////////////////////////////////////////////////////
938// Operations
939///////////////////////////////////////////////////////////////////////////////
940
Jeff Brown162a0212011-07-21 17:02:54 -0700941DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
942 if (!displayList) {
943 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -0800944 } else {
Jeff Brown162a0212011-07-21 17:02:54 -0700945 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800946 }
Romain Guy04c9d8c2011-08-25 14:01:48 -0700947 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -0700948 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -0800949}
950
Romain Guyb051e892010-09-28 19:09:36 -0700951void DisplayListRenderer::setViewport(int width, int height) {
952 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
953
954 mWidth = width;
955 mHeight = height;
956}
957
Romain Guy7d7b5492011-01-24 16:33:45 -0800958void DisplayListRenderer::prepareDirty(float left, float top,
959 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700960 mSnapshot = new Snapshot(mFirstSnapshot,
961 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
962 mSaveCount = 1;
963 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -0800964 mRestoreSaveCount = -1;
965}
966
967void DisplayListRenderer::finish() {
968 insertRestoreToCount();
969 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -0700970}
971
Chet Haasedaf98e92011-01-10 14:10:36 -0800972void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800973}
Romain Guy2b1847e2011-01-26 13:43:01 -0800974
Chet Haasedaf98e92011-01-10 14:10:36 -0800975void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700976}
977
Romain Guycabfcc12011-03-07 18:06:46 -0800978bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
979 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -0800980 addOp(DisplayList::DrawGLFunction);
981 addInt((int) functor);
982 return false; // No invalidate needed at record-time
983}
984
Romain Guy4aa90572010-09-26 18:40:37 -0700985int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700986 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700987 addInt(flags);
988 return OpenGLRenderer::save(flags);
989}
990
991void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700992 if (mRestoreSaveCount < 0) {
993 addOp(DisplayList::Restore);
994 } else {
995 mRestoreSaveCount--;
996 }
Romain Guy4aa90572010-09-26 18:40:37 -0700997 OpenGLRenderer::restore();
998}
999
1000void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001001 mRestoreSaveCount = saveCount;
Romain Guy4aa90572010-09-26 18:40:37 -07001002 OpenGLRenderer::restoreToCount(saveCount);
1003}
1004
1005int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001006 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001007 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001008 addBounds(left, top, right, bottom);
1009 addPaint(p);
1010 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001011 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001012}
1013
Romain Guy5b3b3522010-10-27 18:57:51 -07001014int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1015 int alpha, int flags) {
1016 addOp(DisplayList::SaveLayerAlpha);
1017 addBounds(left, top, right, bottom);
1018 addInt(alpha);
1019 addInt(flags);
1020 return OpenGLRenderer::save(flags);
1021}
1022
Romain Guy4aa90572010-09-26 18:40:37 -07001023void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -07001024 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -07001025 addPoint(dx, dy);
1026 OpenGLRenderer::translate(dx, dy);
1027}
1028
1029void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001030 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001031 addFloat(degrees);
1032 OpenGLRenderer::rotate(degrees);
1033}
1034
1035void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001036 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001037 addPoint(sx, sy);
1038 OpenGLRenderer::scale(sx, sy);
1039}
1040
Romain Guy807daf72011-01-18 11:19:19 -08001041void DisplayListRenderer::skew(float sx, float sy) {
1042 addOp(DisplayList::Skew);
1043 addPoint(sx, sy);
1044 OpenGLRenderer::skew(sx, sy);
1045}
1046
Romain Guy4aa90572010-09-26 18:40:37 -07001047void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001048 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001049 addMatrix(matrix);
1050 OpenGLRenderer::setMatrix(matrix);
1051}
1052
1053void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001054 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001055 addMatrix(matrix);
1056 OpenGLRenderer::concatMatrix(matrix);
1057}
1058
1059bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1060 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001061 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001062 addBounds(left, top, right, bottom);
1063 addInt(op);
1064 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1065}
1066
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001067bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
1068 uint32_t width, uint32_t height, Rect& dirty, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001069 // dirty is an out parameter and should not be recorded,
1070 // it matters only when replaying the display list
Romain Guy0fe478e2010-11-08 12:08:41 -08001071 addOp(DisplayList::DrawDisplayList);
1072 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001073 addSize(width, height);
Chet Haasedaf98e92011-01-10 14:10:36 -08001074 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001075}
1076
Romain Guyada830f2011-01-13 12:13:20 -08001077void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001078 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001079 addInt((int) layer);
1080 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001081 addPaint(paint);
1082}
1083
Romain Guy4aa90572010-09-26 18:40:37 -07001084void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -07001085 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001086 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -07001087 addBitmap(bitmap);
1088 addPoint(left, top);
1089 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001090}
1091
Chet Haase5c13d892010-10-08 08:37:55 -07001092void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
1093 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001094 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001095 addBitmap(bitmap);
1096 addMatrix(matrix);
1097 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001098}
1099
1100void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1101 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001102 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001103 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001104 addBitmap(bitmap);
1105 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1106 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1107 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001108}
1109
Romain Guy5a7b4662011-01-20 19:09:30 -08001110void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1111 float* vertices, int* colors, SkPaint* paint) {
1112 addOp(DisplayList::DrawBitmapMesh);
1113 addBitmap(bitmap);
1114 addInt(meshWidth);
1115 addInt(meshHeight);
1116 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1117 if (colors) {
1118 addInt(1);
1119 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1120 } else {
1121 addInt(0);
1122 }
1123 addPaint(paint);
1124}
1125
Romain Guy4aa90572010-09-26 18:40:37 -07001126void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001127 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001128 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001129 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -07001130 addBitmap(bitmap);
1131 addInts(xDivs, width);
1132 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001133 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001134 addBounds(left, top, right, bottom);
1135 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001136}
1137
1138void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001139 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001140 addInt(color);
1141 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001142}
1143
1144void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001145 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001146 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001147 addBounds(left, top, right, bottom);
1148 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001149}
1150
Romain Guy01d58e42011-01-19 21:54:02 -08001151void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1152 float rx, float ry, SkPaint* paint) {
1153 addOp(DisplayList::DrawRoundRect);
1154 addBounds(left, top, right, bottom);
1155 addPoint(rx, ry);
1156 addPaint(paint);
1157}
1158
1159void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1160 addOp(DisplayList::DrawCircle);
1161 addPoint(x, y);
1162 addFloat(radius);
1163 addPaint(paint);
1164}
1165
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001166void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1167 SkPaint* paint) {
1168 addOp(DisplayList::DrawOval);
1169 addBounds(left, top, right, bottom);
1170 addPaint(paint);
1171}
1172
Romain Guy8b2f5262011-01-23 16:15:02 -08001173void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1174 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001175 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001176 addBounds(left, top, right, bottom);
1177 addPoint(startAngle, sweepAngle);
1178 addInt(useCenter ? 1 : 0);
1179 addPaint(paint);
1180}
1181
Romain Guy4aa90572010-09-26 18:40:37 -07001182void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001183 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -07001184 addPath(path);
1185 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001186}
1187
Chet Haase5c13d892010-10-08 08:37:55 -07001188void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001189 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001190 addFloats(points, count);
1191 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001192}
1193
Romain Guyed6fcb02011-03-21 13:11:28 -07001194void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1195 addOp(DisplayList::DrawPoints);
1196 addFloats(points, count);
1197 addPaint(paint);
1198}
1199
Romain Guy4aa90572010-09-26 18:40:37 -07001200void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Romain Guycac5fd32011-12-01 20:08:50 -08001201 float x, float y, SkPaint* paint, float length) {
Romain Guy726aeba2011-06-01 14:52:00 -07001202 if (count <= 0) return;
Romain Guyb051e892010-09-28 19:09:36 -07001203 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -07001204 addText(text, bytesCount);
1205 addInt(count);
1206 addPoint(x, y);
Romain Guy8f9a9f62011-12-05 11:53:26 -08001207 // TODO: We should probably make a copy of the paint instead of modifying
1208 // it; modifying the paint will change its generationID the first
1209 // time, which might impact caches. More investigation needed to
1210 // see if it matters.
1211 // If we make a copy, then drawTextDecorations() should *not* make
1212 // its own copy as it does right now.
1213 paint->setAntiAlias(true);
1214#if RENDER_TEXT_AS_GLYPHS
1215 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1216#endif
Romain Guy4aa90572010-09-26 18:40:37 -07001217 addPaint(paint);
Romain Guycac5fd32011-12-01 20:08:50 -08001218 addFloat(length < 0.0f ? paint->measureText(text, bytesCount) : length);
Romain Guy4aa90572010-09-26 18:40:37 -07001219}
1220
1221void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001222 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001223}
1224
1225void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001226 addOp(DisplayList::SetupShader);
1227 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001228}
1229
1230void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001231 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001232}
1233
1234void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001235 addOp(DisplayList::SetupColorFilter);
1236 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001237}
1238
1239void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001240 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001241}
1242
1243void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001244 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001245 addFloat(radius);
1246 addPoint(dx, dy);
1247 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001248}
1249
Romain Guy4aa90572010-09-26 18:40:37 -07001250}; // namespace uirenderer
1251}; // namespace android