John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 ATRACE_TAG ATRACE_TAG_VIEW |
| 18 | |
| 19 | #include "RenderNode.h" |
| 20 | |
| 21 | #include <SkCanvas.h> |
| 22 | #include <algorithm> |
| 23 | |
| 24 | #include <utils/Trace.h> |
| 25 | |
| 26 | #include "Debug.h" |
| 27 | #include "DisplayListOp.h" |
| 28 | #include "DisplayListLogBuffer.h" |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 29 | #include "utils/MathUtils.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace uirenderer { |
| 33 | |
| 34 | void RenderNode::outputLogBuffer(int fd) { |
| 35 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 36 | if (logBuffer.isEmpty()) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | FILE *file = fdopen(fd, "a"); |
| 41 | |
| 42 | fprintf(file, "\nRecent DisplayList operations\n"); |
| 43 | logBuffer.outputCommands(file); |
| 44 | |
| 45 | String8 cachesLog; |
| 46 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 47 | fprintf(file, "\nCaches:\n%s", cachesLog.string()); |
| 48 | fprintf(file, "\n"); |
| 49 | |
| 50 | fflush(file); |
| 51 | } |
| 52 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 53 | RenderNode::RenderNode() |
Chris Craik | 143912f | 2014-04-11 13:47:36 -0700 | [diff] [blame] | 54 | : mNeedsPropertiesSync(false) |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 55 | , mNeedsDisplayListDataSync(false) |
| 56 | , mDisplayListData(0) |
| 57 | , mStagingDisplayListData(0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | RenderNode::~RenderNode() { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 61 | delete mDisplayListData; |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 62 | delete mStagingDisplayListData; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 63 | } |
| 64 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 65 | void RenderNode::setStagingDisplayList(DisplayListData* data) { |
| 66 | mNeedsDisplayListDataSync = true; |
| 67 | delete mStagingDisplayListData; |
| 68 | mStagingDisplayListData = data; |
| 69 | if (mStagingDisplayListData) { |
| 70 | Caches::getInstance().registerFunctors(mStagingDisplayListData->functorCount); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 76 | * display list. This function should remain in sync with the replay() function. |
| 77 | */ |
| 78 | void RenderNode::output(uint32_t level) { |
| 79 | ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 80 | getName(), isRenderable()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 81 | ALOGD("%*s%s %d", level * 2, "", "Save", |
| 82 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 83 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 84 | properties().debugOutputProperties(level); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 85 | int flags = DisplayListOp::kOpLogFlag_Recurse; |
| 86 | for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { |
| 87 | mDisplayListData->displayListOps[i]->output(level, flags); |
| 88 | } |
| 89 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 90 | ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 91 | } |
| 92 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 93 | void RenderNode::prepareTree(TreeInfo& info) { |
| 94 | ATRACE_CALL(); |
| 95 | |
| 96 | prepareTreeImpl(info); |
| 97 | } |
| 98 | |
| 99 | void RenderNode::prepareTreeImpl(TreeInfo& info) { |
| 100 | pushStagingChanges(info); |
| 101 | prepareSubTree(info, mDisplayListData); |
| 102 | } |
| 103 | |
| 104 | void RenderNode::pushStagingChanges(TreeInfo& info) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 105 | if (mNeedsPropertiesSync) { |
| 106 | mNeedsPropertiesSync = false; |
| 107 | mProperties = mStagingProperties; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 108 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 109 | if (mNeedsDisplayListDataSync) { |
| 110 | mNeedsDisplayListDataSync = false; |
| 111 | // Do a push pass on the old tree to handle freeing DisplayListData |
| 112 | // that are no longer used |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 113 | TreeInfo oldTreeInfo; |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 114 | prepareSubTree(oldTreeInfo, mDisplayListData); |
| 115 | // TODO: The damage for the old tree should be accounted for |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 116 | delete mDisplayListData; |
| 117 | mDisplayListData = mStagingDisplayListData; |
| 118 | mStagingDisplayListData = 0; |
| 119 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 120 | } |
| 121 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 122 | void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 123 | if (subtree) { |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 124 | TextureCache& cache = Caches::getInstance().textureCache; |
| 125 | info.hasFunctors |= subtree->functorCount; |
| 126 | // TODO: Fix ownedBitmapResources to not require disabling prepareTextures |
| 127 | // and thus falling out of async drawing path. |
| 128 | if (subtree->ownedBitmapResources.size()) { |
| 129 | info.prepareTextures = false; |
| 130 | } |
| 131 | for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) { |
| 132 | info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 133 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 134 | for (size_t i = 0; i < subtree->children().size(); i++) { |
| 135 | RenderNode* childNode = subtree->children()[i]->mDisplayList; |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 136 | childNode->prepareTreeImpl(info); |
John Reck | 5bf11bb | 2014-03-25 10:22:09 -0700 | [diff] [blame] | 137 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * For property operations, we pass a savecount of 0, since the operations aren't part of the |
| 143 | * displaylist, and thus don't have to compensate for the record-time/playback-time discrepancy in |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 144 | * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount()) |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 145 | */ |
| 146 | #define PROPERTY_SAVECOUNT 0 |
| 147 | |
| 148 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 149 | void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 150 | #if DEBUG_DISPLAY_LIST |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 151 | properties().debugOutputProperties(handler.level() + 1); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 152 | #endif |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 153 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 154 | renderer.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 155 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 156 | if (properties().getStaticMatrix()) { |
| 157 | renderer.concatMatrix(properties().getStaticMatrix()); |
| 158 | } else if (properties().getAnimationMatrix()) { |
| 159 | renderer.concatMatrix(properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 160 | } |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 161 | if (properties().hasTransformMatrix()) { |
| 162 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 163 | renderer.translate(properties().getTranslationX(), properties().getTranslationY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 164 | } else { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 165 | renderer.concatMatrix(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 168 | bool clipToBoundsNeeded = properties().getCaching() ? false : properties().getClipToBounds(); |
| 169 | if (properties().getAlpha() < 1) { |
| 170 | if (properties().getCaching()) { |
| 171 | renderer.setOverrideLayerAlpha(properties().getAlpha()); |
| 172 | } else if (!properties().getHasOverlappingRendering()) { |
| 173 | renderer.scaleAlpha(properties().getAlpha()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 174 | } else { |
| 175 | // TODO: should be able to store the size of a DL at record time and not |
| 176 | // have to pass it into this call. In fact, this information might be in the |
| 177 | // location/size info that we store with the new native transform data. |
| 178 | int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag; |
| 179 | if (clipToBoundsNeeded) { |
| 180 | saveFlags |= SkCanvas::kClipToLayer_SaveFlag; |
| 181 | clipToBoundsNeeded = false; // clipping done by saveLayer |
| 182 | } |
| 183 | |
| 184 | SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 185 | 0, 0, properties().getWidth(), properties().getHeight(), |
| 186 | properties().getAlpha() * 255, saveFlags); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 187 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | if (clipToBoundsNeeded) { |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 191 | ClipRectOp* op = new (handler.allocator()) ClipRectOp( |
| 192 | 0, 0, properties().getWidth(), properties().getHeight(), SkRegion::kIntersect_Op); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 193 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 194 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 195 | |
| 196 | if (CC_UNLIKELY(properties().hasClippingPath())) { |
| 197 | // TODO: optimize for round rect/circle clipping |
| 198 | const SkPath* path = properties().getClippingPath(); |
| 199 | ClipPathOp* op = new (handler.allocator()) ClipPathOp(path, SkRegion::kIntersect_Op); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 200 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Apply property-based transformations to input matrix |
| 206 | * |
| 207 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 208 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 209 | */ |
| 210 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 211 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 212 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 213 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 214 | if (properties().getStaticMatrix()) { |
| 215 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 216 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 217 | } else if (properties().getAnimationMatrix()) { |
| 218 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 219 | matrix.multiply(anim); |
| 220 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 221 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 222 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 223 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 224 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 225 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 226 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 227 | } else { |
| 228 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 229 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 230 | } else { |
| 231 | mat4 true3dMat; |
| 232 | true3dMat.loadTranslate( |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 233 | properties().getPivotX() + properties().getTranslationX(), |
| 234 | properties().getPivotY() + properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 235 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 236 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 237 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 238 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 239 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 240 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 241 | |
| 242 | matrix.multiply(true3dMat); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Organizes the DisplayList hierarchy to prepare for background projection reordering. |
| 250 | * |
| 251 | * This should be called before a call to defer() or drawDisplayList() |
| 252 | * |
| 253 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 254 | * which are flagged to not draw in the standard draw loop. |
| 255 | */ |
| 256 | void RenderNode::computeOrdering() { |
| 257 | ATRACE_CALL(); |
| 258 | mProjectedNodes.clear(); |
| 259 | |
| 260 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 261 | // transform properties are applied correctly to top level children |
| 262 | if (mDisplayListData == NULL) return; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 263 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
| 264 | DrawDisplayListOp* childOp = mDisplayListData->children()[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 265 | childOp->mDisplayList->computeOrderingImpl(childOp, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 266 | properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
| 270 | void RenderNode::computeOrderingImpl( |
| 271 | DrawDisplayListOp* opState, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 272 | const SkPath* outlineOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 273 | Vector<DrawDisplayListOp*>* compositedChildrenOfProjectionSurface, |
| 274 | const mat4* transformFromProjectionSurface) { |
| 275 | mProjectedNodes.clear(); |
| 276 | if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return; |
| 277 | |
| 278 | // TODO: should avoid this calculation in most cases |
| 279 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 280 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
| 281 | localTransformFromProjectionSurface.multiply(opState->mTransformFromParent); |
| 282 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 283 | if (properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 284 | // composited projectee, flag for out of order draw, save matrix, and store in proj surface |
| 285 | opState->mSkipInOrderDraw = true; |
| 286 | opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface); |
| 287 | compositedChildrenOfProjectionSurface->add(opState); |
| 288 | } else { |
| 289 | // standard in order draw |
| 290 | opState->mSkipInOrderDraw = false; |
| 291 | } |
| 292 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 293 | if (mDisplayListData->children().size() > 0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 294 | const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0; |
| 295 | bool haveAppliedPropertiesToProjection = false; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 296 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
| 297 | DrawDisplayListOp* childOp = mDisplayListData->children()[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 298 | RenderNode* child = childOp->mDisplayList; |
| 299 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 300 | const SkPath* projectionOutline = NULL; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 301 | Vector<DrawDisplayListOp*>* projectionChildren = NULL; |
| 302 | const mat4* projectionTransform = NULL; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 303 | if (isProjectionReceiver && !child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 304 | // if receiving projections, collect projecting descendent |
| 305 | |
| 306 | // Note that if a direct descendent is projecting backwards, we pass it's |
| 307 | // grandparent projection collection, since it shouldn't project onto it's |
| 308 | // parent, where it will already be drawing. |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 309 | projectionOutline = properties().getOutline().getPath(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 310 | projectionChildren = &mProjectedNodes; |
| 311 | projectionTransform = &mat4::identity(); |
| 312 | } else { |
| 313 | if (!haveAppliedPropertiesToProjection) { |
| 314 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 315 | haveAppliedPropertiesToProjection = true; |
| 316 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 317 | projectionOutline = outlineOfProjectionSurface; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 318 | projectionChildren = compositedChildrenOfProjectionSurface; |
| 319 | projectionTransform = &localTransformFromProjectionSurface; |
| 320 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 321 | child->computeOrderingImpl(childOp, |
| 322 | projectionOutline, projectionChildren, projectionTransform); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | class DeferOperationHandler { |
| 328 | public: |
| 329 | DeferOperationHandler(DeferStateStruct& deferStruct, int level) |
| 330 | : mDeferStruct(deferStruct), mLevel(level) {} |
| 331 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 332 | operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); |
| 333 | } |
| 334 | inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 335 | inline void startMark(const char* name) {} // do nothing |
| 336 | inline void endMark() {} |
| 337 | inline int level() { return mLevel; } |
| 338 | inline int replayFlags() { return mDeferStruct.mReplayFlags; } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 339 | |
| 340 | private: |
| 341 | DeferStateStruct& mDeferStruct; |
| 342 | const int mLevel; |
| 343 | }; |
| 344 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 345 | void RenderNode::deferNodeTree(DeferStateStruct& deferStruct) { |
| 346 | DeferOperationHandler handler(deferStruct, 0); |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 347 | if (MathUtils::isPositive(properties().getZ())) { |
| 348 | issueDrawShadowOperation(Matrix4::identity(), handler); |
| 349 | } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 350 | issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); |
| 351 | } |
| 352 | |
| 353 | void RenderNode::deferNodeInParent(DeferStateStruct& deferStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 354 | DeferOperationHandler handler(deferStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 355 | issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | class ReplayOperationHandler { |
| 359 | public: |
| 360 | ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) |
| 361 | : mReplayStruct(replayStruct), mLevel(level) {} |
| 362 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 363 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 364 | mReplayStruct.mRenderer.eventMark(operation->name()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 365 | #endif |
| 366 | operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); |
| 367 | } |
| 368 | inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 369 | inline void startMark(const char* name) { |
| 370 | mReplayStruct.mRenderer.startMark(name); |
| 371 | } |
| 372 | inline void endMark() { |
| 373 | mReplayStruct.mRenderer.endMark(); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 374 | } |
| 375 | inline int level() { return mLevel; } |
| 376 | inline int replayFlags() { return mReplayStruct.mReplayFlags; } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 377 | |
| 378 | private: |
| 379 | ReplayStateStruct& mReplayStruct; |
| 380 | const int mLevel; |
| 381 | }; |
| 382 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 383 | void RenderNode::replayNodeTree(ReplayStateStruct& replayStruct) { |
| 384 | ReplayOperationHandler handler(replayStruct, 0); |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 385 | if (MathUtils::isPositive(properties().getZ())) { |
| 386 | issueDrawShadowOperation(Matrix4::identity(), handler); |
| 387 | } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 388 | issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); |
| 389 | } |
| 390 | |
| 391 | void RenderNode::replayNodeInParent(ReplayStateStruct& replayStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 392 | ReplayOperationHandler handler(replayStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 393 | issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void RenderNode::buildZSortedChildList(Vector<ZDrawDisplayListOpPair>& zTranslatedNodes) { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 397 | if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 398 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 399 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
| 400 | DrawDisplayListOp* childOp = mDisplayListData->children()[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 401 | RenderNode* child = childOp->mDisplayList; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 402 | float childZ = child->properties().getZ(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 403 | |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 404 | if (!MathUtils::isZero(childZ)) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 405 | zTranslatedNodes.add(ZDrawDisplayListOpPair(childZ, childOp)); |
| 406 | childOp->mSkipInOrderDraw = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 407 | } else if (!child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 408 | // regular, in order drawing DisplayList |
| 409 | childOp->mSkipInOrderDraw = false; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order) |
| 414 | std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end()); |
| 415 | } |
| 416 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 417 | template <class T> |
| 418 | void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) { |
| 419 | if (properties().getAlpha() <= 0.0f) return; |
| 420 | |
| 421 | mat4 shadowMatrixXY(transformFromParent); |
| 422 | applyViewPropertyTransforms(shadowMatrixXY); |
| 423 | |
| 424 | // Z matrix needs actual 3d transformation, so mapped z values will be correct |
| 425 | mat4 shadowMatrixZ(transformFromParent); |
| 426 | applyViewPropertyTransforms(shadowMatrixZ, true); |
| 427 | |
| 428 | const SkPath* outlinePath = properties().getOutline().getPath(); |
| 429 | const RevealClip& revealClip = properties().getRevealClip(); |
| 430 | const SkPath* revealClipPath = revealClip.hasConvexClip() |
| 431 | ? revealClip.getPath() : NULL; // only pass the reveal clip's path if it's convex |
| 432 | |
| 433 | /** |
| 434 | * The drawing area of the caster is always the same as the its perimeter (which |
| 435 | * the shadow system uses) *except* in the inverse clip case. Inform the shadow |
| 436 | * system that the caster's drawing area (as opposed to its perimeter) has been |
| 437 | * clipped, so that it knows the caster can't be opaque. |
| 438 | */ |
| 439 | bool casterUnclipped = !revealClip.willClip() || revealClip.hasConvexClip(); |
| 440 | |
| 441 | DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp( |
| 442 | shadowMatrixXY, shadowMatrixZ, |
| 443 | properties().getAlpha(), casterUnclipped, |
| 444 | properties().getWidth(), properties().getHeight(), |
| 445 | outlinePath, revealClipPath); |
| 446 | handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 447 | } |
| 448 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 449 | #define SHADOW_DELTA 0.1f |
| 450 | |
| 451 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 452 | void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawDisplayListOpPair>& zTranslatedNodes, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 453 | ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) { |
| 454 | const int size = zTranslatedNodes.size(); |
| 455 | if (size == 0 |
| 456 | || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f) |
| 457 | || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { |
| 458 | // no 3d children to draw |
| 459 | return; |
| 460 | } |
| 461 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 462 | /** |
| 463 | * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters |
| 464 | * with very similar Z heights to draw together. |
| 465 | * |
| 466 | * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are |
| 467 | * underneath both, and neither's shadow is drawn on top of the other. |
| 468 | */ |
| 469 | const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); |
| 470 | size_t drawIndex, shadowIndex, endIndex; |
| 471 | if (mode == kNegativeZChildren) { |
| 472 | drawIndex = 0; |
| 473 | endIndex = nonNegativeIndex; |
| 474 | shadowIndex = endIndex; // draw no shadows |
| 475 | } else { |
| 476 | drawIndex = nonNegativeIndex; |
| 477 | endIndex = size; |
| 478 | shadowIndex = drawIndex; // potentially draw shadow for each pos Z child |
| 479 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 480 | |
| 481 | DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "", |
| 482 | endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive"); |
| 483 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 484 | float lastCasterZ = 0.0f; |
| 485 | while (shadowIndex < endIndex || drawIndex < endIndex) { |
| 486 | if (shadowIndex < endIndex) { |
| 487 | DrawDisplayListOp* casterOp = zTranslatedNodes[shadowIndex].value; |
| 488 | RenderNode* caster = casterOp->mDisplayList; |
| 489 | const float casterZ = zTranslatedNodes[shadowIndex].key; |
| 490 | // attempt to render the shadow if the caster about to be drawn is its caster, |
| 491 | // OR if its caster's Z value is similar to the previous potential caster |
| 492 | if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) { |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 493 | caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 494 | |
| 495 | lastCasterZ = casterZ; // must do this even if current caster not casting a shadow |
| 496 | shadowIndex++; |
| 497 | continue; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // only the actual child DL draw needs to be in save/restore, |
| 502 | // since it modifies the renderer's matrix |
| 503 | int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); |
| 504 | |
| 505 | DrawDisplayListOp* childOp = zTranslatedNodes[drawIndex].value; |
| 506 | RenderNode* child = childOp->mDisplayList; |
| 507 | |
| 508 | renderer.concatMatrix(childOp->mTransformFromParent); |
| 509 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 510 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 511 | childOp->mSkipInOrderDraw = true; |
| 512 | |
| 513 | renderer.restoreToCount(restoreTo); |
| 514 | drawIndex++; |
| 515 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 519 | void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 520 | DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size()); |
| 521 | const SkPath* projectionReceiverOutline = properties().getOutline().getPath(); |
| 522 | bool maskProjecteesWithPath = projectionReceiverOutline != NULL |
| 523 | && !projectionReceiverOutline->isRect(NULL); |
| 524 | int restoreTo = renderer.getSaveCount(); |
| 525 | |
| 526 | // If the projection reciever has an outline, we mask each of the projected rendernodes to it |
| 527 | // Either with clipRect, or special saveLayer masking |
| 528 | LinearAllocator& alloc = handler.allocator(); |
| 529 | if (projectionReceiverOutline != NULL) { |
| 530 | const SkRect& outlineBounds = projectionReceiverOutline->getBounds(); |
| 531 | if (projectionReceiverOutline->isRect(NULL)) { |
| 532 | // mask to the rect outline simply with clipRect |
| 533 | handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
| 534 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 535 | ClipRectOp* clipOp = new (alloc) ClipRectOp( |
| 536 | outlineBounds.left(), outlineBounds.top(), |
| 537 | outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op); |
| 538 | handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 539 | } else { |
| 540 | // wrap the projected RenderNodes with a SaveLayer that will mask to the outline |
| 541 | SaveLayerOp* op = new (alloc) SaveLayerOp( |
| 542 | outlineBounds.left(), outlineBounds.top(), |
| 543 | outlineBounds.right(), outlineBounds.bottom(), |
| 544 | 255, SkCanvas::kARGB_ClipLayer_SaveFlag); |
| 545 | op->setMask(projectionReceiverOutline); |
| 546 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 547 | |
| 548 | /* TODO: add optimizations here to take advantage of placement/size of projected |
| 549 | * children (which may shrink saveLayer area significantly). This is dependent on |
| 550 | * passing actual drawing/dirtying bounds of projected content down to native. |
| 551 | */ |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // draw projected nodes |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 556 | for (size_t i = 0; i < mProjectedNodes.size(); i++) { |
| 557 | DrawDisplayListOp* childOp = mProjectedNodes[i]; |
| 558 | |
| 559 | // matrix save, concat, and restore can be done safely without allocating operations |
| 560 | int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); |
| 561 | renderer.concatMatrix(childOp->mTransformFromCompositingAncestor); |
| 562 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 563 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 564 | childOp->mSkipInOrderDraw = true; |
| 565 | renderer.restoreToCount(restoreTo); |
| 566 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 567 | |
| 568 | if (projectionReceiverOutline != NULL) { |
| 569 | handler(new (alloc) RestoreToCountOp(restoreTo), |
| 570 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 571 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** |
| 575 | * This function serves both defer and replay modes, and will organize the displayList's component |
| 576 | * operations for a single frame: |
| 577 | * |
| 578 | * Every 'simple' state operation that affects just the matrix and alpha (or other factors of |
| 579 | * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom |
| 580 | * defer logic) and operations in displayListOps are issued through the 'handler' which handles the |
| 581 | * defer vs replay logic, per operation |
| 582 | */ |
| 583 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 584 | void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { |
| 585 | const int level = handler.level(); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 586 | if (mDisplayListData->isEmpty() || properties().getAlpha() <= 0) { |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 587 | DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 588 | return; |
| 589 | } |
| 590 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 591 | handler.startMark(getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 592 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 593 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 594 | const Rect& clipRect = renderer.getLocalClipBounds(); |
| 595 | DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f", |
| 596 | level * 2, "", this, getName(), |
| 597 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 598 | #endif |
| 599 | |
| 600 | LinearAllocator& alloc = handler.allocator(); |
| 601 | int restoreTo = renderer.getSaveCount(); |
| 602 | handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 603 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 604 | |
| 605 | DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "", |
| 606 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo); |
| 607 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 608 | setViewProperties<T>(renderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 609 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 610 | bool quickRejected = properties().getClipToBounds() |
| 611 | && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 612 | if (!quickRejected) { |
| 613 | Vector<ZDrawDisplayListOpPair> zTranslatedNodes; |
| 614 | buildZSortedChildList(zTranslatedNodes); |
| 615 | |
| 616 | // for 3d root, draw children with negative z values |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 617 | issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 618 | |
| 619 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 620 | const int saveCountOffset = renderer.getSaveCount() - 1; |
| 621 | const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex; |
| 622 | for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { |
| 623 | DisplayListOp *op = mDisplayListData->displayListOps[i]; |
| 624 | |
| 625 | #if DEBUG_DISPLAY_LIST |
| 626 | op->output(level + 1); |
| 627 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 628 | logBuffer.writeCommand(level, op->name()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 629 | handler(op, saveCountOffset, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 630 | |
| 631 | if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) { |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 632 | issueOperationsOfProjectedChildren(renderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | // for 3d root, draw children with positive z values |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 637 | issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo); |
| 641 | handler(new (alloc) RestoreToCountOp(restoreTo), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 642 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 643 | renderer.setOverrideLayerAlpha(1.0f); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 644 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 645 | DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 646 | handler.endMark(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | } /* namespace uirenderer */ |
| 650 | } /* namespace android */ |