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 | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 304 | if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable())) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 305 | if (CC_UNLIKELY(mLayer)) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 306 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 307 | mLayer = nullptr; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 308 | } |
| 309 | return; |
| 310 | } |
| 311 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 312 | bool transformUpdateNeeded = false; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 313 | if (!mLayer) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 314 | mLayer = createLayer(info.canvasContext.getRenderState(), getWidth(), getHeight()); |
Chris Craik | f559bd1 | 2015-11-18 14:42:00 -0800 | [diff] [blame] | 315 | #if !HWUI_NEW_OPS |
| 316 | applyLayerPropertiesToLayer(info); |
| 317 | #endif |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 318 | damageSelf(info); |
| 319 | transformUpdateNeeded = true; |
| 320 | } else if (!layerMatchesWidthAndHeight(mLayer, getWidth(), getHeight())) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 321 | #if HWUI_NEW_OPS |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 322 | RenderState& renderState = mLayer->renderState; |
| 323 | if (properties().fitsOnLayer()) { |
| 324 | mLayer = renderState.layerPool().resize(mLayer, getWidth(), getHeight()); |
| 325 | } else { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 326 | #else |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 327 | if (!LayerRenderer::resizeLayer(mLayer, getWidth(), getHeight())) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 328 | #endif |
| 329 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 330 | mLayer = nullptr; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 331 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 332 | damageSelf(info); |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 333 | transformUpdateNeeded = true; |
| 334 | } |
| 335 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 336 | SkRect dirty; |
| 337 | info.damageAccumulator->peekAtDirty(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 338 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 339 | if (!mLayer) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 340 | Caches::getInstance().dumpMemoryUsage(); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 341 | if (info.errorHandler) { |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 342 | std::ostringstream err; |
| 343 | err << "Unable to create layer for " << getName(); |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 344 | const int maxTextureSize = Caches::getInstance().maxTextureSize; |
John Reck | 77c4010 | 2015-10-26 15:49:47 -0700 | [diff] [blame] | 345 | if (getWidth() > maxTextureSize || getHeight() > maxTextureSize) { |
| 346 | err << ", size " << getWidth() << "x" << getHeight() |
| 347 | << " exceeds max size " << maxTextureSize; |
| 348 | } else { |
| 349 | err << ", see logcat for more info"; |
| 350 | } |
| 351 | info.errorHandler->onError(err.str()); |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 352 | } |
| 353 | return; |
| 354 | } |
| 355 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 356 | if (transformUpdateNeeded && mLayer) { |
Chris Craik | c71bfca | 2014-08-21 10:18:58 -0700 | [diff] [blame] | 357 | // update the transform in window of the layer to reset its origin wrt light source position |
| 358 | Matrix4 windowTransform; |
| 359 | info.damageAccumulator->computeCurrentTransform(&windowTransform); |
| 360 | mLayer->setWindowTransform(windowTransform); |
| 361 | } |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 362 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 363 | #if HWUI_NEW_OPS |
| 364 | info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty); |
| 365 | #else |
John Reck | c79eabc | 2014-08-05 11:03:42 -0700 | [diff] [blame] | 366 | if (dirty.intersect(0, 0, getWidth(), getHeight())) { |
Mike Reed | 71487eb | 2014-11-19 16:13:20 -0500 | [diff] [blame] | 367 | dirty.roundOut(&dirty); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 368 | mLayer->updateDeferred(this, dirty.fLeft, dirty.fTop, dirty.fRight, dirty.fBottom); |
| 369 | } |
| 370 | // This is not inside the above if because we may have called |
| 371 | // updateDeferred on a previous prepare pass that didn't have a renderer |
| 372 | if (info.renderer && mLayer->deferredUpdateScheduled) { |
| 373 | info.renderer->pushLayerUpdate(mLayer); |
| 374 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 375 | #endif |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 376 | |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 377 | // There might be prefetched layers that need to be accounted for. |
| 378 | // That might be us, so tell CanvasContext that this layer is in the |
| 379 | // tree and should not be destroyed. |
| 380 | info.canvasContext.markLayerInUse(this); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 383 | /** |
| 384 | * Traverse down the the draw tree to prepare for a frame. |
| 385 | * |
| 386 | * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven |
| 387 | * |
| 388 | * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the |
| 389 | * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer. |
| 390 | */ |
| 391 | void RenderNode::prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer) { |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 392 | info.damageAccumulator->pushTransform(this); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 393 | |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 394 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 395 | pushStagingPropertiesChanges(info); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 396 | } |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 397 | uint32_t animatorDirtyMask = 0; |
| 398 | if (CC_LIKELY(info.runAnimations)) { |
| 399 | animatorDirtyMask = mAnimatorManager.animate(info); |
| 400 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 401 | |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 402 | bool willHaveFunctor = false; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 403 | if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 404 | willHaveFunctor = !mStagingDisplayList->getFunctors().empty(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 405 | } else if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 406 | willHaveFunctor = !mDisplayList->getFunctors().empty(); |
John Reck | 3f725f0 | 2015-06-16 10:29:31 -0700 | [diff] [blame] | 407 | } |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 408 | bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence( |
| 409 | willHaveFunctor, functorsNeedLayer); |
| 410 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 411 | if (CC_UNLIKELY(mPositionListener.get())) { |
| 412 | mPositionListener->onPositionUpdated(*this, info); |
| 413 | } |
| 414 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 415 | prepareLayer(info, animatorDirtyMask); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 416 | if (info.mode == TreeInfo::MODE_FULL) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 417 | pushStagingDisplayListChanges(info); |
| 418 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 419 | prepareSubTree(info, childFunctorsNeedLayer, mDisplayList); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 420 | pushLayerUpdate(info); |
| 421 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 422 | info.damageAccumulator->popTransform(); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 425 | void RenderNode::syncProperties() { |
| 426 | mProperties = mStagingProperties; |
| 427 | } |
| 428 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 429 | void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) { |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 430 | // Push the animators first so that setupStartValueIfNecessary() is called |
| 431 | // before properties() is trampled by stagingProperties(), as they are |
| 432 | // required by some animators. |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 433 | if (CC_LIKELY(info.runAnimations)) { |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 434 | mAnimatorManager.pushStaging(); |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 435 | } |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 436 | if (mDirtyPropertyFields) { |
| 437 | mDirtyPropertyFields = 0; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 438 | damageSelf(info); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 439 | info.damageAccumulator->popTransform(); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 440 | syncProperties(); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 441 | #if !HWUI_NEW_OPS |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 442 | applyLayerPropertiesToLayer(info); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 443 | #endif |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 444 | // We could try to be clever and only re-damage if the matrix changed. |
| 445 | // However, we don't need to worry about that. The cost of over-damaging |
| 446 | // here is only going to be a single additional map rect of this node |
| 447 | // plus a rect join(). The parent's transform (and up) will only be |
| 448 | // performed once. |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 449 | info.damageAccumulator->pushTransform(this); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 450 | damageSelf(info); |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 451 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 454 | #if !HWUI_NEW_OPS |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 455 | void RenderNode::applyLayerPropertiesToLayer(TreeInfo& info) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 456 | if (CC_LIKELY(!mLayer)) return; |
| 457 | |
| 458 | const LayerProperties& props = properties().layerProperties(); |
| 459 | mLayer->setAlpha(props.alpha(), props.xferMode()); |
| 460 | mLayer->setColorFilter(props.colorFilter()); |
| 461 | mLayer->setBlend(props.needsBlending()); |
| 462 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 463 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 464 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 465 | void RenderNode::syncDisplayList(TreeObserver* observer) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 466 | // Make sure we inc first so that we don't fluctuate between 0 and 1, |
| 467 | // which would thrash the layer cache |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 468 | if (mStagingDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 469 | for (auto&& child : mStagingDisplayList->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 470 | child->renderNode->incParentRefCount(); |
| 471 | } |
| 472 | } |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 473 | deleteDisplayList(observer); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 474 | mDisplayList = mStagingDisplayList; |
| 475 | mStagingDisplayList = nullptr; |
| 476 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 477 | for (size_t i = 0; i < mDisplayList->getFunctors().size(); i++) { |
| 478 | (*mDisplayList->getFunctors()[i])(DrawGlInfo::kModeSync, nullptr); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 479 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 480 | for (size_t i = 0; i < mDisplayList->getPushStagingFunctors().size(); i++) { |
| 481 | (*mDisplayList->getPushStagingFunctors()[i])(); |
| 482 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 486 | void RenderNode::pushStagingDisplayListChanges(TreeInfo& info) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 487 | if (mNeedsDisplayListSync) { |
| 488 | mNeedsDisplayListSync = false; |
John Reck | 5c9d717 | 2014-10-22 11:32:27 -0700 | [diff] [blame] | 489 | // Damage with the old display list first then the new one to catch any |
| 490 | // changes in isRenderable or, in the future, bounds |
| 491 | damageSelf(info); |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 492 | syncDisplayList(info.observer); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 493 | damageSelf(info); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 494 | } |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 495 | } |
| 496 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 497 | void RenderNode::deleteDisplayList(TreeObserver* observer) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 498 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 499 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 500 | child->renderNode->decParentRefCount(observer); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 503 | delete mDisplayList; |
| 504 | mDisplayList = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 507 | void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) { |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 508 | if (subtree) { |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 509 | TextureCache& cache = Caches::getInstance().textureCache; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 510 | info.out.hasFunctors |= subtree->getFunctors().size(); |
| 511 | for (auto&& bitmapResource : subtree->getBitmapResources()) { |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 512 | void* ownerToken = &info.canvasContext; |
| 513 | info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource); |
John Reck | f4198b7 | 2014-04-09 17:00:04 -0700 | [diff] [blame] | 514 | } |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 515 | for (auto&& op : subtree->getChildren()) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 516 | RenderNode* childNode = op->renderNode; |
| 517 | #if HWUI_NEW_OPS |
| 518 | info.damageAccumulator->pushTransform(&op->localMatrix); |
| 519 | bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip; |
| 520 | #else |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 521 | info.damageAccumulator->pushTransform(&op->localMatrix); |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 522 | bool childFunctorsNeedLayer = functorsNeedLayer |
| 523 | // Recorded with non-rect clip, or canvas-rotated by parent |
| 524 | || op->mRecordedWithPotentialStencilClip; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 525 | #endif |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 526 | childNode->prepareTreeImpl(info, childFunctorsNeedLayer); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 527 | info.damageAccumulator->popTransform(); |
John Reck | 5bf11bb | 2014-03-25 10:22:09 -0700 | [diff] [blame] | 528 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 532 | void RenderNode::destroyHardwareResources(TreeObserver* observer) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 533 | if (mLayer) { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 534 | destroyLayer(mLayer); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 535 | mLayer = nullptr; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 536 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 537 | if (mDisplayList) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 538 | for (auto&& child : mDisplayList->getChildren()) { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 539 | child->renderNode->destroyHardwareResources(observer); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 540 | } |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 541 | if (mNeedsDisplayListSync) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 542 | // Next prepare tree we are going to push a new display list, so we can |
| 543 | // drop our current one now |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 544 | deleteDisplayList(observer); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 549 | void RenderNode::decParentRefCount(TreeObserver* observer) { |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 550 | LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!"); |
| 551 | mParentCount--; |
| 552 | if (!mParentCount) { |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 553 | if (observer) { |
| 554 | observer->onMaybeRemovedFromTree(this); |
| 555 | } |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 556 | // If a child of ours is being attached to our parent then this will incorrectly |
| 557 | // destroy its hardware resources. However, this situation is highly unlikely |
| 558 | // and the failure is "just" that the layer is re-created, so this should |
| 559 | // be safe enough |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 560 | destroyHardwareResources(observer); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 564 | /* |
| 565 | * For property operations, we pass a savecount of 0, since the operations aren't part of the |
| 566 | * 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] | 567 | * base saveCount (i.e., how RestoreToCount uses saveCount + properties().getCount()) |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 568 | */ |
| 569 | #define PROPERTY_SAVECOUNT 0 |
| 570 | |
| 571 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 572 | void RenderNode::setViewProperties(OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 573 | #if DEBUG_DISPLAY_LIST |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 574 | properties().debugOutputProperties(handler.level() + 1); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 575 | #endif |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 576 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 577 | renderer.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 578 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 579 | if (properties().getStaticMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 580 | renderer.concatMatrix(*properties().getStaticMatrix()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 581 | } else if (properties().getAnimationMatrix()) { |
Derek Sollenberger | 1390882 | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 582 | renderer.concatMatrix(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 583 | } |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 584 | if (properties().hasTransformMatrix()) { |
| 585 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 586 | renderer.translate(properties().getTranslationX(), properties().getTranslationY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 587 | } else { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 588 | renderer.concatMatrix(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 591 | const bool isLayer = properties().effectiveLayerType() != LayerType::None; |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 592 | int clipFlags = properties().getClippingFlags(); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 593 | if (properties().getAlpha() < 1) { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 594 | if (isLayer) { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 595 | clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 596 | } |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 597 | if (CC_LIKELY(isLayer || !properties().getHasOverlappingRendering())) { |
| 598 | // simply scale rendering content's alpha |
| 599 | renderer.scaleAlpha(properties().getAlpha()); |
| 600 | } else { |
| 601 | // savelayer needed to create an offscreen buffer |
| 602 | Rect layerBounds(0, 0, getWidth(), getHeight()); |
| 603 | if (clipFlags) { |
| 604 | properties().getClippingRectForFlags(clipFlags, &layerBounds); |
| 605 | clipFlags = 0; // all clipping done by savelayer |
| 606 | } |
| 607 | SaveLayerOp* op = new (handler.allocator()) SaveLayerOp( |
| 608 | layerBounds.left, layerBounds.top, |
| 609 | layerBounds.right, layerBounds.bottom, |
| 610 | (int) (properties().getAlpha() * 255), |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 611 | SaveFlags::HasAlphaLayer | SaveFlags::ClipToLayer); |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 612 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 613 | } |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 614 | |
| 615 | if (CC_UNLIKELY(ATRACE_ENABLED() && properties().promotedToLayer())) { |
Chris Craik | 4e9d9b2 | 2015-06-12 11:07:23 -0700 | [diff] [blame] | 616 | // pretend alpha always causes savelayer to warn about |
| 617 | // performance problem affecting old versions |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 618 | ATRACE_FORMAT("%s alpha caused saveLayer %dx%d", getName(), |
| 619 | static_cast<int>(getWidth()), |
| 620 | static_cast<int>(getHeight())); |
| 621 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 622 | } |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 623 | if (clipFlags) { |
| 624 | Rect clipRect; |
| 625 | properties().getClippingRectForFlags(clipFlags, &clipRect); |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 626 | ClipRectOp* op = new (handler.allocator()) ClipRectOp( |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 627 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom, |
| 628 | SkRegion::kIntersect_Op); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 629 | handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 630 | } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 631 | |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 632 | // TODO: support nesting round rect clips |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 633 | if (mProperties.getRevealClip().willClip()) { |
| 634 | Rect bounds; |
| 635 | mProperties.getRevealClip().getBounds(&bounds); |
| 636 | renderer.setClippingRoundRect(handler.allocator(), bounds, mProperties.getRevealClip().getRadius()); |
| 637 | } else if (mProperties.getOutline().willClip()) { |
| 638 | renderer.setClippingOutline(handler.allocator(), &(mProperties.getOutline())); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Apply property-based transformations to input matrix |
| 644 | * |
| 645 | * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4 |
| 646 | * matrix computation instead of the Skia 3x3 matrix + camera hackery. |
| 647 | */ |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 648 | void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 649 | if (properties().getLeft() != 0 || properties().getTop() != 0) { |
| 650 | matrix.translate(properties().getLeft(), properties().getTop()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 651 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 652 | if (properties().getStaticMatrix()) { |
| 653 | mat4 stat(*properties().getStaticMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 654 | matrix.multiply(stat); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 655 | } else if (properties().getAnimationMatrix()) { |
| 656 | mat4 anim(*properties().getAnimationMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 657 | matrix.multiply(anim); |
| 658 | } |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 659 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 660 | bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ()); |
Chris Craik | e0bb87d | 2014-04-22 17:55:41 -0700 | [diff] [blame] | 661 | if (properties().hasTransformMatrix() || applyTranslationZ) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 662 | if (properties().isTransformTranslateOnly()) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 663 | matrix.translate(properties().getTranslationX(), properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 664 | true3dTransform ? properties().getZ() : 0.0f); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 665 | } else { |
| 666 | if (!true3dTransform) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 667 | matrix.multiply(*properties().getTransformMatrix()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 668 | } else { |
| 669 | mat4 true3dMat; |
| 670 | true3dMat.loadTranslate( |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 671 | properties().getPivotX() + properties().getTranslationX(), |
| 672 | properties().getPivotY() + properties().getTranslationY(), |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 673 | properties().getZ()); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 674 | true3dMat.rotate(properties().getRotationX(), 1, 0, 0); |
| 675 | true3dMat.rotate(properties().getRotationY(), 0, 1, 0); |
| 676 | true3dMat.rotate(properties().getRotation(), 0, 0, 1); |
| 677 | true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1); |
| 678 | true3dMat.translate(-properties().getPivotX(), -properties().getPivotY()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 679 | |
| 680 | matrix.multiply(true3dMat); |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Organizes the DisplayList hierarchy to prepare for background projection reordering. |
| 688 | * |
| 689 | * This should be called before a call to defer() or drawDisplayList() |
| 690 | * |
| 691 | * Each DisplayList that serves as a 3d root builds its list of composited children, |
| 692 | * which are flagged to not draw in the standard draw loop. |
| 693 | */ |
| 694 | void RenderNode::computeOrdering() { |
| 695 | ATRACE_CALL(); |
| 696 | mProjectedNodes.clear(); |
| 697 | |
| 698 | // TODO: create temporary DDLOp and call computeOrderingImpl on top DisplayList so that |
| 699 | // transform properties are applied correctly to top level children |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 700 | if (mDisplayList == nullptr) return; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 701 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 702 | renderNodeOp_t* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 703 | childOp->renderNode->computeOrderingImpl(childOp, &mProjectedNodes, &mat4::identity()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
| 707 | void RenderNode::computeOrderingImpl( |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 708 | renderNodeOp_t* opState, |
| 709 | std::vector<renderNodeOp_t*>* compositedChildrenOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 710 | const mat4* transformFromProjectionSurface) { |
| 711 | mProjectedNodes.clear(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 712 | if (mDisplayList == nullptr || mDisplayList->isEmpty()) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 713 | |
| 714 | // TODO: should avoid this calculation in most cases |
| 715 | // TODO: just calculate single matrix, down to all leaf composited elements |
| 716 | Matrix4 localTransformFromProjectionSurface(*transformFromProjectionSurface); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 717 | localTransformFromProjectionSurface.multiply(opState->localMatrix); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 718 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 719 | if (properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 720 | // 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] | 721 | opState->skipInOrderDraw = true; |
| 722 | opState->transformFromCompositingAncestor = localTransformFromProjectionSurface; |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 723 | compositedChildrenOfProjectionSurface->push_back(opState); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 724 | } else { |
| 725 | // standard in order draw |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 726 | opState->skipInOrderDraw = false; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 729 | if (mDisplayList->getChildren().size() > 0) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 730 | const bool isProjectionReceiver = mDisplayList->projectionReceiveIndex >= 0; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 731 | bool haveAppliedPropertiesToProjection = false; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 732 | for (unsigned int i = 0; i < mDisplayList->getChildren().size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 733 | renderNodeOp_t* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 734 | RenderNode* child = childOp->renderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 735 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 736 | std::vector<renderNodeOp_t*>* projectionChildren = nullptr; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 737 | const mat4* projectionTransform = nullptr; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 738 | if (isProjectionReceiver && !child->properties().getProjectBackwards()) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 739 | // if receiving projections, collect projecting descendant |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 740 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 741 | // Note that if a direct descendant is projecting backwards, we pass its |
| 742 | // grandparent projection collection, since it shouldn't project onto its |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 743 | // parent, where it will already be drawing. |
| 744 | projectionChildren = &mProjectedNodes; |
| 745 | projectionTransform = &mat4::identity(); |
| 746 | } else { |
| 747 | if (!haveAppliedPropertiesToProjection) { |
| 748 | applyViewPropertyTransforms(localTransformFromProjectionSurface); |
| 749 | haveAppliedPropertiesToProjection = true; |
| 750 | } |
| 751 | projectionChildren = compositedChildrenOfProjectionSurface; |
| 752 | projectionTransform = &localTransformFromProjectionSurface; |
| 753 | } |
Derek Sollenberger | f293259 | 2015-08-13 14:59:33 -0400 | [diff] [blame] | 754 | child->computeOrderingImpl(childOp, projectionChildren, projectionTransform); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 755 | } |
| 756 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | class DeferOperationHandler { |
| 760 | public: |
| 761 | DeferOperationHandler(DeferStateStruct& deferStruct, int level) |
| 762 | : mDeferStruct(deferStruct), mLevel(level) {} |
| 763 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 764 | operation->defer(mDeferStruct, saveCount, mLevel, clipToBounds); |
| 765 | } |
| 766 | inline LinearAllocator& allocator() { return *(mDeferStruct.mAllocator); } |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 767 | inline void startMark(const char* name) {} // do nothing |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 768 | inline void endMark() {} |
| 769 | inline int level() { return mLevel; } |
| 770 | inline int replayFlags() { return mDeferStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 771 | inline SkPath* allocPathForFrame() { return mDeferStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 772 | |
| 773 | private: |
| 774 | DeferStateStruct& mDeferStruct; |
| 775 | const int mLevel; |
| 776 | }; |
| 777 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 778 | void RenderNode::defer(DeferStateStruct& deferStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 779 | DeferOperationHandler handler(deferStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 780 | issueOperations<DeferOperationHandler>(deferStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | class ReplayOperationHandler { |
| 784 | public: |
| 785 | ReplayOperationHandler(ReplayStateStruct& replayStruct, int level) |
| 786 | : mReplayStruct(replayStruct), mLevel(level) {} |
| 787 | inline void operator()(DisplayListOp* operation, int saveCount, bool clipToBounds) { |
| 788 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 789 | mReplayStruct.mRenderer.eventMark(operation->name()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 790 | #endif |
| 791 | operation->replay(mReplayStruct, saveCount, mLevel, clipToBounds); |
| 792 | } |
| 793 | inline LinearAllocator& allocator() { return *(mReplayStruct.mAllocator); } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 794 | inline void startMark(const char* name) { |
| 795 | mReplayStruct.mRenderer.startMark(name); |
| 796 | } |
| 797 | inline void endMark() { |
| 798 | mReplayStruct.mRenderer.endMark(); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 799 | } |
| 800 | inline int level() { return mLevel; } |
| 801 | inline int replayFlags() { return mReplayStruct.mReplayFlags; } |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 802 | inline SkPath* allocPathForFrame() { return mReplayStruct.allocPathForFrame(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 803 | |
| 804 | private: |
| 805 | ReplayStateStruct& mReplayStruct; |
| 806 | const int mLevel; |
| 807 | }; |
| 808 | |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 809 | void RenderNode::replay(ReplayStateStruct& replayStruct, const int level) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 810 | ReplayOperationHandler handler(replayStruct, level); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 811 | issueOperations<ReplayOperationHandler>(replayStruct.mRenderer, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 814 | void RenderNode::buildZSortedChildList(const DisplayList::Chunk& chunk, |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 815 | std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 816 | #if !HWUI_NEW_OPS |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 817 | if (chunk.beginChildIndex == chunk.endChildIndex) return; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 818 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 819 | for (unsigned int i = chunk.beginChildIndex; i < chunk.endChildIndex; i++) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 820 | DrawRenderNodeOp* childOp = mDisplayList->getChildren()[i]; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 821 | RenderNode* child = childOp->renderNode; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 822 | float childZ = child->properties().getZ(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 823 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 824 | if (!MathUtils::isZero(childZ) && chunk.reorderChildren) { |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 825 | zTranslatedNodes.push_back(ZDrawRenderNodeOpPair(childZ, childOp)); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 826 | childOp->skipInOrderDraw = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 827 | } else if (!child->properties().getProjectBackwards()) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 828 | // regular, in order drawing DisplayList |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 829 | childOp->skipInOrderDraw = false; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 833 | // 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] | 834 | std::stable_sort(zTranslatedNodes.begin(), zTranslatedNodes.end()); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 835 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 838 | template <class T> |
| 839 | void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 840 | if (properties().getAlpha() <= 0.0f |
| 841 | || properties().getOutline().getAlpha() <= 0.0f |
Teng-Hui Zhu | 8d0ec38 | 2015-10-01 16:49:16 -0700 | [diff] [blame] | 842 | || !properties().getOutline().getPath() |
| 843 | || properties().getScaleX() == 0 |
| 844 | || properties().getScaleY() == 0) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 845 | // no shadow to draw |
| 846 | return; |
| 847 | } |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 848 | |
| 849 | mat4 shadowMatrixXY(transformFromParent); |
| 850 | applyViewPropertyTransforms(shadowMatrixXY); |
| 851 | |
| 852 | // Z matrix needs actual 3d transformation, so mapped z values will be correct |
| 853 | mat4 shadowMatrixZ(transformFromParent); |
| 854 | applyViewPropertyTransforms(shadowMatrixZ, true); |
| 855 | |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 856 | const SkPath* casterOutlinePath = properties().getOutline().getPath(); |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 857 | const SkPath* revealClipPath = properties().getRevealClip().getPath(); |
Chris Craik | 6131732 | 2014-05-21 13:03:52 -0700 | [diff] [blame] | 858 | if (revealClipPath && revealClipPath->isEmpty()) return; |
| 859 | |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 860 | float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha(); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 861 | |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 862 | |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 863 | // holds temporary SkPath to store the result of intersections |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 864 | SkPath* frameAllocatedPath = nullptr; |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 865 | const SkPath* outlinePath = casterOutlinePath; |
| 866 | |
| 867 | // intersect the outline with the reveal clip, if present |
| 868 | if (revealClipPath) { |
| 869 | frameAllocatedPath = handler.allocPathForFrame(); |
| 870 | |
Tom Hudson | 02a2630 | 2015-06-24 11:32:42 -0400 | [diff] [blame] | 871 | Op(*outlinePath, *revealClipPath, kIntersect_SkPathOp, frameAllocatedPath); |
Chris Craik | faa79ff | 2014-12-01 13:44:21 -0800 | [diff] [blame] | 872 | outlinePath = frameAllocatedPath; |
| 873 | } |
| 874 | |
| 875 | // intersect the outline with the clipBounds, if present |
| 876 | if (properties().getClippingFlags() & CLIP_TO_CLIP_BOUNDS) { |
| 877 | if (!frameAllocatedPath) { |
| 878 | frameAllocatedPath = handler.allocPathForFrame(); |
| 879 | } |
| 880 | |
| 881 | Rect clipBounds; |
| 882 | properties().getClippingRectForFlags(CLIP_TO_CLIP_BOUNDS, &clipBounds); |
| 883 | SkPath clipBoundsPath; |
| 884 | clipBoundsPath.addRect(clipBounds.left, clipBounds.top, |
| 885 | clipBounds.right, clipBounds.bottom); |
| 886 | |
Tom Hudson | 02a2630 | 2015-06-24 11:32:42 -0400 | [diff] [blame] | 887 | Op(*outlinePath, clipBoundsPath, kIntersect_SkPathOp, frameAllocatedPath); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 888 | outlinePath = frameAllocatedPath; |
| 889 | } |
| 890 | |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 891 | DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp( |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 892 | shadowMatrixXY, shadowMatrixZ, casterAlpha, outlinePath); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 893 | handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 894 | } |
| 895 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 896 | #define SHADOW_DELTA 0.1f |
| 897 | |
| 898 | template <class T> |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 899 | void RenderNode::issueOperationsOf3dChildren(ChildrenSelectMode mode, |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 900 | const Matrix4& initialTransform, const std::vector<ZDrawRenderNodeOpPair>& zTranslatedNodes, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 901 | OpenGLRenderer& renderer, T& handler) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 902 | const int size = zTranslatedNodes.size(); |
| 903 | if (size == 0 |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 904 | || (mode == ChildrenSelectMode::NegativeZChildren && zTranslatedNodes[0].key > 0.0f) |
| 905 | || (mode == ChildrenSelectMode::PositiveZChildren && zTranslatedNodes[size - 1].key < 0.0f)) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 906 | // no 3d children to draw |
| 907 | return; |
| 908 | } |
| 909 | |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 910 | // Apply the base transform of the parent of the 3d children. This isolates |
| 911 | // 3d children of the current chunk from transformations made in previous chunks. |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 912 | int rootRestoreTo = renderer.save(SaveFlags::Matrix); |
Chris Craik | 6daa13c | 2015-08-19 13:32:12 -0700 | [diff] [blame] | 913 | renderer.setGlobalMatrix(initialTransform); |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 914 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 915 | /** |
| 916 | * Draw shadows and (potential) casters mostly in order, but allow the shadows of casters |
| 917 | * with very similar Z heights to draw together. |
| 918 | * |
| 919 | * This way, if Views A & B have the same Z height and are both casting shadows, the shadows are |
| 920 | * underneath both, and neither's shadow is drawn on top of the other. |
| 921 | */ |
| 922 | const size_t nonNegativeIndex = findNonNegativeIndex(zTranslatedNodes); |
| 923 | size_t drawIndex, shadowIndex, endIndex; |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 924 | if (mode == ChildrenSelectMode::NegativeZChildren) { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 925 | drawIndex = 0; |
| 926 | endIndex = nonNegativeIndex; |
| 927 | shadowIndex = endIndex; // draw no shadows |
| 928 | } else { |
| 929 | drawIndex = nonNegativeIndex; |
| 930 | endIndex = size; |
| 931 | shadowIndex = drawIndex; // potentially draw shadow for each pos Z child |
| 932 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 933 | |
| 934 | DISPLAY_LIST_LOGD("%*s%d %s 3d children:", (handler.level() + 1) * 2, "", |
| 935 | endIndex - drawIndex, mode == kNegativeZChildren ? "negative" : "positive"); |
| 936 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 937 | float lastCasterZ = 0.0f; |
| 938 | while (shadowIndex < endIndex || drawIndex < endIndex) { |
| 939 | if (shadowIndex < endIndex) { |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 940 | DrawRenderNodeOp* casterOp = zTranslatedNodes[shadowIndex].value; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 941 | RenderNode* caster = casterOp->renderNode; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 942 | const float casterZ = zTranslatedNodes[shadowIndex].key; |
| 943 | // attempt to render the shadow if the caster about to be drawn is its caster, |
| 944 | // OR if its caster's Z value is similar to the previous potential caster |
| 945 | if (shadowIndex == drawIndex || casterZ - lastCasterZ < SHADOW_DELTA) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 946 | caster->issueDrawShadowOperation(casterOp->localMatrix, handler); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 947 | |
| 948 | lastCasterZ = casterZ; // must do this even if current caster not casting a shadow |
| 949 | shadowIndex++; |
| 950 | continue; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | // only the actual child DL draw needs to be in save/restore, |
| 955 | // since it modifies the renderer's matrix |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 956 | int restoreTo = renderer.save(SaveFlags::Matrix); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 957 | |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 958 | DrawRenderNodeOp* childOp = zTranslatedNodes[drawIndex].value; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 959 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 960 | renderer.concatMatrix(childOp->localMatrix); |
| 961 | childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 962 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 963 | childOp->skipInOrderDraw = true; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 964 | |
| 965 | renderer.restoreToCount(restoreTo); |
| 966 | drawIndex++; |
| 967 | } |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 968 | renderer.restoreToCount(rootRestoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 972 | void RenderNode::issueOperationsOfProjectedChildren(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 973 | DISPLAY_LIST_LOGD("%*s%d projected children:", (handler.level() + 1) * 2, "", mProjectedNodes.size()); |
| 974 | const SkPath* projectionReceiverOutline = properties().getOutline().getPath(); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 975 | int restoreTo = renderer.getSaveCount(); |
| 976 | |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 977 | LinearAllocator& alloc = handler.allocator(); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 978 | handler(new (alloc) SaveOp(SaveFlags::MatrixClip), |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 979 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
| 980 | |
| 981 | // Transform renderer to match background we're projecting onto |
| 982 | // (by offsetting canvas by translationX/Y of background rendernode, since only those are set) |
| 983 | const DisplayListOp* op = |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 984 | #if HWUI_NEW_OPS |
| 985 | nullptr; |
| 986 | LOG_ALWAYS_FATAL("unsupported"); |
| 987 | #else |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 988 | (mDisplayList->getOps()[mDisplayList->projectionReceiveIndex]); |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 989 | #endif |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 990 | const DrawRenderNodeOp* backgroundOp = reinterpret_cast<const DrawRenderNodeOp*>(op); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 991 | const RenderProperties& backgroundProps = backgroundOp->renderNode->properties(); |
Chris Craik | b3cca87 | 2014-08-08 18:42:51 -0700 | [diff] [blame] | 992 | renderer.translate(backgroundProps.getTranslationX(), backgroundProps.getTranslationY()); |
| 993 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 994 | // 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] | 995 | // (which we know, apriori, are all tessellated paths) |
| 996 | renderer.setProjectionPathMask(alloc, projectionReceiverOutline); |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 997 | |
| 998 | // draw projected nodes |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 999 | for (size_t i = 0; i < mProjectedNodes.size(); i++) { |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1000 | renderNodeOp_t* childOp = mProjectedNodes[i]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1001 | |
| 1002 | // matrix save, concat, and restore can be done safely without allocating operations |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1003 | int restoreTo = renderer.save(SaveFlags::Matrix); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1004 | renderer.concatMatrix(childOp->transformFromCompositingAncestor); |
| 1005 | childOp->skipInOrderDraw = false; // this is horrible, I'm so sorry everyone |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1006 | handler(childOp, renderer.getSaveCount() - 1, properties().getClipToBounds()); |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 1007 | childOp->skipInOrderDraw = true; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1008 | renderer.restoreToCount(restoreTo); |
| 1009 | } |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1010 | |
Chris Craik | fca52b75 | 2015-04-28 11:45:59 -0700 | [diff] [blame] | 1011 | handler(new (alloc) RestoreToCountOp(restoreTo), |
| 1012 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * This function serves both defer and replay modes, and will organize the displayList's component |
| 1017 | * operations for a single frame: |
| 1018 | * |
| 1019 | * Every 'simple' state operation that affects just the matrix and alpha (or other factors of |
| 1020 | * DeferredDisplayState) may be issued directly to the renderer, but complex operations (with custom |
| 1021 | * defer logic) and operations in displayListOps are issued through the 'handler' which handles the |
| 1022 | * defer vs replay logic, per operation |
| 1023 | */ |
| 1024 | template <class T> |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1025 | void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1026 | if (mDisplayList->isEmpty()) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1027 | DISPLAY_LIST_LOGD("%*sEmpty display list (%p, %s)", handler.level() * 2, "", |
| 1028 | this, getName()); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1029 | return; |
| 1030 | } |
| 1031 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 1032 | #if HWUI_NEW_OPS |
| 1033 | const bool drawLayer = false; |
| 1034 | #else |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 1035 | const bool drawLayer = (mLayer && (&renderer != mLayer->renderer.get())); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 1036 | #endif |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1037 | // If we are updating the contents of mLayer, we don't want to apply any of |
| 1038 | // the RenderNode's properties to this issueOperations pass. Those will all |
| 1039 | // be applied when the layer is drawn, aka when this is true. |
| 1040 | const bool useViewProperties = (!mLayer || drawLayer); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1041 | if (useViewProperties) { |
| 1042 | const Outline& outline = properties().getOutline(); |
Teng-Hui Zhu | 8d0ec38 | 2015-10-01 16:49:16 -0700 | [diff] [blame] | 1043 | if (properties().getAlpha() <= 0 |
| 1044 | || (outline.getShouldClip() && outline.isEmpty()) |
| 1045 | || properties().getScaleX() == 0 |
| 1046 | || properties().getScaleY() == 0) { |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1047 | DISPLAY_LIST_LOGD("%*sRejected display list (%p, %s)", handler.level() * 2, "", |
| 1048 | this, getName()); |
Chris Craik | 0645128 | 2014-07-21 10:25:54 -0700 | [diff] [blame] | 1049 | return; |
| 1050 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1053 | handler.startMark(getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1054 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1055 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1056 | const Rect& clipRect = renderer.getLocalClipBounds(); |
| 1057 | 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] | 1058 | handler.level() * 2, "", this, getName(), |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 1059 | clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1060 | #endif |
| 1061 | |
| 1062 | LinearAllocator& alloc = handler.allocator(); |
| 1063 | int restoreTo = renderer.getSaveCount(); |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1064 | handler(new (alloc) SaveOp(SaveFlags::MatrixClip), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1065 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1066 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1067 | DISPLAY_LIST_LOGD("%*sSave %d %d", (handler.level() + 1) * 2, "", |
Florin Malita | eecff56 | 2015-12-21 10:43:01 -0500 | [diff] [blame] | 1068 | SaveFlags::MatrixClip, restoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1069 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1070 | if (useViewProperties) { |
| 1071 | setViewProperties<T>(renderer, handler); |
| 1072 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1073 | |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1074 | #if HWUI_NEW_OPS |
| 1075 | LOG_ALWAYS_FATAL("legacy op traversal not supported"); |
| 1076 | #else |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 1077 | bool quickRejected = properties().getClipToBounds() |
| 1078 | && renderer.quickRejectConservative(0, 0, properties().getWidth(), properties().getHeight()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1079 | if (!quickRejected) { |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1080 | Matrix4 initialTransform(*(renderer.currentTransform())); |
Tom Hudson | ac7b6d3 | 2015-06-30 11:26:13 -0400 | [diff] [blame] | 1081 | renderer.setBaseTransform(initialTransform); |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1082 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1083 | if (drawLayer) { |
Chris Craik | 3aadd60 | 2015-08-20 12:41:40 -0700 | [diff] [blame] | 1084 | handler(new (alloc) DrawLayerOp(mLayer), |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1085 | renderer.getSaveCount() - 1, properties().getClipToBounds()); |
| 1086 | } else { |
Chris Craik | c166b6c | 2014-09-05 19:55:30 -0700 | [diff] [blame] | 1087 | const int saveCountOffset = renderer.getSaveCount() - 1; |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1088 | const int projectionReceiveIndex = mDisplayList->projectionReceiveIndex; |
| 1089 | for (size_t chunkIndex = 0; chunkIndex < mDisplayList->getChunks().size(); chunkIndex++) { |
| 1090 | const DisplayList::Chunk& chunk = mDisplayList->getChunks()[chunkIndex]; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1091 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 1092 | std::vector<ZDrawRenderNodeOpPair> zTranslatedNodes; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1093 | buildZSortedChildList(chunk, zTranslatedNodes); |
| 1094 | |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 1095 | issueOperationsOf3dChildren(ChildrenSelectMode::NegativeZChildren, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1096 | initialTransform, zTranslatedNodes, renderer, handler); |
| 1097 | |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 1098 | for (size_t opIndex = chunk.beginOpIndex; opIndex < chunk.endOpIndex; opIndex++) { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 1099 | DisplayListOp *op = mDisplayList->getOps()[opIndex]; |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 1100 | #if DEBUG_DISPLAY_LIST |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 1101 | op->output(handler.level() + 1); |
Chris Craik | 80d4902 | 2014-06-20 15:03:43 -0700 | [diff] [blame] | 1102 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1103 | handler(op, saveCountOffset, properties().getClipToBounds()); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1104 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 1105 | if (CC_UNLIKELY(!mProjectedNodes.empty() && projectionReceiveIndex >= 0 && |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 1106 | opIndex == static_cast<size_t>(projectionReceiveIndex))) { |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1107 | issueOperationsOfProjectedChildren(renderer, handler); |
| 1108 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1109 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1110 | |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame] | 1111 | issueOperationsOf3dChildren(ChildrenSelectMode::PositiveZChildren, |
Chris Craik | c3e75f9 | 2014-08-27 15:34:52 -0700 | [diff] [blame] | 1112 | initialTransform, zTranslatedNodes, renderer, handler); |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 1113 | } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 1114 | } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1115 | } |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 1116 | #endif |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1117 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1118 | DISPLAY_LIST_LOGD("%*sRestoreToCount %d", (handler.level() + 1) * 2, "", restoreTo); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1119 | handler(new (alloc) RestoreToCountOp(restoreTo), |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 1120 | PROPERTY_SAVECOUNT, properties().getClipToBounds()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1121 | |
Chris Craik | bf72eb8 | 2015-06-08 11:30:44 -0700 | [diff] [blame] | 1122 | DISPLAY_LIST_LOGD("%*sDone (%p, %s)", handler.level() * 2, "", this, getName()); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 1123 | handler.endMark(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | } /* namespace uirenderer */ |
| 1127 | } /* namespace android */ |