Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_VIEW |
| 18 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 19 | #include <SkCanvas.h> |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 20 | #include <algorithm> |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 21 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 22 | #include <utils/Trace.h> |
| 23 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 24 | #include "Debug.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 25 | #include "DisplayList.h" |
| 26 | #include "DisplayListOp.h" |
| 27 | #include "DisplayListLogBuffer.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
| 32 | void DisplayList::outputLogBuffer(int fd) { |
| 33 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 34 | if (logBuffer.isEmpty()) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | FILE *file = fdopen(fd, "a"); |
| 39 | |
| 40 | fprintf(file, "\nRecent DisplayList operations\n"); |
| 41 | logBuffer.outputCommands(file); |
| 42 | |
| 43 | String8 cachesLog; |
| 44 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 45 | fprintf(file, "\nCaches:\n%s", cachesLog.string()); |
| 46 | fprintf(file, "\n"); |
| 47 | |
| 48 | fflush(file); |
| 49 | } |
| 50 | |
| 51 | DisplayList::DisplayList(const DisplayListRenderer& recorder) : |
Chris Craik | 9846de6 | 2013-06-12 16:23:00 -0700 | [diff] [blame] | 52 | mDestroyed(false), mTransformMatrix(NULL), mTransformCamera(NULL), mTransformMatrix3D(NULL), |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 53 | mStaticMatrix(NULL), mAnimationMatrix(NULL) { |
| 54 | |
| 55 | initFromDisplayListRenderer(recorder); |
| 56 | } |
| 57 | |
| 58 | DisplayList::~DisplayList() { |
Chris Craik | 9846de6 | 2013-06-12 16:23:00 -0700 | [diff] [blame] | 59 | mDestroyed = true; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 60 | clearResources(); |
| 61 | } |
| 62 | |
| 63 | void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) { |
| 64 | if (displayList) { |
| 65 | DISPLAY_LIST_LOGD("Deferring display list destruction"); |
| 66 | Caches::getInstance().deleteDisplayListDeferred(displayList); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void DisplayList::clearResources() { |
| 71 | mDisplayListData = NULL; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 72 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 73 | 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++) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 94 | const SkBitmap* bitmap = mOwnedBitmapResources.itemAt(i); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 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 Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 103 | for (size_t i = 0; i < mPatchResources.size(); i++) { |
| 104 | caches.resourceCache.decrementRefcountLocked(mPatchResources.itemAt(i)); |
| 105 | } |
| 106 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 107 | 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 Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 131 | delete mPaths.itemAt(i); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 132 | } |
| 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 Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 141 | mPatchResources.clear(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 142 | mShaders.clear(); |
| 143 | mSourcePaths.clear(); |
| 144 | mPaints.clear(); |
| 145 | mRegions.clear(); |
| 146 | mPaths.clear(); |
| 147 | mMatrices.clear(); |
| 148 | mLayers.clear(); |
| 149 | } |
| 150 | |
| 151 | void DisplayList::reset() { |
| 152 | clearResources(); |
| 153 | init(); |
| 154 | } |
| 155 | |
| 156 | void 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 | |
| 171 | mFunctorCount = recorder.getFunctorCount(); |
| 172 | |
| 173 | Caches& caches = Caches::getInstance(); |
| 174 | caches.registerFunctors(mFunctorCount); |
| 175 | caches.resourceCache.lock(); |
| 176 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 177 | const Vector<const SkBitmap*>& bitmapResources = recorder.getBitmapResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 178 | for (size_t i = 0; i < bitmapResources.size(); i++) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 179 | const SkBitmap* resource = bitmapResources.itemAt(i); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 180 | mBitmapResources.add(resource); |
| 181 | caches.resourceCache.incrementRefcountLocked(resource); |
| 182 | } |
| 183 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 184 | const Vector<const SkBitmap*>& ownedBitmapResources = recorder.getOwnedBitmapResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 185 | for (size_t i = 0; i < ownedBitmapResources.size(); i++) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 186 | const SkBitmap* resource = ownedBitmapResources.itemAt(i); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 187 | mOwnedBitmapResources.add(resource); |
| 188 | caches.resourceCache.incrementRefcountLocked(resource); |
| 189 | } |
| 190 | |
| 191 | const Vector<SkiaColorFilter*>& filterResources = recorder.getFilterResources(); |
| 192 | for (size_t i = 0; i < filterResources.size(); i++) { |
| 193 | SkiaColorFilter* resource = filterResources.itemAt(i); |
| 194 | mFilterResources.add(resource); |
| 195 | caches.resourceCache.incrementRefcountLocked(resource); |
| 196 | } |
| 197 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 198 | const Vector<const Res_png_9patch*>& patchResources = recorder.getPatchResources(); |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 199 | for (size_t i = 0; i < patchResources.size(); i++) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 200 | const Res_png_9patch* resource = patchResources.itemAt(i); |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 201 | mPatchResources.add(resource); |
| 202 | caches.resourceCache.incrementRefcountLocked(resource); |
| 203 | } |
| 204 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 205 | const Vector<SkiaShader*>& shaders = recorder.getShaders(); |
| 206 | for (size_t i = 0; i < shaders.size(); i++) { |
| 207 | SkiaShader* resource = shaders.itemAt(i); |
| 208 | mShaders.add(resource); |
| 209 | caches.resourceCache.incrementRefcountLocked(resource); |
| 210 | } |
| 211 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 212 | const SortedVector<const SkPath*>& sourcePaths = recorder.getSourcePaths(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 213 | for (size_t i = 0; i < sourcePaths.size(); i++) { |
| 214 | mSourcePaths.add(sourcePaths.itemAt(i)); |
| 215 | caches.resourceCache.incrementRefcountLocked(sourcePaths.itemAt(i)); |
| 216 | } |
| 217 | |
| 218 | const Vector<Layer*>& layers = recorder.getLayers(); |
| 219 | for (size_t i = 0; i < layers.size(); i++) { |
| 220 | mLayers.add(layers.itemAt(i)); |
| 221 | caches.resourceCache.incrementRefcountLocked(layers.itemAt(i)); |
| 222 | } |
| 223 | |
| 224 | caches.resourceCache.unlock(); |
| 225 | |
| 226 | mPaints.appendVector(recorder.getPaints()); |
| 227 | mRegions.appendVector(recorder.getRegions()); |
| 228 | mPaths.appendVector(recorder.getPaths()); |
| 229 | mMatrices.appendVector(recorder.getMatrices()); |
| 230 | } |
| 231 | |
| 232 | void DisplayList::init() { |
| 233 | mSize = 0; |
| 234 | mIsRenderable = true; |
| 235 | mFunctorCount = 0; |
| 236 | mLeft = 0; |
| 237 | mTop = 0; |
| 238 | mRight = 0; |
| 239 | mBottom = 0; |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 240 | mClipToBounds = true; |
Chris Craik | 6657a6c | 2014-01-26 11:30:58 -0800 | [diff] [blame] | 241 | mIsolatedZVolume = true; |
| 242 | mProjectBackwards = false; |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 243 | mOutline.rewind(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 244 | mAlpha = 1; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 245 | mHasOverlappingRendering = true; |
| 246 | mTranslationX = 0; |
| 247 | mTranslationY = 0; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 248 | mTranslationZ = 0; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 249 | mRotation = 0; |
| 250 | mRotationX = 0; |
| 251 | mRotationY= 0; |
| 252 | mScaleX = 1; |
| 253 | mScaleY = 1; |
| 254 | mPivotX = 0; |
| 255 | mPivotY = 0; |
| 256 | mCameraDistance = 0; |
| 257 | mMatrixDirty = false; |
| 258 | mMatrixFlags = 0; |
| 259 | mPrevWidth = -1; |
| 260 | mPrevHeight = -1; |
| 261 | mWidth = 0; |
| 262 | mHeight = 0; |
| 263 | mPivotExplicitlySet = false; |
| 264 | mCaching = false; |
| 265 | } |
| 266 | |
| 267 | size_t DisplayList::getSize() { |
| 268 | return mSize; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 273 | * display list. This function should remain in sync with the replay() function. |
| 274 | */ |
| 275 | void DisplayList::output(uint32_t level) { |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 276 | ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this, |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 277 | mName.string(), isRenderable()); |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 278 | ALOGD("%*s%s %d", level * 2, "", "Save", |
| 279 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 280 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 281 | outputViewProperties(level); |
| 282 | int flags = DisplayListOp::kOpLogFlag_Recurse; |
| 283 | for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { |
| 284 | mDisplayListData->displayListOps[i]->output(level, flags); |
| 285 | } |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 286 | |
| 287 | ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, mName.string()); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Romain Guy | 52036b1 | 2013-02-14 18:03:37 -0800 | [diff] [blame] | 290 | float DisplayList::getPivotX() { |
| 291 | updateMatrix(); |
| 292 | return mPivotX; |
| 293 | } |
| 294 | |
| 295 | float DisplayList::getPivotY() { |
| 296 | updateMatrix(); |
| 297 | return mPivotY; |
| 298 | } |
| 299 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 300 | void DisplayList::updateMatrix() { |
| 301 | if (mMatrixDirty) { |
| 302 | if (!mTransformMatrix) { |
| 303 | mTransformMatrix = new SkMatrix(); |
| 304 | } |
| 305 | if (mMatrixFlags == 0 || mMatrixFlags == TRANSLATION) { |
| 306 | mTransformMatrix->reset(); |
| 307 | } else { |
| 308 | if (!mPivotExplicitlySet) { |
| 309 | if (mWidth != mPrevWidth || mHeight != mPrevHeight) { |
| 310 | mPrevWidth = mWidth; |
| 311 | mPrevHeight = mHeight; |
Chet Haase | 259b696 | 2013-05-03 15:25:33 -0700 | [diff] [blame] | 312 | mPivotX = mPrevWidth / 2.0f; |
| 313 | mPivotY = mPrevHeight / 2.0f; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 316 | if (!Caches::getInstance().propertyEnable3d && (mMatrixFlags & ROTATION_3D) == 0) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 317 | mTransformMatrix->setTranslate(mTranslationX, mTranslationY); |
| 318 | mTransformMatrix->preRotate(mRotation, mPivotX, mPivotY); |
| 319 | mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY); |
| 320 | } else { |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 321 | if (Caches::getInstance().propertyEnable3d) { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 322 | mTransform.loadTranslate(mPivotX + mTranslationX, mPivotY + mTranslationY, |
| 323 | mTranslationZ); |
| 324 | mTransform.rotate(mRotationX, 1, 0, 0); |
| 325 | mTransform.rotate(mRotationY, 0, 1, 0); |
| 326 | mTransform.rotate(mRotation, 0, 0, 1); |
| 327 | mTransform.scale(mScaleX, mScaleY, 1); |
| 328 | mTransform.translate(-mPivotX, -mPivotY); |
| 329 | } else { |
| 330 | /* TODO: support this old transform approach, based on API level */ |
| 331 | if (!mTransformCamera) { |
| 332 | mTransformCamera = new Sk3DView(); |
| 333 | mTransformMatrix3D = new SkMatrix(); |
| 334 | } |
| 335 | mTransformMatrix->reset(); |
| 336 | mTransformCamera->save(); |
| 337 | mTransformMatrix->preScale(mScaleX, mScaleY, mPivotX, mPivotY); |
| 338 | mTransformCamera->rotateX(mRotationX); |
| 339 | mTransformCamera->rotateY(mRotationY); |
| 340 | mTransformCamera->rotateZ(-mRotation); |
| 341 | mTransformCamera->getMatrix(mTransformMatrix3D); |
| 342 | mTransformMatrix3D->preTranslate(-mPivotX, -mPivotY); |
| 343 | mTransformMatrix3D->postTranslate(mPivotX + mTranslationX, |
| 344 | mPivotY + mTranslationY); |
| 345 | mTransformMatrix->postConcat(*mTransformMatrix3D); |
| 346 | mTransformCamera->restore(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 347 | } |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | mMatrixDirty = false; |
| 351 | } |
| 352 | } |
| 353 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 354 | void DisplayList::outputViewProperties(const int level) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 355 | updateMatrix(); |
| 356 | if (mLeft != 0 || mTop != 0) { |
| 357 | ALOGD("%*sTranslate (left, top) %d, %d", level * 2, "", mLeft, mTop); |
| 358 | } |
| 359 | if (mStaticMatrix) { |
| 360 | ALOGD("%*sConcatMatrix (static) %p: " MATRIX_STRING, |
| 361 | level * 2, "", mStaticMatrix, MATRIX_ARGS(mStaticMatrix)); |
| 362 | } |
| 363 | if (mAnimationMatrix) { |
| 364 | ALOGD("%*sConcatMatrix (animation) %p: " MATRIX_STRING, |
Chris Craik | 66063ae | 2013-09-05 16:11:18 -0700 | [diff] [blame] | 365 | level * 2, "", mAnimationMatrix, MATRIX_ARGS(mAnimationMatrix)); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 366 | } |
| 367 | if (mMatrixFlags != 0) { |
| 368 | if (mMatrixFlags == TRANSLATION) { |
| 369 | ALOGD("%*sTranslate %f, %f", level * 2, "", mTranslationX, mTranslationY); |
| 370 | } else { |
| 371 | ALOGD("%*sConcatMatrix %p: " MATRIX_STRING, |
| 372 | level * 2, "", mTransformMatrix, MATRIX_ARGS(mTransformMatrix)); |
| 373 | } |
| 374 | } |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 375 | |
Romain Guy | 1de466f | 2013-09-12 16:09:19 -0700 | [diff] [blame] | 376 | bool clipToBoundsNeeded = mCaching ? false : mClipToBounds; |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 377 | if (mAlpha < 1) { |
Chris Craik | 16ecda5 | 2013-03-29 10:59:59 -0700 | [diff] [blame] | 378 | if (mCaching) { |
| 379 | ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", mAlpha); |
| 380 | } else if (!mHasOverlappingRendering) { |
Chris Craik | 5f80362 | 2013-03-21 14:39:04 -0700 | [diff] [blame] | 381 | ALOGD("%*sScaleAlpha %.2f", level * 2, "", mAlpha); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 382 | } else { |
| 383 | int flags = SkCanvas::kHasAlphaLayer_SaveFlag; |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 384 | if (clipToBoundsNeeded) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 385 | flags |= SkCanvas::kClipToLayer_SaveFlag; |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 386 | clipToBoundsNeeded = false; // clipping done by save layer |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 387 | } |
| 388 | ALOGD("%*sSaveLayerAlpha %.2f, %.2f, %.2f, %.2f, %d, 0x%x", level * 2, "", |
| 389 | (float) 0, (float) 0, (float) mRight - mLeft, (float) mBottom - mTop, |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 390 | (int)(mAlpha * 255), flags); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 393 | if (clipToBoundsNeeded) { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 394 | ALOGD("%*sClipRect %.2f, %.2f, %.2f, %.2f", level * 2, "", 0.0f, 0.0f, |
| 395 | (float) mRight - mLeft, (float) mBottom - mTop); |
| 396 | } |
| 397 | } |
| 398 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 399 | /* |
| 400 | * For property operations, we pass a savecount of 0, since the operations aren't part of the |
| 401 | * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in |
| 402 | * base saveCount (i.e., how RestoreToCount uses saveCount + mCount) |
| 403 | */ |
| 404 | #define PROPERTY_SAVECOUNT 0 |
| 405 | |
| 406 | template <class T> |
| 407 | void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler, |
| 408 | const int level) { |
| 409 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 410 | outputViewProperties(level); |
| 411 | #endif |
| 412 | updateMatrix(); |
| 413 | if (mLeft != 0 || mTop != 0) { |
| 414 | renderer.translate(mLeft, mTop); |
| 415 | } |
| 416 | if (mStaticMatrix) { |
| 417 | renderer.concatMatrix(mStaticMatrix); |
| 418 | } else if (mAnimationMatrix) { |
| 419 | renderer.concatMatrix(mAnimationMatrix); |
| 420 | } |
| 421 | if (mMatrixFlags != 0) { |
Chris Craik | cf8d9d4 | 2014-01-16 14:48:54 -0800 | [diff] [blame] | 422 | if (Caches::getInstance().propertyEnable3d) { |
| 423 | if (mMatrixFlags == TRANSLATION) { |
| 424 | renderer.translate(mTranslationX, mTranslationY, mTranslationZ); |
| 425 | } else { |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 426 | renderer.concatMatrix(mTransform); |
Chris Craik | cf8d9d4 | 2014-01-16 14:48:54 -0800 | [diff] [blame] | 427 | } |
| 428 | } else { |
| 429 | // avoid setting translationZ, use SkMatrix |
| 430 | if (mMatrixFlags == TRANSLATION) { |
| 431 | renderer.translate(mTranslationX, mTranslationY, 0); |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 432 | } else { |
| 433 | renderer.concatMatrix(mTransformMatrix); |
| 434 | } |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
Romain Guy | 1de466f | 2013-09-12 16:09:19 -0700 | [diff] [blame] | 437 | bool clipToBoundsNeeded = mCaching ? false : mClipToBounds; |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 438 | if (mAlpha < 1) { |
Chris Craik | 16ecda5 | 2013-03-29 10:59:59 -0700 | [diff] [blame] | 439 | if (mCaching) { |
| 440 | renderer.setOverrideLayerAlpha(mAlpha); |
| 441 | } else if (!mHasOverlappingRendering) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 442 | renderer.scaleAlpha(mAlpha); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 443 | } else { |
| 444 | // TODO: should be able to store the size of a DL at record time and not |
| 445 | // have to pass it into this call. In fact, this information might be in the |
| 446 | // location/size info that we store with the new native transform data. |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 447 | int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag; |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 448 | if (clipToBoundsNeeded) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 449 | saveFlags |= SkCanvas::kClipToLayer_SaveFlag; |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 450 | clipToBoundsNeeded = false; // clipping done by saveLayer |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 451 | } |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 452 | |
| 453 | SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( |
| 454 | 0, 0, mRight - mLeft, mBottom - mTop, |
| 455 | mAlpha * 255, SkXfermode::kSrcOver_Mode, saveFlags); |
| 456 | handler(op, PROPERTY_SAVECOUNT, mClipToBounds); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
Chris Craik | 39a908c | 2013-06-13 14:39:01 -0700 | [diff] [blame] | 459 | if (clipToBoundsNeeded) { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 460 | ClipRectOp* op = new (handler.allocator()) ClipRectOp(0, 0, |
| 461 | mRight - mLeft, mBottom - mTop, SkRegion::kIntersect_Op); |
| 462 | handler(op, PROPERTY_SAVECOUNT, mClipToBounds); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Apply property-based transformations to input matrix |
| 468 | */ |
| 469 | void DisplayList::applyViewPropertyTransforms(mat4& matrix) { |
| 470 | if (mLeft != 0 || mTop != 0) { |
| 471 | matrix.translate(mLeft, mTop); |
| 472 | } |
| 473 | if (mStaticMatrix) { |
| 474 | mat4 stat(*mStaticMatrix); |
| 475 | matrix.multiply(stat); |
| 476 | } else if (mAnimationMatrix) { |
| 477 | mat4 anim(*mAnimationMatrix); |
| 478 | matrix.multiply(anim); |
| 479 | } |
| 480 | if (mMatrixFlags != 0) { |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 481 | updateMatrix(); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 482 | if (mMatrixFlags == TRANSLATION) { |
| 483 | matrix.translate(mTranslationX, mTranslationY, mTranslationZ); |
| 484 | } else { |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 485 | if (Caches::getInstance().propertyEnable3d) { |
| 486 | matrix.multiply(mTransform); |
| 487 | } else { |
| 488 | mat4 temp(*mTransformMatrix); |
| 489 | matrix.multiply(temp); |
| 490 | } |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Organizes the DisplayList hierarchy to prepare for Z-based draw order. |
| 497 | * |
| 498 | * This should be called before a call to defer() or drawDisplayList() |
| 499 | * |
| 500 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 501 | * which are flagged to not draw in the standard draw loop. |
| 502 | */ |
| 503 | void DisplayList::computeOrdering() { |
| 504 | ATRACE_CALL(); |
Chris Craik | bb615a6 | 2014-01-24 13:22:35 -0800 | [diff] [blame] | 505 | m3dNodes.clear(); |
| 506 | mProjectedNodes.clear(); |
Chris Craik | 8b62cda | 2013-12-17 15:07:47 -0800 | [diff] [blame] | 507 | |
Chris Craik | bb615a6 | 2014-01-24 13:22:35 -0800 | [diff] [blame] | 508 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 509 | // transform properties are applied correctly to top level children |
| 510 | if (mDisplayListData == NULL) return; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 511 | for (unsigned int i = 0; i < mDisplayListData->children.size(); i++) { |
| 512 | DrawDisplayListOp* childOp = mDisplayListData->children[i]; |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 513 | childOp->mDisplayList->computeOrderingImpl(childOp, |
| 514 | &m3dNodes, &mat4::identity(), |
Chris Craik | 3783e70 | 2014-01-27 14:26:14 -0800 | [diff] [blame] | 515 | &mProjectedNodes, &mat4::identity()); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
| 519 | void DisplayList::computeOrderingImpl( |
| 520 | DrawDisplayListOp* opState, |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 521 | Vector<ZDrawDisplayListOpPair>* compositedChildrenOf3dRoot, |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 522 | const mat4* transformFrom3dRoot, |
| 523 | Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface, |
Chris Craik | 3783e70 | 2014-01-27 14:26:14 -0800 | [diff] [blame] | 524 | const mat4* transformFromProjectionSurface) { |
Chris Craik | bb615a6 | 2014-01-24 13:22:35 -0800 | [diff] [blame] | 525 | m3dNodes.clear(); |
| 526 | mProjectedNodes.clear(); |
| 527 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 528 | // TODO: should avoid this calculation in most cases |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 529 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 530 | Matrix4 localTransformFrom3dRoot(*transformFrom3dRoot); |
| 531 | localTransformFrom3dRoot.multiply(opState->mTransformFromParent); |
| 532 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
| 533 | localTransformFromProjectionSurface.multiply(opState->mTransformFromParent); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 534 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 535 | if (mTranslationZ != 0.0f) { // TODO: other signals for 3d compositing, such as custom matrix4 |
| 536 | // composited 3d layer, flag for out of order draw and save matrix... |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 537 | opState->mSkipInOrderDraw = true; |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 538 | opState->mTransformFromCompositingAncestor.load(localTransformFrom3dRoot); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 539 | |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 540 | // ... and insert into current 3d root, keyed with pivot z for later sorting |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 541 | Vector3 pivot(mPivotX, mPivotY, 0.0f); |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 542 | mat4 totalTransform(localTransformFrom3dRoot); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 543 | applyViewPropertyTransforms(totalTransform); |
| 544 | totalTransform.mapPoint3d(pivot); |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 545 | compositedChildrenOf3dRoot->add(ZDrawDisplayListOpPair(pivot.z, opState)); |
Chris Craik | 6657a6c | 2014-01-26 11:30:58 -0800 | [diff] [blame] | 546 | } else if (mProjectBackwards) { |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 547 | // composited projectee, flag for out of order draw, save matrix, and store in proj surface |
| 548 | opState->mSkipInOrderDraw = true; |
| 549 | opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface); |
| 550 | compositedChildrenOfProjectionSurface->add(opState); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 551 | } else { |
| 552 | // standard in order draw |
| 553 | opState->mSkipInOrderDraw = false; |
| 554 | } |
| 555 | |
Chris Craik | 6657a6c | 2014-01-26 11:30:58 -0800 | [diff] [blame] | 556 | if (mIsolatedZVolume) { |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 557 | // create a new 3d space for descendents by collecting them |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 558 | compositedChildrenOf3dRoot = &m3dNodes; |
| 559 | transformFrom3dRoot = &mat4::identity(); |
| 560 | } else { |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 561 | applyViewPropertyTransforms(localTransformFrom3dRoot); |
| 562 | transformFrom3dRoot = &localTransformFrom3dRoot; |
| 563 | } |
| 564 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 565 | if (mDisplayListData != NULL && mDisplayListData->projectionIndex >= 0) { |
| 566 | // create a new projection surface for descendents by collecting them |
| 567 | compositedChildrenOfProjectionSurface = &mProjectedNodes; |
| 568 | transformFromProjectionSurface = &mat4::identity(); |
| 569 | } else { |
| 570 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 571 | transformFromProjectionSurface = &localTransformFromProjectionSurface; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Chris Craik | 8b62cda | 2013-12-17 15:07:47 -0800 | [diff] [blame] | 574 | if (mDisplayListData != NULL && mDisplayListData->children.size() > 0) { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 575 | for (unsigned int i = 0; i < mDisplayListData->children.size(); i++) { |
| 576 | DrawDisplayListOp* childOp = mDisplayListData->children[i]; |
| 577 | childOp->mDisplayList->computeOrderingImpl(childOp, |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 578 | compositedChildrenOf3dRoot, transformFrom3dRoot, |
Chris Craik | 3783e70 | 2014-01-27 14:26:14 -0800 | [diff] [blame] | 579 | compositedChildrenOfProjectionSurface, transformFromProjectionSurface); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 580 | } |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 584 | class DeferOperationHandler { |
| 585 | public: |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 586 | DeferOperationHandler(DeferStateStruct& deferStruct, int level) |
| 587 | : mDeferStruct(deferStruct), mLevel(level) {} |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 588 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 589 | operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 590 | } |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 591 | inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } |
| 592 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 593 | private: |
| 594 | DeferStateStruct& mDeferStruct; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 595 | const int mLevel; |
| 596 | }; |
| 597 | |
| 598 | void DisplayList::defer(DeferStateStruct& deferStruct, const int level) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 599 | DeferOperationHandler handler(deferStruct, level); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 600 | iterate<DeferOperationHandler>(deferStruct.mRenderer, handler, level); |
| 601 | } |
| 602 | |
| 603 | class ReplayOperationHandler { |
| 604 | public: |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 605 | ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) |
| 606 | : mReplayStruct(replayStruct), mLevel(level) {} |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 607 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 608 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 609 | mReplayStruct.mRenderer.eventMark(operation->name()); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 610 | #endif |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 611 | operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 612 | } |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 613 | inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } |
| 614 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 615 | private: |
| 616 | ReplayStateStruct& mReplayStruct; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 617 | const int mLevel; |
| 618 | }; |
| 619 | |
| 620 | void DisplayList::replay(ReplayStateStruct& replayStruct, const int level) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 621 | ReplayOperationHandler handler(replayStruct, level); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 622 | |
| 623 | replayStruct.mRenderer.startMark(mName.string()); |
| 624 | iterate<ReplayOperationHandler>(replayStruct.mRenderer, handler, level); |
| 625 | replayStruct.mRenderer.endMark(); |
| 626 | |
| 627 | DISPLAY_LIST_LOGD("%*sDone (%p, %s), returning %d", level * 2, "", this, mName.string(), |
| 628 | replayStruct.mDrawGlStatus); |
| 629 | } |
| 630 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 631 | template <class T> |
| 632 | void DisplayList::iterate3dChildren(ChildrenSelectMode mode, OpenGLRenderer& renderer, |
| 633 | T& handler, const int level) { |
| 634 | if (m3dNodes.size() == 0 || |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 635 | (mode == kNegativeZChildren && m3dNodes[0].key > 0.0f) || |
| 636 | (mode == kPositiveZChildren && m3dNodes[m3dNodes.size() - 1].key < 0.0f)) { |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 637 | // no 3d children to draw |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 638 | return; |
| 639 | } |
| 640 | |
| 641 | LinearAllocator& alloc = handler.allocator(); |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 642 | ClipRectOp* clipOp = new (alloc) ClipRectOp(0, 0, mWidth, mHeight, |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 643 | SkRegion::kIntersect_Op); // clip to 3d root bounds for now |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 644 | handler(clipOp, PROPERTY_SAVECOUNT, mClipToBounds); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 645 | int rootRestoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 646 | |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 647 | for (size_t i = 0; i < m3dNodes.size(); i++) { |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 648 | const float zValue = m3dNodes[i].key; |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 649 | DrawDisplayListOp* childOp = m3dNodes[i].value; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 650 | |
| 651 | if (mode == kPositiveZChildren && zValue < 0.0f) continue; |
| 652 | if (mode == kNegativeZChildren && zValue > 0.0f) break; |
| 653 | |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 654 | if (mode == kPositiveZChildren && zValue > 0.0f) { |
| 655 | /* draw shadow with parent matrix applied, passing in the child's total matrix |
| 656 | * |
| 657 | * TODO: |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 658 | * -view must opt-in to shadows |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 659 | * -consider depth in more complex scenarios (neg z, added shadow depth) |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 660 | */ |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 661 | mat4 shadowMatrix(childOp->mTransformFromCompositingAncestor); |
| 662 | childOp->mDisplayList->applyViewPropertyTransforms(shadowMatrix); |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 663 | DisplayList* child = childOp->mDisplayList; |
| 664 | |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 665 | DisplayListOp* shadowOp = new (alloc) DrawShadowOp(shadowMatrix, |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 666 | child->mAlpha, &(child->mOutline), child->mWidth, child->mHeight); |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 667 | handler(shadowOp, PROPERTY_SAVECOUNT, mClipToBounds); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 668 | } |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 669 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 670 | renderer.concatMatrix(childOp->mTransformFromCompositingAncestor); |
| 671 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
| 672 | handler(childOp, renderer.getSaveCount() - 1, mClipToBounds); |
| 673 | childOp->mSkipInOrderDraw = true; |
| 674 | } |
| 675 | handler(new (alloc) RestoreToCountOp(rootRestoreTo), PROPERTY_SAVECOUNT, mClipToBounds); |
| 676 | } |
| 677 | |
| 678 | template <class T> |
| 679 | void DisplayList::iterateProjectedChildren(OpenGLRenderer& renderer, T& handler, const int level) { |
| 680 | LinearAllocator& alloc = handler.allocator(); |
| 681 | ClipRectOp* clipOp = new (alloc) ClipRectOp(0, 0, mWidth, mHeight, |
| 682 | SkRegion::kReplace_Op); // clip to projection surface root bounds |
| 683 | handler(clipOp, PROPERTY_SAVECOUNT, mClipToBounds); |
| 684 | int rootRestoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 685 | |
| 686 | for (size_t i = 0; i < mProjectedNodes.size(); i++) { |
| 687 | DrawDisplayListOp* childOp = mProjectedNodes[i]; |
| 688 | renderer.concatMatrix(childOp->mTransformFromCompositingAncestor); |
| 689 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
| 690 | handler(childOp, renderer.getSaveCount() - 1, mClipToBounds); |
| 691 | childOp->mSkipInOrderDraw = true; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 692 | } |
| 693 | handler(new (alloc) RestoreToCountOp(rootRestoreTo), PROPERTY_SAVECOUNT, mClipToBounds); |
| 694 | } |
| 695 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 696 | /** |
| 697 | * This function serves both defer and replay modes, and will organize the displayList's component |
| 698 | * operations for a single frame: |
| 699 | * |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 700 | * Every 'simple' state operation that affects just the matrix and alpha (or other factors of |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 701 | * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom |
| 702 | * defer logic) and operations in displayListOps are issued through the 'handler' which handles the |
| 703 | * defer vs replay logic, per operation |
| 704 | */ |
| 705 | template <class T> |
| 706 | void DisplayList::iterate(OpenGLRenderer& renderer, T& handler, const int level) { |
Chris Craik | 9846de6 | 2013-06-12 16:23:00 -0700 | [diff] [blame] | 707 | if (CC_UNLIKELY(mDestroyed)) { // temporary debug logging |
| 708 | ALOGW("Error: %s is drawing after destruction, size %d", getName(), mSize); |
| 709 | CRASH(); |
| 710 | } |
| 711 | if (mSize == 0 || mAlpha <= 0) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 712 | DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, mName.string()); |
| 713 | return; |
| 714 | } |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 715 | |
| 716 | #if DEBUG_DISPLAY_LIST |
| 717 | Rect* clipRect = renderer.getClipRect(); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 718 | DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), clipRect: %.0f, %.0f, %.0f, %.0f", |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 719 | level * 2, "", this, mName.string(), clipRect->left, clipRect->top, |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 720 | clipRect->right, clipRect->bottom); |
| 721 | #endif |
| 722 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 723 | LinearAllocator& alloc = handler.allocator(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 724 | int restoreTo = renderer.getSaveCount(); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 725 | handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 726 | PROPERTY_SAVECOUNT, mClipToBounds); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 727 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 728 | DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "", |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 729 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 730 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 731 | setViewProperties<T>(renderer, handler, level + 1); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 732 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 733 | bool quickRejected = mClipToBounds && renderer.quickRejectConservative(0, 0, mWidth, mHeight); |
| 734 | if (!quickRejected) { |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 735 | // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order) |
| 736 | std::stable_sort(m3dNodes.begin(), m3dNodes.end()); |
| 737 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 738 | // for 3d root, draw children with negative z values |
| 739 | iterate3dChildren(kNegativeZChildren, renderer, handler, level); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 740 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 741 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 742 | const int saveCountOffset = renderer.getSaveCount() - 1; |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 743 | const int projectionIndex = mDisplayListData->projectionIndex; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 744 | for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { |
| 745 | DisplayListOp *op = mDisplayListData->displayListOps[i]; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 746 | |
Chris Craik | 6045d2b | 2013-05-21 10:49:47 -0700 | [diff] [blame] | 747 | #if DEBUG_DISPLAY_LIST |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 748 | op->output(level + 1); |
Chris Craik | 6045d2b | 2013-05-21 10:49:47 -0700 | [diff] [blame] | 749 | #endif |
| 750 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 751 | logBuffer.writeCommand(level, op->name()); |
| 752 | handler(op, saveCountOffset, mClipToBounds); |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 753 | |
| 754 | if (CC_UNLIKELY(i == projectionIndex && mProjectedNodes.size() > 0)) { |
| 755 | iterateProjectedChildren(renderer, handler, level); |
| 756 | } |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | // for 3d root, draw children with positive z values |
| 760 | iterate3dChildren(kPositiveZChildren, renderer, handler, level); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 761 | } |
| 762 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 763 | DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 764 | handler(new (alloc) RestoreToCountOp(restoreTo), |
| 765 | PROPERTY_SAVECOUNT, mClipToBounds); |
Chris Craik | 16ecda5 | 2013-03-29 10:59:59 -0700 | [diff] [blame] | 766 | renderer.setOverrideLayerAlpha(1.0f); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | }; // namespace uirenderer |
| 770 | }; // namespace android |