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