blob: cebfd268bbd25609707420c2f308033971cabc23 [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
2 * Copyright (C) 2013 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
Romain Guyc46d07a2013-03-15 19:06:39 -070017#include <SkCanvas.h>
18
Chris Craikc3566d02013-02-04 16:16:33 -080019#include "Debug.h"
Chris Craik0776a602013-02-14 15:36:01 -080020#include "DisplayList.h"
21#include "DisplayListOp.h"
22#include "DisplayListLogBuffer.h"
23
24namespace android {
25namespace uirenderer {
26
27void DisplayList::outputLogBuffer(int fd) {
28 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
29 if (logBuffer.isEmpty()) {
30 return;
31 }
32
33 FILE *file = fdopen(fd, "a");
34
35 fprintf(file, "\nRecent DisplayList operations\n");
36 logBuffer.outputCommands(file);
37
38 String8 cachesLog;
39 Caches::getInstance().dumpMemoryUsage(cachesLog);
40 fprintf(file, "\nCaches:\n%s", cachesLog.string());
41 fprintf(file, "\n");
42
43 fflush(file);
44}
45
46DisplayList::DisplayList(const DisplayListRenderer& recorder) :
Chris Craik9846de62013-06-12 16:23:00 -070047 mDestroyed(false), mTransformMatrix(NULL), mTransformCamera(NULL), mTransformMatrix3D(NULL),
Chris Craik0776a602013-02-14 15:36:01 -080048 mStaticMatrix(NULL), mAnimationMatrix(NULL) {
49
50 initFromDisplayListRenderer(recorder);
51}
52
53DisplayList::~DisplayList() {
Chris Craik9846de62013-06-12 16:23:00 -070054 mDestroyed = true;
Chris Craik0776a602013-02-14 15:36:01 -080055 clearResources();
56}
57
58void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {
59 if (displayList) {
60 DISPLAY_LIST_LOGD("Deferring display list destruction");
61 Caches::getInstance().deleteDisplayListDeferred(displayList);
62 }
63}
64
65void DisplayList::clearResources() {
66 mDisplayListData = NULL;
Chris Craikff785832013-03-08 13:12:16 -080067
68 mClipRectOp = NULL;
69 mSaveLayerOp = NULL;
70 mSaveOp = NULL;
71 mRestoreToCountOp = NULL;
72
Chris Craik0776a602013-02-14 15:36:01 -080073 delete mTransformMatrix;
74 delete mTransformCamera;
75 delete mTransformMatrix3D;
76 delete mStaticMatrix;
77 delete mAnimationMatrix;
78
79 mTransformMatrix = NULL;
80 mTransformCamera = NULL;
81 mTransformMatrix3D = NULL;
82 mStaticMatrix = NULL;
83 mAnimationMatrix = NULL;
84
85 Caches& caches = Caches::getInstance();
86 caches.unregisterFunctors(mFunctorCount);
87 caches.resourceCache.lock();
88
89 for (size_t i = 0; i < mBitmapResources.size(); i++) {
90 caches.resourceCache.decrementRefcountLocked(mBitmapResources.itemAt(i));
91 }
92
93 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
94 SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i);
95 caches.resourceCache.decrementRefcountLocked(bitmap);
96 caches.resourceCache.destructorLocked(bitmap);
97 }
98
99 for (size_t i = 0; i < mFilterResources.size(); i++) {
100 caches.resourceCache.decrementRefcountLocked(mFilterResources.itemAt(i));
101 }
102
Romain Guye3b0a012013-06-26 15:45:41 -0700103 for (size_t i = 0; i < mPatchResources.size(); i++) {
104 caches.resourceCache.decrementRefcountLocked(mPatchResources.itemAt(i));
105 }
106
Chris Craik0776a602013-02-14 15:36:01 -0800107 for (size_t i = 0; i < mShaders.size(); i++) {
108 caches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
109 caches.resourceCache.destructorLocked(mShaders.itemAt(i));
110 }
111
112 for (size_t i = 0; i < mSourcePaths.size(); i++) {
113 caches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
114 }
115
116 for (size_t i = 0; i < mLayers.size(); i++) {
117 caches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
118 }
119
120 caches.resourceCache.unlock();
121
122 for (size_t i = 0; i < mPaints.size(); i++) {
123 delete mPaints.itemAt(i);
124 }
125
126 for (size_t i = 0; i < mRegions.size(); i++) {
127 delete mRegions.itemAt(i);
128 }
129
130 for (size_t i = 0; i < mPaths.size(); i++) {
Romain Guyc46d07a2013-03-15 19:06:39 -0700131 delete mPaths.itemAt(i);
Chris Craik0776a602013-02-14 15:36:01 -0800132 }
133
134 for (size_t i = 0; i < mMatrices.size(); i++) {
135 delete mMatrices.itemAt(i);
136 }
137
138 mBitmapResources.clear();
139 mOwnedBitmapResources.clear();
140 mFilterResources.clear();
Romain Guye3b0a012013-06-26 15:45:41 -0700141 mPatchResources.clear();
Chris Craik0776a602013-02-14 15:36:01 -0800142 mShaders.clear();
143 mSourcePaths.clear();
144 mPaints.clear();
145 mRegions.clear();
146 mPaths.clear();
147 mMatrices.clear();
148 mLayers.clear();
149}
150
151void DisplayList::reset() {
152 clearResources();
153 init();
154}
155
156void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
157 if (reusing) {
158 // re-using display list - clear out previous allocations
159 clearResources();
160 }
161
162 init();
163
164 mDisplayListData = recorder.getDisplayListData();
165 mSize = mDisplayListData->allocator.usedSize();
166
167 if (mSize == 0) {
168 return;
169 }
170
Chris Craikff785832013-03-08 13:12:16 -0800171 // allocate reusable ops for state-deferral
172 LinearAllocator& alloc = mDisplayListData->allocator;
173 mClipRectOp = new (alloc) ClipRectOp();
174 mSaveLayerOp = new (alloc) SaveLayerOp();
175 mSaveOp = new (alloc) SaveOp();
176 mRestoreToCountOp = new (alloc) RestoreToCountOp();
Chris Craik9846de62013-06-12 16:23:00 -0700177 if (CC_UNLIKELY(!mSaveOp)) { // temporary debug logging
178 ALOGW("Error: %s's SaveOp not allocated, size %d", getName(), mSize);
179 CRASH();
180 }
Chris Craikff785832013-03-08 13:12:16 -0800181
Chris Craik0776a602013-02-14 15:36:01 -0800182 mFunctorCount = recorder.getFunctorCount();
183
184 Caches& caches = Caches::getInstance();
185 caches.registerFunctors(mFunctorCount);
186 caches.resourceCache.lock();
187
188 const Vector<SkBitmap*>& bitmapResources = recorder.getBitmapResources();
189 for (size_t i = 0; i < bitmapResources.size(); i++) {
190 SkBitmap* resource = bitmapResources.itemAt(i);
191 mBitmapResources.add(resource);
192 caches.resourceCache.incrementRefcountLocked(resource);
193 }
194
195 const Vector<SkBitmap*> &ownedBitmapResources = recorder.getOwnedBitmapResources();
196 for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
197 SkBitmap* resource = ownedBitmapResources.itemAt(i);
198 mOwnedBitmapResources.add(resource);
199 caches.resourceCache.incrementRefcountLocked(resource);
200 }
201
202 const Vector<SkiaColorFilter*>& filterResources = recorder.getFilterResources();
203 for (size_t i = 0; i < filterResources.size(); i++) {
204 SkiaColorFilter* resource = filterResources.itemAt(i);
205 mFilterResources.add(resource);
206 caches.resourceCache.incrementRefcountLocked(resource);
207 }
208
Romain Guye3b0a012013-06-26 15:45:41 -0700209 const Vector<Res_png_9patch*>& patchResources = recorder.getPatchResources();
210 for (size_t i = 0; i < patchResources.size(); i++) {
211 Res_png_9patch* resource = patchResources.itemAt(i);
212 mPatchResources.add(resource);
213 caches.resourceCache.incrementRefcountLocked(resource);
214 }
215
Chris Craik0776a602013-02-14 15:36:01 -0800216 const Vector<SkiaShader*>& shaders = recorder.getShaders();
217 for (size_t i = 0; i < shaders.size(); i++) {
218 SkiaShader* resource = shaders.itemAt(i);
219 mShaders.add(resource);
220 caches.resourceCache.incrementRefcountLocked(resource);
221 }
222
223 const SortedVector<SkPath*>& sourcePaths = recorder.getSourcePaths();
224 for (size_t i = 0; i < sourcePaths.size(); i++) {
225 mSourcePaths.add(sourcePaths.itemAt(i));
226 caches.resourceCache.incrementRefcountLocked(sourcePaths.itemAt(i));
227 }
228
229 const Vector<Layer*>& layers = recorder.getLayers();
230 for (size_t i = 0; i < layers.size(); i++) {
231 mLayers.add(layers.itemAt(i));
232 caches.resourceCache.incrementRefcountLocked(layers.itemAt(i));
233 }
234
235 caches.resourceCache.unlock();
236
237 mPaints.appendVector(recorder.getPaints());
238 mRegions.appendVector(recorder.getRegions());
239 mPaths.appendVector(recorder.getPaths());
240 mMatrices.appendVector(recorder.getMatrices());
241}
242
243void DisplayList::init() {
244 mSize = 0;
245 mIsRenderable = true;
246 mFunctorCount = 0;
247 mLeft = 0;
248 mTop = 0;
249 mRight = 0;
250 mBottom = 0;
Chet Haasedd671592013-04-19 14:54:34 -0700251 mClipToBounds = true;
Chris Craik0776a602013-02-14 15:36:01 -0800252 mAlpha = 1;
Chris Craik0776a602013-02-14 15:36:01 -0800253 mHasOverlappingRendering = true;
254 mTranslationX = 0;
255 mTranslationY = 0;
256 mRotation = 0;
257 mRotationX = 0;
258 mRotationY= 0;
259 mScaleX = 1;
260 mScaleY = 1;
261 mPivotX = 0;
262 mPivotY = 0;
263 mCameraDistance = 0;
264 mMatrixDirty = false;
265 mMatrixFlags = 0;
266 mPrevWidth = -1;
267 mPrevHeight = -1;
268 mWidth = 0;
269 mHeight = 0;
270 mPivotExplicitlySet = false;
271 mCaching = false;
272}
273
274size_t DisplayList::getSize() {
275 return mSize;
276}
277
278/**
279 * This function is a simplified version of replay(), where we simply retrieve and log the
280 * display list. This function should remain in sync with the replay() function.
281 */
282void DisplayList::output(uint32_t level) {
Romain Guy7031ff62013-02-22 11:48:16 -0800283 ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this,
Chris Craik0776a602013-02-14 15:36:01 -0800284 mName.string(), isRenderable());
Romain Guy7031ff62013-02-22 11:48:16 -0800285 ALOGD("%*s%s %d", level * 2, "", "Save",
286 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
Chris Craik0776a602013-02-14 15:36:01 -0800287
Chris Craik0776a602013-02-14 15:36:01 -0800288 outputViewProperties(level);
289 int flags = DisplayListOp::kOpLogFlag_Recurse;
290 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
291 mDisplayListData->displayListOps[i]->output(level, flags);
292 }
Romain Guy7031ff62013-02-22 11:48:16 -0800293
294 ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, mName.string());
Chris Craik0776a602013-02-14 15:36:01 -0800295}
296
Romain Guy52036b12013-02-14 18:03:37 -0800297float DisplayList::getPivotX() {
298 updateMatrix();
299 return mPivotX;
300}
301
302float DisplayList::getPivotY() {
303 updateMatrix();
304 return mPivotY;
305}
306
Chris Craik0776a602013-02-14 15:36:01 -0800307void DisplayList::updateMatrix() {
308 if (mMatrixDirty) {
309 if (!mTransformMatrix) {
310 mTransformMatrix = new SkMatrix();
311 }
312 if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) {
313 mTransformMatrix->reset();
314 } else {
315 if (!mPivotExplicitlySet) {
316 if (mWidth != mPrevWidth || mHeight != mPrevHeight) {
317 mPrevWidth = mWidth;
318 mPrevHeight = mHeight;
Chet Haase259b6962013-05-03 15:25:33 -0700319 mPivotX = mPrevWidth / 2.0f;
320 mPivotY = mPrevHeight / 2.0f;
Chris Craik0776a602013-02-14 15:36:01 -0800321 }
322 }
323 if ((mMatrixFlags & ROTATION_3D) == 0) {
324 mTransformMatrix->setTranslate(mTranslationX, mTranslationY);
325 mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY);
326 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
327 } else {
328 if (!mTransformCamera) {
329 mTransformCamera = new Sk3DView();
330 mTransformMatrix3D = new SkMatrix();
331 }
332 mTransformMatrix->reset();
333 mTransformCamera->save();
334 mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY);
335 mTransformCamera->rotateX(mRotationX);
336 mTransformCamera->rotateY(mRotationY);
337 mTransformCamera->rotateZ(-mRotation);
338 mTransformCamera->getMatrix(mTransformMatrix3D);
339 mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY);
340 mTransformMatrix3D->postTranslate(mPivotX + mTranslationX,
341 mPivotY + mTranslationY);
342 mTransformMatrix->postConcat(*mTransformMatrix3D);
343 mTransformCamera->restore();
344 }
345 }
346 mMatrixDirty = false;
347 }
348}
349
Chris Craikff785832013-03-08 13:12:16 -0800350void DisplayList::outputViewProperties(const int level) {
Chris Craik0776a602013-02-14 15:36:01 -0800351 updateMatrix();
352 if (mLeft != 0 || mTop != 0) {
353 ALOGD("%*sTranslate (left, top) %d, %d", level * 2, "", mLeft, mTop);
354 }
355 if (mStaticMatrix) {
356 ALOGD("%*sConcatMatrix (static) %p: " MATRIX_STRING,
357 level * 2, "", mStaticMatrix, MATRIX_ARGS(mStaticMatrix));
358 }
359 if (mAnimationMatrix) {
360 ALOGD("%*sConcatMatrix (animation) %p: " MATRIX_STRING,
361 level * 2, "", mAnimationMatrix, MATRIX_ARGS(mStaticMatrix));
362 }
363 if (mMatrixFlags != 0) {
364 if (mMatrixFlags == TRANSLATION) {
365 ALOGD("%*sTranslate %f, %f", level * 2, "", mTranslationX, mTranslationY);
366 } else {
367 ALOGD("%*sConcatMatrix %p: " MATRIX_STRING,
368 level * 2, "", mTransformMatrix, MATRIX_ARGS(mTransformMatrix));
369 }
370 }
Chris Craik39a908c2013-06-13 14:39:01 -0700371
372 bool clipToBoundsNeeded = mClipToBounds;
Chris Craik5f803622013-03-21 14:39:04 -0700373 if (mAlpha < 1) {
Chris Craik16ecda52013-03-29 10:59:59 -0700374 if (mCaching) {
375 ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", mAlpha);
Chris Craik39a908c2013-06-13 14:39:01 -0700376 clipToBoundsNeeded = false; // clipping done by layer
Chris Craik16ecda52013-03-29 10:59:59 -0700377 } else if (!mHasOverlappingRendering) {
Chris Craik5f803622013-03-21 14:39:04 -0700378 ALOGD("%*sScaleAlpha %.2f", level * 2, "", mAlpha);
Chris Craik0776a602013-02-14 15:36:01 -0800379 } else {
380 int flags = SkCanvas::kHasAlphaLayer_SaveFlag;
Chris Craik39a908c2013-06-13 14:39:01 -0700381 if (clipToBoundsNeeded) {
Chris Craik0776a602013-02-14 15:36:01 -0800382 flags |= SkCanvas::kClipToLayer_SaveFlag;
Chris Craik39a908c2013-06-13 14:39:01 -0700383 clipToBoundsNeeded = false; // clipping done by save layer
Chris Craik0776a602013-02-14 15:36:01 -0800384 }
385 ALOGD("%*sSaveLayerAlpha %.2f, %.2f, %.2f, %.2f, %d, 0x%x", level * 2, "",
386 (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop,
Chris Craika08f95c2013-03-15 17:24:33 -0700387 (int)(mAlpha * 255), flags);
Chris Craik0776a602013-02-14 15:36:01 -0800388 }
389 }
Chris Craik39a908c2013-06-13 14:39:01 -0700390 if (clipToBoundsNeeded) {
Chris Craik0776a602013-02-14 15:36:01 -0800391 ALOGD("%*sClipRect %.2f, %.2f, %.2f, %.2f", level * 2, "", 0.0f, 0.0f,
392 (float) mRight - mLeft, (float) mBottom - mTop);
393 }
394}
395
Chris Craikff785832013-03-08 13:12:16 -0800396/*
397 * For property operations, we pass a savecount of 0, since the operations aren't part of the
398 * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in
399 * base saveCount (i.e., how RestoreToCount uses saveCount + mCount)
400 */
401#define PROPERTY_SAVECOUNT 0
402
403template <class T>
404void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler,
405 const int level) {
406#if DEBUG_DISPLAY_LIST
Chris Craik0776a602013-02-14 15:36:01 -0800407 outputViewProperties(level);
408#endif
409 updateMatrix();
410 if (mLeft != 0 || mTop != 0) {
411 renderer.translate(mLeft, mTop);
412 }
413 if (mStaticMatrix) {
414 renderer.concatMatrix(mStaticMatrix);
415 } else if (mAnimationMatrix) {
416 renderer.concatMatrix(mAnimationMatrix);
417 }
418 if (mMatrixFlags != 0) {
419 if (mMatrixFlags == TRANSLATION) {
420 renderer.translate(mTranslationX, mTranslationY);
421 } else {
422 renderer.concatMatrix(mTransformMatrix);
423 }
424 }
Chris Craik39a908c2013-06-13 14:39:01 -0700425 bool clipToBoundsNeeded = mClipToBounds;
Chris Craika08f95c2013-03-15 17:24:33 -0700426 if (mAlpha < 1) {
Chris Craik16ecda52013-03-29 10:59:59 -0700427 if (mCaching) {
428 renderer.setOverrideLayerAlpha(mAlpha);
Chris Craik39a908c2013-06-13 14:39:01 -0700429 clipToBoundsNeeded = false; // clipping done by layer
Chris Craik16ecda52013-03-29 10:59:59 -0700430 } else if (!mHasOverlappingRendering) {
Chris Craika08f95c2013-03-15 17:24:33 -0700431 renderer.scaleAlpha(mAlpha);
Chris Craik0776a602013-02-14 15:36:01 -0800432 } else {
433 // TODO: should be able to store the size of a DL at record time and not
434 // have to pass it into this call. In fact, this information might be in the
435 // location/size info that we store with the new native transform data.
Chris Craikff785832013-03-08 13:12:16 -0800436 int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
Chris Craik39a908c2013-06-13 14:39:01 -0700437 if (clipToBoundsNeeded) {
Chris Craikff785832013-03-08 13:12:16 -0800438 saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
Chris Craik39a908c2013-06-13 14:39:01 -0700439 clipToBoundsNeeded = false; // clipping done by saveLayer
Chris Craik0776a602013-02-14 15:36:01 -0800440 }
Chris Craikff785832013-03-08 13:12:16 -0800441 handler(mSaveLayerOp->reinit(0, 0, mRight - mLeft, mBottom - mTop,
Chet Haasedd671592013-04-19 14:54:34 -0700442 mAlpha * 255, SkXfermode::kSrcOver_Mode, saveFlags), PROPERTY_SAVECOUNT,
443 mClipToBounds);
Chris Craik0776a602013-02-14 15:36:01 -0800444 }
445 }
Chris Craik39a908c2013-06-13 14:39:01 -0700446 if (clipToBoundsNeeded) {
Chris Craikff785832013-03-08 13:12:16 -0800447 handler(mClipRectOp->reinit(0, 0, mRight - mLeft, mBottom - mTop, SkRegion::kIntersect_Op),
Chet Haasedd671592013-04-19 14:54:34 -0700448 PROPERTY_SAVECOUNT, mClipToBounds);
Chris Craik0776a602013-02-14 15:36:01 -0800449 }
450}
451
Chris Craikff785832013-03-08 13:12:16 -0800452class DeferOperationHandler {
453public:
Chris Craika08f95c2013-03-15 17:24:33 -0700454 DeferOperationHandler(DeferStateStruct& deferStruct, int level)
455 : mDeferStruct(deferStruct), mLevel(level) {}
Chet Haasedd671592013-04-19 14:54:34 -0700456 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
457 operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds);
Chris Craikff785832013-03-08 13:12:16 -0800458 }
459private:
460 DeferStateStruct& mDeferStruct;
Chris Craikff785832013-03-08 13:12:16 -0800461 const int mLevel;
462};
463
464void DisplayList::defer(DeferStateStruct& deferStruct, const int level) {
Chris Craika08f95c2013-03-15 17:24:33 -0700465 DeferOperationHandler handler(deferStruct, level);
Chris Craikff785832013-03-08 13:12:16 -0800466 iterate<DeferOperationHandler>(deferStruct.mRenderer, handler, level);
467}
468
469class ReplayOperationHandler {
470public:
Chris Craika08f95c2013-03-15 17:24:33 -0700471 ReplayOperationHandler(ReplayStateStruct& replayStruct, int level)
472 : mReplayStruct(replayStruct), mLevel(level) {}
Chet Haasedd671592013-04-19 14:54:34 -0700473 inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) {
Chris Craikff785832013-03-08 13:12:16 -0800474#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
Chris Craikd90144d2013-03-19 15:03:48 -0700475 mReplayStruct.mRenderer.eventMark(operation->name());
Chris Craikff785832013-03-08 13:12:16 -0800476#endif
Chet Haasedd671592013-04-19 14:54:34 -0700477 operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds);
Chris Craikff785832013-03-08 13:12:16 -0800478 }
479private:
480 ReplayStateStruct& mReplayStruct;
Chris Craikff785832013-03-08 13:12:16 -0800481 const int mLevel;
482};
483
484void DisplayList::replay(ReplayStateStruct& replayStruct, const int level) {
Chris Craika08f95c2013-03-15 17:24:33 -0700485 ReplayOperationHandler handler(replayStruct, level);
Chris Craikff785832013-03-08 13:12:16 -0800486
487 replayStruct.mRenderer.startMark(mName.string());
488 iterate<ReplayOperationHandler>(replayStruct.mRenderer, handler, level);
489 replayStruct.mRenderer.endMark();
490
491 DISPLAY_LIST_LOGD("%*sDone (%p, %s), returning %d", level * 2, "", this, mName.string(),
492 replayStruct.mDrawGlStatus);
493}
494
495/**
496 * This function serves both defer and replay modes, and will organize the displayList's component
497 * operations for a single frame:
498 *
499 * Every 'simple' operation that affects just the matrix and alpha (or other factors of
500 * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom
501 * defer logic) and operations in displayListOps are issued through the 'handler' which handles the
502 * defer vs replay logic, per operation
503 */
504template <class T>
505void DisplayList::iterate(OpenGLRenderer& renderer, T& handler, const int level) {
Chris Craik9846de62013-06-12 16:23:00 -0700506 if (CC_UNLIKELY(mDestroyed)) { // temporary debug logging
507 ALOGW("Error: %s is drawing after destruction, size %d", getName(), mSize);
508 CRASH();
509 }
510 if (mSize == 0 || mAlpha <= 0) {
Chris Craikff785832013-03-08 13:12:16 -0800511 DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, mName.string());
512 return;
513 }
Chris Craik0776a602013-02-14 15:36:01 -0800514
515#if DEBUG_DISPLAY_LIST
516 Rect* clipRect = renderer.getClipRect();
Chris Craik527a3aa2013-03-04 10:19:31 -0800517 DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), clipRect: %.0f, %.0f, %.0f, %.0f",
Chris Craikff785832013-03-08 13:12:16 -0800518 level * 2, "", this, mName.string(), clipRect->left, clipRect->top,
Chris Craik0776a602013-02-14 15:36:01 -0800519 clipRect->right, clipRect->bottom);
520#endif
521
Chris Craikff785832013-03-08 13:12:16 -0800522 int restoreTo = renderer.getSaveCount();
523 handler(mSaveOp->reinit(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag),
Chet Haasedd671592013-04-19 14:54:34 -0700524 PROPERTY_SAVECOUNT, mClipToBounds);
Chris Craik0776a602013-02-14 15:36:01 -0800525
Chris Craikff785832013-03-08 13:12:16 -0800526 DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "",
Chris Craik0776a602013-02-14 15:36:01 -0800527 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
Chris Craikc3566d02013-02-04 16:16:33 -0800528
Chris Craikff785832013-03-08 13:12:16 -0800529 setViewProperties<T>(renderer, handler, level + 1);
Chris Craik0776a602013-02-14 15:36:01 -0800530
Chet Haasedd671592013-04-19 14:54:34 -0700531 if (mClipToBounds && renderer.quickRejectNoScissor(0, 0, mWidth, mHeight)) {
Chet Haasec7259032013-05-23 07:57:17 -0700532 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
Chet Haasedd671592013-04-19 14:54:34 -0700533 handler(mRestoreToCountOp->reinit(restoreTo), PROPERTY_SAVECOUNT, mClipToBounds);
Chet Haasec7259032013-05-23 07:57:17 -0700534 renderer.restoreToCount(restoreTo);
535 renderer.setOverrideLayerAlpha(1.0f);
Chris Craikff785832013-03-08 13:12:16 -0800536 return;
Chris Craik0776a602013-02-14 15:36:01 -0800537 }
538
539 DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
540 int saveCount = renderer.getSaveCount() - 1;
541 for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) {
542 DisplayListOp *op = mDisplayListData->displayListOps[i];
Chris Craikff785832013-03-08 13:12:16 -0800543
Chris Craik6045d2b2013-05-21 10:49:47 -0700544#if DEBUG_DISPLAY_LIST
545 op->output(level + 1);
546#endif
547
Chris Craik0776a602013-02-14 15:36:01 -0800548 logBuffer.writeCommand(level, op->name());
Chris Craikd4b43b32013-05-09 13:07:52 -0700549 handler(op, saveCount, mClipToBounds);
Chris Craik0776a602013-02-14 15:36:01 -0800550 }
551
Chris Craikff785832013-03-08 13:12:16 -0800552 DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo);
Chet Haasedd671592013-04-19 14:54:34 -0700553 handler(mRestoreToCountOp->reinit(restoreTo), PROPERTY_SAVECOUNT, mClipToBounds);
Chris Craik0776a602013-02-14 15:36:01 -0800554 renderer.restoreToCount(restoreTo);
Chris Craik16ecda52013-03-29 10:59:59 -0700555 renderer.setOverrideLayerAlpha(1.0f);
Chris Craik0776a602013-02-14 15:36:01 -0800556}
557
558}; // namespace uirenderer
559}; // namespace android