blob: f8582d8fff9e09cf12079f37c6d1135773ab6e19 [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 Guy24c00212011-01-14 15:31:00 -0800104 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800105 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800106 }
Romain Guy24c00212011-01-14 15:31:00 -0800107 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800108
109 for (size_t i = 0; i < mPaints.size(); i++) {
110 delete mPaints.itemAt(i);
111 }
112 mPaints.clear();
113
Romain Guy2fc941e2011-02-03 15:06:05 -0800114 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700115 SkPath* path = mPaths.itemAt(i);
116 caches.pathCache.remove(path);
117 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800118 }
119 mPaths.clear();
120
Chet Haase5977baa2011-01-05 18:01:22 -0800121 for (size_t i = 0; i < mMatrices.size(); i++) {
122 delete mMatrices.itemAt(i);
123 }
124 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800125}
126
Chet Haased63cbd12011-02-03 16:32:46 -0800127void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700128 const SkWriter32& writer = recorder.writeStream();
129 init();
130
131 if (writer.size() == 0) {
132 return;
133 }
134
Chet Haased63cbd12011-02-03 16:32:46 -0800135 if (reusing) {
136 // re-using display list - clear out previous allocations
137 clearResources();
138 }
139
Romain Guyb051e892010-09-28 19:09:36 -0700140 size_t size = writer.size();
141 void* buffer = sk_malloc_throw(size);
142 writer.flatten(buffer);
143 mReader.setMemory(buffer, size);
144
Chet Haase5c13d892010-10-08 08:37:55 -0700145 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700146
Chet Haase5c13d892010-10-08 08:37:55 -0700147 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
148 for (size_t i = 0; i < bitmapResources.size(); i++) {
149 SkBitmap* resource = bitmapResources.itemAt(i);
150 mBitmapResources.add(resource);
151 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700152 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700153
Romain Guy24c00212011-01-14 15:31:00 -0800154 const Vector<SkiaShader*> &shaders = recorder.getShaders();
155 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800156 SkiaShader* shader = shaders.itemAt(i);
157 mShaders.add(shader);
158 caches.resourceCache.incrementRefcount(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700159 }
160
Chet Haased98aa2d2010-10-25 15:47:32 -0700161 const Vector<SkPaint*> &paints = recorder.getPaints();
162 for (size_t i = 0; i < paints.size(); i++) {
163 mPaints.add(paints.itemAt(i));
164 }
165
Romain Guy2fc941e2011-02-03 15:06:05 -0800166 const Vector<SkPath*> &paths = recorder.getPaths();
167 for (size_t i = 0; i < paths.size(); i++) {
168 mPaths.add(paths.itemAt(i));
169 }
170
Chet Haased98aa2d2010-10-25 15:47:32 -0700171 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
172 for (size_t i = 0; i < matrices.size(); i++) {
173 mMatrices.add(matrices.itemAt(i));
174 }
Romain Guyb051e892010-09-28 19:09:36 -0700175}
176
Romain Guyb051e892010-09-28 19:09:36 -0700177void DisplayList::init() {
Romain Guyb051e892010-09-28 19:09:36 -0700178}
179
Chet Haaseed30fd82011-04-22 16:18:45 -0700180/**
181 * This function is a simplified version of replay(), where we simply retrieve and log the
182 * display list. This function should remain in sync with the replay() function.
183 */
184void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
185 TextContainer text;
186
187 uint32_t count = (level + 1) * 2;
188 char indent[count + 1];
189 for (uint32_t i = 0; i < count; i++) {
190 indent[i] = ' ';
191 }
192 indent[count] = '\0';
193 LOGD("%sStart display list (%p)", (char*) indent + 2, this);
194
195 int saveCount = renderer.getSaveCount() - 1;
196
197 mReader.rewind();
198
199 while (!mReader.eof()) {
200 int op = mReader.readInt();
201
202 switch (op) {
203 case DrawGLFunction: {
204 Functor *functor = (Functor *) getInt();
205 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
206 }
207 break;
208 case Save: {
209 int rendererNum = getInt();
210 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
211 }
212 break;
213 case Restore: {
214 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
215 }
216 break;
217 case RestoreToCount: {
218 int restoreCount = saveCount + getInt();
219 LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
220 }
221 break;
222 case SaveLayer: {
223 float f1 = getFloat();
224 float f2 = getFloat();
225 float f3 = getFloat();
226 float f4 = getFloat();
227 SkPaint* paint = getPaint();
228 int flags = getInt();
229 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
230 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
231 }
232 break;
233 case SaveLayerAlpha: {
234 float f1 = getFloat();
235 float f2 = getFloat();
236 float f3 = getFloat();
237 float f4 = getFloat();
238 int alpha = getInt();
239 int flags = getInt();
240 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
241 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
242 }
243 break;
244 case Translate: {
245 float f1 = getFloat();
246 float f2 = getFloat();
247 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
248 }
249 break;
250 case Rotate: {
251 float rotation = getFloat();
252 LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
253 }
254 break;
255 case Scale: {
256 float sx = getFloat();
257 float sy = getFloat();
258 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
259 }
260 break;
261 case Skew: {
262 float sx = getFloat();
263 float sy = getFloat();
264 LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
265 }
266 break;
267 case SetMatrix: {
268 SkMatrix* matrix = getMatrix();
269 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
270 }
271 break;
272 case ConcatMatrix: {
273 SkMatrix* matrix = getMatrix();
274 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
275 }
276 break;
277 case ClipRect: {
278 float f1 = getFloat();
279 float f2 = getFloat();
280 float f3 = getFloat();
281 float f4 = getFloat();
282 int regionOp = getInt();
283 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
284 f1, f2, f3, f4, regionOp);
285 }
286 break;
287 case DrawDisplayList: {
288 DisplayList* displayList = getDisplayList();
289 uint32_t width = getUInt();
290 uint32_t height = getUInt();
291 LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
292 displayList, width, height, level + 1);
293 renderer.outputDisplayList(displayList, level + 1);
294 }
295 break;
296 case DrawLayer: {
297 Layer* layer = (Layer*) getInt();
298 float x = getFloat();
299 float y = getFloat();
300 SkPaint* paint = getPaint();
301 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
302 layer, x, y, paint);
303 }
304 break;
305 case DrawBitmap: {
306 SkBitmap* bitmap = getBitmap();
307 float x = getFloat();
308 float y = getFloat();
309 SkPaint* paint = getPaint();
310 LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
311 bitmap, x, y, paint);
312 }
313 break;
314 case DrawBitmapMatrix: {
315 SkBitmap* bitmap = getBitmap();
316 SkMatrix* matrix = getMatrix();
317 SkPaint* paint = getPaint();
318 LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
319 bitmap, matrix, paint);
320 }
321 break;
322 case DrawBitmapRect: {
323 SkBitmap* bitmap = getBitmap();
324 float f1 = getFloat();
325 float f2 = getFloat();
326 float f3 = getFloat();
327 float f4 = getFloat();
328 float f5 = getFloat();
329 float f6 = getFloat();
330 float f7 = getFloat();
331 float f8 = getFloat();
332 SkPaint* paint = getPaint();
333 LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
334 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
335 }
336 break;
337 case DrawBitmapMesh: {
338 int verticesCount = 0;
339 uint32_t colorsCount = 0;
340 SkBitmap* bitmap = getBitmap();
341 uint32_t meshWidth = getInt();
342 uint32_t meshHeight = getInt();
343 float* vertices = getFloats(verticesCount);
344 bool hasColors = getInt();
345 int* colors = hasColors ? getInts(colorsCount) : NULL;
346 SkPaint* paint = getPaint();
347 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
348 }
349 break;
350 case DrawPatch: {
351 int32_t* xDivs = NULL;
352 int32_t* yDivs = NULL;
353 uint32_t* colors = NULL;
354 uint32_t xDivsCount = 0;
355 uint32_t yDivsCount = 0;
356 int8_t numColors = 0;
357 SkBitmap* bitmap = getBitmap();
358 xDivs = getInts(xDivsCount);
359 yDivs = getInts(yDivsCount);
360 colors = getUInts(numColors);
361 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
362 getFloat();
363 getFloat();
364 getFloat();
365 getFloat();
366 getPaint();
367 }
368 break;
369 case DrawColor: {
370 int color = getInt();
371 int xferMode = getInt();
372 LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
373 }
374 break;
375 case DrawRect: {
376 float f1 = getFloat();
377 float f2 = getFloat();
378 float f3 = getFloat();
379 float f4 = getFloat();
380 SkPaint* paint = getPaint();
381 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
382 f1, f2, f3, f4, paint);
383 }
384 break;
385 case DrawRoundRect: {
386 float f1 = getFloat();
387 float f2 = getFloat();
388 float f3 = getFloat();
389 float f4 = getFloat();
390 float f5 = getFloat();
391 float f6 = getFloat();
392 SkPaint* paint = getPaint();
393 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
394 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
395 }
396 break;
397 case DrawCircle: {
398 float f1 = getFloat();
399 float f2 = getFloat();
400 float f3 = getFloat();
401 SkPaint* paint = getPaint();
402 LOGD("%s%s %.2f, %.2f, %.2f, %p",
403 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
404 }
405 break;
406 case DrawOval: {
407 float f1 = getFloat();
408 float f2 = getFloat();
409 float f3 = getFloat();
410 float f4 = getFloat();
411 SkPaint* paint = getPaint();
412 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
413 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
414 }
415 break;
416 case DrawArc: {
417 float f1 = getFloat();
418 float f2 = getFloat();
419 float f3 = getFloat();
420 float f4 = getFloat();
421 float f5 = getFloat();
422 float f6 = getFloat();
423 int i1 = getInt();
424 SkPaint* paint = getPaint();
425 LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
426 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
427 }
428 break;
429 case DrawPath: {
430 SkPath* path = getPath();
431 SkPaint* paint = getPaint();
432 LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
433 }
434 break;
435 case DrawLines: {
436 int count = 0;
437 float* points = getFloats(count);
438 SkPaint* paint = getPaint();
439 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
440 }
441 break;
442 case DrawPoints: {
443 int count = 0;
444 float* points = getFloats(count);
445 SkPaint* paint = getPaint();
446 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
447 }
448 break;
449 case DrawText: {
450 getText(&text);
451 int count = getInt();
452 float x = getFloat();
453 float y = getFloat();
454 SkPaint* paint = getPaint();
455 LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
456 text.text(), text.length(), count, x, y, paint);
457 }
458 break;
459 case ResetShader: {
460 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
461 }
462 break;
463 case SetupShader: {
464 SkiaShader* shader = getShader();
465 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
466 }
467 break;
468 case ResetColorFilter: {
469 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
470 }
471 break;
472 case SetupColorFilter: {
473 SkiaColorFilter *colorFilter = getColorFilter();
474 LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
475 }
476 break;
477 case ResetShadow: {
478 LOGD("%s%s", (char*) indent, OP_NAMES[op]);
479 }
480 break;
481 case SetupShadow: {
482 float radius = getFloat();
483 float dx = getFloat();
484 float dy = getFloat();
485 int color = getInt();
486 LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
487 radius, dx, dy, color);
488 }
489 break;
490 default:
491 LOGD("Display List error: op not handled: %s%s",
492 (char*) indent, OP_NAMES[op]);
493 break;
494 }
495 }
496
497 LOGD("%sDone", (char*) indent + 2);
498}
499
500/**
501 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
502 * in the output() function, since that function processes the same list of opcodes for the
503 * purposes of logging display list info for a given view.
504 */
Romain Guycabfcc12011-03-07 18:06:46 -0800505bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800506 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700507 TextContainer text;
508 mReader.rewind();
509
Romain Guyffac7fc2011-01-13 17:21:49 -0800510#if DEBUG_DISPLAY_LIST
511 uint32_t count = (level + 1) * 2;
512 char indent[count + 1];
513 for (uint32_t i = 0; i < count; i++) {
514 indent[i] = ' ';
515 }
516 indent[count] = '\0';
517 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
518#endif
Romain Guyb051e892010-09-28 19:09:36 -0700519
Chet Haase9c1e23b2011-03-24 10:51:31 -0700520 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800521 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700522 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700523 int op = mReader.readInt();
Chet Haase9c1e23b2011-03-24 10:51:31 -0700524 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800525
Romain Guy5b3b3522010-10-27 18:57:51 -0700526 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800527 case DrawGLFunction: {
528 Functor *functor = (Functor *) getInt();
529 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guycabfcc12011-03-07 18:06:46 -0800530 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Chet Haasedaf98e92011-01-10 14:10:36 -0800531 }
532 break;
Romain Guyb051e892010-09-28 19:09:36 -0700533 case Save: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800534 int rendererNum = getInt();
535 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
536 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700537 }
538 break;
539 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800540 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700541 renderer.restore();
542 }
543 break;
544 case RestoreToCount: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800545 int restoreCount = saveCount + getInt();
546 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
547 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700548 }
549 break;
550 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800551 float f1 = getFloat();
552 float f2 = getFloat();
553 float f3 = getFloat();
554 float f4 = getFloat();
555 SkPaint* paint = getPaint();
556 int flags = getInt();
557 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
558 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
559 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700560 }
561 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700562 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800563 float f1 = getFloat();
564 float f2 = getFloat();
565 float f3 = getFloat();
566 float f4 = getFloat();
567 int alpha = getInt();
568 int flags = getInt();
569 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
570 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
571 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700572 }
573 break;
Romain Guyb051e892010-09-28 19:09:36 -0700574 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800575 float f1 = getFloat();
576 float f2 = getFloat();
577 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
578 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700579 }
580 break;
581 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800582 float rotation = getFloat();
583 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
584 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700585 }
586 break;
587 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800588 float sx = getFloat();
589 float sy = getFloat();
590 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
591 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700592 }
593 break;
Romain Guy807daf72011-01-18 11:19:19 -0800594 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800595 float sx = getFloat();
596 float sy = getFloat();
597 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
598 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800599 }
600 break;
Romain Guyb051e892010-09-28 19:09:36 -0700601 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800602 SkMatrix* matrix = getMatrix();
603 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
604 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700605 }
606 break;
607 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800608 SkMatrix* matrix = getMatrix();
609 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
610 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700611 }
612 break;
613 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800614 float f1 = getFloat();
615 float f2 = getFloat();
616 float f3 = getFloat();
617 float f4 = getFloat();
618 int regionOp = getInt();
619 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
620 f1, f2, f3, f4, regionOp);
621 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700622 }
623 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800624 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800625 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700626 uint32_t width = getUInt();
627 uint32_t height = getUInt();
628 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op],
629 displayList, width, height, level + 1);
630 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
631 dirty, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800632 }
633 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800634 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800635 Layer* layer = (Layer*) getInt();
636 float x = getFloat();
637 float y = getFloat();
638 SkPaint* paint = getPaint();
639 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
640 layer, x, y, paint);
641 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800642 }
643 break;
Romain Guyb051e892010-09-28 19:09:36 -0700644 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800645 SkBitmap* bitmap = getBitmap();
646 float x = getFloat();
647 float y = getFloat();
648 SkPaint* paint = getPaint();
649 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
650 bitmap, x, y, paint);
651 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700652 }
653 break;
654 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800655 SkBitmap* bitmap = getBitmap();
656 SkMatrix* matrix = getMatrix();
657 SkPaint* paint = getPaint();
658 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
659 bitmap, matrix, paint);
660 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700661 }
662 break;
663 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800664 SkBitmap* bitmap = getBitmap();
665 float f1 = getFloat();
666 float f2 = getFloat();
667 float f3 = getFloat();
668 float f4 = getFloat();
669 float f5 = getFloat();
670 float f6 = getFloat();
671 float f7 = getFloat();
672 float f8 = getFloat();
673 SkPaint* paint = getPaint();
674 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
675 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
676 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700677 }
678 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800679 case DrawBitmapMesh: {
680 int verticesCount = 0;
681 uint32_t colorsCount = 0;
682
683 SkBitmap* bitmap = getBitmap();
684 uint32_t meshWidth = getInt();
685 uint32_t meshHeight = getInt();
686 float* vertices = getFloats(verticesCount);
687 bool hasColors = getInt();
688 int* colors = hasColors ? getInts(colorsCount) : NULL;
689
Chet Haasedaf98e92011-01-10 14:10:36 -0800690 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy5a7b4662011-01-20 19:09:30 -0800691 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint());
692 }
Romain Guya566b7c2011-01-23 16:36:11 -0800693 break;
Romain Guyb051e892010-09-28 19:09:36 -0700694 case DrawPatch: {
695 int32_t* xDivs = NULL;
696 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700697 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700698 uint32_t xDivsCount = 0;
699 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700700 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700701
702 SkBitmap* bitmap = getBitmap();
703
704 xDivs = getInts(xDivsCount);
705 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700706 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700707
Chet Haasedaf98e92011-01-10 14:10:36 -0800708 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700709 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
710 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
Romain Guyb051e892010-09-28 19:09:36 -0700711 }
712 break;
713 case DrawColor: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800714 int color = getInt();
715 int xferMode = getInt();
716 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
717 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700718 }
719 break;
720 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800721 float f1 = getFloat();
722 float f2 = getFloat();
723 float f3 = getFloat();
724 float f4 = getFloat();
725 SkPaint* paint = getPaint();
726 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
727 f1, f2, f3, f4, paint);
728 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700729 }
730 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800731 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800732 float f1 = getFloat();
733 float f2 = getFloat();
734 float f3 = getFloat();
735 float f4 = getFloat();
736 float f5 = getFloat();
737 float f6 = getFloat();
738 SkPaint* paint = getPaint();
739 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
740 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
741 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800742 }
743 break;
744 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800745 float f1 = getFloat();
746 float f2 = getFloat();
747 float f3 = getFloat();
748 SkPaint* paint = getPaint();
749 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
750 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
751 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800752 }
753 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800754 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800755 float f1 = getFloat();
756 float f2 = getFloat();
757 float f3 = getFloat();
758 float f4 = getFloat();
759 SkPaint* paint = getPaint();
760 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
761 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
762 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800763 }
764 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800765 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800766 float f1 = getFloat();
767 float f2 = getFloat();
768 float f3 = getFloat();
769 float f4 = getFloat();
770 float f5 = getFloat();
771 float f6 = getFloat();
772 int i1 = getInt();
773 SkPaint* paint = getPaint();
774 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
775 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
776 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800777 }
778 break;
Romain Guyb051e892010-09-28 19:09:36 -0700779 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800780 SkPath* path = getPath();
781 SkPaint* paint = getPaint();
782 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
783 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700784 }
785 break;
786 case DrawLines: {
787 int count = 0;
788 float* points = getFloats(count);
Chet Haasedaf98e92011-01-10 14:10:36 -0800789 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700790 renderer.drawLines(points, count, getPaint());
791 }
792 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700793 case DrawPoints: {
794 int count = 0;
795 float* points = getFloats(count);
796 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
797 renderer.drawPoints(points, count, getPaint());
798 }
799 break;
Romain Guyb051e892010-09-28 19:09:36 -0700800 case DrawText: {
801 getText(&text);
Chet Haasedaf98e92011-01-10 14:10:36 -0800802 int count = getInt();
803 float x = getFloat();
804 float y = getFloat();
805 SkPaint* paint = getPaint();
806 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
807 text.text(), text.length(), count, x, y, paint);
808 renderer.drawText(text.text(), text.length(), count, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700809 }
810 break;
811 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800812 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700813 renderer.resetShader();
814 }
815 break;
816 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800817 SkiaShader* shader = getShader();
818 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
819 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700820 }
821 break;
822 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800823 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700824 renderer.resetColorFilter();
825 }
826 break;
827 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800828 SkiaColorFilter *colorFilter = getColorFilter();
829 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
830 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700831 }
832 break;
833 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800834 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700835 renderer.resetShadow();
836 }
837 break;
838 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800839 float radius = getFloat();
840 float dx = getFloat();
841 float dy = getFloat();
842 int color = getInt();
843 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
844 radius, dx, dy, color);
845 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700846 }
847 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800848 default:
849 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
850 (char*) indent, OP_NAMES[op]);
851 break;
Romain Guyb051e892010-09-28 19:09:36 -0700852 }
853 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800854
Chet Haasedaf98e92011-01-10 14:10:36 -0800855 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
856 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700857}
858
859///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700860// Base structure
861///////////////////////////////////////////////////////////////////////////////
862
Romain Guy2fc941e2011-02-03 15:06:05 -0800863DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) {
Chet Haase5977baa2011-01-05 18:01:22 -0800864 mDisplayList = NULL;
Romain Guy4aa90572010-09-26 18:40:37 -0700865}
866
867DisplayListRenderer::~DisplayListRenderer() {
868 reset();
869}
870
871void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -0700872 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700873
874 Caches& caches = Caches::getInstance();
875 for (size_t i = 0; i < mBitmapResources.size(); i++) {
876 SkBitmap* resource = mBitmapResources.itemAt(i);
877 caches.resourceCache.decrementRefcount(resource);
878 }
879 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700880
Romain Guy43ccf462011-01-14 18:51:01 -0800881 for (size_t i = 0; i < mShaders.size(); i++) {
882 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
883 }
Romain Guy24c00212011-01-14 15:31:00 -0800884 mShaders.clear();
885 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800886
887 mPaints.clear();
888 mPaintMap.clear();
Romain Guy2fc941e2011-02-03 15:06:05 -0800889 mPaths.clear();
890 mPathMap.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700891 mMatrices.clear();
Romain Guy4aa90572010-09-26 18:40:37 -0700892}
893
894///////////////////////////////////////////////////////////////////////////////
895// Operations
896///////////////////////////////////////////////////////////////////////////////
897
Chet Haase5977baa2011-01-05 18:01:22 -0800898DisplayList* DisplayListRenderer::getDisplayList() {
899 if (mDisplayList == NULL) {
900 mDisplayList = new DisplayList(*this);
901 } else {
Chet Haased63cbd12011-02-03 16:32:46 -0800902 mDisplayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800903 }
904 return mDisplayList;
905}
906
Romain Guyb051e892010-09-28 19:09:36 -0700907void DisplayListRenderer::setViewport(int width, int height) {
908 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
909
910 mWidth = width;
911 mHeight = height;
912}
913
Romain Guy7d7b5492011-01-24 16:33:45 -0800914void DisplayListRenderer::prepareDirty(float left, float top,
915 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700916 mSnapshot = new Snapshot(mFirstSnapshot,
917 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
918 mSaveCount = 1;
919 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -0800920 mRestoreSaveCount = -1;
921}
922
923void DisplayListRenderer::finish() {
924 insertRestoreToCount();
925 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -0700926}
927
Chet Haasedaf98e92011-01-10 14:10:36 -0800928void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800929}
Romain Guy2b1847e2011-01-26 13:43:01 -0800930
Chet Haasedaf98e92011-01-10 14:10:36 -0800931void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700932}
933
Romain Guycabfcc12011-03-07 18:06:46 -0800934bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
935 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -0800936 addOp(DisplayList::DrawGLFunction);
937 addInt((int) functor);
938 return false; // No invalidate needed at record-time
939}
940
Romain Guy4aa90572010-09-26 18:40:37 -0700941int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700942 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700943 addInt(flags);
944 return OpenGLRenderer::save(flags);
945}
946
947void DisplayListRenderer::restore() {
Romain Guyb051e892010-09-28 19:09:36 -0700948 addOp(DisplayList::Restore);
Romain Guy4aa90572010-09-26 18:40:37 -0700949 OpenGLRenderer::restore();
950}
951
952void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800953 mRestoreSaveCount = saveCount;
Romain Guy4aa90572010-09-26 18:40:37 -0700954 OpenGLRenderer::restoreToCount(saveCount);
955}
956
957int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700958 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700959 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -0700960 addBounds(left, top, right, bottom);
961 addPaint(p);
962 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -0700963 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700964}
965
Romain Guy5b3b3522010-10-27 18:57:51 -0700966int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
967 int alpha, int flags) {
968 addOp(DisplayList::SaveLayerAlpha);
969 addBounds(left, top, right, bottom);
970 addInt(alpha);
971 addInt(flags);
972 return OpenGLRenderer::save(flags);
973}
974
Romain Guy4aa90572010-09-26 18:40:37 -0700975void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -0700976 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -0700977 addPoint(dx, dy);
978 OpenGLRenderer::translate(dx, dy);
979}
980
981void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -0700982 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -0700983 addFloat(degrees);
984 OpenGLRenderer::rotate(degrees);
985}
986
987void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -0700988 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -0700989 addPoint(sx, sy);
990 OpenGLRenderer::scale(sx, sy);
991}
992
Romain Guy807daf72011-01-18 11:19:19 -0800993void DisplayListRenderer::skew(float sx, float sy) {
994 addOp(DisplayList::Skew);
995 addPoint(sx, sy);
996 OpenGLRenderer::skew(sx, sy);
997}
998
Romain Guy4aa90572010-09-26 18:40:37 -0700999void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001000 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001001 addMatrix(matrix);
1002 OpenGLRenderer::setMatrix(matrix);
1003}
1004
1005void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001006 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001007 addMatrix(matrix);
1008 OpenGLRenderer::concatMatrix(matrix);
1009}
1010
1011bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1012 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001013 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001014 addBounds(left, top, right, bottom);
1015 addInt(op);
1016 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1017}
1018
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001019bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
1020 uint32_t width, uint32_t height, Rect& dirty, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001021 // dirty is an out parameter and should not be recorded,
1022 // it matters only when replaying the display list
Romain Guy0fe478e2010-11-08 12:08:41 -08001023 addOp(DisplayList::DrawDisplayList);
1024 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001025 addSize(width, height);
Chet Haasedaf98e92011-01-10 14:10:36 -08001026 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001027}
1028
Romain Guyada830f2011-01-13 12:13:20 -08001029void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001030 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001031 addInt((int) layer);
1032 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001033 addPaint(paint);
1034}
1035
Romain Guy4aa90572010-09-26 18:40:37 -07001036void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -07001037 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001038 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -07001039 addBitmap(bitmap);
1040 addPoint(left, top);
1041 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001042}
1043
Chet Haase5c13d892010-10-08 08:37:55 -07001044void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
1045 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001046 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001047 addBitmap(bitmap);
1048 addMatrix(matrix);
1049 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001050}
1051
1052void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1053 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001054 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001055 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001056 addBitmap(bitmap);
1057 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1058 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1059 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001060}
1061
Romain Guy5a7b4662011-01-20 19:09:30 -08001062void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1063 float* vertices, int* colors, SkPaint* paint) {
1064 addOp(DisplayList::DrawBitmapMesh);
1065 addBitmap(bitmap);
1066 addInt(meshWidth);
1067 addInt(meshHeight);
1068 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1069 if (colors) {
1070 addInt(1);
1071 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1072 } else {
1073 addInt(0);
1074 }
1075 addPaint(paint);
1076}
1077
Romain Guy4aa90572010-09-26 18:40:37 -07001078void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001079 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001080 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001081 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -07001082 addBitmap(bitmap);
1083 addInts(xDivs, width);
1084 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001085 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001086 addBounds(left, top, right, bottom);
1087 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001088}
1089
1090void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001091 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001092 addInt(color);
1093 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001094}
1095
1096void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001097 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001098 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001099 addBounds(left, top, right, bottom);
1100 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001101}
1102
Romain Guy01d58e42011-01-19 21:54:02 -08001103void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1104 float rx, float ry, SkPaint* paint) {
1105 addOp(DisplayList::DrawRoundRect);
1106 addBounds(left, top, right, bottom);
1107 addPoint(rx, ry);
1108 addPaint(paint);
1109}
1110
1111void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1112 addOp(DisplayList::DrawCircle);
1113 addPoint(x, y);
1114 addFloat(radius);
1115 addPaint(paint);
1116}
1117
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001118void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1119 SkPaint* paint) {
1120 addOp(DisplayList::DrawOval);
1121 addBounds(left, top, right, bottom);
1122 addPaint(paint);
1123}
1124
Romain Guy8b2f5262011-01-23 16:15:02 -08001125void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1126 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001127 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001128 addBounds(left, top, right, bottom);
1129 addPoint(startAngle, sweepAngle);
1130 addInt(useCenter ? 1 : 0);
1131 addPaint(paint);
1132}
1133
Romain Guy4aa90572010-09-26 18:40:37 -07001134void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001135 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -07001136 addPath(path);
1137 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001138}
1139
Chet Haase5c13d892010-10-08 08:37:55 -07001140void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001141 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001142 addFloats(points, count);
1143 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001144}
1145
Romain Guyed6fcb02011-03-21 13:11:28 -07001146void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1147 addOp(DisplayList::DrawPoints);
1148 addFloats(points, count);
1149 addPaint(paint);
1150}
1151
Romain Guy4aa90572010-09-26 18:40:37 -07001152void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
1153 float x, float y, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001154 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -07001155 addText(text, bytesCount);
1156 addInt(count);
1157 addPoint(x, y);
1158 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001159}
1160
1161void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001162 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001163}
1164
1165void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001166 addOp(DisplayList::SetupShader);
1167 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001168}
1169
1170void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001171 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001172}
1173
1174void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001175 addOp(DisplayList::SetupColorFilter);
1176 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001177}
1178
1179void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001180 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001181}
1182
1183void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001184 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001185 addFloat(radius);
1186 addPoint(dx, dy);
1187 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001188}
1189
Romain Guy4aa90572010-09-26 18:40:37 -07001190}; // namespace uirenderer
1191}; // namespace android