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