blob: e43f6e55fb23416fb6c9758fc87d19e644487bcc [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 }
77 String8 cachesLog;
78 Caches::getInstance().dumpMemoryUsage(cachesLog);
79 FILE *file = fdopen(fd, "a");
80 fprintf(file, "\nCaches:\n%s", cachesLog.string());
81 fprintf(file, "\nRecent DisplayList operations\n");
82 logBuffer.outputCommands(file, OP_NAMES);
83 fflush(file);
84}
85
Romain Guyb051e892010-09-28 19:09:36 -070086DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -080087 initFromDisplayListRenderer(recorder);
88}
89
90DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -080091 clearResources();
92}
93
94void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -080095 sk_free((void*) mReader.base());
96
97 Caches& caches = Caches::getInstance();
98
99 for (size_t i = 0; i < mBitmapResources.size(); i++) {
100 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
101 }
102 mBitmapResources.clear();
103
Romain Guyd586ad92011-06-22 16:14:36 -0700104 for (size_t i = 0; i < mFilterResources.size(); i++) {
105 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
106 }
107 mFilterResources.clear();
108
Romain Guy24c00212011-01-14 15:31:00 -0800109 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800110 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700111 caches.resourceCache.destructor(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800112 }
Romain Guy24c00212011-01-14 15:31:00 -0800113 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800114
115 for (size_t i = 0; i < mPaints.size(); i++) {
116 delete mPaints.itemAt(i);
117 }
118 mPaints.clear();
119
Romain Guy2fc941e2011-02-03 15:06:05 -0800120 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700121 SkPath* path = mPaths.itemAt(i);
122 caches.pathCache.remove(path);
123 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800124 }
125 mPaths.clear();
126
Chet Haase5977baa2011-01-05 18:01:22 -0800127 for (size_t i = 0; i < mMatrices.size(); i++) {
128 delete mMatrices.itemAt(i);
129 }
130 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800131}
132
Chet Haased63cbd12011-02-03 16:32:46 -0800133void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700134 const SkWriter32& writer = recorder.writeStream();
135 init();
136
137 if (writer.size() == 0) {
138 return;
139 }
140
Chet Haased63cbd12011-02-03 16:32:46 -0800141 if (reusing) {
142 // re-using display list - clear out previous allocations
143 clearResources();
144 }
145
Romain Guyb051e892010-09-28 19:09:36 -0700146 size_t size = writer.size();
147 void* buffer = sk_malloc_throw(size);
148 writer.flatten(buffer);
149 mReader.setMemory(buffer, size);
150
Chet Haase5c13d892010-10-08 08:37:55 -0700151 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700152
Chet Haase5c13d892010-10-08 08:37:55 -0700153 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
154 for (size_t i = 0; i < bitmapResources.size(); i++) {
155 SkBitmap* resource = bitmapResources.itemAt(i);
156 mBitmapResources.add(resource);
157 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700158 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700159
Romain Guyd586ad92011-06-22 16:14:36 -0700160 const Vector<SkiaColorFilter*> &filterResources = recorder.getFilterResources();
161 for (size_t i = 0; i < filterResources.size(); i++) {
162 SkiaColorFilter* resource = filterResources.itemAt(i);
163 mFilterResources.add(resource);
164 caches.resourceCache.incrementRefcount(resource);
165 }
166
Romain Guy24c00212011-01-14 15:31:00 -0800167 const Vector<SkiaShader*> &shaders = recorder.getShaders();
168 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700169 SkiaShader* resource = shaders.itemAt(i);
170 mShaders.add(resource);
171 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700172 }
173
Chet Haased98aa2d2010-10-25 15:47:32 -0700174 const Vector<SkPaint*> &paints = recorder.getPaints();
175 for (size_t i = 0; i < paints.size(); i++) {
176 mPaints.add(paints.itemAt(i));
177 }
178
Romain Guy2fc941e2011-02-03 15:06:05 -0800179 const Vector<SkPath*> &paths = recorder.getPaths();
180 for (size_t i = 0; i < paths.size(); i++) {
181 mPaths.add(paths.itemAt(i));
182 }
183
Chet Haased98aa2d2010-10-25 15:47:32 -0700184 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
185 for (size_t i = 0; i < matrices.size(); i++) {
186 mMatrices.add(matrices.itemAt(i));
187 }
Romain Guyb051e892010-09-28 19:09:36 -0700188}
189
Romain Guyb051e892010-09-28 19:09:36 -0700190void DisplayList::init() {
Romain Guyb051e892010-09-28 19:09:36 -0700191}
192
Chet Haaseed30fd82011-04-22 16:18:45 -0700193/**
194 * This function is a simplified version of replay(), where we simply retrieve and log the
195 * display list. This function should remain in sync with the replay() function.
196 */
197void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
198 TextContainer text;
199
200 uint32_t count = (level + 1) * 2;
201 char indent[count + 1];
202 for (uint32_t i = 0; i < count; i++) {
203 indent[i] = ' ';
204 }
205 indent[count] = '\0';
206 LOGD("%sStart display list (%p)", (char*) indent + 2, this);
207
208 int saveCount = renderer.getSaveCount() - 1;
209
210 mReader.rewind();
211
212 while (!mReader.eof()) {
213 int op = mReader.readInt();
214
215 switch (op) {
216 case DrawGLFunction: {
217 Functor *functor = (Functor *) getInt();
218 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
219 }
220 break;
221 case Save: {
222 int rendererNum = getInt();
223 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
224 }
225 break;
226 case Restore: {
227 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
228 }
229 break;
230 case RestoreToCount: {
231 int restoreCount = saveCount + getInt();
232 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
233 }
234 break;
235 case SaveLayer: {
236 float f1 = getFloat();
237 float f2 = getFloat();
238 float f3 = getFloat();
239 float f4 = getFloat();
240 SkPaint* paint = getPaint();
241 int flags = getInt();
242 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
243 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
244 }
245 break;
246 case SaveLayerAlpha: {
247 float f1 = getFloat();
248 float f2 = getFloat();
249 float f3 = getFloat();
250 float f4 = getFloat();
251 int alpha = getInt();
252 int flags = getInt();
253 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
254 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
255 }
256 break;
257 case Translate: {
258 float f1 = getFloat();
259 float f2 = getFloat();
260 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
261 }
262 break;
263 case Rotate: {
264 float rotation = getFloat();
265 LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
266 }
267 break;
268 case Scale: {
269 float sx = getFloat();
270 float sy = getFloat();
271 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
272 }
273 break;
274 case Skew: {
275 float sx = getFloat();
276 float sy = getFloat();
277 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
278 }
279 break;
280 case SetMatrix: {
281 SkMatrix* matrix = getMatrix();
282 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
283 }
284 break;
285 case ConcatMatrix: {
286 SkMatrix* matrix = getMatrix();
287 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
288 }
289 break;
290 case ClipRect: {
291 float f1 = getFloat();
292 float f2 = getFloat();
293 float f3 = getFloat();
294 float f4 = getFloat();
295 int regionOp = getInt();
296 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
297 f1, f2, f3, f4, regionOp);
298 }
299 break;
300 case DrawDisplayList: {
301 DisplayList* displayList = getDisplayList();
302 uint32_t width = getUInt();
303 uint32_t height = getUInt();
304 LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
305 displayList, width, height, level + 1);
306 renderer.outputDisplayList(displayList, level + 1);
307 }
308 break;
309 case DrawLayer: {
310 Layer* layer = (Layer*) getInt();
311 float x = getFloat();
312 float y = getFloat();
313 SkPaint* paint = getPaint();
314 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
315 layer, x, y, paint);
316 }
317 break;
318 case DrawBitmap: {
319 SkBitmap* bitmap = getBitmap();
320 float x = getFloat();
321 float y = getFloat();
322 SkPaint* paint = getPaint();
323 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
324 bitmap, x, y, paint);
325 }
326 break;
327 case DrawBitmapMatrix: {
328 SkBitmap* bitmap = getBitmap();
329 SkMatrix* matrix = getMatrix();
330 SkPaint* paint = getPaint();
331 LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
332 bitmap, matrix, paint);
333 }
334 break;
335 case DrawBitmapRect: {
336 SkBitmap* bitmap = getBitmap();
337 float f1 = getFloat();
338 float f2 = getFloat();
339 float f3 = getFloat();
340 float f4 = getFloat();
341 float f5 = getFloat();
342 float f6 = getFloat();
343 float f7 = getFloat();
344 float f8 = getFloat();
345 SkPaint* paint = getPaint();
346 LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
347 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
348 }
349 break;
350 case DrawBitmapMesh: {
351 int verticesCount = 0;
352 uint32_t colorsCount = 0;
353 SkBitmap* bitmap = getBitmap();
354 uint32_t meshWidth = getInt();
355 uint32_t meshHeight = getInt();
356 float* vertices = getFloats(verticesCount);
357 bool hasColors = getInt();
358 int* colors = hasColors ? getInts(colorsCount) : NULL;
359 SkPaint* paint = getPaint();
360 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
361 }
362 break;
363 case DrawPatch: {
364 int32_t* xDivs = NULL;
365 int32_t* yDivs = NULL;
366 uint32_t* colors = NULL;
367 uint32_t xDivsCount = 0;
368 uint32_t yDivsCount = 0;
369 int8_t numColors = 0;
370 SkBitmap* bitmap = getBitmap();
371 xDivs = getInts(xDivsCount);
372 yDivs = getInts(yDivsCount);
373 colors = getUInts(numColors);
374 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
375 getFloat();
376 getFloat();
377 getFloat();
378 getFloat();
379 getPaint();
380 }
381 break;
382 case DrawColor: {
383 int color = getInt();
384 int xferMode = getInt();
385 LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
386 }
387 break;
388 case DrawRect: {
389 float f1 = getFloat();
390 float f2 = getFloat();
391 float f3 = getFloat();
392 float f4 = getFloat();
393 SkPaint* paint = getPaint();
394 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
395 f1, f2, f3, f4, paint);
396 }
397 break;
398 case DrawRoundRect: {
399 float f1 = getFloat();
400 float f2 = getFloat();
401 float f3 = getFloat();
402 float f4 = getFloat();
403 float f5 = getFloat();
404 float f6 = getFloat();
405 SkPaint* paint = getPaint();
406 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
407 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
408 }
409 break;
410 case DrawCircle: {
411 float f1 = getFloat();
412 float f2 = getFloat();
413 float f3 = getFloat();
414 SkPaint* paint = getPaint();
415 LOGD("%s%s %.2f, %.2f, %.2f, %p",
416 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
417 }
418 break;
419 case DrawOval: {
420 float f1 = getFloat();
421 float f2 = getFloat();
422 float f3 = getFloat();
423 float f4 = getFloat();
424 SkPaint* paint = getPaint();
425 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
426 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
427 }
428 break;
429 case DrawArc: {
430 float f1 = getFloat();
431 float f2 = getFloat();
432 float f3 = getFloat();
433 float f4 = getFloat();
434 float f5 = getFloat();
435 float f6 = getFloat();
436 int i1 = getInt();
437 SkPaint* paint = getPaint();
438 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
439 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
440 }
441 break;
442 case DrawPath: {
443 SkPath* path = getPath();
444 SkPaint* paint = getPaint();
445 LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
446 }
447 break;
448 case DrawLines: {
449 int count = 0;
450 float* points = getFloats(count);
451 SkPaint* paint = getPaint();
452 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
453 }
454 break;
455 case DrawPoints: {
456 int count = 0;
457 float* points = getFloats(count);
458 SkPaint* paint = getPaint();
459 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
460 }
461 break;
462 case DrawText: {
463 getText(&text);
464 int count = getInt();
465 float x = getFloat();
466 float y = getFloat();
467 SkPaint* paint = getPaint();
468 LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
469 text.text(), text.length(), count, x, y, paint);
470 }
471 break;
472 case ResetShader: {
473 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
474 }
475 break;
476 case SetupShader: {
477 SkiaShader* shader = getShader();
478 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
479 }
480 break;
481 case ResetColorFilter: {
482 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
483 }
484 break;
485 case SetupColorFilter: {
486 SkiaColorFilter *colorFilter = getColorFilter();
487 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
488 }
489 break;
490 case ResetShadow: {
491 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
492 }
493 break;
494 case SetupShadow: {
495 float radius = getFloat();
496 float dx = getFloat();
497 float dy = getFloat();
498 int color = getInt();
499 LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
500 radius, dx, dy, color);
501 }
502 break;
503 default:
504 LOGD("Display List error: op not handled: %s%s",
505 (char*) indent, OP_NAMES[op]);
506 break;
507 }
508 }
509
510 LOGD("%sDone", (char*) indent + 2);
511}
512
513/**
514 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
515 * in the output() function, since that function processes the same list of opcodes for the
516 * purposes of logging display list info for a given view.
517 */
Romain Guycabfcc12011-03-07 18:06:46 -0800518bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800519 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700520 TextContainer text;
521 mReader.rewind();
522
Romain Guyffac7fc2011-01-13 17:21:49 -0800523#if DEBUG_DISPLAY_LIST
524 uint32_t count = (level + 1) * 2;
525 char indent[count + 1];
526 for (uint32_t i = 0; i < count; i++) {
527 indent[i] = ' ';
528 }
529 indent[count] = '\0';
530 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
531#endif
Romain Guyb051e892010-09-28 19:09:36 -0700532
Chet Haase9c1e23b2011-03-24 10:51:31 -0700533 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800534 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700535 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700536 int op = mReader.readInt();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700537 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800538
Romain Guy5b3b3522010-10-27 18:57:51 -0700539 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800540 case DrawGLFunction: {
541 Functor *functor = (Functor *) getInt();
542 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guycabfcc12011-03-07 18:06:46 -0800543 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Chet Haasedaf98e92011-01-10 14:10:36 -0800544 }
545 break;
Romain Guyb051e892010-09-28 19:09:36 -0700546 case Save: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800547 int rendererNum = getInt();
548 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
549 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700550 }
551 break;
552 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800553 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700554 renderer.restore();
555 }
556 break;
557 case RestoreToCount: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800558 int restoreCount = saveCount + getInt();
559 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
560 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700561 }
562 break;
563 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800564 float f1 = getFloat();
565 float f2 = getFloat();
566 float f3 = getFloat();
567 float f4 = getFloat();
568 SkPaint* paint = getPaint();
569 int flags = getInt();
570 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
571 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
572 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700573 }
574 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700575 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800576 float f1 = getFloat();
577 float f2 = getFloat();
578 float f3 = getFloat();
579 float f4 = getFloat();
580 int alpha = getInt();
581 int flags = getInt();
582 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
583 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
584 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700585 }
586 break;
Romain Guyb051e892010-09-28 19:09:36 -0700587 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800588 float f1 = getFloat();
589 float f2 = getFloat();
590 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
591 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700592 }
593 break;
594 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800595 float rotation = getFloat();
596 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
597 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700598 }
599 break;
600 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800601 float sx = getFloat();
602 float sy = getFloat();
603 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
604 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700605 }
606 break;
Romain Guy807daf72011-01-18 11:19:19 -0800607 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800608 float sx = getFloat();
609 float sy = getFloat();
610 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
611 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800612 }
613 break;
Romain Guyb051e892010-09-28 19:09:36 -0700614 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800615 SkMatrix* matrix = getMatrix();
616 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
617 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700618 }
619 break;
620 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800621 SkMatrix* matrix = getMatrix();
622 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
623 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700624 }
625 break;
626 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800627 float f1 = getFloat();
628 float f2 = getFloat();
629 float f3 = getFloat();
630 float f4 = getFloat();
631 int regionOp = getInt();
632 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
633 f1, f2, f3, f4, regionOp);
634 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700635 }
636 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800637 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800638 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700639 uint32_t width = getUInt();
640 uint32_t height = getUInt();
641 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
642 displayList, width, height, level + 1);
643 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
644 dirty, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800645 }
646 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800647 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800648 Layer* layer = (Layer*) getInt();
649 float x = getFloat();
650 float y = getFloat();
651 SkPaint* paint = getPaint();
652 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
653 layer, x, y, paint);
654 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800655 }
656 break;
Romain Guyb051e892010-09-28 19:09:36 -0700657 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800658 SkBitmap* bitmap = getBitmap();
659 float x = getFloat();
660 float y = getFloat();
661 SkPaint* paint = getPaint();
662 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
663 bitmap, x, y, paint);
664 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700665 }
666 break;
667 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800668 SkBitmap* bitmap = getBitmap();
669 SkMatrix* matrix = getMatrix();
670 SkPaint* paint = getPaint();
671 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
672 bitmap, matrix, paint);
673 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700674 }
675 break;
676 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800677 SkBitmap* bitmap = getBitmap();
678 float f1 = getFloat();
679 float f2 = getFloat();
680 float f3 = getFloat();
681 float f4 = getFloat();
682 float f5 = getFloat();
683 float f6 = getFloat();
684 float f7 = getFloat();
685 float f8 = getFloat();
686 SkPaint* paint = getPaint();
687 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
688 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
689 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700690 }
691 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800692 case DrawBitmapMesh: {
693 int verticesCount = 0;
694 uint32_t colorsCount = 0;
695
696 SkBitmap* bitmap = getBitmap();
697 uint32_t meshWidth = getInt();
698 uint32_t meshHeight = getInt();
699 float* vertices = getFloats(verticesCount);
700 bool hasColors = getInt();
701 int* colors = hasColors ? getInts(colorsCount) : NULL;
702
Chet Haasedaf98e92011-01-10 14:10:36 -0800703 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy5a7b4662011-01-20 19:09:30 -0800704 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint());
705 }
Romain Guya566b7c2011-01-23 16:36:11 -0800706 break;
Romain Guyb051e892010-09-28 19:09:36 -0700707 case DrawPatch: {
708 int32_t* xDivs = NULL;
709 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700710 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700711 uint32_t xDivsCount = 0;
712 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700713 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700714
715 SkBitmap* bitmap = getBitmap();
716
717 xDivs = getInts(xDivsCount);
718 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700719 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700720
Chet Haasedaf98e92011-01-10 14:10:36 -0800721 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700722 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
723 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
Romain Guyb051e892010-09-28 19:09:36 -0700724 }
725 break;
726 case DrawColor: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800727 int color = getInt();
728 int xferMode = getInt();
729 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
730 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700731 }
732 break;
733 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800734 float f1 = getFloat();
735 float f2 = getFloat();
736 float f3 = getFloat();
737 float f4 = getFloat();
738 SkPaint* paint = getPaint();
739 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
740 f1, f2, f3, f4, paint);
741 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700742 }
743 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800744 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800745 float f1 = getFloat();
746 float f2 = getFloat();
747 float f3 = getFloat();
748 float f4 = getFloat();
749 float f5 = getFloat();
750 float f6 = getFloat();
751 SkPaint* paint = getPaint();
752 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
753 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
754 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800755 }
756 break;
757 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800758 float f1 = getFloat();
759 float f2 = getFloat();
760 float f3 = getFloat();
761 SkPaint* paint = getPaint();
762 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
763 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
764 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800765 }
766 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800767 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800768 float f1 = getFloat();
769 float f2 = getFloat();
770 float f3 = getFloat();
771 float f4 = getFloat();
772 SkPaint* paint = getPaint();
773 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
774 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
775 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800776 }
777 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800778 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800779 float f1 = getFloat();
780 float f2 = getFloat();
781 float f3 = getFloat();
782 float f4 = getFloat();
783 float f5 = getFloat();
784 float f6 = getFloat();
785 int i1 = getInt();
786 SkPaint* paint = getPaint();
787 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
788 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
789 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800790 }
791 break;
Romain Guyb051e892010-09-28 19:09:36 -0700792 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800793 SkPath* path = getPath();
794 SkPaint* paint = getPaint();
795 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
796 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700797 }
798 break;
799 case DrawLines: {
800 int count = 0;
801 float* points = getFloats(count);
Chet Haasedaf98e92011-01-10 14:10:36 -0800802 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700803 renderer.drawLines(points, count, getPaint());
804 }
805 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700806 case DrawPoints: {
807 int count = 0;
808 float* points = getFloats(count);
809 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
810 renderer.drawPoints(points, count, getPaint());
811 }
812 break;
Romain Guyb051e892010-09-28 19:09:36 -0700813 case DrawText: {
814 getText(&text);
Chet Haasedaf98e92011-01-10 14:10:36 -0800815 int count = getInt();
816 float x = getFloat();
817 float y = getFloat();
818 SkPaint* paint = getPaint();
819 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
820 text.text(), text.length(), count, x, y, paint);
821 renderer.drawText(text.text(), text.length(), count, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700822 }
823 break;
824 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800825 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700826 renderer.resetShader();
827 }
828 break;
829 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800830 SkiaShader* shader = getShader();
831 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
832 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700833 }
834 break;
835 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800836 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700837 renderer.resetColorFilter();
838 }
839 break;
840 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800841 SkiaColorFilter *colorFilter = getColorFilter();
842 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
843 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700844 }
845 break;
846 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800847 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700848 renderer.resetShadow();
849 }
850 break;
851 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800852 float radius = getFloat();
853 float dx = getFloat();
854 float dy = getFloat();
855 int color = getInt();
856 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
857 radius, dx, dy, color);
858 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700859 }
860 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800861 default:
862 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
863 (char*) indent, OP_NAMES[op]);
864 break;
Romain Guyb051e892010-09-28 19:09:36 -0700865 }
866 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800867
Chet Haasedaf98e92011-01-10 14:10:36 -0800868 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
869 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700870}
871
872///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700873// Base structure
874///////////////////////////////////////////////////////////////////////////////
875
Romain Guy2fc941e2011-02-03 15:06:05 -0800876DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) {
Chet Haase5977baa2011-01-05 18:01:22 -0800877 mDisplayList = NULL;
Romain Guy4aa90572010-09-26 18:40:37 -0700878}
879
880DisplayListRenderer::~DisplayListRenderer() {
881 reset();
882}
883
884void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -0700885 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700886
887 Caches& caches = Caches::getInstance();
888 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700889 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -0700890 }
891 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700892
Romain Guyd586ad92011-06-22 16:14:36 -0700893 for (size_t i = 0; i < mFilterResources.size(); i++) {
894 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
895 }
896 mFilterResources.clear();
897
Romain Guy43ccf462011-01-14 18:51:01 -0800898 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700899 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -0800900 }
Romain Guy24c00212011-01-14 15:31:00 -0800901 mShaders.clear();
902 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800903
904 mPaints.clear();
905 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700906
Romain Guy2fc941e2011-02-03 15:06:05 -0800907 mPaths.clear();
908 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -0700909
Chet Haased98aa2d2010-10-25 15:47:32 -0700910 mMatrices.clear();
Romain Guy4aa90572010-09-26 18:40:37 -0700911}
912
913///////////////////////////////////////////////////////////////////////////////
914// Operations
915///////////////////////////////////////////////////////////////////////////////
916
Chet Haase5977baa2011-01-05 18:01:22 -0800917DisplayList* DisplayListRenderer::getDisplayList() {
918 if (mDisplayList == NULL) {
919 mDisplayList = new DisplayList(*this);
920 } else {
Chet Haased63cbd12011-02-03 16:32:46 -0800921 mDisplayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800922 }
923 return mDisplayList;
924}
925
Romain Guyb051e892010-09-28 19:09:36 -0700926void DisplayListRenderer::setViewport(int width, int height) {
927 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
928
929 mWidth = width;
930 mHeight = height;
931}
932
Romain Guy7d7b5492011-01-24 16:33:45 -0800933void DisplayListRenderer::prepareDirty(float left, float top,
934 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700935 mSnapshot = new Snapshot(mFirstSnapshot,
936 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
937 mSaveCount = 1;
938 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -0800939 mRestoreSaveCount = -1;
940}
941
942void DisplayListRenderer::finish() {
943 insertRestoreToCount();
944 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -0700945}
946
Chet Haasedaf98e92011-01-10 14:10:36 -0800947void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800948}
Romain Guy2b1847e2011-01-26 13:43:01 -0800949
Chet Haasedaf98e92011-01-10 14:10:36 -0800950void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700951}
952
Romain Guycabfcc12011-03-07 18:06:46 -0800953bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
954 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -0800955 addOp(DisplayList::DrawGLFunction);
956 addInt((int) functor);
957 return false; // No invalidate needed at record-time
958}
959
Romain Guy4aa90572010-09-26 18:40:37 -0700960int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700961 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700962 addInt(flags);
963 return OpenGLRenderer::save(flags);
964}
965
966void DisplayListRenderer::restore() {
Romain Guyb051e892010-09-28 19:09:36 -0700967 addOp(DisplayList::Restore);
Romain Guy4aa90572010-09-26 18:40:37 -0700968 OpenGLRenderer::restore();
969}
970
971void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800972 mRestoreSaveCount = saveCount;
Romain Guy4aa90572010-09-26 18:40:37 -0700973 OpenGLRenderer::restoreToCount(saveCount);
974}
975
976int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700977 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700978 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -0700979 addBounds(left, top, right, bottom);
980 addPaint(p);
981 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -0700982 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700983}
984
Romain Guy5b3b3522010-10-27 18:57:51 -0700985int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
986 int alpha, int flags) {
987 addOp(DisplayList::SaveLayerAlpha);
988 addBounds(left, top, right, bottom);
989 addInt(alpha);
990 addInt(flags);
991 return OpenGLRenderer::save(flags);
992}
993
Romain Guy4aa90572010-09-26 18:40:37 -0700994void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -0700995 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -0700996 addPoint(dx, dy);
997 OpenGLRenderer::translate(dx, dy);
998}
999
1000void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001001 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001002 addFloat(degrees);
1003 OpenGLRenderer::rotate(degrees);
1004}
1005
1006void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001007 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001008 addPoint(sx, sy);
1009 OpenGLRenderer::scale(sx, sy);
1010}
1011
Romain Guy807daf72011-01-18 11:19:19 -08001012void DisplayListRenderer::skew(float sx, float sy) {
1013 addOp(DisplayList::Skew);
1014 addPoint(sx, sy);
1015 OpenGLRenderer::skew(sx, sy);
1016}
1017
Romain Guy4aa90572010-09-26 18:40:37 -07001018void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001019 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001020 addMatrix(matrix);
1021 OpenGLRenderer::setMatrix(matrix);
1022}
1023
1024void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001025 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001026 addMatrix(matrix);
1027 OpenGLRenderer::concatMatrix(matrix);
1028}
1029
1030bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1031 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001032 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001033 addBounds(left, top, right, bottom);
1034 addInt(op);
1035 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1036}
1037
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001038bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
1039 uint32_t width, uint32_t height, Rect& dirty, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001040 // dirty is an out parameter and should not be recorded,
1041 // it matters only when replaying the display list
Romain Guy0fe478e2010-11-08 12:08:41 -08001042 addOp(DisplayList::DrawDisplayList);
1043 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001044 addSize(width, height);
Chet Haasedaf98e92011-01-10 14:10:36 -08001045 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001046}
1047
Romain Guyada830f2011-01-13 12:13:20 -08001048void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001049 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001050 addInt((int) layer);
1051 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001052 addPaint(paint);
1053}
1054
Romain Guy4aa90572010-09-26 18:40:37 -07001055void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -07001056 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001057 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -07001058 addBitmap(bitmap);
1059 addPoint(left, top);
1060 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001061}
1062
Chet Haase5c13d892010-10-08 08:37:55 -07001063void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
1064 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001065 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001066 addBitmap(bitmap);
1067 addMatrix(matrix);
1068 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001069}
1070
1071void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1072 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001073 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001074 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001075 addBitmap(bitmap);
1076 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1077 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1078 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001079}
1080
Romain Guy5a7b4662011-01-20 19:09:30 -08001081void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1082 float* vertices, int* colors, SkPaint* paint) {
1083 addOp(DisplayList::DrawBitmapMesh);
1084 addBitmap(bitmap);
1085 addInt(meshWidth);
1086 addInt(meshHeight);
1087 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1088 if (colors) {
1089 addInt(1);
1090 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1091 } else {
1092 addInt(0);
1093 }
1094 addPaint(paint);
1095}
1096
Romain Guy4aa90572010-09-26 18:40:37 -07001097void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001098 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001099 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001100 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -07001101 addBitmap(bitmap);
1102 addInts(xDivs, width);
1103 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001104 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001105 addBounds(left, top, right, bottom);
1106 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001107}
1108
1109void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001110 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001111 addInt(color);
1112 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001113}
1114
1115void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001116 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001117 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001118 addBounds(left, top, right, bottom);
1119 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001120}
1121
Romain Guy01d58e42011-01-19 21:54:02 -08001122void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1123 float rx, float ry, SkPaint* paint) {
1124 addOp(DisplayList::DrawRoundRect);
1125 addBounds(left, top, right, bottom);
1126 addPoint(rx, ry);
1127 addPaint(paint);
1128}
1129
1130void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1131 addOp(DisplayList::DrawCircle);
1132 addPoint(x, y);
1133 addFloat(radius);
1134 addPaint(paint);
1135}
1136
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001137void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1138 SkPaint* paint) {
1139 addOp(DisplayList::DrawOval);
1140 addBounds(left, top, right, bottom);
1141 addPaint(paint);
1142}
1143
Romain Guy8b2f5262011-01-23 16:15:02 -08001144void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1145 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001146 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001147 addBounds(left, top, right, bottom);
1148 addPoint(startAngle, sweepAngle);
1149 addInt(useCenter ? 1 : 0);
1150 addPaint(paint);
1151}
1152
Romain Guy4aa90572010-09-26 18:40:37 -07001153void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001154 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -07001155 addPath(path);
1156 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001157}
1158
Chet Haase5c13d892010-10-08 08:37:55 -07001159void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001160 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001161 addFloats(points, count);
1162 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001163}
1164
Romain Guyed6fcb02011-03-21 13:11:28 -07001165void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1166 addOp(DisplayList::DrawPoints);
1167 addFloats(points, count);
1168 addPaint(paint);
1169}
1170
Romain Guy4aa90572010-09-26 18:40:37 -07001171void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
1172 float x, float y, SkPaint* paint) {
Romain Guy726aeba2011-06-01 14:52:00 -07001173 if (count <= 0) return;
Romain Guyb051e892010-09-28 19:09:36 -07001174 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -07001175 addText(text, bytesCount);
1176 addInt(count);
1177 addPoint(x, y);
1178 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001179}
1180
1181void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001182 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001183}
1184
1185void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001186 addOp(DisplayList::SetupShader);
1187 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001188}
1189
1190void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001191 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001192}
1193
1194void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001195 addOp(DisplayList::SetupColorFilter);
1196 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001197}
1198
1199void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001200 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001201}
1202
1203void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001204 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001205 addFloat(radius);
1206 addPoint(dx, dy);
1207 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001208}
1209
Romain Guy4aa90572010-09-26 18:40:37 -07001210}; // namespace uirenderer
1211}; // namespace android