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 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 19 | #include "DamageAccumulator.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 20 | #include "Debug.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 21 | #if HWUI_NEW_OPS |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 22 | #include "BakedOpRenderer.h" |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 23 | #include "RecordedOp.h" |
| 24 | #include "OpDumper.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 25 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 26 | #include "DisplayListOp.h" |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 27 | #include "LayerRenderer.h" |
| 28 | #include "OpenGLRenderer.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 29 | #include "TreeInfo.h" |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 30 | #include "utils/MathUtils.h" |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 31 | #include "utils/TraceUtils.h" |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 32 | #include "renderthread/CanvasContext.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 33 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 34 | #include "protos/hwui.pb.h" |
| 35 | #include "protos/ProtoHelpers.h" |
| 36 | |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | #include <sstream> |
| 39 | #include <string> |
| 40 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace uirenderer { |
| 43 | |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 44 | void RenderNode::debugDumpLayers(const char* prefix) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 45 | #if HWUI_NEW_OPS |
| 46 | LOG_ALWAYS_FATAL("TODO: dump layer"); |
| 47 | #else |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 48 | if (mLayer) { |
| 49 | ALOGD("%sNode %p (%s) has layer %p (fbo = %u, wasBuildLayered = %s)", |
| 50 | prefix, this, getName(), mLayer, mLayer->getFbo(), |
| 51 | mLayer->wasBuildLayered ? "true" : "false"); |
| 52 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 53 | #endif |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 54 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 55 | for (auto&& child : mDisplayList->getChildren()) { |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 56 | child->renderNode->debugDumpLayers(prefix); |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 61 | RenderNode::RenderNode() |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 62 | : mDirtyPropertyFields(0) |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 63 | , mNeedsDisplayListSync(false) |
| 64 | , mDisplayList(nullptr) |
| 65 | , mStagingDisplayList(nullptr) |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 66 | , mAnimatorManager(*this) |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 67 | , mParentCount(0) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | RenderNode::~RenderNode() { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 71 | deleteDisplayList(nullptr); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 72 | delete mStagingDisplayList; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 73 | #if HWUI_NEW_OPS |
| 74 | LOG_ALWAYS_FATAL_IF(mLayer, "layer missed detachment!"); |
| 75 | #else |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 76 | if (mLayer) { |
| 77 | ALOGW("Memory Warning: Layer %p missed its detachment, held on to for far too long!", mLayer); |
| 78 | mLayer->postDecStrong(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 79 | mLayer = nullptr; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 80 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 81 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 82 | } |
| 83 | |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 84 | void RenderNode::setStagingDisplayList(DisplayList* displayList, TreeObserver* observer) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 85 | mNeedsDisplayListSync = true; |
| 86 | delete mStagingDisplayList; |
| 87 | mStagingDisplayList = displayList; |
John Reck | 9dea0d5 | 2015-10-27 10:04:38 -0700 | [diff] [blame] | 88 | // If mParentCount == 0 we are the sole reference to this RenderNode, |
| 89 | // so immediately free the old display list |
| 90 | if (!mParentCount && !mStagingDisplayList) { |
John Reck | 51f2d60 | 2016-04-06 07:50:47 -0700 | [diff] [blame] | 91 | deleteDisplayList(observer); |
John Reck | 9dea0d5 | 2015-10-27 10:04:38 -0700 | [diff] [blame] | 92 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * This function is a simplified version of replay(), where we simply retrieve and log the |
| 97 | * display list. This function should remain in sync with the replay() function. |
| 98 | */ |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 99 | #if HWUI_NEW_OPS |
| 100 | void RenderNode::output(uint32_t level, const char* label) { |
| 101 | ALOGD("%s (%s %p%s%s%s%s%s)", |
| 102 | label, |
| 103 | getName(), |
| 104 | this, |
| 105 | (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : ""), |
| 106 | (properties().hasShadow() ? ", casting shadow" : ""), |
| 107 | (isRenderable() ? "" : ", empty"), |
| 108 | (properties().getProjectBackwards() ? ", projected" : ""), |
| 109 | (mLayer != nullptr ? ", on HW Layer" : "")); |
| 110 | properties().debugOutputProperties(level + 1); |
| 111 | |
| 112 | if (mDisplayList) { |
| 113 | for (auto&& op : mDisplayList->getOps()) { |
| 114 | std::stringstream strout; |
| 115 | OpDumper::dump(*op, strout, level + 1); |
| 116 | if (op->opId == RecordedOpId::RenderNodeOp) { |
| 117 | auto rnOp = reinterpret_cast<const RenderNodeOp*>(op); |
| 118 | rnOp->renderNode->output(level + 1, strout.str().c_str()); |
| 119 | } else { |
| 120 | ALOGD("%s", strout.str().c_str()); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | ALOGD("%*s/RenderNode(%s %p)", level * 2, "", getName(), this); |
| 125 | } |
| 126 | #else |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 127 | void RenderNode::output(uint32_t level) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 128 | ALOGD("%*sStart display list (%p, %s%s%s%s%s%s)", (level - 1) * 2, "", this, |
Chris Craik | b5a5435 | 2014-11-21 14:54:35 -0800 | [diff] [blame] | 129 | getName(), |
Chris Craik | 43a1d31 | 2015-05-27 11:28:14 -0700 | [diff] [blame] | 130 | (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : ""), |
Chris Craik | b5a5435 | 2014-11-21 14:54:35 -0800 | [diff] [blame] | 131 | (properties().hasShadow() ? ", casting shadow" : ""), |
| 132 | (isRenderable() ? "" : ", empty"), |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 133 | (properties().getProjectBackwards() ? ", projected" : ""), |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 134 | (mLayer != nullptr ? ", on HW Layer" : "")); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 135 | ALOGD("%*s%s %d", level * 2, "", "Save", SaveFlags::MatrixClip); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 136 | properties().debugOutputProperties(level); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 137 | if (mDisplayList) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 138 | // TODO: consider printing the chunk boundaries here |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 139 | for (auto&& op : mDisplayList->getOps()) { |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 140 | op->output(level, DisplayListOp::kOpLogFlag_Recurse); |
John Reck | dc0349b | 2014-08-06 15:28:07 -0700 | [diff] [blame] | 141 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 142 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 143 | ALOGD("%*sDone (%p, %s)", (level - 1) * 2, "", this, getName()); |
Chris Craik | 91eff22 | 2016-02-22 13:39:33 -0800 | [diff] [blame] | 144 | } |
| 145 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 146 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 147 | void RenderNode::copyTo(proto::RenderNode *pnode) { |
| 148 | pnode->set_id(static_cast<uint64_t>( |
| 149 | reinterpret_cast<uintptr_t>(this))); |
| 150 | pnode->set_name(mName.string(), mName.length()); |
| 151 | |
| 152 | proto::RenderProperties* pprops = pnode->mutable_properties(); |
| 153 | pprops->set_left(properties().getLeft()); |
| 154 | pprops->set_top(properties().getTop()); |
| 155 | pprops->set_right(properties().getRight()); |
| 156 | pprops->set_bottom(properties().getBottom()); |
| 157 | pprops->set_clip_flags(properties().getClippingFlags()); |
| 158 | pprops->set_alpha(properties().getAlpha()); |
| 159 | pprops->set_translation_x(properties().getTranslationX()); |
| 160 | pprops->set_translation_y(properties().getTranslationY()); |
| 161 | pprops->set_translation_z(properties().getTranslationZ()); |
| 162 | pprops->set_elevation(properties().getElevation()); |
| 163 | pprops->set_rotation(properties().getRotation()); |
| 164 | pprops->set_rotation_x(properties().getRotationX()); |
| 165 | pprops->set_rotation_y(properties().getRotationY()); |
| 166 | pprops->set_scale_x(properties().getScaleX()); |
| 167 | pprops->set_scale_y(properties().getScaleY()); |
| 168 | pprops->set_pivot_x(properties().getPivotX()); |
| 169 | pprops->set_pivot_y(properties().getPivotY()); |
| 170 | pprops->set_has_overlapping_rendering(properties().getHasOverlappingRendering()); |
| 171 | pprops->set_pivot_explicitly_set(properties().isPivotExplicitlySet()); |
| 172 | pprops->set_project_backwards(properties().getProjectBackwards()); |
| 173 | pprops->set_projection_receiver(properties().isProjectionReceiver()); |
| 174 | set(pprops->mutable_clip_bounds(), properties().getClipBounds()); |
| 175 | |
| 176 | const Outline& outline = properties().getOutline(); |
| 177 | if (outline.getType() != Outline::Type::None) { |
| 178 | proto::Outline* poutline = pprops->mutable_outline(); |
| 179 | poutline->clear_path(); |
| 180 | if (outline.getType() == Outline::Type::Empty) { |
| 181 | poutline->set_type(proto::Outline_Type_Empty); |
| 182 | } else if (outline.getType() == Outline::Type::ConvexPath) { |
| 183 | poutline->set_type(proto::Outline_Type_ConvexPath); |
| 184 | if (const SkPath* path = outline.getPath()) { |
| 185 | set(poutline->mutable_path(), *path); |
| 186 | } |
| 187 | } else if (outline.getType() == Outline::Type::RoundRect) { |
| 188 | poutline->set_type(proto::Outline_Type_RoundRect); |
| 189 | } else { |
| 190 | ALOGW("Uknown outline type! %d", static_cast<int>(outline.getType())); |
| 191 | poutline->set_type(proto::Outline_Type_None); |
| 192 | } |
| 193 | poutline->set_should_clip(outline.getShouldClip()); |
| 194 | poutline->set_alpha(outline.getAlpha()); |
| 195 | poutline->set_radius(outline.getRadius()); |
| 196 | set(poutline->mutable_bounds(), outline.getBounds()); |
| 197 | } else { |
| 198 | pprops->clear_outline(); |
| 199 | } |
| 200 | |
| 201 | const RevealClip& revealClip = properties().getRevealClip(); |
| 202 | if (revealClip.willClip()) { |
| 203 | proto::RevealClip* prevealClip = pprops->mutable_reveal_clip(); |
| 204 | prevealClip->set_x(revealClip.getX()); |
| 205 | prevealClip->set_y(revealClip.getY()); |
| 206 | prevealClip->set_radius(revealClip.getRadius()); |
| 207 | } else { |
| 208 | pprops->clear_reveal_clip(); |
| 209 | } |
| 210 | |
| 211 | pnode->clear_children(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 212 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 213 | for (auto&& child : mDisplayList->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 214 | child->renderNode->copyTo(pnode->add_children()); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 219 | int RenderNode::getDebugSize() { |
| 220 | int size = sizeof(RenderNode); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 221 | if (mStagingDisplayList) { |
| 222 | size += mStagingDisplayList->getUsedSize(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 223 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 224 | if (mDisplayList && mDisplayList != mStagingDisplayList) { |
| 225 | size += mDisplayList->getUsedSize(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 226 | } |
| 227 | return size; |
| 228 | } |
| 229 | |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 230 | void RenderNode::prepareTree(TreeInfo& info) { |
| 231 | ATRACE_CALL(); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 232 | LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing"); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 233 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 234 | // Functors don't correctly handle stencil usage of overdraw debugging - shove 'em in a layer. |
| 235 | bool functorsNeedLayer = Properties::debugOverdraw; |
| 236 | |
| 237 | prepareTreeImpl(info, functorsNeedLayer); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 238 | } |
| 239 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 240 | void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 241 | mAnimatorManager.addAnimator(animator); |
| 242 | } |
| 243 | |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 244 | void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) { |
| 245 | mAnimatorManager.removeAnimator(animator); |
| 246 | } |
| 247 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 248 | void RenderNode::damageSelf(TreeInfo& info) { |
John Reck | ce9f308 | 2014-06-17 16:18:09 -0700 | [diff] [blame] | 249 | if (isRenderable()) { |
John Reck | 293e868 | 2014-06-17 10:34:02 -0700 | [diff] [blame] | 250 | if (properties().getClipDamageToBounds()) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 251 | info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight()); |
| 252 | } else { |
| 253 | // Hope this is big enough? |
| 254 | // TODO: Get this from the display list ops or something |
John Reck | c128823 | 2015-08-12 13:39:11 -0700 | [diff] [blame] | 255 | info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 256 | } |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 260 | void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) { |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 261 | LayerType layerType = properties().effectiveLayerType(); |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 262 | if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) { |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 263 | // Damage applied so far needs to affect our parent, but does not require |
| 264 | // the layer to be updated. So we pop/push here to clear out the current |
| 265 | // damage and get a clean state for display list or children updates to |
| 266 | // affect, which will require the layer to be updated |
| 267 | info.damageAccumulator->popTransform(); |
| 268 | info.damageAccumulator->pushTransform(this); |
| 269 | if (dirtyMask & DISPLAY_LIST) { |
| 270 | damageSelf(info); |
| 271 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 275 | static layer_t* createLayer(RenderState& renderState, uint32_t width, uint32_t height) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 276 | #if HWUI_NEW_OPS |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 277 | return renderState.layerPool().get(renderState, width, height); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 278 | #else |
| 279 | return LayerRenderer::createRenderLayer(renderState, width, height); |
| 280 | #endif |
| 281 | } |
| 282 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 283 | static void destroyLayer(layer_t* layer) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 284 | #if HWUI_NEW_OPS |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 285 | RenderState& renderState = layer->renderState; |
| 286 | renderState.layerPool().putOrDelete(layer); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 287 | #else |
| 288 | LayerRenderer::destroyLayer(layer); |
| 289 | #endif |
| 290 | } |
| 291 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 292 | static bool layerMatchesWidthAndHeight(layer_t* layer, int width, int height) { |
| 293 | #if HWUI_NEW_OPS |
| 294 | return layer->viewportWidth == (uint32_t) width && layer->viewportHeight == (uint32_t)height; |
| 295 | #else |
| 296 | return layer->layer.getWidth() == width && layer->layer.getHeight() == height; |
| 297 | #endif |
| 298 | } |
| 299 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 300 | void RenderNode::pushLayerUpdate(TreeInfo& info) { |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 301 | LayerType layerType = properties().effectiveLayerType(); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 302 | // If we are not a layer OR we cannot be rendered (eg, view was detached) |
| 303 | // we need to destroy any Layers we may have had previously |
Chris Craik | e3e481d | 2016-07-11 12:20:51 -0700 | [diff] [blame] | 304 | if (CC_LIKELY(layerType != LayerType::RenderLayer) |
| 305 | || CC_UNLIKELY(!isRenderable()) |
| 306 | || CC_UNLIKELY(properties().getWidth() == 0) |
| 307 | || CC_UNLIKELY(properties().getHeight() == 0)) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 308 | if (CC_UNLIKELY(mLayer)) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 309 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 310 | mLayer = nullptr; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 311 | } |
| 312 | return; |
| 313 | } |
| 314 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 315 | bool transformUpdateNeeded = false; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 316 | if (!mLayer) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 317 | mLayer = createLayer(info.canvasContext.getRenderState(), getWidth(), getHeight()); |
Chris Craik | f559bd1 | 2015-11-18 14:42:00 -0800 | [diff] [blame] | 318 | #if !HWUI_NEW_OPS |
| 319 | applyLayerPropertiesToLayer(info); |
| 320 | #endif |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 321 | damageSelf(info); |
| 322 | transformUpdateNeeded = true; |
| 323 | } else if (!layerMatchesWidthAndHeight(mLayer, getWidth(), getHeight())) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 324 | #if HWUI_NEW_OPS |
Chris Craik | d4fe4d3 | 2016-06-09 16:57:11 -0700 | [diff] [blame] | 325 | // TODO: remove now irrelevant, currently enqueued damage (respecting damage ordering) |
| 326 | // 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] | 327 | RenderState& renderState = mLayer->renderState; |
| 328 | if (properties().fitsOnLayer()) { |
| 329 | mLayer = renderState.layerPool().resize(mLayer, getWidth(), getHeight()); |
| 330 | } else { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 331 | #else |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 332 | if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 333 | #endif |
| 334 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 335 | mLayer = nullptr; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 336 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 337 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 338 | transformUpdateNeeded = true; |
| 339 | } |
| 340 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 341 | SkRect dirty; |
| 342 | info.damageAccumulator->peekAtDirty(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 343 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 344 | if (!mLayer) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 345 | Caches::getInstance().dumpMemoryUsage(); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 346 | if (info.errorHandler) { |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 347 | std::ostringstream err; |
| 348 | err << "Unable to create layer for " << getName(); |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 349 | const int maxTextureSize = Caches::getInstance().maxTextureSize; |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 350 | if (getWidth() > maxTextureSize || getHeight() > maxTextureSize) { |
| 351 | err << ", size " << getWidth() << "x" << getHeight() |
| 352 | << " exceeds max size " << maxTextureSize; |
| 353 | } else { |
| 354 | err << ", see logcat for more info"; |
| 355 | } |
| 356 | info.errorHandler->onError(err.str()); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 357 | } |
| 358 | return; |
| 359 | } |
| 360 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 361 | if (transformUpdateNeeded && mLayer) { |
Chris Craik | c71bfca | 2014-08-21 10:18:58 -0700 | [diff] [blame] | 362 | // update the transform in window of the layer to reset its origin wrt light source position |
| 363 | Matrix4 windowTransform; |
| 364 | info.damageAccumulator->computeCurrentTransform(&windowTransform); |
| 365 | mLayer->setWindowTransform(windowTransform); |
| 366 | } |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 367 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 368 | #if HWUI_NEW_OPS |
| 369 | info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty); |
| 370 | #else |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 371 | if (dirty.intersect(0, 0, getWidth(), getHeight())) { |
Mike Reed | 71487eb | 2014-11-19 16:13:20 -0500 | [diff] [blame] | 372 | dirty.roundOut(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 373 | mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom); |
| 374 | } |
| 375 | // This is not inside the above if because we may have called |
| 376 | // updateDeferred on a previous prepare pass that didn't have a renderer |
| 377 | if (info.renderer && mLayer->deferredUpdateScheduled) { |
| 378 | info.renderer->pushLayerUpdate(mLayer); |
| 379 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 380 | #endif |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 381 | |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 382 | // There might be prefetched layers that need to be accounted for. |
| 383 | // That might be us, so tell CanvasContext that this layer is in the |
| 384 | // tree and should not be destroyed. |
| 385 | info.canvasContext.markLayerInUse(this); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 388 | /** |
| 389 | * Traverse down the the draw tree to prepare for a frame. |
| 390 | * |
| 391 | * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven |
| 392 | * |
| 393 | * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the |
| 394 | * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer. |
| 395 | */ |
| 396 | void RenderNode::prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 397 | info.damageAccumulator->pushTransform(this); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 398 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 399 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 400 | pushStagingPropertiesChanges(info); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 401 | } |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 402 | uint32_t animatorDirtyMask = 0; |
| 403 | if (CC_LIKELY(info.runAnimations)) { |
| 404 | animatorDirtyMask = mAnimatorManager.animate(info); |
| 405 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 406 | |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 407 | bool willHaveFunctor = false; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 408 | if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 409 | willHaveFunctor = !mStagingDisplayList->getFunctors().empty(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 410 | } else if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 411 | willHaveFunctor = !mDisplayList->getFunctors().empty(); |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 412 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 413 | bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence( |
| 414 | willHaveFunctor, functorsNeedLayer); |
| 415 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 416 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 417 | mPositionListener->onPositionUpdated(*this, info); |
| 418 | } |
| 419 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 420 | prepareLayer(info, animatorDirtyMask); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 421 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 422 | pushStagingDisplayListChanges(info); |
| 423 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 424 | prepareSubTree(info, childFunctorsNeedLayer, mDisplayList); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 425 | |
Doris Liu | 07c056d | 2016-06-13 12:52:44 -0700 | [diff] [blame] | 426 | if (mDisplayList) { |
| 427 | for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) { |
| 428 | // If any vector drawable in the display list needs update, damage the node. |
| 429 | if (vectorDrawable->isDirty()) { |
| 430 | damageSelf(info); |
| 431 | } |
| 432 | vectorDrawable->setPropertyChangeWillBeConsumed(true); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 433 | } |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 434 | } |
Doris Liu | b51b286 | 2016-08-01 19:56:47 -0700 | [diff] [blame] | 435 | pushLayerUpdate(info); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 436 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 437 | info.damageAccumulator->popTransform(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 440 | void RenderNode::syncProperties() { |
| 441 | mProperties = mStagingProperties; |
| 442 | } |
| 443 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 444 | void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) { |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 445 | // Push the animators first so that setupStartValueIfNecessary() is called |
| 446 | // before properties() is trampled by stagingProperties(), as they are |
| 447 | // required by some animators. |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 448 | if (CC_LIKELY(info.runAnimations)) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 449 | mAnimatorManager.pushStaging(); |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 450 | } |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 451 | if (mDirtyPropertyFields) { |
| 452 | mDirtyPropertyFields = 0; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 453 | damageSelf(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 454 | info.damageAccumulator->popTransform(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 455 | syncProperties(); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 456 | #if !HWUI_NEW_OPS |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 457 | applyLayerPropertiesToLayer(info); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 458 | #endif |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 459 | // We could try to be clever and only re-damage if the matrix changed. |
| 460 | // However, we don't need to worry about that. The cost of over-damaging |
| 461 | // here is only going to be a single additional map rect of this node |
| 462 | // plus a rect join(). The parent's transform (and up) will only be |
| 463 | // performed once. |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 464 | info.damageAccumulator->pushTransform(this); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 465 | damageSelf(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 466 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 469 | #if !HWUI_NEW_OPS |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 470 | void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 471 | if (CC_LIKELY(!mLayer)) return; |
| 472 | |
| 473 | const LayerProperties& props = properties().layerProperties(); |
| 474 | mLayer->setAlpha(props.alpha(), props.xferMode()); |
| 475 | mLayer->setColorFilter(props.colorFilter()); |
| 476 | mLayer->setBlend(props.needsBlending()); |
| 477 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 478 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 479 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 480 | void RenderNode::syncDisplayList(TreeInfo* info) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 481 | // Make sure we inc first so that we don't fluctuate between 0 and 1, |
| 482 | // which would thrash the layer cache |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 483 | if (mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 484 | for (auto&& child : mStagingDisplayList->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 485 | child->renderNode->incParentRefCount(); |
| 486 | } |
| 487 | } |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 488 | deleteDisplayList(info ? info->observer : nullptr, info); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 489 | mDisplayList = mStagingDisplayList; |
| 490 | mStagingDisplayList = nullptr; |
| 491 | if (mDisplayList) { |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 492 | for (auto& iter : mDisplayList->getFunctors()) { |
| 493 | (*iter.functor)(DrawGlInfo::kModeSync, nullptr); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 494 | } |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 495 | for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) { |
| 496 | vectorDrawable->syncProperties(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 497 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 501 | void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 502 | if (mNeedsDisplayListSync) { |
| 503 | mNeedsDisplayListSync = false; |
John Reck | 5c9d717 | 2014-10-22 11:32:27 -0700 | [diff] [blame] | 504 | // Damage with the old display list first then the new one to catch any |
| 505 | // changes in isRenderable or, in the future, bounds |
| 506 | damageSelf(info); |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 507 | syncDisplayList(&info); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 508 | damageSelf(info); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 509 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 510 | } |
| 511 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 512 | void RenderNode::deleteDisplayList(TreeObserver* observer, TreeInfo* info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 513 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 514 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 515 | child->renderNode->decParentRefCount(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 516 | } |
| 517 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 518 | delete mDisplayList; |
| 519 | mDisplayList = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 522 | void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 523 | if (subtree) { |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 524 | TextureCache& cache = Caches::getInstance().textureCache; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 525 | info.out.hasFunctors |= subtree->getFunctors().size(); |
| 526 | for (auto&& bitmapResource : subtree->getBitmapResources()) { |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 527 | void* ownerToken = &info.canvasContext; |
| 528 | info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 529 | } |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 530 | for (auto&& op : subtree->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 531 | RenderNode* childNode = op->renderNode; |
| 532 | #if HWUI_NEW_OPS |
| 533 | info.damageAccumulator->pushTransform(&op->localMatrix); |
| 534 | bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip; |
| 535 | #else |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 536 | info.damageAccumulator->pushTransform(&op->localMatrix); |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 537 | bool childFunctorsNeedLayer = functorsNeedLayer |
| 538 | // Recorded with non-rect clip, or canvas-rotated by parent |
| 539 | || op->mRecordedWithPotentialStencilClip; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 540 | #endif |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 541 | childNode->prepareTreeImpl(info, childFunctorsNeedLayer); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 542 | info.damageAccumulator->popTransform(); |
John Reck | 5bf11bb | 2014-03-25 10:22:09 -0700 | [diff] [blame] | 543 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 547 | void RenderNode::destroyHardwareResources(TreeObserver* observer, TreeInfo* info) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 548 | if (mLayer) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 549 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 550 | mLayer = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 551 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 552 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 553 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 554 | child->renderNode->destroyHardwareResources(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 555 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 556 | if (mNeedsDisplayListSync) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 557 | // Next prepare tree we are going to push a new display list, so we can |
| 558 | // drop our current one now |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 559 | deleteDisplayList(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 564 | void RenderNode::decParentRefCount(TreeObserver* observer, TreeInfo* info) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 565 | LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!"); |
| 566 | mParentCount--; |
| 567 | if (!mParentCount) { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 568 | if (observer) { |
| 569 | observer->onMaybeRemovedFromTree(this); |
| 570 | } |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 571 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 572 | mPositionListener->onPositionLost(*this, info); |
| 573 | } |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 574 | // If a child of ours is being attached to our parent then this will incorrectly |
| 575 | // destroy its hardware resources. However, this situation is highly unlikely |
| 576 | // and the failure is "just" that the layer is re-created, so this should |
| 577 | // be safe enough |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 578 | destroyHardwareResources(observer, info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 582 | /* |
| 583 | * For property operations, we pass a savecount of 0, since the operations aren't part of the |
| 584 | * 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] | 585 | * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount()) |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 586 | */ |
| 587 | #define PROPERTY_SAVECOUNT 0 |
| 588 | |
| 589 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 590 | void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 591 | #if DEBUG_DISPLAY_LIST |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 592 | properties().debugOutputProperties(handler.level() + 1); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 593 | #endif |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 594 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 595 | renderer.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 596 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 597 | if (properties().getStaticMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 598 | renderer.concatMatrix(*properties().getStaticMatrix()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 599 | } else if (properties().getAnimationMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 600 | renderer.concatMatrix(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 601 | } |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 602 | if (properties().hasTransformMatrix()) { |
| 603 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 604 | renderer.translate(properties().getTranslationX(), properties().getTranslationY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 605 | } else { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 606 | renderer.concatMatrix(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 609 | const bool isLayer = properties().effectiveLayerType() != LayerType::None; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 610 | int clipFlags = properties().getClippingFlags(); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 611 | if (properties().getAlpha() < 1) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 612 | if (isLayer) { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 613 | clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 614 | } |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 615 | if (CC_LIKELY(isLayer || !properties().getHasOverlappingRendering())) { |
| 616 | // simply scale rendering content's alpha |
| 617 | renderer.scaleAlpha(properties().getAlpha()); |
| 618 | } else { |
| 619 | // savelayer needed to create an offscreen buffer |
| 620 | Rect layerBounds(0, 0, getWidth(), getHeight()); |
| 621 | if (clipFlags) { |
| 622 | properties().getClippingRectForFlags(clipFlags, &layerBounds); |
| 623 | clipFlags = 0; // all clipping done by savelayer |
| 624 | } |
| 625 | SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( |
| 626 | layerBounds.left, layerBounds.top, |
| 627 | layerBounds.right, layerBounds.bottom, |
| 628 | (int) (properties().getAlpha() * 255), |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 629 | SaveFlags::HasAlphaLayer | SaveFlags::ClipToLayer); |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 630 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 631 | } |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 632 | |
| 633 | if (CC_UNLIKELY(ATRACE_ENABLED() && properties().promotedToLayer())) { |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 634 | // pretend alpha always causes savelayer to warn about |
| 635 | // performance problem affecting old versions |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 636 | ATRACE_FORMAT("%s alpha caused saveLayer %dx%d", getName(), |
| 637 | static_cast<int>(getWidth()), |
| 638 | static_cast<int>(getHeight())); |
| 639 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 640 | } |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 641 | if (clipFlags) { |
| 642 | Rect clipRect; |
| 643 | properties().getClippingRectForFlags(clipFlags, &clipRect); |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 644 | ClipRectOp* op = new (handler.allocator()) ClipRectOp( |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 645 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom, |
| 646 | SkRegion::kIntersect_Op); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 647 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 648 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 649 | |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 650 | // TODO: support nesting round rect clips |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 651 | if (mProperties.getRevealClip().willClip()) { |
| 652 | Rect bounds; |
| 653 | mProperties.getRevealClip().getBounds(&bounds); |
| 654 | renderer.setClippingRoundRect(handler.allocator(), bounds, mProperties.getRevealClip().getRadius()); |
| 655 | } else if (mProperties.getOutline().willClip()) { |
| 656 | renderer.setClippingOutline(handler.allocator(), &(mProperties.getOutline())); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Apply property-based transformations to input matrix |
| 662 | * |
| 663 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 664 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 665 | */ |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 666 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 667 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 668 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 669 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 670 | if (properties().getStaticMatrix()) { |
| 671 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 672 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 673 | } else if (properties().getAnimationMatrix()) { |
| 674 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 675 | matrix.multiply(anim); |
| 676 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 677 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 678 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 679 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 680 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 681 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 682 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 683 | } else { |
| 684 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 685 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 686 | } else { |
| 687 | mat4 true3dMat; |
| 688 | true3dMat.loadTranslate( |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 689 | properties().getPivotX() + properties().getTranslationX(), |
| 690 | properties().getPivotY() + properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 691 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 692 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 693 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 694 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 695 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 696 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 697 | |
| 698 | matrix.multiply(true3dMat); |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Organizes the DisplayList hierarchy to prepare for background projection reordering. |
| 706 | * |
| 707 | * This should be called before a call to defer() or drawDisplayList() |
| 708 | * |
| 709 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 710 | * which are flagged to not draw in the standard draw loop. |
| 711 | */ |
| 712 | void RenderNode::computeOrdering() { |
| 713 | ATRACE_CALL(); |
| 714 | mProjectedNodes.clear(); |
| 715 | |
| 716 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 717 | // transform properties are applied correctly to top level children |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 718 | if (mDisplayList == nullptr) return; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 719 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 720 | renderNodeOp_t* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 721 | childOp->renderNode->computeOrderingImpl(childOp, &mProjectedNodes, &mat4::identity()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
| 725 | void RenderNode::computeOrderingImpl( |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 726 | renderNodeOp_t* opState, |
| 727 | std::vector<renderNodeOp_t*>* compositedChildrenOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 728 | const mat4* transformFromProjectionSurface) { |
| 729 | mProjectedNodes.clear(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 730 | if (mDisplayList == nullptr || mDisplayList->isEmpty()) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 731 | |
| 732 | // TODO: should avoid this calculation in most cases |
| 733 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 734 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 735 | localTransformFromProjectionSurface.multiply(opState->localMatrix); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 736 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 737 | if (properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 738 | // 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] | 739 | opState->skipInOrderDraw = true; |
| 740 | opState->transformFromCompositingAncestor = localTransformFromProjectionSurface; |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 741 | compositedChildrenOfProjectionSurface->push_back(opState); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 742 | } else { |
| 743 | // standard in order draw |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 744 | opState->skipInOrderDraw = false; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 747 | if (mDisplayList->getChildren().size() > 0) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 748 | const bool isProjectionReceiver = mDisplayList->projectionReceiveIndex >= 0; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 749 | bool haveAppliedPropertiesToProjection = false; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 750 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 751 | renderNodeOp_t* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 752 | RenderNode* child = childOp->renderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 753 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 754 | std::vector<renderNodeOp_t*>* projectionChildren = nullptr; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 755 | const mat4* projectionTransform = nullptr; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 756 | if (isProjectionReceiver && !child->properties().getProjectBackwards()) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 757 | // if receiving projections, collect projecting descendant |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 758 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 759 | // Note that if a direct descendant is projecting backwards, we pass its |
| 760 | // grandparent projection collection, since it shouldn't project onto its |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 761 | // parent, where it will already be drawing. |
| 762 | projectionChildren = &mProjectedNodes; |
| 763 | projectionTransform = &mat4::identity(); |
| 764 | } else { |
| 765 | if (!haveAppliedPropertiesToProjection) { |
| 766 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 767 | haveAppliedPropertiesToProjection = true; |
| 768 | } |
| 769 | projectionChildren = compositedChildrenOfProjectionSurface; |
| 770 | projectionTransform = &localTransformFromProjectionSurface; |
| 771 | } |
Derek Sollenberger | f293259 | 2015-08-13 14:59:33 -0400 | [diff] [blame] | 772 | child->computeOrderingImpl(childOp, projectionChildren, projectionTransform); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | class DeferOperationHandler { |
| 778 | public: |
| 779 | DeferOperationHandler(DeferStateStruct& deferStruct, int level) |
| 780 | : mDeferStruct(deferStruct), mLevel(level) {} |
| 781 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 782 | operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); |
| 783 | } |
| 784 | inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 785 | inline void startMark(const char* name) {} // do nothing |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 786 | inline void endMark() {} |
| 787 | inline int level() { return mLevel; } |
| 788 | inline int replayFlags() { return mDeferStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 789 | inline SkPath* allocPathForFrame() { return mDeferStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 790 | |
| 791 | private: |
| 792 | DeferStateStruct& mDeferStruct; |
| 793 | const int mLevel; |
| 794 | }; |
| 795 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 796 | void RenderNode::defer(DeferStateStruct& deferStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 797 | DeferOperationHandler handler(deferStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 798 | issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | class ReplayOperationHandler { |
| 802 | public: |
| 803 | ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) |
| 804 | : mReplayStruct(replayStruct), mLevel(level) {} |
| 805 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 806 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 807 | mReplayStruct.mRenderer.eventMark(operation->name()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 808 | #endif |
| 809 | operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); |
| 810 | } |
| 811 | inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 812 | inline void startMark(const char* name) { |
| 813 | mReplayStruct.mRenderer.startMark(name); |
| 814 | } |
| 815 | inline void endMark() { |
| 816 | mReplayStruct.mRenderer.endMark(); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 817 | } |
| 818 | inline int level() { return mLevel; } |
| 819 | inline int replayFlags() { return mReplayStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 820 | inline SkPath* allocPathForFrame() { return mReplayStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 821 | |
| 822 | private: |
| 823 | ReplayStateStruct& mReplayStruct; |
| 824 | const int mLevel; |
| 825 | }; |
| 826 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 827 | void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 828 | ReplayOperationHandler handler(replayStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 829 | issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 832 | void RenderNode::buildZSortedChildList(const DisplayList::Chunk& chunk, |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 833 | std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 834 | #if !HWUI_NEW_OPS |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 835 | if (chunk.beginChildIndex == chunk.endChildIndex) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 836 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 837 | for (unsigned int i = chunk.beginChildIndex; i < chunk.endChildIndex; i++) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 838 | DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 839 | RenderNode* child = childOp->renderNode; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 840 | float childZ = child->properties().getZ(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 841 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 842 | if (!MathUtils::isZero(childZ) && chunk.reorderChildren) { |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 843 | zTranslatedNodes.push_back(ZDrawRenderNodeOpPair(childZ, childOp)); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 844 | childOp->skipInOrderDraw = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 845 | } else if (!child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 846 | // regular, in order drawing DisplayList |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 847 | childOp->skipInOrderDraw = false; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 851 | // 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] | 852 | std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end()); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 853 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 856 | template <class T> |
| 857 | void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 858 | if (properties().getAlpha() <= 0.0f |
| 859 | || properties().getOutline().getAlpha() <= 0.0f |
Teng-Hui Zhu | 8d0ec38 | 2015-10-01 16:49:16 -0700 | [diff] [blame] | 860 | || !properties().getOutline().getPath() |
| 861 | || properties().getScaleX() == 0 |
| 862 | || properties().getScaleY() == 0) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 863 | // no shadow to draw |
| 864 | return; |
| 865 | } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 866 | |
| 867 | mat4 shadowMatrixXY(transformFromParent); |
| 868 | applyViewPropertyTransforms(shadowMatrixXY); |
| 869 | |
| 870 | // Z matrix needs actual 3d transformation, so mapped z values will be correct |
| 871 | mat4 shadowMatrixZ(transformFromParent); |
| 872 | applyViewPropertyTransforms(shadowMatrixZ, true); |
| 873 | |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 874 | const SkPath* casterOutlinePath = properties().getOutline().getPath(); |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 875 | const SkPath* revealClipPath = properties().getRevealClip().getPath(); |
Chris Craik | 6131732 | 2014-05-21 13:03:52 -0700 | [diff] [blame] | 876 | if (revealClipPath && revealClipPath->isEmpty()) return; |
| 877 | |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 878 | float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha(); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 879 | |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 880 | |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 881 | // holds temporary SkPath to store the result of intersections |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 882 | SkPath* frameAllocatedPath = nullptr; |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 883 | const SkPath* outlinePath = casterOutlinePath; |
| 884 | |
| 885 | // intersect the outline with the reveal clip, if present |
| 886 | if (revealClipPath) { |
| 887 | frameAllocatedPath = handler.allocPathForFrame(); |
| 888 | |
Tom Hudson | 02a2630 | 2015-06-24 11:32:42 -0400 | [diff] [blame] | 889 | Op(*outlinePath, *revealClipPath, kIntersect_SkPathOp, frameAllocatedPath); |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 890 | outlinePath = frameAllocatedPath; |
| 891 | } |
| 892 | |
| 893 | // intersect the outline with the clipBounds, if present |
| 894 | if (properties().getClippingFlags() & CLIP_TO_CLIP_BOUNDS) { |
| 895 | if (!frameAllocatedPath) { |
| 896 | frameAllocatedPath = handler.allocPathForFrame(); |
| 897 | } |
| 898 | |
| 899 | Rect clipBounds; |
| 900 | properties().getClippingRectForFlags(CLIP_TO_CLIP_BOUNDS, &clipBounds); |
| 901 | SkPath clipBoundsPath; |
| 902 | clipBoundsPath.addRect(clipBounds.left, clipBounds.top, |
| 903 | clipBounds.right, clipBounds.bottom); |
| 904 | |
Tom Hudson | 02a2630 | 2015-06-24 11:32:42 -0400 | [diff] [blame] | 905 | Op(*outlinePath, clipBoundsPath, kIntersect_SkPathOp, frameAllocatedPath); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 906 | outlinePath = frameAllocatedPath; |
| 907 | } |
| 908 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 909 | DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp( |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 910 | shadowMatrixXY, shadowMatrixZ, casterAlpha, outlinePath); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 911 | handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 912 | } |
| 913 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 914 | #define SHADOW_DELTA 0.1f |
| 915 | |
| 916 | template <class T> |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 917 | void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode, |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 918 | const Matrix4& initialTransform, const std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 919 | OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 920 | const int size = zTranslatedNodes.size(); |
| 921 | if (size == 0 |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 922 | || (mode == ChildrenSelectMode::NegativeZChildren && zTranslatedNodes[0].key > 0.0f) |
| 923 | || (mode == ChildrenSelectMode::PositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 924 | // no 3d children to draw |
| 925 | return; |
| 926 | } |
| 927 | |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 928 | // Apply the base transform of the parent of the 3d children. This isolates |
| 929 | // 3d children of the current chunk from transformations made in previous chunks. |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 930 | int rootRestoreTo = renderer.save(SaveFlags::Matrix); |
Chris Craik | 6daa13c | 2015-08-19 13:32:12 -0700 | [diff] [blame] | 931 | renderer.setGlobalMatrix(initialTransform); |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 932 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 933 | /** |
| 934 | * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters |
| 935 | * with very similar Z heights to draw together. |
| 936 | * |
| 937 | * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are |
| 938 | * underneath both, and neither's shadow is drawn on top of the other. |
| 939 | */ |
| 940 | const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); |
| 941 | size_t drawIndex, shadowIndex, endIndex; |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 942 | if (mode == ChildrenSelectMode::NegativeZChildren) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 943 | drawIndex = 0; |
| 944 | endIndex = nonNegativeIndex; |
| 945 | shadowIndex = endIndex; // draw no shadows |
| 946 | } else { |
| 947 | drawIndex = nonNegativeIndex; |
| 948 | endIndex = size; |
| 949 | shadowIndex = drawIndex; // potentially draw shadow for each pos Z child |
| 950 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 951 | |
| 952 | DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "", |
| 953 | endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive"); |
| 954 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 955 | float lastCasterZ = 0.0f; |
| 956 | while (shadowIndex < endIndex || drawIndex < endIndex) { |
| 957 | if (shadowIndex < endIndex) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 958 | DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 959 | RenderNode* caster = casterOp->renderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 960 | const float casterZ = zTranslatedNodes[shadowIndex].key; |
| 961 | // attempt to render the shadow if the caster about to be drawn is its caster, |
| 962 | // OR if its caster's Z value is similar to the previous potential caster |
| 963 | if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 964 | caster->issueDrawShadowOperation(casterOp->localMatrix, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 965 | |
| 966 | lastCasterZ = casterZ; // must do this even if current caster not casting a shadow |
| 967 | shadowIndex++; |
| 968 | continue; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | // only the actual child DL draw needs to be in save/restore, |
| 973 | // since it modifies the renderer's matrix |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 974 | int restoreTo = renderer.save(SaveFlags::Matrix); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 975 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 976 | DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 977 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 978 | renderer.concatMatrix(childOp->localMatrix); |
| 979 | childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 980 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 981 | childOp->skipInOrderDraw = true; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 982 | |
| 983 | renderer.restoreToCount(restoreTo); |
| 984 | drawIndex++; |
| 985 | } |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 986 | renderer.restoreToCount(rootRestoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 990 | void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 991 | DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size()); |
| 992 | const SkPath* projectionReceiverOutline = properties().getOutline().getPath(); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 993 | int restoreTo = renderer.getSaveCount(); |
| 994 | |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 995 | LinearAllocator& alloc = handler.allocator(); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 996 | handler(new (alloc) SaveOp(SaveFlags::MatrixClip), |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 997 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 998 | |
| 999 | // Transform renderer to match background we're projecting onto |
| 1000 | // (by offsetting canvas by translationX/Y of background rendernode, since only those are set) |
| 1001 | const DisplayListOp* op = |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1002 | #if HWUI_NEW_OPS |
| 1003 | nullptr; |
| 1004 | LOG_ALWAYS_FATAL("unsupported"); |
| 1005 | #else |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1006 | (mDisplayList->getOps()[mDisplayList->projectionReceiveIndex]); |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1007 | #endif |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 1008 | const DrawRenderNodeOp* backgroundOp = reinterpret_cast<const DrawRenderNodeOp*>(op); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 1009 | const RenderProperties& backgroundProps = backgroundOp->renderNode->properties(); |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 1010 | renderer.translate(backgroundProps.getTranslationX(), backgroundProps.getTranslationY()); |
| 1011 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 1012 | // If the projection receiver has an outline, we mask projected content to it |
Chris Craik | fca52b75 | 2015-04-28 11:45:59 -0700 | [diff] [blame] | 1013 | // (which we know, apriori, are all tessellated paths) |
| 1014 | renderer.setProjectionPathMask(alloc, projectionReceiverOutline); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1015 | |
| 1016 | // draw projected nodes |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1017 | for (size_t i = 0; i < mProjectedNodes.size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1018 | renderNodeOp_t* childOp = mProjectedNodes[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1019 | |
| 1020 | // matrix save, concat, and restore can be done safely without allocating operations |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1021 | int restoreTo = renderer.save(SaveFlags::Matrix); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1022 | renderer.concatMatrix(childOp->transformFromCompositingAncestor); |
| 1023 | childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1024 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1025 | childOp->skipInOrderDraw = true; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1026 | renderer.restoreToCount(restoreTo); |
| 1027 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1028 | |
Chris Craik | fca52b75 | 2015-04-28 11:45:59 -0700 | [diff] [blame] | 1029 | handler(new (alloc) RestoreToCountOp(restoreTo), |
| 1030 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * This function serves both defer and replay modes, and will organize the displayList's component |
| 1035 | * operations for a single frame: |
| 1036 | * |
| 1037 | * Every 'simple' state operation that affects just the matrix and alpha (or other factors of |
| 1038 | * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom |
| 1039 | * defer logic) and operations in displayListOps are issued through the 'handler' which handles the |
| 1040 | * defer vs replay logic, per operation |
| 1041 | */ |
| 1042 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1043 | void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1044 | if (mDisplayList->isEmpty()) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1045 | DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", handler.level() * 2, "", |
| 1046 | this, getName()); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1047 | return; |
| 1048 | } |
| 1049 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 1050 | #if HWUI_NEW_OPS |
| 1051 | const bool drawLayer = false; |
| 1052 | #else |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 1053 | const bool drawLayer = (mLayer && (&renderer != mLayer->renderer.get())); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 1054 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1055 | // If we are updating the contents of mLayer, we don't want to apply any of |
| 1056 | // the RenderNode's properties to this issueOperations pass. Those will all |
| 1057 | // be applied when the layer is drawn, aka when this is true. |
| 1058 | const bool useViewProperties = (!mLayer || drawLayer); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1059 | if (useViewProperties) { |
| 1060 | const Outline& outline = properties().getOutline(); |
Teng-Hui Zhu | 8d0ec38 | 2015-10-01 16:49:16 -0700 | [diff] [blame] | 1061 | if (properties().getAlpha() <= 0 |
| 1062 | || (outline.getShouldClip() && outline.isEmpty()) |
| 1063 | || properties().getScaleX() == 0 |
| 1064 | || properties().getScaleY() == 0) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1065 | DISPLAY_LIST_LOGD("%*sRejected display list (%p, %s)", handler.level() * 2, "", |
| 1066 | this, getName()); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1067 | return; |
| 1068 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1071 | handler.startMark(getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1072 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1073 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1074 | const Rect& clipRect = renderer.getLocalClipBounds(); |
| 1075 | DISPLAY_LIST_LOGD("%*sStart display list (%p, %s), localClipBounds: %.0f, %.0f, %.0f, %.0f", |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 1076 | handler.level() * 2, "", this, getName(), |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1077 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1078 | #endif |
| 1079 | |
| 1080 | LinearAllocator& alloc = handler.allocator(); |
| 1081 | int restoreTo = renderer.getSaveCount(); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1082 | handler(new (alloc) SaveOp(SaveFlags::MatrixClip), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1083 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1084 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1085 | DISPLAY_LIST_LOGD("%*sSave %d %d", (handler.level() + 1) * 2, "", |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1086 | SaveFlags::MatrixClip, restoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1087 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1088 | if (useViewProperties) { |
| 1089 | setViewProperties<T>(renderer, handler); |
| 1090 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1091 | |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1092 | #if HWUI_NEW_OPS |
| 1093 | LOG_ALWAYS_FATAL("legacy op traversal not supported"); |
| 1094 | #else |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 1095 | bool quickRejected = properties().getClipToBounds() |
| 1096 | && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1097 | if (!quickRejected) { |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1098 | Matrix4 initialTransform(*(renderer.currentTransform())); |
Tom Hudson | ac7b6d3 | 2015-06-30 11:26:13 -0400 | [diff] [blame] | 1099 | renderer.setBaseTransform(initialTransform); |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1100 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1101 | if (drawLayer) { |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 1102 | handler(new (alloc) DrawLayerOp(mLayer), |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1103 | renderer.getSaveCount() - 1, properties().getClipToBounds()); |
| 1104 | } else { |
Chris Craik | c166b6c | 2014-09-05 19:55:30 -0700 | [diff] [blame] | 1105 | const int saveCountOffset = renderer.getSaveCount() - 1; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1106 | const int projectionReceiveIndex = mDisplayList->projectionReceiveIndex; |
| 1107 | for (size_t chunkIndex = 0; chunkIndex < mDisplayList->getChunks().size(); chunkIndex++) { |
| 1108 | const DisplayList::Chunk& chunk = mDisplayList->getChunks()[chunkIndex]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1109 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 1110 | std::vector<ZDrawRenderNodeOpPair> zTranslatedNodes; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1111 | buildZSortedChildList(chunk, zTranslatedNodes); |
| 1112 | |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 1113 | issueOperationsOf3dChildren(ChildrenSelectMode::NegativeZChildren, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1114 | initialTransform, zTranslatedNodes, renderer, handler); |
| 1115 | |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 1116 | for (size_t opIndex = chunk.beginOpIndex; opIndex < chunk.endOpIndex; opIndex++) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1117 | DisplayListOp *op = mDisplayList->getOps()[opIndex]; |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 1118 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 1119 | op->output(handler.level() + 1); |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 1120 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1121 | handler(op, saveCountOffset, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1122 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 1123 | if (CC_UNLIKELY(!mProjectedNodes.empty() && projectionReceiveIndex >= 0 && |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 1124 | opIndex == static_cast<size_t>(projectionReceiveIndex))) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1125 | issueOperationsOfProjectedChildren(renderer, handler); |
| 1126 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1127 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1128 | |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 1129 | issueOperationsOf3dChildren(ChildrenSelectMode::PositiveZChildren, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1130 | initialTransform, zTranslatedNodes, renderer, handler); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1131 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1132 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1133 | } |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1134 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1135 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1136 | DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (handler.level() + 1) * 2, "", restoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1137 | handler(new (alloc) RestoreToCountOp(restoreTo), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1138 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1139 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1140 | DISPLAY_LIST_LOGD("%*sDone (%p, %s)", handler.level() * 2, "", this, getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1141 | handler.endMark(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | } /* namespace uirenderer */ |
| 1145 | } /* namespace android */ |