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 |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 18 | #define LOG_TAG "OpenGLRenderer" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 19 | |
| 20 | #include "RenderNode.h" |
| 21 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 22 | #include <algorithm> |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 23 | #include <string> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 24 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 25 | #include <SkCanvas.h> |
| 26 | #include <algorithm> |
| 27 | |
| 28 | #include <utils/Trace.h> |
| 29 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 30 | #include "DamageAccumulator.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 31 | #include "Debug.h" |
| 32 | #include "DisplayListOp.h" |
| 33 | #include "DisplayListLogBuffer.h" |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 34 | #include "LayerRenderer.h" |
| 35 | #include "OpenGLRenderer.h" |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 36 | #include "utils/MathUtils.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 37 | |
| 38 | namespace android { |
| 39 | namespace uirenderer { |
| 40 | |
| 41 | void RenderNode::outputLogBuffer(int fd) { |
| 42 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 43 | if (logBuffer.isEmpty()) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | FILE *file = fdopen(fd, "a"); |
| 48 | |
| 49 | fprintf(file, "\nRecent DisplayList operations\n"); |
| 50 | logBuffer.outputCommands(file); |
| 51 | |
| 52 | String8 cachesLog; |
| 53 | Caches::getInstance().dumpMemoryUsage(cachesLog); |
| 54 | fprintf(file, "\nCaches:\n%s", cachesLog.string()); |
| 55 | fprintf(file, "\n"); |
| 56 | |
| 57 | fflush(file); |
| 58 | } |
| 59 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 60 | RenderNode::RenderNode() |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 61 | : mDirtyPropertyFields(0) |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 62 | , mNeedsDisplayListDataSync(false) |
| 63 | , mDisplayListData(0) |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 64 | , mStagingDisplayListData(0) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 65 | , mAnimatorManager(*this) |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 66 | , mLayer(0) |
| 67 | , mParentCount(0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | RenderNode::~RenderNode() { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 71 | deleteDisplayListData(); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 72 | delete mStagingDisplayListData; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 73 | LayerRenderer::destroyLayerDeferred(mLayer); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 74 | } |
| 75 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 76 | void RenderNode::setStagingDisplayList(DisplayListData* data) { |
| 77 | mNeedsDisplayListDataSync = true; |
| 78 | delete mStagingDisplayListData; |
| 79 | mStagingDisplayListData = data; |
| 80 | if (mStagingDisplayListData) { |
John Reck | 09d5cdd | 2014-07-24 10:36:08 -0700 | [diff] [blame] | 81 | Caches::getInstance().registerFunctors(mStagingDisplayListData->functors.size()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 87 | * display list. This function should remain in sync with the replay() function. |
| 88 | */ |
| 89 | void RenderNode::output(uint32_t level) { |
| 90 | ALOGD("%*sStart display list (%p, %s, render=%d)", (level - 1) * 2, "", this, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 91 | getName(), isRenderable()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 92 | ALOGD("%*s%s %d", level * 2, "", "Save", |
| 93 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 94 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 95 | properties().debugOutputProperties(level); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 96 | int flags = DisplayListOp::kOpLogFlag_Recurse; |
John Reck | dc0349b | 2014-08-06 15:28:07 -0700 | [diff] [blame] | 97 | if (mDisplayListData) { |
| 98 | for (unsigned int i = 0; i < mDisplayListData->displayListOps.size(); i++) { |
| 99 | mDisplayListData->displayListOps[i]->output(level, flags); |
| 100 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 103 | ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 104 | } |
| 105 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 106 | int RenderNode::getDebugSize() { |
| 107 | int size = sizeof(RenderNode); |
| 108 | if (mStagingDisplayListData) { |
| 109 | size += mStagingDisplayListData->allocator.usedSize(); |
| 110 | } |
| 111 | if (mDisplayListData && mDisplayListData != mStagingDisplayListData) { |
| 112 | size += mDisplayListData->allocator.usedSize(); |
| 113 | } |
| 114 | return size; |
| 115 | } |
| 116 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 117 | void RenderNode::prepareTree(TreeInfo& info) { |
| 118 | ATRACE_CALL(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame^] | 119 | LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing"); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 120 | |
| 121 | prepareTreeImpl(info); |
| 122 | } |
| 123 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 124 | void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 125 | mAnimatorManager.addAnimator(animator); |
| 126 | } |
| 127 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 128 | void RenderNode::damageSelf(TreeInfo& info) { |
John Reck | ce9f308 | 2014-06-17 16:18:09 -0700 | [diff] [blame] | 129 | if (isRenderable()) { |
John Reck | 293e868 | 2014-06-17 10:34:02 -0700 | [diff] [blame] | 130 | if (properties().getClipDamageToBounds()) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 131 | info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight()); |
| 132 | } else { |
| 133 | // Hope this is big enough? |
| 134 | // TODO: Get this from the display list ops or something |
| 135 | info.damageAccumulator->dirty(INT_MIN, INT_MIN, INT_MAX, INT_MAX); |
| 136 | } |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 140 | void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 141 | LayerType layerType = properties().layerProperties().type(); |
| 142 | if (CC_UNLIKELY(layerType == kLayerTypeRenderLayer)) { |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 143 | // Damage applied so far needs to affect our parent, but does not require |
| 144 | // the layer to be updated. So we pop/push here to clear out the current |
| 145 | // damage and get a clean state for display list or children updates to |
| 146 | // affect, which will require the layer to be updated |
| 147 | info.damageAccumulator->popTransform(); |
| 148 | info.damageAccumulator->pushTransform(this); |
| 149 | if (dirtyMask & DISPLAY_LIST) { |
| 150 | damageSelf(info); |
| 151 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | void RenderNode::pushLayerUpdate(TreeInfo& info) { |
| 156 | LayerType layerType = properties().layerProperties().type(); |
| 157 | // If we are not a layer OR we cannot be rendered (eg, view was detached) |
| 158 | // we need to destroy any Layers we may have had previously |
| 159 | if (CC_LIKELY(layerType != kLayerTypeRenderLayer) || CC_UNLIKELY(!isRenderable())) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 160 | if (CC_UNLIKELY(mLayer)) { |
| 161 | LayerRenderer::destroyLayer(mLayer); |
| 162 | mLayer = NULL; |
| 163 | } |
| 164 | return; |
| 165 | } |
| 166 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame^] | 167 | bool transformUpdateNeeded = false; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 168 | if (!mLayer) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 169 | mLayer = LayerRenderer::createRenderLayer(info.renderState, getWidth(), getHeight()); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 170 | applyLayerPropertiesToLayer(info); |
| 171 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame^] | 172 | transformUpdateNeeded = true; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 173 | } else if (mLayer->layer.getWidth() != getWidth() || mLayer->layer.getHeight() != getHeight()) { |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 174 | if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) { |
| 175 | LayerRenderer::destroyLayer(mLayer); |
| 176 | mLayer = 0; |
| 177 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 178 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame^] | 179 | transformUpdateNeeded = true; |
| 180 | } |
| 181 | |
| 182 | if (transformUpdateNeeded) { |
| 183 | // update the transform in window of the layer to reset its origin wrt light source position |
| 184 | Matrix4 windowTransform; |
| 185 | info.damageAccumulator->computeCurrentTransform(&windowTransform); |
| 186 | mLayer->setWindowTransform(windowTransform); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | SkRect dirty; |
| 190 | info.damageAccumulator->peekAtDirty(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 191 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 192 | if (!mLayer) { |
| 193 | if (info.errorHandler) { |
| 194 | std::string msg = "Unable to create layer for "; |
| 195 | msg += getName(); |
| 196 | info.errorHandler->onError(msg); |
| 197 | } |
| 198 | return; |
| 199 | } |
| 200 | |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 201 | |
| 202 | if (dirty.intersect(0, 0, getWidth(), getHeight())) { |
| 203 | dirty.roundOut(); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 204 | mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom); |
| 205 | } |
| 206 | // This is not inside the above if because we may have called |
| 207 | // updateDeferred on a previous prepare pass that didn't have a renderer |
| 208 | if (info.renderer && mLayer->deferredUpdateScheduled) { |
| 209 | info.renderer->pushLayerUpdate(mLayer); |
| 210 | } |
| 211 | } |
| 212 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 213 | void RenderNode::prepareTreeImpl(TreeInfo& info) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 214 | info.damageAccumulator->pushTransform(this); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 215 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 216 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 217 | pushStagingPropertiesChanges(info); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 218 | } |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 219 | uint32_t animatorDirtyMask = mAnimatorManager.animate(info); |
| 220 | prepareLayer(info, animatorDirtyMask); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 221 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 222 | pushStagingDisplayListChanges(info); |
| 223 | } |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 224 | prepareSubTree(info, mDisplayListData); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 225 | pushLayerUpdate(info); |
| 226 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 227 | info.damageAccumulator->popTransform(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 228 | } |
| 229 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 230 | void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) { |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 231 | // Push the animators first so that setupStartValueIfNecessary() is called |
| 232 | // before properties() is trampled by stagingProperties(), as they are |
| 233 | // required by some animators. |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 234 | mAnimatorManager.pushStaging(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 235 | if (mDirtyPropertyFields) { |
| 236 | mDirtyPropertyFields = 0; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 237 | damageSelf(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 238 | info.damageAccumulator->popTransform(); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 239 | mProperties = mStagingProperties; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 240 | applyLayerPropertiesToLayer(info); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 241 | // We could try to be clever and only re-damage if the matrix changed. |
| 242 | // However, we don't need to worry about that. The cost of over-damaging |
| 243 | // here is only going to be a single additional map rect of this node |
| 244 | // plus a rect join(). The parent's transform (and up) will only be |
| 245 | // performed once. |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 246 | info.damageAccumulator->pushTransform(this); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 247 | damageSelf(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 248 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) { |
| 252 | if (CC_LIKELY(!mLayer)) return; |
| 253 | |
| 254 | const LayerProperties& props = properties().layerProperties(); |
| 255 | mLayer->setAlpha(props.alpha(), props.xferMode()); |
| 256 | mLayer->setColorFilter(props.colorFilter()); |
| 257 | mLayer->setBlend(props.needsBlending()); |
| 258 | } |
| 259 | |
| 260 | void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 261 | if (mNeedsDisplayListDataSync) { |
| 262 | mNeedsDisplayListDataSync = false; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 263 | // Make sure we inc first so that we don't fluctuate between 0 and 1, |
| 264 | // which would thrash the layer cache |
| 265 | if (mStagingDisplayListData) { |
| 266 | for (size_t i = 0; i < mStagingDisplayListData->children().size(); i++) { |
| 267 | mStagingDisplayListData->children()[i]->mRenderNode->incParentRefCount(); |
| 268 | } |
| 269 | } |
| 270 | deleteDisplayListData(); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 271 | mDisplayListData = mStagingDisplayListData; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 272 | mStagingDisplayListData = NULL; |
John Reck | 09d5cdd | 2014-07-24 10:36:08 -0700 | [diff] [blame] | 273 | if (mDisplayListData) { |
| 274 | for (size_t i = 0; i < mDisplayListData->functors.size(); i++) { |
| 275 | (*mDisplayListData->functors[i])(DrawGlInfo::kModeSync, NULL); |
| 276 | } |
| 277 | } |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 278 | damageSelf(info); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 279 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 280 | } |
| 281 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 282 | void RenderNode::deleteDisplayListData() { |
| 283 | if (mDisplayListData) { |
| 284 | for (size_t i = 0; i < mDisplayListData->children().size(); i++) { |
| 285 | mDisplayListData->children()[i]->mRenderNode->decParentRefCount(); |
| 286 | } |
| 287 | } |
| 288 | delete mDisplayListData; |
| 289 | mDisplayListData = NULL; |
| 290 | } |
| 291 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 292 | void RenderNode::prepareSubTree(TreeInfo& info, DisplayListData* subtree) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 293 | if (subtree) { |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 294 | TextureCache& cache = Caches::getInstance().textureCache; |
John Reck | 09d5cdd | 2014-07-24 10:36:08 -0700 | [diff] [blame] | 295 | info.out.hasFunctors |= subtree->functors.size(); |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 296 | // TODO: Fix ownedBitmapResources to not require disabling prepareTextures |
| 297 | // and thus falling out of async drawing path. |
| 298 | if (subtree->ownedBitmapResources.size()) { |
| 299 | info.prepareTextures = false; |
| 300 | } |
| 301 | for (size_t i = 0; info.prepareTextures && i < subtree->bitmapResources.size(); i++) { |
| 302 | info.prepareTextures = cache.prefetchAndMarkInUse(subtree->bitmapResources[i]); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 303 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 304 | for (size_t i = 0; i < subtree->children().size(); i++) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 305 | DrawRenderNodeOp* op = subtree->children()[i]; |
| 306 | RenderNode* childNode = op->mRenderNode; |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 307 | info.damageAccumulator->pushTransform(&op->mTransformFromParent); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 308 | childNode->prepareTreeImpl(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 309 | info.damageAccumulator->popTransform(); |
John Reck | 5bf11bb | 2014-03-25 10:22:09 -0700 | [diff] [blame] | 310 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 314 | void RenderNode::destroyHardwareResources() { |
| 315 | if (mLayer) { |
| 316 | LayerRenderer::destroyLayer(mLayer); |
| 317 | mLayer = NULL; |
| 318 | } |
| 319 | if (mDisplayListData) { |
| 320 | for (size_t i = 0; i < mDisplayListData->children().size(); i++) { |
| 321 | mDisplayListData->children()[i]->mRenderNode->destroyHardwareResources(); |
| 322 | } |
| 323 | if (mNeedsDisplayListDataSync) { |
| 324 | // Next prepare tree we are going to push a new display list, so we can |
| 325 | // drop our current one now |
| 326 | deleteDisplayListData(); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void RenderNode::decParentRefCount() { |
| 332 | LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!"); |
| 333 | mParentCount--; |
| 334 | if (!mParentCount) { |
| 335 | // If a child of ours is being attached to our parent then this will incorrectly |
| 336 | // destroy its hardware resources. However, this situation is highly unlikely |
| 337 | // and the failure is "just" that the layer is re-created, so this should |
| 338 | // be safe enough |
| 339 | destroyHardwareResources(); |
| 340 | } |
| 341 | } |
| 342 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 343 | /* |
| 344 | * For property operations, we pass a savecount of 0, since the operations aren't part of the |
| 345 | * 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] | 346 | * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount()) |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 347 | */ |
| 348 | #define PROPERTY_SAVECOUNT 0 |
| 349 | |
| 350 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 351 | void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 352 | #if DEBUG_DISPLAY_LIST |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 353 | properties().debugOutputProperties(handler.level() + 1); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 354 | #endif |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 355 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 356 | renderer.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 357 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 358 | if (properties().getStaticMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 359 | renderer.concatMatrix(*properties().getStaticMatrix()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 360 | } else if (properties().getAnimationMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 361 | renderer.concatMatrix(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 362 | } |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 363 | if (properties().hasTransformMatrix()) { |
| 364 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 365 | renderer.translate(properties().getTranslationX(), properties().getTranslationY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 366 | } else { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 367 | renderer.concatMatrix(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 370 | const bool isLayer = properties().layerProperties().type() != kLayerTypeNone; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 371 | int clipFlags = properties().getClippingFlags(); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 372 | if (properties().getAlpha() < 1) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 373 | if (isLayer) { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 374 | clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer |
| 375 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 376 | renderer.setOverrideLayerAlpha(properties().getAlpha()); |
| 377 | } else if (!properties().getHasOverlappingRendering()) { |
| 378 | renderer.scaleAlpha(properties().getAlpha()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 379 | } else { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 380 | Rect layerBounds(0, 0, getWidth(), getHeight()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 381 | int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 382 | if (clipFlags) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 383 | saveFlags |= SkCanvas::kClipToLayer_SaveFlag; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 384 | properties().getClippingRectForFlags(clipFlags, &layerBounds); |
| 385 | clipFlags = 0; // all clipping done by saveLayer |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 389 | layerBounds.left, layerBounds.top, layerBounds.right, layerBounds.bottom, |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 390 | properties().getAlpha() * 255, saveFlags); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 391 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 394 | if (clipFlags) { |
| 395 | Rect clipRect; |
| 396 | properties().getClippingRectForFlags(clipFlags, &clipRect); |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 397 | ClipRectOp* op = new (handler.allocator()) ClipRectOp( |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 398 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom, |
| 399 | SkRegion::kIntersect_Op); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 400 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 401 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 402 | |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 403 | // TODO: support both reveal clip and outline clip simultaneously |
| 404 | if (mProperties.getRevealClip().willClip()) { |
| 405 | Rect bounds; |
| 406 | mProperties.getRevealClip().getBounds(&bounds); |
| 407 | renderer.setClippingRoundRect(handler.allocator(), bounds, mProperties.getRevealClip().getRadius()); |
| 408 | } else if (mProperties.getOutline().willClip()) { |
| 409 | renderer.setClippingOutline(handler.allocator(), &(mProperties.getOutline())); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 410 | } |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 411 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Apply property-based transformations to input matrix |
| 416 | * |
| 417 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 418 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 419 | */ |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame^] | 420 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 421 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 422 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 423 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 424 | if (properties().getStaticMatrix()) { |
| 425 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 426 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 427 | } else if (properties().getAnimationMatrix()) { |
| 428 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 429 | matrix.multiply(anim); |
| 430 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 431 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 432 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 433 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 434 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 435 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 436 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 437 | } else { |
| 438 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 439 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 440 | } else { |
| 441 | mat4 true3dMat; |
| 442 | true3dMat.loadTranslate( |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 443 | properties().getPivotX() + properties().getTranslationX(), |
| 444 | properties().getPivotY() + properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 445 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 446 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 447 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 448 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 449 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 450 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 451 | |
| 452 | matrix.multiply(true3dMat); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Organizes the DisplayList hierarchy to prepare for background projection reordering. |
| 460 | * |
| 461 | * This should be called before a call to defer() or drawDisplayList() |
| 462 | * |
| 463 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 464 | * which are flagged to not draw in the standard draw loop. |
| 465 | */ |
| 466 | void RenderNode::computeOrdering() { |
| 467 | ATRACE_CALL(); |
| 468 | mProjectedNodes.clear(); |
| 469 | |
| 470 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 471 | // transform properties are applied correctly to top level children |
| 472 | if (mDisplayListData == NULL) return; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 473 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 474 | DrawRenderNodeOp* childOp = mDisplayListData->children()[i]; |
| 475 | childOp->mRenderNode->computeOrderingImpl(childOp, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 476 | properties().getOutline().getPath(), &mProjectedNodes, &mat4::identity()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
| 480 | void RenderNode::computeOrderingImpl( |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 481 | DrawRenderNodeOp* opState, |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 482 | const SkPath* outlineOfProjectionSurface, |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 483 | Vector<DrawRenderNodeOp*>* compositedChildrenOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 484 | const mat4* transformFromProjectionSurface) { |
| 485 | mProjectedNodes.clear(); |
| 486 | if (mDisplayListData == NULL || mDisplayListData->isEmpty()) return; |
| 487 | |
| 488 | // TODO: should avoid this calculation in most cases |
| 489 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 490 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
| 491 | localTransformFromProjectionSurface.multiply(opState->mTransformFromParent); |
| 492 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 493 | if (properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 494 | // composited projectee, flag for out of order draw, save matrix, and store in proj surface |
| 495 | opState->mSkipInOrderDraw = true; |
| 496 | opState->mTransformFromCompositingAncestor.load(localTransformFromProjectionSurface); |
| 497 | compositedChildrenOfProjectionSurface->add(opState); |
| 498 | } else { |
| 499 | // standard in order draw |
| 500 | opState->mSkipInOrderDraw = false; |
| 501 | } |
| 502 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 503 | if (mDisplayListData->children().size() > 0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 504 | const bool isProjectionReceiver = mDisplayListData->projectionReceiveIndex >= 0; |
| 505 | bool haveAppliedPropertiesToProjection = false; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 506 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 507 | DrawRenderNodeOp* childOp = mDisplayListData->children()[i]; |
| 508 | RenderNode* child = childOp->mRenderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 509 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 510 | const SkPath* projectionOutline = NULL; |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 511 | Vector<DrawRenderNodeOp*>* projectionChildren = NULL; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 512 | const mat4* projectionTransform = NULL; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 513 | if (isProjectionReceiver && !child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 514 | // if receiving projections, collect projecting descendent |
| 515 | |
| 516 | // Note that if a direct descendent is projecting backwards, we pass it's |
| 517 | // grandparent projection collection, since it shouldn't project onto it's |
| 518 | // parent, where it will already be drawing. |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 519 | projectionOutline = properties().getOutline().getPath(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 520 | projectionChildren = &mProjectedNodes; |
| 521 | projectionTransform = &mat4::identity(); |
| 522 | } else { |
| 523 | if (!haveAppliedPropertiesToProjection) { |
| 524 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 525 | haveAppliedPropertiesToProjection = true; |
| 526 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 527 | projectionOutline = outlineOfProjectionSurface; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 528 | projectionChildren = compositedChildrenOfProjectionSurface; |
| 529 | projectionTransform = &localTransformFromProjectionSurface; |
| 530 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 531 | child->computeOrderingImpl(childOp, |
| 532 | projectionOutline, projectionChildren, projectionTransform); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | class DeferOperationHandler { |
| 538 | public: |
| 539 | DeferOperationHandler(DeferStateStruct& deferStruct, int level) |
| 540 | : mDeferStruct(deferStruct), mLevel(level) {} |
| 541 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 542 | operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); |
| 543 | } |
| 544 | inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 545 | inline void startMark(const char* name) {} // do nothing |
| 546 | inline void endMark() {} |
| 547 | inline int level() { return mLevel; } |
| 548 | inline int replayFlags() { return mDeferStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 549 | inline SkPath* allocPathForFrame() { return mDeferStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 550 | |
| 551 | private: |
| 552 | DeferStateStruct& mDeferStruct; |
| 553 | const int mLevel; |
| 554 | }; |
| 555 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 556 | void RenderNode::defer(DeferStateStruct& deferStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 557 | DeferOperationHandler handler(deferStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 558 | issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | class ReplayOperationHandler { |
| 562 | public: |
| 563 | ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) |
| 564 | : mReplayStruct(replayStruct), mLevel(level) {} |
| 565 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 566 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 567 | mReplayStruct.mRenderer.eventMark(operation->name()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 568 | #endif |
| 569 | operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); |
| 570 | } |
| 571 | inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 572 | inline void startMark(const char* name) { |
| 573 | mReplayStruct.mRenderer.startMark(name); |
| 574 | } |
| 575 | inline void endMark() { |
| 576 | mReplayStruct.mRenderer.endMark(); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 577 | } |
| 578 | inline int level() { return mLevel; } |
| 579 | inline int replayFlags() { return mReplayStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 580 | inline SkPath* allocPathForFrame() { return mReplayStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 581 | |
| 582 | private: |
| 583 | ReplayStateStruct& mReplayStruct; |
| 584 | const int mLevel; |
| 585 | }; |
| 586 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 587 | void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 588 | ReplayOperationHandler handler(replayStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 589 | issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 592 | void RenderNode::buildZSortedChildList(Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) { |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 593 | if (mDisplayListData == NULL || mDisplayListData->children().size() == 0) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 594 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 595 | for (unsigned int i = 0; i < mDisplayListData->children().size(); i++) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 596 | DrawRenderNodeOp* childOp = mDisplayListData->children()[i]; |
| 597 | RenderNode* child = childOp->mRenderNode; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 598 | float childZ = child->properties().getZ(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 599 | |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 600 | if (!MathUtils::isZero(childZ)) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 601 | zTranslatedNodes.add(ZDrawRenderNodeOpPair(childZ, childOp)); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 602 | childOp->mSkipInOrderDraw = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 603 | } else if (!child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 604 | // regular, in order drawing DisplayList |
| 605 | childOp->mSkipInOrderDraw = false; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | // Z sort 3d children (stable-ness makes z compare fall back to standard drawing order) |
| 610 | std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end()); |
| 611 | } |
| 612 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 613 | template <class T> |
| 614 | void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 615 | if (properties().getAlpha() <= 0.0f |
| 616 | || properties().getOutline().getAlpha() <= 0.0f |
| 617 | || !properties().getOutline().getPath()) { |
| 618 | // no shadow to draw |
| 619 | return; |
| 620 | } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 621 | |
| 622 | mat4 shadowMatrixXY(transformFromParent); |
| 623 | applyViewPropertyTransforms(shadowMatrixXY); |
| 624 | |
| 625 | // Z matrix needs actual 3d transformation, so mapped z values will be correct |
| 626 | mat4 shadowMatrixZ(transformFromParent); |
| 627 | applyViewPropertyTransforms(shadowMatrixZ, true); |
| 628 | |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 629 | const SkPath* casterOutlinePath = properties().getOutline().getPath(); |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 630 | const SkPath* revealClipPath = properties().getRevealClip().getPath(); |
Chris Craik | 6131732 | 2014-05-21 13:03:52 -0700 | [diff] [blame] | 631 | if (revealClipPath && revealClipPath->isEmpty()) return; |
| 632 | |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 633 | float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha(); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 634 | |
| 635 | const SkPath* outlinePath = casterOutlinePath; |
| 636 | if (revealClipPath) { |
| 637 | // if we can't simply use the caster's path directly, create a temporary one |
| 638 | SkPath* frameAllocatedPath = handler.allocPathForFrame(); |
| 639 | |
| 640 | // intersect the outline with the convex reveal clip |
| 641 | Op(*casterOutlinePath, *revealClipPath, kIntersect_PathOp, frameAllocatedPath); |
| 642 | outlinePath = frameAllocatedPath; |
| 643 | } |
| 644 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 645 | DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp( |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 646 | shadowMatrixXY, shadowMatrixZ, casterAlpha, outlinePath); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 647 | handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 648 | } |
| 649 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 650 | template <class T> |
| 651 | int RenderNode::issueOperationsOfNegZChildren( |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 652 | const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes, |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 653 | OpenGLRenderer& renderer, T& handler) { |
| 654 | if (zTranslatedNodes.isEmpty()) return -1; |
| 655 | |
| 656 | // create a save around the body of the ViewGroup's draw method, so that |
| 657 | // matrix/clip methods don't affect composited children |
| 658 | int shadowSaveCount = renderer.getSaveCount(); |
| 659 | handler(new (handler.allocator()) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
| 660 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 661 | |
| 662 | issueOperationsOf3dChildren(zTranslatedNodes, kNegativeZChildren, renderer, handler); |
| 663 | return shadowSaveCount; |
| 664 | } |
| 665 | |
| 666 | template <class T> |
| 667 | void RenderNode::issueOperationsOfPosZChildren(int shadowRestoreTo, |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 668 | const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes, |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 669 | OpenGLRenderer& renderer, T& handler) { |
| 670 | if (zTranslatedNodes.isEmpty()) return; |
| 671 | |
| 672 | LOG_ALWAYS_FATAL_IF(shadowRestoreTo < 0, "invalid save to restore to"); |
| 673 | handler(new (handler.allocator()) RestoreToCountOp(shadowRestoreTo), |
| 674 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 675 | renderer.setOverrideLayerAlpha(1.0f); |
| 676 | |
| 677 | issueOperationsOf3dChildren(zTranslatedNodes, kPositiveZChildren, renderer, handler); |
| 678 | } |
| 679 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 680 | #define SHADOW_DELTA 0.1f |
| 681 | |
| 682 | template <class T> |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 683 | void RenderNode::issueOperationsOf3dChildren(const Vector<ZDrawRenderNodeOpPair>& zTranslatedNodes, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 684 | ChildrenSelectMode mode, OpenGLRenderer& renderer, T& handler) { |
| 685 | const int size = zTranslatedNodes.size(); |
| 686 | if (size == 0 |
| 687 | || (mode == kNegativeZChildren && zTranslatedNodes[0].key > 0.0f) |
| 688 | || (mode == kPositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { |
| 689 | // no 3d children to draw |
| 690 | return; |
| 691 | } |
| 692 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 693 | /** |
| 694 | * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters |
| 695 | * with very similar Z heights to draw together. |
| 696 | * |
| 697 | * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are |
| 698 | * underneath both, and neither's shadow is drawn on top of the other. |
| 699 | */ |
| 700 | const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); |
| 701 | size_t drawIndex, shadowIndex, endIndex; |
| 702 | if (mode == kNegativeZChildren) { |
| 703 | drawIndex = 0; |
| 704 | endIndex = nonNegativeIndex; |
| 705 | shadowIndex = endIndex; // draw no shadows |
| 706 | } else { |
| 707 | drawIndex = nonNegativeIndex; |
| 708 | endIndex = size; |
| 709 | shadowIndex = drawIndex; // potentially draw shadow for each pos Z child |
| 710 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 711 | |
| 712 | DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "", |
| 713 | endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive"); |
| 714 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 715 | float lastCasterZ = 0.0f; |
| 716 | while (shadowIndex < endIndex || drawIndex < endIndex) { |
| 717 | if (shadowIndex < endIndex) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 718 | DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value; |
| 719 | RenderNode* caster = casterOp->mRenderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 720 | const float casterZ = zTranslatedNodes[shadowIndex].key; |
| 721 | // attempt to render the shadow if the caster about to be drawn is its caster, |
| 722 | // OR if its caster's Z value is similar to the previous potential caster |
| 723 | if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) { |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 724 | caster->issueDrawShadowOperation(casterOp->mTransformFromParent, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 725 | |
| 726 | lastCasterZ = casterZ; // must do this even if current caster not casting a shadow |
| 727 | shadowIndex++; |
| 728 | continue; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | // only the actual child DL draw needs to be in save/restore, |
| 733 | // since it modifies the renderer's matrix |
| 734 | int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); |
| 735 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 736 | DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value; |
| 737 | RenderNode* child = childOp->mRenderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 738 | |
| 739 | renderer.concatMatrix(childOp->mTransformFromParent); |
| 740 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 741 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 742 | childOp->mSkipInOrderDraw = true; |
| 743 | |
| 744 | renderer.restoreToCount(restoreTo); |
| 745 | drawIndex++; |
| 746 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 750 | void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 751 | DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size()); |
| 752 | const SkPath* projectionReceiverOutline = properties().getOutline().getPath(); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 753 | int restoreTo = renderer.getSaveCount(); |
| 754 | |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 755 | LinearAllocator& alloc = handler.allocator(); |
| 756 | handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
| 757 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 758 | |
| 759 | // Transform renderer to match background we're projecting onto |
| 760 | // (by offsetting canvas by translationX/Y of background rendernode, since only those are set) |
| 761 | const DisplayListOp* op = |
| 762 | (mDisplayListData->displayListOps[mDisplayListData->projectionReceiveIndex]); |
| 763 | const DrawRenderNodeOp* backgroundOp = reinterpret_cast<const DrawRenderNodeOp*>(op); |
| 764 | const RenderProperties& backgroundProps = backgroundOp->mRenderNode->properties(); |
| 765 | renderer.translate(backgroundProps.getTranslationX(), backgroundProps.getTranslationY()); |
| 766 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 767 | // If the projection reciever has an outline, we mask each of the projected rendernodes to it |
| 768 | // Either with clipRect, or special saveLayer masking |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 769 | if (projectionReceiverOutline != NULL) { |
| 770 | const SkRect& outlineBounds = projectionReceiverOutline->getBounds(); |
| 771 | if (projectionReceiverOutline->isRect(NULL)) { |
| 772 | // mask to the rect outline simply with clipRect |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 773 | ClipRectOp* clipOp = new (alloc) ClipRectOp( |
| 774 | outlineBounds.left(), outlineBounds.top(), |
| 775 | outlineBounds.right(), outlineBounds.bottom(), SkRegion::kIntersect_Op); |
| 776 | handler(clipOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 777 | } else { |
| 778 | // wrap the projected RenderNodes with a SaveLayer that will mask to the outline |
| 779 | SaveLayerOp* op = new (alloc) SaveLayerOp( |
| 780 | outlineBounds.left(), outlineBounds.top(), |
| 781 | outlineBounds.right(), outlineBounds.bottom(), |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 782 | 255, SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag | SkCanvas::kARGB_ClipLayer_SaveFlag); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 783 | op->setMask(projectionReceiverOutline); |
| 784 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 785 | |
| 786 | /* TODO: add optimizations here to take advantage of placement/size of projected |
| 787 | * children (which may shrink saveLayer area significantly). This is dependent on |
| 788 | * passing actual drawing/dirtying bounds of projected content down to native. |
| 789 | */ |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | // draw projected nodes |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 794 | for (size_t i = 0; i < mProjectedNodes.size(); i++) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 795 | DrawRenderNodeOp* childOp = mProjectedNodes[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 796 | |
| 797 | // matrix save, concat, and restore can be done safely without allocating operations |
| 798 | int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag); |
| 799 | renderer.concatMatrix(childOp->mTransformFromCompositingAncestor); |
| 800 | childOp->mSkipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 801 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 802 | childOp->mSkipInOrderDraw = true; |
| 803 | renderer.restoreToCount(restoreTo); |
| 804 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 805 | |
| 806 | if (projectionReceiverOutline != NULL) { |
| 807 | handler(new (alloc) RestoreToCountOp(restoreTo), |
| 808 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 809 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /** |
| 813 | * This function serves both defer and replay modes, and will organize the displayList's component |
| 814 | * operations for a single frame: |
| 815 | * |
| 816 | * Every 'simple' state operation that affects just the matrix and alpha (or other factors of |
| 817 | * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom |
| 818 | * defer logic) and operations in displayListOps are issued through the 'handler' which handles the |
| 819 | * defer vs replay logic, per operation |
| 820 | */ |
| 821 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 822 | void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 823 | const int level = handler.level(); |
| 824 | if (mDisplayListData->isEmpty()) { |
| 825 | DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", level * 2, "", this, getName()); |
| 826 | return; |
| 827 | } |
| 828 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 829 | const bool drawLayer = (mLayer && (&renderer != mLayer->renderer)); |
| 830 | // If we are updating the contents of mLayer, we don't want to apply any of |
| 831 | // the RenderNode's properties to this issueOperations pass. Those will all |
| 832 | // be applied when the layer is drawn, aka when this is true. |
| 833 | const bool useViewProperties = (!mLayer || drawLayer); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 834 | if (useViewProperties) { |
| 835 | const Outline& outline = properties().getOutline(); |
| 836 | if (properties().getAlpha() <= 0 || (outline.getShouldClip() && outline.isEmpty())) { |
| 837 | DISPLAY_LIST_LOGD("%*sRejected display list (%p, %s)", level * 2, "", this, getName()); |
| 838 | return; |
| 839 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 842 | handler.startMark(getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 843 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 844 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 845 | const Rect& clipRect = renderer.getLocalClipBounds(); |
| 846 | DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f", |
| 847 | level * 2, "", this, getName(), |
| 848 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 849 | #endif |
| 850 | |
| 851 | LinearAllocator& alloc = handler.allocator(); |
| 852 | int restoreTo = renderer.getSaveCount(); |
| 853 | handler(new (alloc) SaveOp(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 854 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 855 | |
| 856 | DISPLAY_LIST_LOGD("%*sSave %d %d", (level + 1) * 2, "", |
| 857 | SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo); |
| 858 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 859 | if (useViewProperties) { |
| 860 | setViewProperties<T>(renderer, handler); |
| 861 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 862 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 863 | bool quickRejected = properties().getClipToBounds() |
| 864 | && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 865 | if (!quickRejected) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 866 | if (drawLayer) { |
| 867 | handler(new (alloc) DrawLayerOp(mLayer, 0, 0), |
| 868 | renderer.getSaveCount() - 1, properties().getClipToBounds()); |
| 869 | } else { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 870 | Vector<ZDrawRenderNodeOpPair> zTranslatedNodes; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 871 | buildZSortedChildList(zTranslatedNodes); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 872 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 873 | // for 3d root, draw children with negative z values |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 874 | int shadowRestoreTo = issueOperationsOfNegZChildren(zTranslatedNodes, renderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 875 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 876 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 877 | const int saveCountOffset = renderer.getSaveCount() - 1; |
| 878 | const int projectionReceiveIndex = mDisplayListData->projectionReceiveIndex; |
John Reck | 1aa5d2d | 2014-07-24 13:38:28 -0700 | [diff] [blame] | 879 | const int size = static_cast<int>(mDisplayListData->displayListOps.size()); |
| 880 | for (int i = 0; i < size; i++) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 881 | DisplayListOp *op = mDisplayListData->displayListOps[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 882 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 883 | #if DEBUG_DISPLAY_LIST |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 884 | op->output(level + 1); |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 885 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 886 | logBuffer.writeCommand(level, op->name()); |
| 887 | handler(op, saveCountOffset, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 888 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 889 | if (CC_UNLIKELY(i == projectionReceiveIndex && mProjectedNodes.size() > 0)) { |
| 890 | issueOperationsOfProjectedChildren(renderer, handler); |
| 891 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 892 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 893 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 894 | // for 3d root, draw children with positive z values |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 895 | issueOperationsOfPosZChildren(shadowRestoreTo, zTranslatedNodes, renderer, handler); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 896 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (level + 1) * 2, "", restoreTo); |
| 900 | handler(new (alloc) RestoreToCountOp(restoreTo), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 901 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 902 | renderer.setOverrideLayerAlpha(1.0f); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 903 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 904 | DISPLAY_LIST_LOGD("%*sDone (%p, %s)", level * 2, "", this, getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 905 | handler.endMark(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | } /* namespace uirenderer */ |
| 909 | } /* namespace android */ |