blob: cedf456e22c3279303ce661d29eab37cdee28db0 [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);
385 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
386 getFloat();
387 getFloat();
388 getFloat();
389 getFloat();
390 getPaint();
391 }
392 break;
393 case DrawColor: {
394 int color = getInt();
395 int xferMode = getInt();
396 LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
397 }
398 break;
399 case DrawRect: {
400 float f1 = getFloat();
401 float f2 = getFloat();
402 float f3 = getFloat();
403 float f4 = getFloat();
404 SkPaint* paint = getPaint();
405 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
406 f1, f2, f3, f4, paint);
407 }
408 break;
409 case DrawRoundRect: {
410 float f1 = getFloat();
411 float f2 = getFloat();
412 float f3 = getFloat();
413 float f4 = getFloat();
414 float f5 = getFloat();
415 float f6 = getFloat();
416 SkPaint* paint = getPaint();
417 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
418 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
419 }
420 break;
421 case DrawCircle: {
422 float f1 = getFloat();
423 float f2 = getFloat();
424 float f3 = getFloat();
425 SkPaint* paint = getPaint();
426 LOGD("%s%s %.2f, %.2f, %.2f, %p",
427 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
428 }
429 break;
430 case DrawOval: {
431 float f1 = getFloat();
432 float f2 = getFloat();
433 float f3 = getFloat();
434 float f4 = getFloat();
435 SkPaint* paint = getPaint();
436 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
437 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
438 }
439 break;
440 case DrawArc: {
441 float f1 = getFloat();
442 float f2 = getFloat();
443 float f3 = getFloat();
444 float f4 = getFloat();
445 float f5 = getFloat();
446 float f6 = getFloat();
447 int i1 = getInt();
448 SkPaint* paint = getPaint();
449 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
450 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
451 }
452 break;
453 case DrawPath: {
454 SkPath* path = getPath();
455 SkPaint* paint = getPaint();
456 LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
457 }
458 break;
459 case DrawLines: {
460 int count = 0;
461 float* points = getFloats(count);
462 SkPaint* paint = getPaint();
463 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
464 }
465 break;
466 case DrawPoints: {
467 int count = 0;
468 float* points = getFloats(count);
469 SkPaint* paint = getPaint();
470 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
471 }
472 break;
473 case DrawText: {
474 getText(&text);
475 int count = getInt();
476 float x = getFloat();
477 float y = getFloat();
478 SkPaint* paint = getPaint();
479 LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
480 text.text(), text.length(), count, x, y, paint);
481 }
482 break;
483 case ResetShader: {
484 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
485 }
486 break;
487 case SetupShader: {
488 SkiaShader* shader = getShader();
489 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
490 }
491 break;
492 case ResetColorFilter: {
493 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
494 }
495 break;
496 case SetupColorFilter: {
497 SkiaColorFilter *colorFilter = getColorFilter();
498 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
499 }
500 break;
501 case ResetShadow: {
502 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
503 }
504 break;
505 case SetupShadow: {
506 float radius = getFloat();
507 float dx = getFloat();
508 float dy = getFloat();
509 int color = getInt();
510 LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
511 radius, dx, dy, color);
512 }
513 break;
514 default:
515 LOGD("Display List error: op not handled: %s%s",
516 (char*) indent, OP_NAMES[op]);
517 break;
518 }
519 }
520
521 LOGD("%sDone", (char*) indent + 2);
522}
523
524/**
525 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
526 * in the output() function, since that function processes the same list of opcodes for the
527 * purposes of logging display list info for a given view.
528 */
Romain Guycabfcc12011-03-07 18:06:46 -0800529bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800530 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700531 TextContainer text;
532 mReader.rewind();
533
Romain Guyffac7fc2011-01-13 17:21:49 -0800534#if DEBUG_DISPLAY_LIST
535 uint32_t count = (level + 1) * 2;
536 char indent[count + 1];
537 for (uint32_t i = 0; i < count; i++) {
538 indent[i] = ' ';
539 }
540 indent[count] = '\0';
541 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
542#endif
Romain Guyb051e892010-09-28 19:09:36 -0700543
Chet Haase9c1e23b2011-03-24 10:51:31 -0700544 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800545 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700546 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700547 int op = mReader.readInt();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700548 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800549
Romain Guy5b3b3522010-10-27 18:57:51 -0700550 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800551 case DrawGLFunction: {
552 Functor *functor = (Functor *) getInt();
553 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guycabfcc12011-03-07 18:06:46 -0800554 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Chet Haasedaf98e92011-01-10 14:10:36 -0800555 }
556 break;
Romain Guyb051e892010-09-28 19:09:36 -0700557 case Save: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800558 int rendererNum = getInt();
559 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
560 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700561 }
562 break;
563 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800564 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700565 renderer.restore();
566 }
567 break;
568 case RestoreToCount: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800569 int restoreCount = saveCount + getInt();
570 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
571 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700572 }
573 break;
574 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800575 float f1 = getFloat();
576 float f2 = getFloat();
577 float f3 = getFloat();
578 float f4 = getFloat();
579 SkPaint* paint = getPaint();
580 int flags = getInt();
581 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
582 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
583 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700584 }
585 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700586 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800587 float f1 = getFloat();
588 float f2 = getFloat();
589 float f3 = getFloat();
590 float f4 = getFloat();
591 int alpha = getInt();
592 int flags = getInt();
593 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
594 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
595 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700596 }
597 break;
Romain Guyb051e892010-09-28 19:09:36 -0700598 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800599 float f1 = getFloat();
600 float f2 = getFloat();
601 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
602 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700603 }
604 break;
605 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800606 float rotation = getFloat();
607 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
608 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700609 }
610 break;
611 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800612 float sx = getFloat();
613 float sy = getFloat();
614 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
615 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700616 }
617 break;
Romain Guy807daf72011-01-18 11:19:19 -0800618 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800619 float sx = getFloat();
620 float sy = getFloat();
621 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
622 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800623 }
624 break;
Romain Guyb051e892010-09-28 19:09:36 -0700625 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800626 SkMatrix* matrix = getMatrix();
627 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
628 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700629 }
630 break;
631 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800632 SkMatrix* matrix = getMatrix();
633 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
634 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700635 }
636 break;
637 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800638 float f1 = getFloat();
639 float f2 = getFloat();
640 float f3 = getFloat();
641 float f4 = getFloat();
642 int regionOp = getInt();
643 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
644 f1, f2, f3, f4, regionOp);
645 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700646 }
647 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800648 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800649 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700650 uint32_t width = getUInt();
651 uint32_t height = getUInt();
652 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
653 displayList, width, height, level + 1);
654 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
655 dirty, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800656 }
657 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800658 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800659 Layer* layer = (Layer*) getInt();
660 float x = getFloat();
661 float y = getFloat();
662 SkPaint* paint = getPaint();
663 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
664 layer, x, y, paint);
665 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800666 }
667 break;
Romain Guyb051e892010-09-28 19:09:36 -0700668 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800669 SkBitmap* bitmap = getBitmap();
670 float x = getFloat();
671 float y = getFloat();
672 SkPaint* paint = getPaint();
673 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
674 bitmap, x, y, paint);
675 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700676 }
677 break;
678 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800679 SkBitmap* bitmap = getBitmap();
680 SkMatrix* matrix = getMatrix();
681 SkPaint* paint = getPaint();
682 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
683 bitmap, matrix, paint);
684 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700685 }
686 break;
687 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800688 SkBitmap* bitmap = getBitmap();
689 float f1 = getFloat();
690 float f2 = getFloat();
691 float f3 = getFloat();
692 float f4 = getFloat();
693 float f5 = getFloat();
694 float f6 = getFloat();
695 float f7 = getFloat();
696 float f8 = getFloat();
697 SkPaint* paint = getPaint();
698 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
699 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
700 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700701 }
702 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800703 case DrawBitmapMesh: {
704 int verticesCount = 0;
705 uint32_t colorsCount = 0;
706
707 SkBitmap* bitmap = getBitmap();
708 uint32_t meshWidth = getInt();
709 uint32_t meshHeight = getInt();
710 float* vertices = getFloats(verticesCount);
711 bool hasColors = getInt();
712 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy9ff3cb52011-06-28 14:02:11 -0700713 SkPaint* paint = getPaint();
Romain Guy5a7b4662011-01-20 19:09:30 -0800714
Chet Haasedaf98e92011-01-10 14:10:36 -0800715 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700716 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -0800717 }
Romain Guya566b7c2011-01-23 16:36:11 -0800718 break;
Romain Guyb051e892010-09-28 19:09:36 -0700719 case DrawPatch: {
720 int32_t* xDivs = NULL;
721 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700722 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700723 uint32_t xDivsCount = 0;
724 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700725 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700726
727 SkBitmap* bitmap = getBitmap();
728
729 xDivs = getInts(xDivsCount);
730 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700731 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700732
Romain Guy9ff3cb52011-06-28 14:02:11 -0700733 float left = getFloat();
734 float top = getFloat();
735 float right = getFloat();
736 float bottom = getFloat();
737 SkPaint* paint = getPaint();
738
Chet Haasedaf98e92011-01-10 14:10:36 -0800739 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700740 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
Romain Guy9ff3cb52011-06-28 14:02:11 -0700741 numColors, left, top, right, bottom, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700742 }
743 break;
744 case DrawColor: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800745 int color = getInt();
746 int xferMode = getInt();
747 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
748 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700749 }
750 break;
751 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800752 float f1 = getFloat();
753 float f2 = getFloat();
754 float f3 = getFloat();
755 float f4 = getFloat();
756 SkPaint* paint = getPaint();
757 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
758 f1, f2, f3, f4, paint);
759 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700760 }
761 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800762 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800763 float f1 = getFloat();
764 float f2 = getFloat();
765 float f3 = getFloat();
766 float f4 = getFloat();
767 float f5 = getFloat();
768 float f6 = getFloat();
769 SkPaint* paint = getPaint();
770 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
771 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
772 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800773 }
774 break;
775 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800776 float f1 = getFloat();
777 float f2 = getFloat();
778 float f3 = getFloat();
779 SkPaint* paint = getPaint();
780 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
781 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
782 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800783 }
784 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800785 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800786 float f1 = getFloat();
787 float f2 = getFloat();
788 float f3 = getFloat();
789 float f4 = getFloat();
790 SkPaint* paint = getPaint();
791 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
792 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
793 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800794 }
795 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800796 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800797 float f1 = getFloat();
798 float f2 = getFloat();
799 float f3 = getFloat();
800 float f4 = getFloat();
801 float f5 = getFloat();
802 float f6 = getFloat();
803 int i1 = getInt();
804 SkPaint* paint = getPaint();
805 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
806 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
807 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800808 }
809 break;
Romain Guyb051e892010-09-28 19:09:36 -0700810 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800811 SkPath* path = getPath();
812 SkPaint* paint = getPaint();
813 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
814 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700815 }
816 break;
817 case DrawLines: {
818 int count = 0;
819 float* points = getFloats(count);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700820 SkPaint* paint = getPaint();
Chet Haasedaf98e92011-01-10 14:10:36 -0800821 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700822 renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700823 }
824 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700825 case DrawPoints: {
826 int count = 0;
827 float* points = getFloats(count);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700828 SkPaint* paint = getPaint();
Romain Guyed6fcb02011-03-21 13:11:28 -0700829 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700830 renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700831 }
832 break;
Romain Guyb051e892010-09-28 19:09:36 -0700833 case DrawText: {
834 getText(&text);
Chet Haasedaf98e92011-01-10 14:10:36 -0800835 int count = getInt();
836 float x = getFloat();
837 float y = getFloat();
838 SkPaint* paint = getPaint();
839 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
840 text.text(), text.length(), count, x, y, paint);
841 renderer.drawText(text.text(), text.length(), count, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700842 }
843 break;
844 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800845 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700846 renderer.resetShader();
847 }
848 break;
849 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800850 SkiaShader* shader = getShader();
851 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
852 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700853 }
854 break;
855 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800856 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700857 renderer.resetColorFilter();
858 }
859 break;
860 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800861 SkiaColorFilter *colorFilter = getColorFilter();
862 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
863 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700864 }
865 break;
866 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800867 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700868 renderer.resetShadow();
869 }
870 break;
871 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800872 float radius = getFloat();
873 float dx = getFloat();
874 float dy = getFloat();
875 int color = getInt();
876 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
877 radius, dx, dy, color);
878 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700879 }
880 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800881 default:
882 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
883 (char*) indent, OP_NAMES[op]);
884 break;
Romain Guyb051e892010-09-28 19:09:36 -0700885 }
886 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800887
Chet Haasedaf98e92011-01-10 14:10:36 -0800888 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
889 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700890}
891
892///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700893// Base structure
894///////////////////////////////////////////////////////////////////////////////
895
Romain Guy04c9d8c2011-08-25 14:01:48 -0700896DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -0700897}
898
899DisplayListRenderer::~DisplayListRenderer() {
900 reset();
901}
902
903void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -0700904 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700905
906 Caches& caches = Caches::getInstance();
907 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700908 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -0700909 }
910 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700911
Romain Guyd586ad92011-06-22 16:14:36 -0700912 for (size_t i = 0; i < mFilterResources.size(); i++) {
913 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
914 }
915 mFilterResources.clear();
916
Romain Guy43ccf462011-01-14 18:51:01 -0800917 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700918 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -0800919 }
Romain Guy24c00212011-01-14 15:31:00 -0800920 mShaders.clear();
921 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800922
923 mPaints.clear();
924 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700925
Romain Guy2fc941e2011-02-03 15:06:05 -0800926 mPaths.clear();
927 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700928
Chet Haased98aa2d2010-10-25 15:47:32 -0700929 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -0700930
931 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -0700932}
933
934///////////////////////////////////////////////////////////////////////////////
935// Operations
936///////////////////////////////////////////////////////////////////////////////
937
Jeff Brown162a0212011-07-21 17:02:54 -0700938DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
939 if (!displayList) {
940 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -0800941 } else {
Jeff Brown162a0212011-07-21 17:02:54 -0700942 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800943 }
Romain Guy04c9d8c2011-08-25 14:01:48 -0700944 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -0700945 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -0800946}
947
Romain Guyb051e892010-09-28 19:09:36 -0700948void DisplayListRenderer::setViewport(int width, int height) {
949 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
950
951 mWidth = width;
952 mHeight = height;
953}
954
Romain Guy7d7b5492011-01-24 16:33:45 -0800955void DisplayListRenderer::prepareDirty(float left, float top,
956 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700957 mSnapshot = new Snapshot(mFirstSnapshot,
958 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
959 mSaveCount = 1;
960 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -0800961 mRestoreSaveCount = -1;
962}
963
964void DisplayListRenderer::finish() {
965 insertRestoreToCount();
966 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -0700967}
968
Chet Haasedaf98e92011-01-10 14:10:36 -0800969void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800970}
Romain Guy2b1847e2011-01-26 13:43:01 -0800971
Chet Haasedaf98e92011-01-10 14:10:36 -0800972void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700973}
974
Romain Guycabfcc12011-03-07 18:06:46 -0800975bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
976 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -0800977 addOp(DisplayList::DrawGLFunction);
978 addInt((int) functor);
979 return false; // No invalidate needed at record-time
980}
981
Romain Guy4aa90572010-09-26 18:40:37 -0700982int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700983 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700984 addInt(flags);
985 return OpenGLRenderer::save(flags);
986}
987
988void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700989 if (mRestoreSaveCount < 0) {
990 addOp(DisplayList::Restore);
991 } else {
992 mRestoreSaveCount--;
993 }
Romain Guy4aa90572010-09-26 18:40:37 -0700994 OpenGLRenderer::restore();
995}
996
997void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800998 mRestoreSaveCount = saveCount;
Romain Guy4aa90572010-09-26 18:40:37 -0700999 OpenGLRenderer::restoreToCount(saveCount);
1000}
1001
1002int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001003 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001004 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001005 addBounds(left, top, right, bottom);
1006 addPaint(p);
1007 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001008 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001009}
1010
Romain Guy5b3b3522010-10-27 18:57:51 -07001011int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1012 int alpha, int flags) {
1013 addOp(DisplayList::SaveLayerAlpha);
1014 addBounds(left, top, right, bottom);
1015 addInt(alpha);
1016 addInt(flags);
1017 return OpenGLRenderer::save(flags);
1018}
1019
Romain Guy4aa90572010-09-26 18:40:37 -07001020void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -07001021 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -07001022 addPoint(dx, dy);
1023 OpenGLRenderer::translate(dx, dy);
1024}
1025
1026void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001027 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001028 addFloat(degrees);
1029 OpenGLRenderer::rotate(degrees);
1030}
1031
1032void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001033 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001034 addPoint(sx, sy);
1035 OpenGLRenderer::scale(sx, sy);
1036}
1037
Romain Guy807daf72011-01-18 11:19:19 -08001038void DisplayListRenderer::skew(float sx, float sy) {
1039 addOp(DisplayList::Skew);
1040 addPoint(sx, sy);
1041 OpenGLRenderer::skew(sx, sy);
1042}
1043
Romain Guy4aa90572010-09-26 18:40:37 -07001044void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001045 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001046 addMatrix(matrix);
1047 OpenGLRenderer::setMatrix(matrix);
1048}
1049
1050void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001051 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001052 addMatrix(matrix);
1053 OpenGLRenderer::concatMatrix(matrix);
1054}
1055
1056bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1057 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001058 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001059 addBounds(left, top, right, bottom);
1060 addInt(op);
1061 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1062}
1063
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001064bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
1065 uint32_t width, uint32_t height, Rect& dirty, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001066 // dirty is an out parameter and should not be recorded,
1067 // it matters only when replaying the display list
Romain Guy0fe478e2010-11-08 12:08:41 -08001068 addOp(DisplayList::DrawDisplayList);
1069 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001070 addSize(width, height);
Chet Haasedaf98e92011-01-10 14:10:36 -08001071 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001072}
1073
Romain Guyada830f2011-01-13 12:13:20 -08001074void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001075 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001076 addInt((int) layer);
1077 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001078 addPaint(paint);
1079}
1080
Romain Guy4aa90572010-09-26 18:40:37 -07001081void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -07001082 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001083 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -07001084 addBitmap(bitmap);
1085 addPoint(left, top);
1086 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001087}
1088
Chet Haase5c13d892010-10-08 08:37:55 -07001089void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
1090 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001091 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001092 addBitmap(bitmap);
1093 addMatrix(matrix);
1094 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001095}
1096
1097void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1098 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001099 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001100 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001101 addBitmap(bitmap);
1102 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1103 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1104 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001105}
1106
Romain Guy5a7b4662011-01-20 19:09:30 -08001107void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1108 float* vertices, int* colors, SkPaint* paint) {
1109 addOp(DisplayList::DrawBitmapMesh);
1110 addBitmap(bitmap);
1111 addInt(meshWidth);
1112 addInt(meshHeight);
1113 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1114 if (colors) {
1115 addInt(1);
1116 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1117 } else {
1118 addInt(0);
1119 }
1120 addPaint(paint);
1121}
1122
Romain Guy4aa90572010-09-26 18:40:37 -07001123void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001124 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001125 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001126 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -07001127 addBitmap(bitmap);
1128 addInts(xDivs, width);
1129 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001130 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001131 addBounds(left, top, right, bottom);
1132 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001133}
1134
1135void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001136 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001137 addInt(color);
1138 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001139}
1140
1141void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001142 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001143 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001144 addBounds(left, top, right, bottom);
1145 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001146}
1147
Romain Guy01d58e42011-01-19 21:54:02 -08001148void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1149 float rx, float ry, SkPaint* paint) {
1150 addOp(DisplayList::DrawRoundRect);
1151 addBounds(left, top, right, bottom);
1152 addPoint(rx, ry);
1153 addPaint(paint);
1154}
1155
1156void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1157 addOp(DisplayList::DrawCircle);
1158 addPoint(x, y);
1159 addFloat(radius);
1160 addPaint(paint);
1161}
1162
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001163void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1164 SkPaint* paint) {
1165 addOp(DisplayList::DrawOval);
1166 addBounds(left, top, right, bottom);
1167 addPaint(paint);
1168}
1169
Romain Guy8b2f5262011-01-23 16:15:02 -08001170void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1171 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001172 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001173 addBounds(left, top, right, bottom);
1174 addPoint(startAngle, sweepAngle);
1175 addInt(useCenter ? 1 : 0);
1176 addPaint(paint);
1177}
1178
Romain Guy4aa90572010-09-26 18:40:37 -07001179void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001180 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -07001181 addPath(path);
1182 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001183}
1184
Chet Haase5c13d892010-10-08 08:37:55 -07001185void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001186 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001187 addFloats(points, count);
1188 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001189}
1190
Romain Guyed6fcb02011-03-21 13:11:28 -07001191void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1192 addOp(DisplayList::DrawPoints);
1193 addFloats(points, count);
1194 addPaint(paint);
1195}
1196
Romain Guy4aa90572010-09-26 18:40:37 -07001197void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
1198 float x, float y, SkPaint* paint) {
Romain Guy726aeba2011-06-01 14:52:00 -07001199 if (count <= 0) return;
Romain Guyb051e892010-09-28 19:09:36 -07001200 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -07001201 addText(text, bytesCount);
1202 addInt(count);
1203 addPoint(x, y);
1204 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001205}
1206
1207void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001208 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001209}
1210
1211void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001212 addOp(DisplayList::SetupShader);
1213 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001214}
1215
1216void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001217 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001218}
1219
1220void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001221 addOp(DisplayList::SetupColorFilter);
1222 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001223}
1224
1225void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001226 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001227}
1228
1229void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001230 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001231 addFloat(radius);
1232 addPoint(dx, dy);
1233 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001234}
1235
Romain Guy4aa90572010-09-26 18:40:37 -07001236}; // namespace uirenderer
1237}; // namespace android