blob: 815382362468173c41bfcbf2c4623ed4acf23428 [file] [log] [blame]
Romain Guy4aa90572010-09-26 18:40:37 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
Chet Haase9c1e23b2011-03-24 10:51:31 -070019
20#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070021#include "DisplayListRenderer.h"
Chet Haase9c1e23b2011-03-24 10:51:31 -070022#include "Caches.h"
Romain Guy4aa90572010-09-26 18:40:37 -070023
Romain Guy13631f32012-01-30 17:41:55 -080024#include <utils/String8.h>
25
Romain Guy4aa90572010-09-26 18:40:37 -070026namespace android {
27namespace uirenderer {
28
Chet Haase9c1e23b2011-03-24 10:51:31 -070029
Romain Guy4aa90572010-09-26 18:40:37 -070030///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070031// Display list
32///////////////////////////////////////////////////////////////////////////////
33
Romain Guyffac7fc2011-01-13 17:21:49 -080034const char* DisplayList::OP_NAMES[] = {
Romain Guyffac7fc2011-01-13 17:21:49 -080035 "Save",
36 "Restore",
37 "RestoreToCount",
38 "SaveLayer",
39 "SaveLayerAlpha",
40 "Translate",
41 "Rotate",
42 "Scale",
Romain Guy4cf6e2f2011-01-23 11:35:13 -080043 "Skew",
Romain Guyffac7fc2011-01-13 17:21:49 -080044 "SetMatrix",
45 "ConcatMatrix",
46 "ClipRect",
47 "DrawDisplayList",
48 "DrawLayer",
49 "DrawBitmap",
50 "DrawBitmapMatrix",
51 "DrawBitmapRect",
Romain Guy5a7b4662011-01-20 19:09:30 -080052 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -080053 "DrawPatch",
54 "DrawColor",
55 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -080056 "DrawRoundRect",
57 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -080058 "DrawOval",
Romain Guy8b2f5262011-01-23 16:15:02 -080059 "DrawArc",
Romain Guyffac7fc2011-01-13 17:21:49 -080060 "DrawPath",
61 "DrawLines",
Romain Guyed6fcb02011-03-21 13:11:28 -070062 "DrawPoints",
Romain Guyffac7fc2011-01-13 17:21:49 -080063 "DrawText",
Romain Guy325740f2012-02-24 16:48:34 -080064 "DrawTextOnPath",
Romain Guyeb9a5362012-01-17 17:39:26 -080065 "DrawPosText",
Romain Guyffac7fc2011-01-13 17:21:49 -080066 "ResetShader",
67 "SetupShader",
68 "ResetColorFilter",
69 "SetupColorFilter",
70 "ResetShadow",
Chet Haasedaf98e92011-01-10 14:10:36 -080071 "SetupShadow",
Romain Guy5ff9df62012-01-23 17:09:05 -080072 "ResetPaintFilter",
73 "SetupPaintFilter",
Chet Haasedaf98e92011-01-10 14:10:36 -080074 "DrawGLFunction"
Romain Guyffac7fc2011-01-13 17:21:49 -080075};
76
Chet Haase9c1e23b2011-03-24 10:51:31 -070077void DisplayList::outputLogBuffer(int fd) {
78 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
79 if (logBuffer.isEmpty()) {
80 return;
81 }
Romain Guy65b345f2011-07-27 18:51:50 -070082
Chet Haase9c1e23b2011-03-24 10:51:31 -070083 FILE *file = fdopen(fd, "a");
Romain Guy65b345f2011-07-27 18:51:50 -070084
Chet Haase9c1e23b2011-03-24 10:51:31 -070085 fprintf(file, "\nRecent DisplayList operations\n");
86 logBuffer.outputCommands(file, OP_NAMES);
Romain Guy65b345f2011-07-27 18:51:50 -070087
88 String8 cachesLog;
89 Caches::getInstance().dumpMemoryUsage(cachesLog);
90 fprintf(file, "\nCaches:\n%s", cachesLog.string());
91 fprintf(file, "\n");
92
Chet Haase9c1e23b2011-03-24 10:51:31 -070093 fflush(file);
94}
95
Romain Guyb051e892010-09-28 19:09:36 -070096DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -080097 initFromDisplayListRenderer(recorder);
98}
99
100DisplayList::~DisplayList() {
Chet Haased63cbd12011-02-03 16:32:46 -0800101 clearResources();
102}
103
104void DisplayList::clearResources() {
Chet Haase5977baa2011-01-05 18:01:22 -0800105 sk_free((void*) mReader.base());
106
107 Caches& caches = Caches::getInstance();
108
109 for (size_t i = 0; i < mBitmapResources.size(); i++) {
110 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
111 }
112 mBitmapResources.clear();
113
Romain Guyd586ad92011-06-22 16:14:36 -0700114 for (size_t i = 0; i < mFilterResources.size(); i++) {
115 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
116 }
117 mFilterResources.clear();
118
Romain Guy24c00212011-01-14 15:31:00 -0800119 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800120 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -0700121 caches.resourceCache.destructor(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800122 }
Romain Guy24c00212011-01-14 15:31:00 -0800123 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800124
125 for (size_t i = 0; i < mPaints.size(); i++) {
126 delete mPaints.itemAt(i);
127 }
128 mPaints.clear();
129
Romain Guy2fc941e2011-02-03 15:06:05 -0800130 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guy1af23a32011-03-24 16:03:55 -0700131 SkPath* path = mPaths.itemAt(i);
132 caches.pathCache.remove(path);
133 delete path;
Romain Guy2fc941e2011-02-03 15:06:05 -0800134 }
135 mPaths.clear();
136
Chet Haase5977baa2011-01-05 18:01:22 -0800137 for (size_t i = 0; i < mMatrices.size(); i++) {
138 delete mMatrices.itemAt(i);
139 }
140 mMatrices.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800141}
142
Chet Haased63cbd12011-02-03 16:32:46 -0800143void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
Romain Guyb051e892010-09-28 19:09:36 -0700144 const SkWriter32& writer = recorder.writeStream();
145 init();
146
147 if (writer.size() == 0) {
148 return;
149 }
150
Chet Haased63cbd12011-02-03 16:32:46 -0800151 if (reusing) {
152 // re-using display list - clear out previous allocations
153 clearResources();
154 }
155
Romain Guy65b345f2011-07-27 18:51:50 -0700156 mSize = writer.size();
157 void* buffer = sk_malloc_throw(mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700158 writer.flatten(buffer);
Romain Guy65b345f2011-07-27 18:51:50 -0700159 mReader.setMemory(buffer, mSize);
Romain Guyb051e892010-09-28 19:09:36 -0700160
Chet Haase5c13d892010-10-08 08:37:55 -0700161 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700162
Chet Haase5c13d892010-10-08 08:37:55 -0700163 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
164 for (size_t i = 0; i < bitmapResources.size(); i++) {
165 SkBitmap* resource = bitmapResources.itemAt(i);
166 mBitmapResources.add(resource);
167 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700168 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700169
Romain Guyd586ad92011-06-22 16:14:36 -0700170 const Vector<SkiaColorFilter*> &filterResources = recorder.getFilterResources();
171 for (size_t i = 0; i < filterResources.size(); i++) {
172 SkiaColorFilter* resource = filterResources.itemAt(i);
173 mFilterResources.add(resource);
174 caches.resourceCache.incrementRefcount(resource);
175 }
176
Romain Guy24c00212011-01-14 15:31:00 -0800177 const Vector<SkiaShader*> &shaders = recorder.getShaders();
178 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -0700179 SkiaShader* resource = shaders.itemAt(i);
180 mShaders.add(resource);
181 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700182 }
183
Chet Haased98aa2d2010-10-25 15:47:32 -0700184 const Vector<SkPaint*> &paints = recorder.getPaints();
185 for (size_t i = 0; i < paints.size(); i++) {
186 mPaints.add(paints.itemAt(i));
187 }
188
Romain Guy2fc941e2011-02-03 15:06:05 -0800189 const Vector<SkPath*> &paths = recorder.getPaths();
190 for (size_t i = 0; i < paths.size(); i++) {
191 mPaths.add(paths.itemAt(i));
192 }
193
Chet Haased98aa2d2010-10-25 15:47:32 -0700194 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
195 for (size_t i = 0; i < matrices.size(); i++) {
196 mMatrices.add(matrices.itemAt(i));
197 }
Romain Guyb051e892010-09-28 19:09:36 -0700198}
199
Romain Guyb051e892010-09-28 19:09:36 -0700200void DisplayList::init() {
Romain Guy65b345f2011-07-27 18:51:50 -0700201 mSize = 0;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700202 mIsRenderable = true;
Romain Guy65b345f2011-07-27 18:51:50 -0700203}
204
205size_t DisplayList::getSize() {
206 return mSize;
Romain Guyb051e892010-09-28 19:09:36 -0700207}
208
Chet Haaseed30fd82011-04-22 16:18:45 -0700209/**
210 * This function is a simplified version of replay(), where we simply retrieve and log the
211 * display list. This function should remain in sync with the replay() function.
212 */
213void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) {
214 TextContainer text;
215
216 uint32_t count = (level + 1) * 2;
217 char indent[count + 1];
218 for (uint32_t i = 0; i < count; i++) {
219 indent[i] = ' ';
220 }
221 indent[count] = '\0';
Romain Guy13631f32012-01-30 17:41:55 -0800222 ALOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
Chet Haaseed30fd82011-04-22 16:18:45 -0700223
224 int saveCount = renderer.getSaveCount() - 1;
225
226 mReader.rewind();
227
228 while (!mReader.eof()) {
229 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800230 if (op & OP_MAY_BE_SKIPPED_MASK) {
231 int skip = mReader.readInt();
232 ALOGD("%sSkip %d", (char*) indent, skip);
233 op &= ~OP_MAY_BE_SKIPPED_MASK;
234 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700235
236 switch (op) {
237 case DrawGLFunction: {
238 Functor *functor = (Functor *) getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000239 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Chet Haaseed30fd82011-04-22 16:18:45 -0700240 }
241 break;
242 case Save: {
243 int rendererNum = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000244 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
Chet Haaseed30fd82011-04-22 16:18:45 -0700245 }
246 break;
247 case Restore: {
Steve Block5baa3a62011-12-20 16:23:08 +0000248 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700249 }
250 break;
251 case RestoreToCount: {
252 int restoreCount = saveCount + getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000253 ALOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
Chet Haaseed30fd82011-04-22 16:18:45 -0700254 }
255 break;
256 case SaveLayer: {
257 float f1 = getFloat();
258 float f2 = getFloat();
259 float f3 = getFloat();
260 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800261 SkPaint* paint = getPaint(renderer);
Chet Haaseed30fd82011-04-22 16:18:45 -0700262 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000263 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
Chet Haaseed30fd82011-04-22 16:18:45 -0700264 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
265 }
266 break;
267 case SaveLayerAlpha: {
268 float f1 = getFloat();
269 float f2 = getFloat();
270 float f3 = getFloat();
271 float f4 = getFloat();
272 int alpha = getInt();
273 int flags = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000274 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
Chet Haaseed30fd82011-04-22 16:18:45 -0700275 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
276 }
277 break;
278 case Translate: {
279 float f1 = getFloat();
280 float f2 = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000281 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700282 }
283 break;
284 case Rotate: {
285 float rotation = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000286 ALOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
Chet Haaseed30fd82011-04-22 16:18:45 -0700287 }
288 break;
289 case Scale: {
290 float sx = getFloat();
291 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000292 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700293 }
294 break;
295 case Skew: {
296 float sx = getFloat();
297 float sy = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000298 ALOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
Chet Haaseed30fd82011-04-22 16:18:45 -0700299 }
300 break;
301 case SetMatrix: {
302 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000303 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700304 }
305 break;
306 case ConcatMatrix: {
307 SkMatrix* matrix = getMatrix();
Steve Block5baa3a62011-12-20 16:23:08 +0000308 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
Chet Haaseed30fd82011-04-22 16:18:45 -0700309 }
310 break;
311 case ClipRect: {
312 float f1 = getFloat();
313 float f2 = getFloat();
314 float f3 = getFloat();
315 float f4 = getFloat();
316 int regionOp = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000317 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700318 f1, f2, f3, f4, regionOp);
319 }
320 break;
321 case DrawDisplayList: {
322 DisplayList* displayList = getDisplayList();
323 uint32_t width = getUInt();
324 uint32_t height = getUInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800325 int32_t flags = getInt();
326 ALOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
327 displayList, width, height, flags, level + 1);
Chet Haaseed30fd82011-04-22 16:18:45 -0700328 renderer.outputDisplayList(displayList, level + 1);
329 }
330 break;
331 case DrawLayer: {
332 Layer* layer = (Layer*) getInt();
333 float x = getFloat();
334 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800335 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000336 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700337 layer, x, y, paint);
338 }
339 break;
340 case DrawBitmap: {
341 SkBitmap* bitmap = getBitmap();
342 float x = getFloat();
343 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800344 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000345 ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700346 bitmap, x, y, paint);
347 }
348 break;
349 case DrawBitmapMatrix: {
350 SkBitmap* bitmap = getBitmap();
351 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800352 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000353 ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700354 bitmap, matrix, paint);
355 }
356 break;
357 case DrawBitmapRect: {
358 SkBitmap* bitmap = getBitmap();
359 float f1 = getFloat();
360 float f2 = getFloat();
361 float f3 = getFloat();
362 float f4 = getFloat();
363 float f5 = getFloat();
364 float f6 = getFloat();
365 float f7 = getFloat();
366 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800367 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000368 ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700369 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
370 }
371 break;
372 case DrawBitmapMesh: {
373 int verticesCount = 0;
374 uint32_t colorsCount = 0;
375 SkBitmap* bitmap = getBitmap();
376 uint32_t meshWidth = getInt();
377 uint32_t meshHeight = getInt();
378 float* vertices = getFloats(verticesCount);
379 bool hasColors = getInt();
380 int* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800381 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000382 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700383 }
384 break;
385 case DrawPatch: {
386 int32_t* xDivs = NULL;
387 int32_t* yDivs = NULL;
388 uint32_t* colors = NULL;
389 uint32_t xDivsCount = 0;
390 uint32_t yDivsCount = 0;
391 int8_t numColors = 0;
392 SkBitmap* bitmap = getBitmap();
393 xDivs = getInts(xDivsCount);
394 yDivs = getInts(yDivsCount);
395 colors = getUInts(numColors);
Romain Guya62f1722011-10-19 17:06:19 -0700396 float left = getFloat();
397 float top = getFloat();
398 float right = getFloat();
399 float bottom = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800400 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000401 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op],
Romain Guya62f1722011-10-19 17:06:19 -0700402 left, top, right, bottom);
Chet Haaseed30fd82011-04-22 16:18:45 -0700403 }
404 break;
405 case DrawColor: {
406 int color = getInt();
407 int xferMode = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000408 ALOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
Chet Haaseed30fd82011-04-22 16:18:45 -0700409 }
410 break;
411 case DrawRect: {
412 float f1 = getFloat();
413 float f2 = getFloat();
414 float f3 = getFloat();
415 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800416 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000417 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700418 f1, f2, f3, f4, paint);
419 }
420 break;
421 case DrawRoundRect: {
422 float f1 = getFloat();
423 float f2 = getFloat();
424 float f3 = getFloat();
425 float f4 = getFloat();
426 float f5 = getFloat();
427 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800428 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000429 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700430 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
431 }
432 break;
433 case DrawCircle: {
434 float f1 = getFloat();
435 float f2 = getFloat();
436 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800437 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000438 ALOGD("%s%s %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700439 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
440 }
441 break;
442 case DrawOval: {
443 float f1 = getFloat();
444 float f2 = getFloat();
445 float f3 = getFloat();
446 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800447 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000448 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700449 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
450 }
451 break;
452 case DrawArc: {
453 float f1 = getFloat();
454 float f2 = getFloat();
455 float f3 = getFloat();
456 float f4 = getFloat();
457 float f5 = getFloat();
458 float f6 = getFloat();
459 int i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800460 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000461 ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
Chet Haaseed30fd82011-04-22 16:18:45 -0700462 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
463 }
464 break;
465 case DrawPath: {
466 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800467 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000468 ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
Chet Haaseed30fd82011-04-22 16:18:45 -0700469 }
470 break;
471 case DrawLines: {
472 int count = 0;
473 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800474 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000475 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700476 }
477 break;
478 case DrawPoints: {
479 int count = 0;
480 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800481 SkPaint* paint = getPaint(renderer);
Steve Block5baa3a62011-12-20 16:23:08 +0000482 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700483 }
484 break;
485 case DrawText: {
486 getText(&text);
Romain Guy325740f2012-02-24 16:48:34 -0800487 int32_t count = getInt();
Chet Haaseed30fd82011-04-22 16:18:45 -0700488 float x = getFloat();
489 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800490 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -0800491 float length = getFloat();
Steve Block5baa3a62011-12-20 16:23:08 +0000492 ALOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op],
Romain Guycac5fd32011-12-01 20:08:50 -0800493 text.text(), text.length(), count, x, y, paint, length);
Chet Haaseed30fd82011-04-22 16:18:45 -0700494 }
495 break;
Romain Guy325740f2012-02-24 16:48:34 -0800496 case DrawTextOnPath: {
497 getText(&text);
498 int32_t count = getInt();
499 SkPath* path = getPath();
500 float hOffset = getFloat();
501 float vOffset = getFloat();
502 SkPaint* paint = getPaint(renderer);
503 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
504 text.text(), text.length(), count, paint);
505 }
506 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800507 case DrawPosText: {
508 getText(&text);
509 int count = getInt();
510 int positionsCount = 0;
511 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800512 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800513 ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
514 text.text(), text.length(), count, paint);
515 }
Chet Haaseed30fd82011-04-22 16:18:45 -0700516 case ResetShader: {
Steve Block5baa3a62011-12-20 16:23:08 +0000517 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700518 }
519 break;
520 case SetupShader: {
521 SkiaShader* shader = getShader();
Steve Block5baa3a62011-12-20 16:23:08 +0000522 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
Chet Haaseed30fd82011-04-22 16:18:45 -0700523 }
524 break;
525 case ResetColorFilter: {
Steve Block5baa3a62011-12-20 16:23:08 +0000526 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700527 }
528 break;
529 case SetupColorFilter: {
530 SkiaColorFilter *colorFilter = getColorFilter();
Steve Block5baa3a62011-12-20 16:23:08 +0000531 ALOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
Chet Haaseed30fd82011-04-22 16:18:45 -0700532 }
533 break;
534 case ResetShadow: {
Steve Block5baa3a62011-12-20 16:23:08 +0000535 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
Chet Haaseed30fd82011-04-22 16:18:45 -0700536 }
537 break;
538 case SetupShadow: {
539 float radius = getFloat();
540 float dx = getFloat();
541 float dy = getFloat();
542 int color = getInt();
Steve Block5baa3a62011-12-20 16:23:08 +0000543 ALOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
Chet Haaseed30fd82011-04-22 16:18:45 -0700544 radius, dx, dy, color);
545 }
546 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800547 case ResetPaintFilter: {
548 ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
549 }
550 break;
551 case SetupPaintFilter: {
552 int clearBits = getInt();
553 int setBits = getInt();
554 ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits);
555 }
556 break;
Chet Haaseed30fd82011-04-22 16:18:45 -0700557 default:
Steve Block5baa3a62011-12-20 16:23:08 +0000558 ALOGD("Display List error: op not handled: %s%s",
Chet Haaseed30fd82011-04-22 16:18:45 -0700559 (char*) indent, OP_NAMES[op]);
560 break;
561 }
562 }
563
Steve Block5baa3a62011-12-20 16:23:08 +0000564 ALOGD("%sDone", (char*) indent + 2);
Chet Haaseed30fd82011-04-22 16:18:45 -0700565}
566
567/**
568 * Changes to replay(), specifically those involving opcode or parameter changes, should be mimicked
569 * in the output() function, since that function processes the same list of opcodes for the
570 * purposes of logging display list info for a given view.
571 */
Romain Guy33f6beb2012-02-16 19:24:51 -0800572bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flags, uint32_t level) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800573 bool needsInvalidate = false;
Romain Guyb051e892010-09-28 19:09:36 -0700574 TextContainer text;
575 mReader.rewind();
576
Romain Guyffac7fc2011-01-13 17:21:49 -0800577#if DEBUG_DISPLAY_LIST
578 uint32_t count = (level + 1) * 2;
579 char indent[count + 1];
580 for (uint32_t i = 0; i < count; i++) {
581 indent[i] = ' ';
582 }
583 indent[count] = '\0';
Romain Guy13631f32012-01-30 17:41:55 -0800584 DISPLAY_LIST_LOGD("%sStart display list (%p, %s)", (char*) indent + 2, this, mName.string());
Romain Guyffac7fc2011-01-13 17:21:49 -0800585#endif
Romain Guyb051e892010-09-28 19:09:36 -0700586
Romain Guy13631f32012-01-30 17:41:55 -0800587 renderer.startMark(mName.string());
588
Chet Haase9c1e23b2011-03-24 10:51:31 -0700589 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
Romain Guyffac7fc2011-01-13 17:21:49 -0800590 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700591 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700592 int op = mReader.readInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800593 if (op & OP_MAY_BE_SKIPPED_MASK) {
594 int32_t skip = mReader.readInt() * 4;
595 if (CC_LIKELY(flags & kReplayFlag_ClipChildren)) {
596 mReader.skip(skip);
597 DISPLAY_LIST_LOGD("%s%s skipping %d bytes", (char*) indent,
598 OP_NAMES[op & ~OP_MAY_BE_SKIPPED_MASK], skip);
599 continue;
600 } else {
601 op &= ~OP_MAY_BE_SKIPPED_MASK;
602 ALOGD("%s", OP_NAMES[op]);
603 }
604 }
Chet Haase9c1e23b2011-03-24 10:51:31 -0700605 logBuffer.writeCommand(level, op);
Romain Guyffac7fc2011-01-13 17:21:49 -0800606
Romain Guy5b3b3522010-10-27 18:57:51 -0700607 switch (op) {
Chet Haasedaf98e92011-01-10 14:10:36 -0800608 case DrawGLFunction: {
609 Functor *functor = (Functor *) getInt();
610 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
Romain Guy13631f32012-01-30 17:41:55 -0800611 renderer.startMark("GL functor");
Romain Guycabfcc12011-03-07 18:06:46 -0800612 needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
Romain Guy13631f32012-01-30 17:41:55 -0800613 renderer.endMark();
Chet Haasedaf98e92011-01-10 14:10:36 -0800614 }
615 break;
Romain Guyb051e892010-09-28 19:09:36 -0700616 case Save: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800617 int32_t rendererNum = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800618 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
619 renderer.save(rendererNum);
Romain Guyb051e892010-09-28 19:09:36 -0700620 }
621 break;
622 case Restore: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800623 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700624 renderer.restore();
625 }
626 break;
627 case RestoreToCount: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800628 int32_t restoreCount = saveCount + getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800629 DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
630 renderer.restoreToCount(restoreCount);
Romain Guyb051e892010-09-28 19:09:36 -0700631 }
632 break;
633 case SaveLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800634 float f1 = getFloat();
635 float f2 = getFloat();
636 float f3 = getFloat();
637 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800638 SkPaint* paint = getPaint(renderer);
Romain Guy33f6beb2012-02-16 19:24:51 -0800639 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800640 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
641 OP_NAMES[op], f1, f2, f3, f4, paint, flags);
642 renderer.saveLayer(f1, f2, f3, f4, paint, flags);
Romain Guyb051e892010-09-28 19:09:36 -0700643 }
644 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700645 case SaveLayerAlpha: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800646 float f1 = getFloat();
647 float f2 = getFloat();
648 float f3 = getFloat();
649 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800650 int32_t alpha = getInt();
651 int32_t flags = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800652 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
653 OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
654 renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700655 }
656 break;
Romain Guyb051e892010-09-28 19:09:36 -0700657 case Translate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800658 float f1 = getFloat();
659 float f2 = getFloat();
660 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
661 renderer.translate(f1, f2);
Romain Guyb051e892010-09-28 19:09:36 -0700662 }
663 break;
664 case Rotate: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800665 float rotation = getFloat();
666 DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
667 renderer.rotate(rotation);
Romain Guyb051e892010-09-28 19:09:36 -0700668 }
669 break;
670 case Scale: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800671 float sx = getFloat();
672 float sy = getFloat();
673 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
674 renderer.scale(sx, sy);
Romain Guyb051e892010-09-28 19:09:36 -0700675 }
676 break;
Romain Guy807daf72011-01-18 11:19:19 -0800677 case Skew: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800678 float sx = getFloat();
679 float sy = getFloat();
680 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
681 renderer.skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800682 }
683 break;
Romain Guyb051e892010-09-28 19:09:36 -0700684 case SetMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800685 SkMatrix* matrix = getMatrix();
686 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
687 renderer.setMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700688 }
689 break;
690 case ConcatMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800691 SkMatrix* matrix = getMatrix();
692 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
693 renderer.concatMatrix(matrix);
Romain Guyb051e892010-09-28 19:09:36 -0700694 }
695 break;
696 case ClipRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800697 float f1 = getFloat();
698 float f2 = getFloat();
699 float f3 = getFloat();
700 float f4 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800701 int32_t regionOp = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800702 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
703 f1, f2, f3, f4, regionOp);
704 renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
Romain Guyb051e892010-09-28 19:09:36 -0700705 }
706 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800707 case DrawDisplayList: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800708 DisplayList* displayList = getDisplayList();
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700709 uint32_t width = getUInt();
710 uint32_t height = getUInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800711 int32_t flags = getInt();
712 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
713 displayList, width, height, flags, level + 1);
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700714 needsInvalidate |= renderer.drawDisplayList(displayList, width, height,
Romain Guy33f6beb2012-02-16 19:24:51 -0800715 dirty, flags, level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800716 }
717 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800718 case DrawLayer: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800719 Layer* layer = (Layer*) getInt();
720 float x = getFloat();
721 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800722 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800723 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
724 layer, x, y, paint);
725 renderer.drawLayer(layer, x, y, paint);
Romain Guy6c319ca2011-01-11 14:29:25 -0800726 }
727 break;
Romain Guyb051e892010-09-28 19:09:36 -0700728 case DrawBitmap: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800729 SkBitmap* bitmap = getBitmap();
730 float x = getFloat();
731 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800732 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800733 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
734 bitmap, x, y, paint);
735 renderer.drawBitmap(bitmap, x, y, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700736 }
737 break;
738 case DrawBitmapMatrix: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800739 SkBitmap* bitmap = getBitmap();
740 SkMatrix* matrix = getMatrix();
Romain Guy5ff9df62012-01-23 17:09:05 -0800741 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800742 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
743 bitmap, matrix, paint);
744 renderer.drawBitmap(bitmap, matrix, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700745 }
746 break;
747 case DrawBitmapRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800748 SkBitmap* bitmap = getBitmap();
749 float f1 = getFloat();
750 float f2 = getFloat();
751 float f3 = getFloat();
752 float f4 = getFloat();
753 float f5 = getFloat();
754 float f6 = getFloat();
755 float f7 = getFloat();
756 float f8 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800757 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800758 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
759 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
760 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700761 }
762 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800763 case DrawBitmapMesh: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800764 int32_t verticesCount = 0;
Romain Guy5a7b4662011-01-20 19:09:30 -0800765 uint32_t colorsCount = 0;
766
767 SkBitmap* bitmap = getBitmap();
768 uint32_t meshWidth = getInt();
769 uint32_t meshHeight = getInt();
770 float* vertices = getFloats(verticesCount);
771 bool hasColors = getInt();
Romain Guy33f6beb2012-02-16 19:24:51 -0800772 int32_t* colors = hasColors ? getInts(colorsCount) : NULL;
Romain Guy5ff9df62012-01-23 17:09:05 -0800773 SkPaint* paint = getPaint(renderer);
Romain Guy5a7b4662011-01-20 19:09:30 -0800774
Chet Haasedaf98e92011-01-10 14:10:36 -0800775 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700776 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint);
Romain Guy5a7b4662011-01-20 19:09:30 -0800777 }
Romain Guya566b7c2011-01-23 16:36:11 -0800778 break;
Romain Guyb051e892010-09-28 19:09:36 -0700779 case DrawPatch: {
780 int32_t* xDivs = NULL;
781 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700782 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700783 uint32_t xDivsCount = 0;
784 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700785 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700786
787 SkBitmap* bitmap = getBitmap();
788
789 xDivs = getInts(xDivsCount);
790 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700791 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700792
Romain Guy9ff3cb52011-06-28 14:02:11 -0700793 float left = getFloat();
794 float top = getFloat();
795 float right = getFloat();
796 float bottom = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800797 SkPaint* paint = getPaint(renderer);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700798
Chet Haasedaf98e92011-01-10 14:10:36 -0800799 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy4bb94202010-10-12 15:59:26 -0700800 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
Romain Guy9ff3cb52011-06-28 14:02:11 -0700801 numColors, left, top, right, bottom, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700802 }
803 break;
804 case DrawColor: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800805 int32_t color = getInt();
806 int32_t xferMode = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800807 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
808 renderer.drawColor(color, (SkXfermode::Mode) xferMode);
Romain Guyb051e892010-09-28 19:09:36 -0700809 }
810 break;
811 case DrawRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800812 float f1 = getFloat();
813 float f2 = getFloat();
814 float f3 = getFloat();
815 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800816 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800817 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
818 f1, f2, f3, f4, paint);
819 renderer.drawRect(f1, f2, f3, f4, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700820 }
821 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800822 case DrawRoundRect: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800823 float f1 = getFloat();
824 float f2 = getFloat();
825 float f3 = getFloat();
826 float f4 = getFloat();
827 float f5 = getFloat();
828 float f6 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800829 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800830 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
831 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
832 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800833 }
834 break;
835 case DrawCircle: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800836 float f1 = getFloat();
837 float f2 = getFloat();
838 float f3 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800839 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800840 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
841 (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
842 renderer.drawCircle(f1, f2, f3, paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800843 }
844 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800845 case DrawOval: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800846 float f1 = getFloat();
847 float f2 = getFloat();
848 float f3 = getFloat();
849 float f4 = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800850 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800851 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
852 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
853 renderer.drawOval(f1, f2, f3, f4, paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800854 }
855 break;
Romain Guy8b2f5262011-01-23 16:15:02 -0800856 case DrawArc: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800857 float f1 = getFloat();
858 float f2 = getFloat();
859 float f3 = getFloat();
860 float f4 = getFloat();
861 float f5 = getFloat();
862 float f6 = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800863 int32_t i1 = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800864 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800865 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
866 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
867 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800868 }
869 break;
Romain Guyb051e892010-09-28 19:09:36 -0700870 case DrawPath: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800871 SkPath* path = getPath();
Romain Guy5ff9df62012-01-23 17:09:05 -0800872 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800873 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
874 renderer.drawPath(path, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700875 }
876 break;
877 case DrawLines: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800878 int32_t count = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700879 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800880 SkPaint* paint = getPaint(renderer);
Chet Haasedaf98e92011-01-10 14:10:36 -0800881 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700882 renderer.drawLines(points, count, paint);
Romain Guyb051e892010-09-28 19:09:36 -0700883 }
884 break;
Romain Guyed6fcb02011-03-21 13:11:28 -0700885 case DrawPoints: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800886 int32_t count = 0;
Romain Guyed6fcb02011-03-21 13:11:28 -0700887 float* points = getFloats(count);
Romain Guy5ff9df62012-01-23 17:09:05 -0800888 SkPaint* paint = getPaint(renderer);
Romain Guyed6fcb02011-03-21 13:11:28 -0700889 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guy9ff3cb52011-06-28 14:02:11 -0700890 renderer.drawPoints(points, count, paint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700891 }
892 break;
Romain Guyb051e892010-09-28 19:09:36 -0700893 case DrawText: {
894 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -0800895 int32_t count = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800896 float x = getFloat();
897 float y = getFloat();
Romain Guy5ff9df62012-01-23 17:09:05 -0800898 SkPaint* paint = getPaint(renderer);
Romain Guycac5fd32011-12-01 20:08:50 -0800899 float length = getFloat();
900 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent,
901 OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length);
902 renderer.drawText(text.text(), text.length(), count, x, y, paint, length);
Romain Guyb051e892010-09-28 19:09:36 -0700903 }
904 break;
Romain Guy325740f2012-02-24 16:48:34 -0800905 case DrawTextOnPath: {
906 getText(&text);
907 int32_t count = getInt();
908 SkPath* path = getPath();
909 float hOffset = getFloat();
910 float vOffset = getFloat();
911 SkPaint* paint = getPaint(renderer);
912 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
913 text.text(), text.length(), count, paint);
914 renderer.drawTextOnPath(text.text(), text.length(), count, path,
915 hOffset, vOffset, paint);
916 }
917 break;
Romain Guyeb9a5362012-01-17 17:39:26 -0800918 case DrawPosText: {
919 getText(&text);
Romain Guy33f6beb2012-02-16 19:24:51 -0800920 int32_t count = getInt();
921 int32_t positionsCount = 0;
Romain Guyeb9a5362012-01-17 17:39:26 -0800922 float* positions = getFloats(positionsCount);
Romain Guy5ff9df62012-01-23 17:09:05 -0800923 SkPaint* paint = getPaint(renderer);
Romain Guyeb9a5362012-01-17 17:39:26 -0800924 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
925 OP_NAMES[op], text.text(), text.length(), count, paint);
926 renderer.drawPosText(text.text(), text.length(), count, positions, paint);
927 }
928 break;
Romain Guyb051e892010-09-28 19:09:36 -0700929 case ResetShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800930 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700931 renderer.resetShader();
932 }
933 break;
934 case SetupShader: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800935 SkiaShader* shader = getShader();
936 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
937 renderer.setupShader(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700938 }
939 break;
940 case ResetColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800941 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700942 renderer.resetColorFilter();
943 }
944 break;
945 case SetupColorFilter: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800946 SkiaColorFilter *colorFilter = getColorFilter();
947 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
948 renderer.setupColorFilter(colorFilter);
Romain Guyb051e892010-09-28 19:09:36 -0700949 }
950 break;
951 case ResetShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800952 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
Romain Guyb051e892010-09-28 19:09:36 -0700953 renderer.resetShadow();
954 }
955 break;
956 case SetupShadow: {
Chet Haasedaf98e92011-01-10 14:10:36 -0800957 float radius = getFloat();
958 float dx = getFloat();
959 float dy = getFloat();
Romain Guy33f6beb2012-02-16 19:24:51 -0800960 int32_t color = getInt();
Chet Haasedaf98e92011-01-10 14:10:36 -0800961 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
962 radius, dx, dy, color);
963 renderer.setupShadow(radius, dx, dy, color);
Romain Guyb051e892010-09-28 19:09:36 -0700964 }
965 break;
Romain Guy5ff9df62012-01-23 17:09:05 -0800966 case ResetPaintFilter: {
967 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
968 renderer.resetPaintFilter();
969 }
970 break;
971 case SetupPaintFilter: {
Romain Guy33f6beb2012-02-16 19:24:51 -0800972 int32_t clearBits = getInt();
973 int32_t setBits = getInt();
Romain Guy5ff9df62012-01-23 17:09:05 -0800974 DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op],
975 clearBits, setBits);
976 renderer.setupPaintFilter(clearBits, setBits);
977 }
978 break;
Chet Haasedaf98e92011-01-10 14:10:36 -0800979 default:
980 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
981 (char*) indent, OP_NAMES[op]);
982 break;
Romain Guyb051e892010-09-28 19:09:36 -0700983 }
984 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800985
Romain Guy13631f32012-01-30 17:41:55 -0800986 renderer.endMark();
987
Chet Haasedaf98e92011-01-10 14:10:36 -0800988 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
989 return needsInvalidate;
Romain Guyb051e892010-09-28 19:09:36 -0700990}
991
992///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700993// Base structure
994///////////////////////////////////////////////////////////////////////////////
995
Romain Guy33f6beb2012-02-16 19:24:51 -0800996DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE),
997 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false), mHasDrawOps(false) {
Romain Guy4aa90572010-09-26 18:40:37 -0700998}
999
1000DisplayListRenderer::~DisplayListRenderer() {
1001 reset();
1002}
1003
1004void DisplayListRenderer::reset() {
Romain Guy4aa90572010-09-26 18:40:37 -07001005 mWriter.reset();
Chet Haase5c13d892010-10-08 08:37:55 -07001006
1007 Caches& caches = Caches::getInstance();
1008 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001009 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -07001010 }
1011 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -07001012
Romain Guyd586ad92011-06-22 16:14:36 -07001013 for (size_t i = 0; i < mFilterResources.size(); i++) {
1014 caches.resourceCache.decrementRefcount(mFilterResources.itemAt(i));
1015 }
1016 mFilterResources.clear();
1017
Romain Guy43ccf462011-01-14 18:51:01 -08001018 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guyd586ad92011-06-22 16:14:36 -07001019 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -08001020 }
Romain Guy24c00212011-01-14 15:31:00 -08001021 mShaders.clear();
1022 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -08001023
1024 mPaints.clear();
1025 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001026
Romain Guy2fc941e2011-02-03 15:06:05 -08001027 mPaths.clear();
1028 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -07001029
Chet Haased98aa2d2010-10-25 15:47:32 -07001030 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -07001031
1032 mHasDrawOps = false;
Romain Guy4aa90572010-09-26 18:40:37 -07001033}
1034
1035///////////////////////////////////////////////////////////////////////////////
1036// Operations
1037///////////////////////////////////////////////////////////////////////////////
1038
Jeff Brown162a0212011-07-21 17:02:54 -07001039DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
1040 if (!displayList) {
1041 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -08001042 } else {
Jeff Brown162a0212011-07-21 17:02:54 -07001043 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -08001044 }
Romain Guy04c9d8c2011-08-25 14:01:48 -07001045 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -07001046 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -08001047}
1048
Romain Guyb051e892010-09-28 19:09:36 -07001049void DisplayListRenderer::setViewport(int width, int height) {
1050 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
1051
1052 mWidth = width;
1053 mHeight = height;
1054}
1055
Romain Guy7d7b5492011-01-24 16:33:45 -08001056void DisplayListRenderer::prepareDirty(float left, float top,
1057 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -07001058 mSnapshot = new Snapshot(mFirstSnapshot,
1059 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
1060 mSaveCount = 1;
1061 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -08001062 mRestoreSaveCount = -1;
1063}
1064
1065void DisplayListRenderer::finish() {
1066 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -08001067 insertTranlate();
Romain Guy27454a42011-01-23 12:01:41 -08001068 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -07001069}
1070
Chet Haasedaf98e92011-01-10 14:10:36 -08001071void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -08001072}
Romain Guy2b1847e2011-01-26 13:43:01 -08001073
Chet Haasedaf98e92011-01-10 14:10:36 -08001074void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -07001075}
1076
Romain Guycabfcc12011-03-07 18:06:46 -08001077bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
1078 // Ignore dirty during recording, it matters only when we replay
Chet Haasedaf98e92011-01-10 14:10:36 -08001079 addOp(DisplayList::DrawGLFunction);
1080 addInt((int) functor);
1081 return false; // No invalidate needed at record-time
1082}
1083
Romain Guy4aa90572010-09-26 18:40:37 -07001084int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001085 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -07001086 addInt(flags);
1087 return OpenGLRenderer::save(flags);
1088}
1089
1090void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -07001091 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001092 restoreToCount(getSaveCount() - 1);
1093 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -07001094 }
Romain Guy33f6beb2012-02-16 19:24:51 -08001095
1096 mRestoreSaveCount--;
1097 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001098 OpenGLRenderer::restore();
1099}
1100
1101void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -08001102 mRestoreSaveCount = saveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -08001103 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -07001104 OpenGLRenderer::restoreToCount(saveCount);
1105}
1106
1107int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001108 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -07001109 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -07001110 addBounds(left, top, right, bottom);
1111 addPaint(p);
1112 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -07001113 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -07001114}
1115
Romain Guy5b3b3522010-10-27 18:57:51 -07001116int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
1117 int alpha, int flags) {
1118 addOp(DisplayList::SaveLayerAlpha);
1119 addBounds(left, top, right, bottom);
1120 addInt(alpha);
1121 addInt(flags);
1122 return OpenGLRenderer::save(flags);
1123}
1124
Romain Guy4aa90572010-09-26 18:40:37 -07001125void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001126 mHasTranslate = true;
1127 mTranslateX += dx;
1128 mTranslateY += dy;
1129 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -07001130 OpenGLRenderer::translate(dx, dy);
1131}
1132
1133void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -07001134 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -07001135 addFloat(degrees);
1136 OpenGLRenderer::rotate(degrees);
1137}
1138
1139void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -07001140 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -07001141 addPoint(sx, sy);
1142 OpenGLRenderer::scale(sx, sy);
1143}
1144
Romain Guy807daf72011-01-18 11:19:19 -08001145void DisplayListRenderer::skew(float sx, float sy) {
1146 addOp(DisplayList::Skew);
1147 addPoint(sx, sy);
1148 OpenGLRenderer::skew(sx, sy);
1149}
1150
Romain Guy4aa90572010-09-26 18:40:37 -07001151void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001152 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001153 addMatrix(matrix);
1154 OpenGLRenderer::setMatrix(matrix);
1155}
1156
1157void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -07001158 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -07001159 addMatrix(matrix);
1160 OpenGLRenderer::concatMatrix(matrix);
1161}
1162
1163bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
1164 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -07001165 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -07001166 addBounds(left, top, right, bottom);
1167 addInt(op);
1168 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
1169}
1170
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001171bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Romain Guy33f6beb2012-02-16 19:24:51 -08001172 uint32_t width, uint32_t height, Rect& dirty, int32_t flags, uint32_t level) {
Romain Guycabfcc12011-03-07 18:06:46 -08001173 // dirty is an out parameter and should not be recorded,
1174 // it matters only when replaying the display list
Romain Guy33f6beb2012-02-16 19:24:51 -08001175 const bool reject = quickReject(0.0f, 0.0f, width, height);
1176 uint32_t* location = addOp(DisplayList::DrawDisplayList, reject);
Romain Guy0fe478e2010-11-08 12:08:41 -08001177 addDisplayList(displayList);
Romain Guy7b5b6ab2011-03-14 18:05:08 -07001178 addSize(width, height);
Romain Guy33f6beb2012-02-16 19:24:51 -08001179 addInt(flags);
1180 addSkip(location);
Chet Haasedaf98e92011-01-10 14:10:36 -08001181 return false;
Romain Guy0fe478e2010-11-08 12:08:41 -08001182}
1183
Romain Guyada830f2011-01-13 12:13:20 -08001184void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -08001185 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -08001186 addInt((int) layer);
1187 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -08001188 addPaint(paint);
1189}
1190
Romain Guy33f6beb2012-02-16 19:24:51 -08001191void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
1192 const bool reject = quickReject(left, top, left + bitmap->width(), top + bitmap->height());
1193 uint32_t* location = addOp(DisplayList::DrawBitmap, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001194 addBitmap(bitmap);
1195 addPoint(left, top);
1196 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001197 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001198}
1199
Romain Guy33f6beb2012-02-16 19:24:51 -08001200void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
1201 Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
1202 const mat4 transform(*matrix);
1203 transform.mapRect(r);
1204
1205 const bool reject = quickReject(r.left, r.top, r.right, r.bottom);
1206 uint32_t* location = addOp(DisplayList::DrawBitmapMatrix, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001207 addBitmap(bitmap);
1208 addMatrix(matrix);
1209 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001210 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001211}
1212
1213void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
1214 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -07001215 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001216 const bool reject = quickReject(dstLeft, dstTop, dstRight, dstBottom);
1217 uint32_t* location = addOp(DisplayList::DrawBitmapRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001218 addBitmap(bitmap);
1219 addBounds(srcLeft, srcTop, srcRight, srcBottom);
1220 addBounds(dstLeft, dstTop, dstRight, dstBottom);
1221 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001222 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001223}
1224
Romain Guy5a7b4662011-01-20 19:09:30 -08001225void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1226 float* vertices, int* colors, SkPaint* paint) {
1227 addOp(DisplayList::DrawBitmapMesh);
1228 addBitmap(bitmap);
1229 addInt(meshWidth);
1230 addInt(meshHeight);
1231 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
1232 if (colors) {
1233 addInt(1);
1234 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
1235 } else {
1236 addInt(0);
1237 }
1238 addPaint(paint);
1239}
1240
Romain Guy4aa90572010-09-26 18:40:37 -07001241void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -07001242 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -07001243 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001244 const bool reject = quickReject(left, top, right, bottom);
1245 uint32_t* location = addOp(DisplayList::DrawPatch, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001246 addBitmap(bitmap);
1247 addInts(xDivs, width);
1248 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -07001249 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -07001250 addBounds(left, top, right, bottom);
1251 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001252 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001253}
1254
1255void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -07001256 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -07001257 addInt(color);
1258 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -07001259}
1260
1261void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -07001262 SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001263 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1264 quickReject(left, top, right, bottom);
1265 uint32_t* location = addOp(DisplayList::DrawRect, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001266 addBounds(left, top, right, bottom);
1267 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001268 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001269}
1270
Romain Guy01d58e42011-01-19 21:54:02 -08001271void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
1272 float rx, float ry, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001273 const bool reject = paint->getStyle() == SkPaint::kFill_Style &&
1274 quickReject(left, top, right, bottom);
1275 uint32_t* location = addOp(DisplayList::DrawRoundRect, reject);
Romain Guy01d58e42011-01-19 21:54:02 -08001276 addBounds(left, top, right, bottom);
1277 addPoint(rx, ry);
1278 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001279 addSkip(location);
Romain Guy01d58e42011-01-19 21:54:02 -08001280}
1281
1282void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
1283 addOp(DisplayList::DrawCircle);
1284 addPoint(x, y);
1285 addFloat(radius);
1286 addPaint(paint);
1287}
1288
Romain Guyc1cd9ba32011-01-23 14:18:41 -08001289void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
1290 SkPaint* paint) {
1291 addOp(DisplayList::DrawOval);
1292 addBounds(left, top, right, bottom);
1293 addPaint(paint);
1294}
1295
Romain Guy8b2f5262011-01-23 16:15:02 -08001296void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
1297 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Romain Guy82d41a52011-01-24 21:53:42 -08001298 addOp(DisplayList::DrawArc);
Romain Guy8b2f5262011-01-23 16:15:02 -08001299 addBounds(left, top, right, bottom);
1300 addPoint(startAngle, sweepAngle);
1301 addInt(useCenter ? 1 : 0);
1302 addPaint(paint);
1303}
1304
Romain Guy4aa90572010-09-26 18:40:37 -07001305void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001306 float left, top, offset;
1307 uint32_t width, height;
1308 computePathBounds(path, paint, left, top, offset, width, height);
1309
1310 const bool reject = quickReject(left - offset, top - offset, width, height);
1311 uint32_t* location = addOp(DisplayList::DrawPath, reject);
Romain Guy4aa90572010-09-26 18:40:37 -07001312 addPath(path);
1313 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001314 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001315}
1316
Chet Haase5c13d892010-10-08 08:37:55 -07001317void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -07001318 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -07001319 addFloats(points, count);
1320 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -07001321}
1322
Romain Guyed6fcb02011-03-21 13:11:28 -07001323void DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
1324 addOp(DisplayList::DrawPoints);
1325 addFloats(points, count);
1326 addPaint(paint);
1327}
1328
Romain Guy4aa90572010-09-26 18:40:37 -07001329void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Romain Guycac5fd32011-12-01 20:08:50 -08001330 float x, float y, SkPaint* paint, float length) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001331 if (!text || count <= 0) return;
1332
Romain Guy8f9a9f62011-12-05 11:53:26 -08001333 // TODO: We should probably make a copy of the paint instead of modifying
1334 // it; modifying the paint will change its generationID the first
1335 // time, which might impact caches. More investigation needed to
1336 // see if it matters.
1337 // If we make a copy, then drawTextDecorations() should *not* make
1338 // its own copy as it does right now.
Fabrice Di Meglioc511bee82012-01-05 13:30:54 -08001339 // Beware: this needs Glyph encoding (already done on the Paint constructor)
Romain Guy8f9a9f62011-12-05 11:53:26 -08001340 paint->setAntiAlias(true);
Romain Guy33f6beb2012-02-16 19:24:51 -08001341 if (length < 0.0f) length = paint->measureText(text, bytesCount);
1342
1343 bool reject = false;
1344 if (CC_LIKELY(paint->getTextAlign() == SkPaint::kLeft_Align)) {
1345 SkPaint::FontMetrics metrics;
1346 paint->getFontMetrics(&metrics, 0.0f);
1347 reject = quickReject(x, y + metrics.fTop, x + length, y + metrics.fBottom);
1348 }
1349
1350 uint32_t* location = addOp(DisplayList::DrawText, reject);
1351 addText(text, bytesCount);
1352 addInt(count);
1353 addPoint(x, y);
Romain Guy4aa90572010-09-26 18:40:37 -07001354 addPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -08001355 addFloat(length);
1356 addSkip(location);
Romain Guy4aa90572010-09-26 18:40:37 -07001357}
1358
Romain Guy325740f2012-02-24 16:48:34 -08001359void DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
1360 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
1361 if (!text || count <= 0) return;
1362 addOp(DisplayList::DrawTextOnPath);
1363 addText(text, bytesCount);
1364 addInt(count);
1365 addPath(path);
1366 addFloat(hOffset);
1367 addFloat(vOffset);
1368 paint->setAntiAlias(true);
1369 addPaint(paint);
1370}
1371
Romain Guyeb9a5362012-01-17 17:39:26 -08001372void DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
1373 const float* positions, SkPaint* paint) {
Romain Guy33f6beb2012-02-16 19:24:51 -08001374 if (!text || count <= 0) return;
Romain Guyeb9a5362012-01-17 17:39:26 -08001375 addOp(DisplayList::DrawPosText);
1376 addText(text, bytesCount);
1377 addInt(count);
1378 addFloats(positions, count * 2);
1379 paint->setAntiAlias(true);
1380 addPaint(paint);
1381}
1382
Romain Guy4aa90572010-09-26 18:40:37 -07001383void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -07001384 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -07001385}
1386
1387void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -07001388 addOp(DisplayList::SetupShader);
1389 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -07001390}
1391
1392void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -07001393 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -07001394}
1395
1396void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -07001397 addOp(DisplayList::SetupColorFilter);
1398 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -07001399}
1400
1401void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -07001402 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001403}
1404
1405void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -07001406 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -07001407 addFloat(radius);
1408 addPoint(dx, dy);
1409 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -07001410}
1411
Romain Guy5ff9df62012-01-23 17:09:05 -08001412void DisplayListRenderer::resetPaintFilter() {
1413 addOp(DisplayList::ResetPaintFilter);
1414}
1415
1416void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
1417 addOp(DisplayList::SetupPaintFilter);
1418 addInt(clearBits);
1419 addInt(setBits);
1420}
1421
Romain Guy4aa90572010-09-26 18:40:37 -07001422}; // namespace uirenderer
1423}; // namespace android