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 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 17 | #include "RenderNode.h" |
| 18 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 19 | #include "BakedOpRenderer.h" |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 20 | #include "DamageAccumulator.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 21 | #include "Debug.h" |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 22 | #include "OpDumper.h" |
| 23 | #include "RecordedOp.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 24 | #include "TreeInfo.h" |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 25 | #include "utils/MathUtils.h" |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 26 | #include "utils/StringUtils.h" |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 27 | #include "utils/TraceUtils.h" |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 28 | #include "VectorDrawable.h" |
| 29 | #include "renderstate/RenderState.h" |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 30 | #include "renderthread/CanvasContext.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 31 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 32 | #include "protos/hwui.pb.h" |
| 33 | #include "protos/ProtoHelpers.h" |
| 34 | |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 35 | #include <algorithm> |
| 36 | #include <sstream> |
| 37 | #include <string> |
| 38 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 39 | namespace android { |
| 40 | namespace uirenderer { |
| 41 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 42 | RenderNode::RenderNode() |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 43 | : mDirtyPropertyFields(0) |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 44 | , mNeedsDisplayListSync(false) |
| 45 | , mDisplayList(nullptr) |
| 46 | , mStagingDisplayList(nullptr) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 47 | , mAnimatorManager(*this) |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 48 | , mParentCount(0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | RenderNode::~RenderNode() { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 52 | deleteDisplayList(nullptr); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 53 | delete mStagingDisplayList; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 54 | LOG_ALWAYS_FATAL_IF(mLayer, "layer missed detachment!"); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 55 | } |
| 56 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 57 | void RenderNode::setStagingDisplayList(DisplayList* displayList, TreeObserver* observer) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 58 | mNeedsDisplayListSync = true; |
| 59 | delete mStagingDisplayList; |
| 60 | mStagingDisplayList = displayList; |
John Reck | 9dea0d5 | 2015-10-27 10:04:38 -0700 | [diff] [blame] | 61 | // If mParentCount == 0 we are the sole reference to this RenderNode, |
| 62 | // so immediately free the old display list |
| 63 | if (!mParentCount && !mStagingDisplayList) { |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 64 | deleteDisplayList(observer); |
John Reck | 9dea0d5 | 2015-10-27 10:04:38 -0700 | [diff] [blame] | 65 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 70 | * display list. This function should remain in sync with the replay() function. |
| 71 | */ |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 72 | void RenderNode::output() { |
| 73 | LogcatStream strout; |
| 74 | strout << "Root"; |
| 75 | output(strout, 0); |
| 76 | } |
| 77 | |
| 78 | void RenderNode::output(std::ostream& output, uint32_t level) { |
| 79 | output << " (" << getName() << " " << this |
| 80 | << (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : "") |
| 81 | << (properties().hasShadow() ? ", casting shadow" : "") |
| 82 | << (isRenderable() ? "" : ", empty") |
| 83 | << (properties().getProjectBackwards() ? ", projected" : "") |
| 84 | << (mLayer != nullptr ? ", on HW Layer" : "") |
| 85 | << ")" << std::endl; |
| 86 | |
| 87 | properties().debugOutputProperties(output, level + 1); |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 88 | |
| 89 | if (mDisplayList) { |
| 90 | for (auto&& op : mDisplayList->getOps()) { |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 91 | OpDumper::dump(*op, output, level + 1); |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 92 | if (op->opId == RecordedOpId::RenderNodeOp) { |
| 93 | auto rnOp = reinterpret_cast<const RenderNodeOp*>(op); |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 94 | rnOp->renderNode->output(output, level + 1); |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 95 | } else { |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 96 | output << std::endl; |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 100 | output << std::string(level * 2, ' ') << "/RenderNode(" << getName() << " " << this << ")"; |
| 101 | output << std::endl; |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 102 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 103 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 104 | void RenderNode::copyTo(proto::RenderNode *pnode) { |
| 105 | pnode->set_id(static_cast<uint64_t>( |
| 106 | reinterpret_cast<uintptr_t>(this))); |
| 107 | pnode->set_name(mName.string(), mName.length()); |
| 108 | |
| 109 | proto::RenderProperties* pprops = pnode->mutable_properties(); |
| 110 | pprops->set_left(properties().getLeft()); |
| 111 | pprops->set_top(properties().getTop()); |
| 112 | pprops->set_right(properties().getRight()); |
| 113 | pprops->set_bottom(properties().getBottom()); |
| 114 | pprops->set_clip_flags(properties().getClippingFlags()); |
| 115 | pprops->set_alpha(properties().getAlpha()); |
| 116 | pprops->set_translation_x(properties().getTranslationX()); |
| 117 | pprops->set_translation_y(properties().getTranslationY()); |
| 118 | pprops->set_translation_z(properties().getTranslationZ()); |
| 119 | pprops->set_elevation(properties().getElevation()); |
| 120 | pprops->set_rotation(properties().getRotation()); |
| 121 | pprops->set_rotation_x(properties().getRotationX()); |
| 122 | pprops->set_rotation_y(properties().getRotationY()); |
| 123 | pprops->set_scale_x(properties().getScaleX()); |
| 124 | pprops->set_scale_y(properties().getScaleY()); |
| 125 | pprops->set_pivot_x(properties().getPivotX()); |
| 126 | pprops->set_pivot_y(properties().getPivotY()); |
| 127 | pprops->set_has_overlapping_rendering(properties().getHasOverlappingRendering()); |
| 128 | pprops->set_pivot_explicitly_set(properties().isPivotExplicitlySet()); |
| 129 | pprops->set_project_backwards(properties().getProjectBackwards()); |
| 130 | pprops->set_projection_receiver(properties().isProjectionReceiver()); |
| 131 | set(pprops->mutable_clip_bounds(), properties().getClipBounds()); |
| 132 | |
| 133 | const Outline& outline = properties().getOutline(); |
| 134 | if (outline.getType() != Outline::Type::None) { |
| 135 | proto::Outline* poutline = pprops->mutable_outline(); |
| 136 | poutline->clear_path(); |
| 137 | if (outline.getType() == Outline::Type::Empty) { |
| 138 | poutline->set_type(proto::Outline_Type_Empty); |
| 139 | } else if (outline.getType() == Outline::Type::ConvexPath) { |
| 140 | poutline->set_type(proto::Outline_Type_ConvexPath); |
| 141 | if (const SkPath* path = outline.getPath()) { |
| 142 | set(poutline->mutable_path(), *path); |
| 143 | } |
| 144 | } else if (outline.getType() == Outline::Type::RoundRect) { |
| 145 | poutline->set_type(proto::Outline_Type_RoundRect); |
| 146 | } else { |
| 147 | ALOGW("Uknown outline type! %d", static_cast<int>(outline.getType())); |
| 148 | poutline->set_type(proto::Outline_Type_None); |
| 149 | } |
| 150 | poutline->set_should_clip(outline.getShouldClip()); |
| 151 | poutline->set_alpha(outline.getAlpha()); |
| 152 | poutline->set_radius(outline.getRadius()); |
| 153 | set(poutline->mutable_bounds(), outline.getBounds()); |
| 154 | } else { |
| 155 | pprops->clear_outline(); |
| 156 | } |
| 157 | |
| 158 | const RevealClip& revealClip = properties().getRevealClip(); |
| 159 | if (revealClip.willClip()) { |
| 160 | proto::RevealClip* prevealClip = pprops->mutable_reveal_clip(); |
| 161 | prevealClip->set_x(revealClip.getX()); |
| 162 | prevealClip->set_y(revealClip.getY()); |
| 163 | prevealClip->set_radius(revealClip.getRadius()); |
| 164 | } else { |
| 165 | pprops->clear_reveal_clip(); |
| 166 | } |
| 167 | |
| 168 | pnode->clear_children(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 169 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 170 | for (auto&& child : mDisplayList->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 171 | child->renderNode->copyTo(pnode->add_children()); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 176 | int RenderNode::getDebugSize() { |
| 177 | int size = sizeof(RenderNode); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 178 | if (mStagingDisplayList) { |
| 179 | size += mStagingDisplayList->getUsedSize(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 180 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 181 | if (mDisplayList && mDisplayList != mStagingDisplayList) { |
| 182 | size += mDisplayList->getUsedSize(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 183 | } |
| 184 | return size; |
| 185 | } |
| 186 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 187 | void RenderNode::prepareTree(TreeInfo& info) { |
| 188 | ATRACE_CALL(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 189 | LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing"); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 190 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 191 | // Functors don't correctly handle stencil usage of overdraw debugging - shove 'em in a layer. |
| 192 | bool functorsNeedLayer = Properties::debugOverdraw; |
| 193 | |
| 194 | prepareTreeImpl(info, functorsNeedLayer); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 195 | } |
| 196 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 197 | void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 198 | mAnimatorManager.addAnimator(animator); |
| 199 | } |
| 200 | |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 201 | void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 202 | mAnimatorManager.removeAnimator(animator); |
| 203 | } |
| 204 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 205 | void RenderNode::damageSelf(TreeInfo& info) { |
John Reck | ce9f308 | 2014-06-17 16:18:09 -0700 | [diff] [blame] | 206 | if (isRenderable()) { |
John Reck | 293e868 | 2014-06-17 10:34:02 -0700 | [diff] [blame] | 207 | if (properties().getClipDamageToBounds()) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 208 | info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight()); |
| 209 | } else { |
| 210 | // Hope this is big enough? |
| 211 | // TODO: Get this from the display list ops or something |
John Reck | c128823 | 2015-08-12 13:39:11 -0700 | [diff] [blame] | 212 | info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 213 | } |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 217 | void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) { |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 218 | LayerType layerType = properties().effectiveLayerType(); |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 219 | if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) { |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 220 | // Damage applied so far needs to affect our parent, but does not require |
| 221 | // the layer to be updated. So we pop/push here to clear out the current |
| 222 | // damage and get a clean state for display list or children updates to |
| 223 | // affect, which will require the layer to be updated |
| 224 | info.damageAccumulator->popTransform(); |
| 225 | info.damageAccumulator->pushTransform(this); |
| 226 | if (dirtyMask & DISPLAY_LIST) { |
| 227 | damageSelf(info); |
| 228 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 232 | static OffscreenBuffer* createLayer(RenderState& renderState, uint32_t width, uint32_t height) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 233 | return renderState.layerPool().get(renderState, width, height); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 236 | static void destroyLayer(OffscreenBuffer* layer) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 237 | RenderState& renderState = layer->renderState; |
| 238 | renderState.layerPool().putOrDelete(layer); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 241 | static bool layerMatchesWidthAndHeight(OffscreenBuffer* layer, int width, int height) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 242 | return layer->viewportWidth == (uint32_t) width && layer->viewportHeight == (uint32_t)height; |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 243 | } |
| 244 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 245 | void RenderNode::pushLayerUpdate(TreeInfo& info) { |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 246 | LayerType layerType = properties().effectiveLayerType(); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 247 | // If we are not a layer OR we cannot be rendered (eg, view was detached) |
| 248 | // we need to destroy any Layers we may have had previously |
Chris Craik | e3e481d | 2016-07-11 12:20:51 -0700 | [diff] [blame] | 249 | if (CC_LIKELY(layerType != LayerType::RenderLayer) |
| 250 | || CC_UNLIKELY(!isRenderable()) |
| 251 | || CC_UNLIKELY(properties().getWidth() == 0) |
| 252 | || CC_UNLIKELY(properties().getHeight() == 0)) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 253 | if (CC_UNLIKELY(mLayer)) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 254 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 255 | mLayer = nullptr; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 256 | } |
| 257 | return; |
| 258 | } |
| 259 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 260 | bool transformUpdateNeeded = false; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 261 | if (!mLayer) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 262 | mLayer = createLayer(info.canvasContext.getRenderState(), getWidth(), getHeight()); |
| 263 | damageSelf(info); |
| 264 | transformUpdateNeeded = true; |
| 265 | } else if (!layerMatchesWidthAndHeight(mLayer, getWidth(), getHeight())) { |
Chris Craik | d4fe4d3 | 2016-06-09 16:57:11 -0700 | [diff] [blame] | 266 | // TODO: remove now irrelevant, currently enqueued damage (respecting damage ordering) |
| 267 | // Or, ideally, maintain damage between frames on node/layer so ordering is always correct |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 268 | RenderState& renderState = mLayer->renderState; |
| 269 | if (properties().fitsOnLayer()) { |
| 270 | mLayer = renderState.layerPool().resize(mLayer, getWidth(), getHeight()); |
| 271 | } else { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 272 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 273 | mLayer = nullptr; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 274 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 275 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 276 | transformUpdateNeeded = true; |
| 277 | } |
| 278 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 279 | SkRect dirty; |
| 280 | info.damageAccumulator->peekAtDirty(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 281 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 282 | if (!mLayer) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 283 | Caches::getInstance().dumpMemoryUsage(); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 284 | if (info.errorHandler) { |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 285 | std::ostringstream err; |
| 286 | err << "Unable to create layer for " << getName(); |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 287 | const int maxTextureSize = Caches::getInstance().maxTextureSize; |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 288 | if (getWidth() > maxTextureSize || getHeight() > maxTextureSize) { |
| 289 | err << ", size " << getWidth() << "x" << getHeight() |
| 290 | << " exceeds max size " << maxTextureSize; |
| 291 | } else { |
| 292 | err << ", see logcat for more info"; |
| 293 | } |
| 294 | info.errorHandler->onError(err.str()); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 295 | } |
| 296 | return; |
| 297 | } |
| 298 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 299 | if (transformUpdateNeeded && mLayer) { |
Chris Craik | c71bfca | 2014-08-21 10:18:58 -0700 | [diff] [blame] | 300 | // update the transform in window of the layer to reset its origin wrt light source position |
| 301 | Matrix4 windowTransform; |
| 302 | info.damageAccumulator->computeCurrentTransform(&windowTransform); |
| 303 | mLayer->setWindowTransform(windowTransform); |
| 304 | } |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 305 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 306 | info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty); |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 307 | |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 308 | // There might be prefetched layers that need to be accounted for. |
| 309 | // That might be us, so tell CanvasContext that this layer is in the |
| 310 | // tree and should not be destroyed. |
| 311 | info.canvasContext.markLayerInUse(this); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 314 | /** |
| 315 | * Traverse down the the draw tree to prepare for a frame. |
| 316 | * |
| 317 | * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven |
| 318 | * |
| 319 | * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the |
| 320 | * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer. |
| 321 | */ |
| 322 | void RenderNode::prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 323 | info.damageAccumulator->pushTransform(this); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 324 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 325 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 326 | pushStagingPropertiesChanges(info); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 327 | } |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 328 | uint32_t animatorDirtyMask = 0; |
| 329 | if (CC_LIKELY(info.runAnimations)) { |
| 330 | animatorDirtyMask = mAnimatorManager.animate(info); |
| 331 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 332 | |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 333 | bool willHaveFunctor = false; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 334 | if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 335 | willHaveFunctor = !mStagingDisplayList->getFunctors().empty(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 336 | } else if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 337 | willHaveFunctor = !mDisplayList->getFunctors().empty(); |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 338 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 339 | bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence( |
| 340 | willHaveFunctor, functorsNeedLayer); |
| 341 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 342 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 343 | mPositionListener->onPositionUpdated(*this, info); |
| 344 | } |
| 345 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 346 | prepareLayer(info, animatorDirtyMask); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 347 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 348 | pushStagingDisplayListChanges(info); |
| 349 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 350 | prepareSubTree(info, childFunctorsNeedLayer, mDisplayList); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 351 | |
Doris Liu | 07c056d | 2016-06-13 12:52:44 -0700 | [diff] [blame] | 352 | if (mDisplayList) { |
| 353 | for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) { |
| 354 | // If any vector drawable in the display list needs update, damage the node. |
| 355 | if (vectorDrawable->isDirty()) { |
| 356 | damageSelf(info); |
| 357 | } |
| 358 | vectorDrawable->setPropertyChangeWillBeConsumed(true); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 359 | } |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 360 | } |
Doris Liu | b51b286 | 2016-08-01 19:56:47 -0700 | [diff] [blame] | 361 | pushLayerUpdate(info); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 362 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 363 | info.damageAccumulator->popTransform(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 366 | void RenderNode::syncProperties() { |
| 367 | mProperties = mStagingProperties; |
| 368 | } |
| 369 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 370 | void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) { |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 371 | // Push the animators first so that setupStartValueIfNecessary() is called |
| 372 | // before properties() is trampled by stagingProperties(), as they are |
| 373 | // required by some animators. |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 374 | if (CC_LIKELY(info.runAnimations)) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 375 | mAnimatorManager.pushStaging(); |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 376 | } |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 377 | if (mDirtyPropertyFields) { |
| 378 | mDirtyPropertyFields = 0; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 379 | damageSelf(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 380 | info.damageAccumulator->popTransform(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 381 | syncProperties(); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 382 | // We could try to be clever and only re-damage if the matrix changed. |
| 383 | // However, we don't need to worry about that. The cost of over-damaging |
| 384 | // here is only going to be a single additional map rect of this node |
| 385 | // plus a rect join(). The parent's transform (and up) will only be |
| 386 | // performed once. |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 387 | info.damageAccumulator->pushTransform(this); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 388 | damageSelf(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 389 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 390 | } |
| 391 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 392 | void RenderNode::syncDisplayList(TreeInfo* info) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 393 | // Make sure we inc first so that we don't fluctuate between 0 and 1, |
| 394 | // which would thrash the layer cache |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 395 | if (mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 396 | for (auto&& child : mStagingDisplayList->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 397 | child->renderNode->incParentRefCount(); |
| 398 | } |
| 399 | } |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 400 | deleteDisplayList(info ? info->observer : nullptr, info); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 401 | mDisplayList = mStagingDisplayList; |
| 402 | mStagingDisplayList = nullptr; |
| 403 | if (mDisplayList) { |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 404 | for (auto& iter : mDisplayList->getFunctors()) { |
| 405 | (*iter.functor)(DrawGlInfo::kModeSync, nullptr); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 406 | } |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 407 | for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) { |
| 408 | vectorDrawable->syncProperties(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 409 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 413 | void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 414 | if (mNeedsDisplayListSync) { |
| 415 | mNeedsDisplayListSync = false; |
John Reck | 5c9d717 | 2014-10-22 11:32:27 -0700 | [diff] [blame] | 416 | // Damage with the old display list first then the new one to catch any |
| 417 | // changes in isRenderable or, in the future, bounds |
| 418 | damageSelf(info); |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 419 | syncDisplayList(&info); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 420 | damageSelf(info); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 421 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 422 | } |
| 423 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 424 | void RenderNode::deleteDisplayList(TreeObserver* observer, TreeInfo* info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 425 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 426 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 427 | child->renderNode->decParentRefCount(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 430 | delete mDisplayList; |
| 431 | mDisplayList = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 434 | void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 435 | if (subtree) { |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 436 | TextureCache& cache = Caches::getInstance().textureCache; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 437 | info.out.hasFunctors |= subtree->getFunctors().size(); |
| 438 | for (auto&& bitmapResource : subtree->getBitmapResources()) { |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 439 | void* ownerToken = &info.canvasContext; |
| 440 | info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 441 | } |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 442 | for (auto&& op : subtree->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 443 | RenderNode* childNode = op->renderNode; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 444 | info.damageAccumulator->pushTransform(&op->localMatrix); |
| 445 | bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip; |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 446 | childNode->prepareTreeImpl(info, childFunctorsNeedLayer); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 447 | info.damageAccumulator->popTransform(); |
John Reck | 5bf11bb | 2014-03-25 10:22:09 -0700 | [diff] [blame] | 448 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 452 | void RenderNode::destroyHardwareResources(TreeObserver* observer, TreeInfo* info) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 453 | if (mLayer) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 454 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 455 | mLayer = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 456 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 457 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 458 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 459 | child->renderNode->destroyHardwareResources(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 460 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 461 | if (mNeedsDisplayListSync) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 462 | // Next prepare tree we are going to push a new display list, so we can |
| 463 | // drop our current one now |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 464 | deleteDisplayList(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 469 | void RenderNode::decParentRefCount(TreeObserver* observer, TreeInfo* info) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 470 | LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!"); |
| 471 | mParentCount--; |
| 472 | if (!mParentCount) { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 473 | if (observer) { |
| 474 | observer->onMaybeRemovedFromTree(this); |
| 475 | } |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 476 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 477 | mPositionListener->onPositionLost(*this, info); |
| 478 | } |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 479 | // If a child of ours is being attached to our parent then this will incorrectly |
| 480 | // destroy its hardware resources. However, this situation is highly unlikely |
| 481 | // and the failure is "just" that the layer is re-created, so this should |
| 482 | // be safe enough |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 483 | destroyHardwareResources(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 487 | /** |
| 488 | * Apply property-based transformations to input matrix |
| 489 | * |
| 490 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 491 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 492 | */ |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 493 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 494 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 495 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 496 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 497 | if (properties().getStaticMatrix()) { |
| 498 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 499 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 500 | } else if (properties().getAnimationMatrix()) { |
| 501 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 502 | matrix.multiply(anim); |
| 503 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 504 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 505 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 506 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 507 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 508 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 509 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 510 | } else { |
| 511 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 512 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 513 | } else { |
| 514 | mat4 true3dMat; |
| 515 | true3dMat.loadTranslate( |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 516 | properties().getPivotX() + properties().getTranslationX(), |
| 517 | properties().getPivotY() + properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 518 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 519 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 520 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 521 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 522 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 523 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 524 | |
| 525 | matrix.multiply(true3dMat); |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Organizes the DisplayList hierarchy to prepare for background projection reordering. |
| 533 | * |
| 534 | * This should be called before a call to defer() or drawDisplayList() |
| 535 | * |
| 536 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 537 | * which are flagged to not draw in the standard draw loop. |
| 538 | */ |
| 539 | void RenderNode::computeOrdering() { |
| 540 | ATRACE_CALL(); |
| 541 | mProjectedNodes.clear(); |
| 542 | |
| 543 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 544 | // transform properties are applied correctly to top level children |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 545 | if (mDisplayList == nullptr) return; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 546 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 547 | RenderNodeOp* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 548 | childOp->renderNode->computeOrderingImpl(childOp, &mProjectedNodes, &mat4::identity()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
| 552 | void RenderNode::computeOrderingImpl( |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 553 | RenderNodeOp* opState, |
| 554 | std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 555 | const mat4* transformFromProjectionSurface) { |
| 556 | mProjectedNodes.clear(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 557 | if (mDisplayList == nullptr || mDisplayList->isEmpty()) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 558 | |
| 559 | // TODO: should avoid this calculation in most cases |
| 560 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 561 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 562 | localTransformFromProjectionSurface.multiply(opState->localMatrix); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 563 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 564 | if (properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 565 | // composited projectee, flag for out of order draw, save matrix, and store in proj surface |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 566 | opState->skipInOrderDraw = true; |
| 567 | opState->transformFromCompositingAncestor = localTransformFromProjectionSurface; |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 568 | compositedChildrenOfProjectionSurface->push_back(opState); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 569 | } else { |
| 570 | // standard in order draw |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 571 | opState->skipInOrderDraw = false; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 574 | if (mDisplayList->getChildren().size() > 0) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 575 | const bool isProjectionReceiver = mDisplayList->projectionReceiveIndex >= 0; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 576 | bool haveAppliedPropertiesToProjection = false; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 577 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 578 | RenderNodeOp* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 579 | RenderNode* child = childOp->renderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 580 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 581 | std::vector<RenderNodeOp*>* projectionChildren = nullptr; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 582 | const mat4* projectionTransform = nullptr; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 583 | if (isProjectionReceiver && !child->properties().getProjectBackwards()) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 584 | // if receiving projections, collect projecting descendant |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 585 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 586 | // Note that if a direct descendant is projecting backwards, we pass its |
| 587 | // grandparent projection collection, since it shouldn't project onto its |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 588 | // parent, where it will already be drawing. |
| 589 | projectionChildren = &mProjectedNodes; |
| 590 | projectionTransform = &mat4::identity(); |
| 591 | } else { |
| 592 | if (!haveAppliedPropertiesToProjection) { |
| 593 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 594 | haveAppliedPropertiesToProjection = true; |
| 595 | } |
| 596 | projectionChildren = compositedChildrenOfProjectionSurface; |
| 597 | projectionTransform = &localTransformFromProjectionSurface; |
| 598 | } |
Derek Sollenberger | f293259 | 2015-08-13 14:59:33 -0400 | [diff] [blame] | 599 | child->computeOrderingImpl(childOp, projectionChildren, projectionTransform); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 602 | } |
| 603 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 604 | } /* namespace uirenderer */ |
| 605 | } /* namespace android */ |