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