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