Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "RenderNodeDrawable.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 18 | #include <SkPaintFilterCanvas.h> |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 19 | #include "RenderNode.h" |
| 20 | #include "SkiaDisplayList.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 21 | #include "SkiaPipeline.h" |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 22 | #include "utils/TraceUtils.h" |
| 23 | |
Ben Wagner | 1d15533 | 2018-08-20 18:36:05 -0400 | [diff] [blame^] | 24 | #include <optional> |
| 25 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | namespace skiapipeline { |
| 29 | |
John Reck | d9d7f12 | 2018-05-03 14:40:56 -0700 | [diff] [blame] | 30 | RenderNodeDrawable::RenderNodeDrawable(RenderNode* node, SkCanvas* canvas, bool composeLayer, |
| 31 | bool inReorderingSection) |
| 32 | : mRenderNode(node) |
| 33 | , mRecordedTransform(canvas->getTotalMatrix()) |
| 34 | , mComposeLayer(composeLayer) |
| 35 | , mInReorderingSection(inReorderingSection) {} |
| 36 | |
| 37 | RenderNodeDrawable::~RenderNodeDrawable() { |
| 38 | // Just here to move the destructor into the cpp file where we can access RenderNode. |
| 39 | |
| 40 | // TODO: Detangle the header nightmare. |
| 41 | } |
| 42 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 43 | void RenderNodeDrawable::drawBackwardsProjectedNodes(SkCanvas* canvas, |
| 44 | const SkiaDisplayList& displayList, |
| 45 | int nestLevel) { |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 46 | LOG_ALWAYS_FATAL_IF(0 == nestLevel && !displayList.mProjectionReceiver); |
| 47 | for (auto& child : displayList.mChildNodes) { |
| 48 | const RenderProperties& childProperties = child.getNodeProperties(); |
| 49 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 50 | // immediate children cannot be projected on their parent |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 51 | if (childProperties.getProjectBackwards() && nestLevel > 0) { |
| 52 | SkAutoCanvasRestore acr2(canvas, true); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 53 | // Apply recorded matrix, which is a total matrix saved at recording time to avoid |
| 54 | // replaying all DL commands. |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 55 | canvas->concat(child.getRecordedMatrix()); |
| 56 | child.drawContent(canvas); |
| 57 | } |
| 58 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 59 | // skip walking sub-nodes if current display list contains a receiver with exception of |
| 60 | // level 0, which is a known receiver |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 61 | if (0 == nestLevel || !displayList.containsProjectionReceiver()) { |
| 62 | SkAutoCanvasRestore acr(canvas, true); |
| 63 | SkMatrix nodeMatrix; |
| 64 | mat4 hwuiMatrix(child.getRecordedMatrix()); |
| 65 | auto childNode = child.getRenderNode(); |
| 66 | childNode->applyViewPropertyTransforms(hwuiMatrix); |
| 67 | hwuiMatrix.copyTo(nodeMatrix); |
| 68 | canvas->concat(nodeMatrix); |
| 69 | SkiaDisplayList* childDisplayList = static_cast<SkiaDisplayList*>( |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 70 | (const_cast<DisplayList*>(childNode->getDisplayList()))); |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 71 | if (childDisplayList) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 72 | drawBackwardsProjectedNodes(canvas, *childDisplayList, nestLevel + 1); |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 78 | static void clipOutline(const Outline& outline, SkCanvas* canvas, const SkRect* pendingClip) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 79 | Rect possibleRect; |
| 80 | float radius; |
Derek Sollenberger | f209c06 | 2017-05-26 12:11:34 -0400 | [diff] [blame] | 81 | |
| 82 | /* To match the existing HWUI behavior we only supports rectangles or |
| 83 | * rounded rectangles; passing in a more complicated outline fails silently. |
| 84 | */ |
| 85 | if (!outline.getAsRoundRect(&possibleRect, &radius)) { |
| 86 | if (pendingClip) { |
| 87 | canvas->clipRect(*pendingClip); |
| 88 | } |
| 89 | return; |
| 90 | } |
| 91 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 92 | SkRect rect = possibleRect.toSkRect(); |
| 93 | if (radius != 0.0f) { |
| 94 | if (pendingClip && !pendingClip->contains(rect)) { |
| 95 | canvas->clipRect(*pendingClip); |
| 96 | } |
Mike Reed | 6c67f1d | 2016-12-14 10:29:54 -0500 | [diff] [blame] | 97 | canvas->clipRRect(SkRRect::MakeRectXY(rect, radius, radius), SkClipOp::kIntersect, true); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 98 | } else { |
| 99 | if (pendingClip) { |
| 100 | (void)rect.intersect(*pendingClip); |
| 101 | } |
| 102 | canvas->clipRect(rect); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | const RenderProperties& RenderNodeDrawable::getNodeProperties() const { |
| 107 | return mRenderNode->properties(); |
| 108 | } |
| 109 | |
| 110 | void RenderNodeDrawable::onDraw(SkCanvas* canvas) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 111 | // negative and positive Z order are drawn out of order, if this render node drawable is in |
| 112 | // a reordering section |
Stan Iliev | 2f06e8a | 2016-11-02 15:29:03 -0400 | [diff] [blame] | 113 | if ((!mInReorderingSection) || MathUtils::isZero(mRenderNode->properties().getZ())) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 114 | this->forceDraw(canvas); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void RenderNodeDrawable::forceDraw(SkCanvas* canvas) { |
| 119 | RenderNode* renderNode = mRenderNode.get(); |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 120 | if (CC_UNLIKELY(Properties::skpCaptureEnabled)) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 121 | SkRect dimensions = SkRect::MakeWH(renderNode->getWidth(), renderNode->getHeight()); |
| 122 | canvas->drawAnnotation(dimensions, renderNode->getName(), nullptr); |
| 123 | } |
| 124 | |
| 125 | // We only respect the nothingToDraw check when we are composing a layer. This |
| 126 | // ensures that we paint the layer even if it is not currently visible in the |
| 127 | // event that the properties change and it becomes visible. |
Yuqian Li | 5ebbc8e | 2017-11-29 09:53:06 -0500 | [diff] [blame] | 128 | if ((mProjectedDisplayList == nullptr && !renderNode->isRenderable()) || |
| 129 | (renderNode->nothingToDraw() && mComposeLayer)) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 133 | SkiaDisplayList* displayList = (SkiaDisplayList*)renderNode->getDisplayList(); |
| 134 | |
| 135 | SkAutoCanvasRestore acr(canvas, true); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 136 | const RenderProperties& properties = this->getNodeProperties(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 137 | // pass this outline to the children that may clip backward projected nodes |
| 138 | displayList->mProjectedOutline = |
| 139 | displayList->containsProjectionReceiver() ? &properties.getOutline() : nullptr; |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 140 | if (!properties.getProjectBackwards()) { |
| 141 | drawContent(canvas); |
| 142 | if (mProjectedDisplayList) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 143 | acr.restore(); // draw projected children using parent matrix |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 144 | LOG_ALWAYS_FATAL_IF(!mProjectedDisplayList->mProjectedOutline); |
| 145 | const bool shouldClip = mProjectedDisplayList->mProjectedOutline->getPath(); |
| 146 | SkAutoCanvasRestore acr2(canvas, shouldClip); |
Stan Iliev | 54d7032 | 2018-06-14 18:00:10 -0400 | [diff] [blame] | 147 | canvas->setMatrix(mProjectedDisplayList->mParentMatrix); |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 148 | if (shouldClip) { |
| 149 | clipOutline(*mProjectedDisplayList->mProjectedOutline, canvas, nullptr); |
| 150 | } |
| 151 | drawBackwardsProjectedNodes(canvas, *mProjectedDisplayList); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 152 | } |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 153 | } |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 154 | displayList->mProjectedOutline = nullptr; |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 155 | } |
| 156 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 157 | static bool layerNeedsPaint(const LayerProperties& properties, float alphaMultiplier, |
| 158 | SkPaint* paint) { |
Stan Iliev | 7e100e9 | 2018-01-22 10:36:33 -0500 | [diff] [blame] | 159 | paint->setFilterQuality(kLow_SkFilterQuality); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 160 | if (alphaMultiplier < 1.0f || properties.alpha() < 255 || |
Ben Wagner | c1a8a46 | 2018-07-12 12:41:28 -0400 | [diff] [blame] | 161 | properties.xferMode() != SkBlendMode::kSrcOver || properties.getColorFilter() != nullptr) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 162 | paint->setAlpha(properties.alpha() * alphaMultiplier); |
| 163 | paint->setBlendMode(properties.xferMode()); |
Ben Wagner | c1a8a46 | 2018-07-12 12:41:28 -0400 | [diff] [blame] | 164 | paint->setColorFilter(sk_ref_sp(properties.getColorFilter())); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 165 | return true; |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 170 | class AlphaFilterCanvas : public SkPaintFilterCanvas { |
| 171 | public: |
| 172 | AlphaFilterCanvas(SkCanvas* canvas, float alpha) : SkPaintFilterCanvas(canvas), mAlpha(alpha) {} |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 173 | |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 174 | protected: |
| 175 | bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type t) const override { |
Ben Wagner | 1d15533 | 2018-08-20 18:36:05 -0400 | [diff] [blame^] | 176 | std::optional<SkPaint> defaultPaint; |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 177 | if (!*paint) { |
Ben Wagner | 1d15533 | 2018-08-20 18:36:05 -0400 | [diff] [blame^] | 178 | paint->init(defaultPaint.emplace()); |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 179 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 180 | paint->writable()->setAlpha((uint8_t)(*paint)->getAlpha() * mAlpha); |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override { |
| 184 | // We unroll the drawable using "this" canvas, so that draw calls contained inside will |
| 185 | // get their alpha applied. THe default SkPaintFilterCanvas::onDrawDrawable does not unroll. |
| 186 | drawable->draw(this, matrix); |
| 187 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 188 | |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 189 | private: |
| 190 | float mAlpha; |
| 191 | }; |
| 192 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 193 | void RenderNodeDrawable::drawContent(SkCanvas* canvas) const { |
| 194 | RenderNode* renderNode = mRenderNode.get(); |
| 195 | float alphaMultiplier = 1.0f; |
| 196 | const RenderProperties& properties = renderNode->properties(); |
| 197 | |
| 198 | // If we are drawing the contents of layer, we don't want to apply any of |
| 199 | // the RenderNode's properties during this pass. Those will all be applied |
| 200 | // when the layer is composited. |
| 201 | if (mComposeLayer) { |
| 202 | setViewProperties(properties, canvas, &alphaMultiplier); |
| 203 | } |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 204 | SkiaDisplayList* displayList = (SkiaDisplayList*)mRenderNode->getDisplayList(); |
Stan Iliev | 54d7032 | 2018-06-14 18:00:10 -0400 | [diff] [blame] | 205 | displayList->mParentMatrix = canvas->getTotalMatrix(); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 206 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 207 | // TODO should we let the bound of the drawable do this for us? |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 208 | const SkRect bounds = SkRect::MakeWH(properties.getWidth(), properties.getHeight()); |
| 209 | bool quickRejected = properties.getClipToBounds() && canvas->quickReject(bounds); |
| 210 | if (!quickRejected) { |
| 211 | SkiaDisplayList* displayList = (SkiaDisplayList*)renderNode->getDisplayList(); |
| 212 | const LayerProperties& layerProperties = properties.layerProperties(); |
| 213 | // composing a hardware layer |
| 214 | if (renderNode->getLayerSurface() && mComposeLayer) { |
| 215 | SkASSERT(properties.effectiveLayerType() == LayerType::RenderLayer); |
Stan Iliev | 7e100e9 | 2018-01-22 10:36:33 -0500 | [diff] [blame] | 216 | SkPaint paint; |
| 217 | layerNeedsPaint(layerProperties, alphaMultiplier, &paint); |
Derek Sollenberger | 03e6cff7 | 2017-12-04 15:07:08 -0500 | [diff] [blame] | 218 | |
| 219 | // surfaces for layers are created on LAYER_SIZE boundaries (which are >= layer size) so |
| 220 | // we need to restrict the portion of the surface drawn to the size of the renderNode. |
| 221 | SkASSERT(renderNode->getLayerSurface()->width() >= bounds.width()); |
| 222 | SkASSERT(renderNode->getLayerSurface()->height() >= bounds.height()); |
| 223 | canvas->drawImageRect(renderNode->getLayerSurface()->makeImageSnapshot().get(), |
Stan Iliev | 7e100e9 | 2018-01-22 10:36:33 -0500 | [diff] [blame] | 224 | bounds, bounds, &paint); |
Matt Sarett | 79756be | 2016-11-09 16:13:54 -0500 | [diff] [blame] | 225 | |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 226 | if (!renderNode->getSkiaLayer()->hasRenderedSinceRepaint) { |
Matt Sarett | 79756be | 2016-11-09 16:13:54 -0500 | [diff] [blame] | 227 | renderNode->getSkiaLayer()->hasRenderedSinceRepaint = true; |
Matt Sarett | f58cc92 | 2016-11-14 18:33:38 -0500 | [diff] [blame] | 228 | if (CC_UNLIKELY(Properties::debugLayersUpdates)) { |
| 229 | SkPaint layerPaint; |
| 230 | layerPaint.setColor(0x7f00ff00); |
| 231 | canvas->drawRect(bounds, layerPaint); |
| 232 | } else if (CC_UNLIKELY(Properties::debugOverdraw)) { |
| 233 | // Render transparent rect to increment overdraw for repaint area. |
| 234 | // This can be "else if" because flashing green on layer updates |
| 235 | // will also increment the overdraw if it happens to be turned on. |
| 236 | SkPaint transparentPaint; |
| 237 | transparentPaint.setColor(SK_ColorTRANSPARENT); |
| 238 | canvas->drawRect(bounds, transparentPaint); |
| 239 | } |
Matt Sarett | 79756be | 2016-11-09 16:13:54 -0500 | [diff] [blame] | 240 | } |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 241 | } else { |
Stan Iliev | 1843ac7 | 2017-09-20 18:05:35 -0400 | [diff] [blame] | 242 | if (alphaMultiplier < 1.0f) { |
| 243 | // Non-layer draw for a view with getHasOverlappingRendering=false, will apply |
| 244 | // the alpha to the paint of each nested draw. |
| 245 | AlphaFilterCanvas alphaCanvas(canvas, alphaMultiplier); |
| 246 | displayList->draw(&alphaCanvas); |
| 247 | } else { |
| 248 | displayList->draw(canvas); |
| 249 | } |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void RenderNodeDrawable::setViewProperties(const RenderProperties& properties, SkCanvas* canvas, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 255 | float* alphaMultiplier) { |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 256 | if (properties.getLeft() != 0 || properties.getTop() != 0) { |
| 257 | canvas->translate(properties.getLeft(), properties.getTop()); |
| 258 | } |
| 259 | if (properties.getStaticMatrix()) { |
| 260 | canvas->concat(*properties.getStaticMatrix()); |
| 261 | } else if (properties.getAnimationMatrix()) { |
| 262 | canvas->concat(*properties.getAnimationMatrix()); |
| 263 | } |
| 264 | if (properties.hasTransformMatrix()) { |
| 265 | if (properties.isTransformTranslateOnly()) { |
| 266 | canvas->translate(properties.getTranslationX(), properties.getTranslationY()); |
| 267 | } else { |
| 268 | canvas->concat(*properties.getTransformMatrix()); |
| 269 | } |
| 270 | } |
| 271 | const bool isLayer = properties.effectiveLayerType() != LayerType::None; |
| 272 | int clipFlags = properties.getClippingFlags(); |
| 273 | if (properties.getAlpha() < 1) { |
| 274 | if (isLayer) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 275 | clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 276 | } |
| 277 | if (CC_LIKELY(isLayer || !properties.getHasOverlappingRendering())) { |
| 278 | *alphaMultiplier = properties.getAlpha(); |
| 279 | } else { |
| 280 | // savelayer needed to create an offscreen buffer |
| 281 | Rect layerBounds(0, 0, properties.getWidth(), properties.getHeight()); |
| 282 | if (clipFlags) { |
| 283 | properties.getClippingRectForFlags(clipFlags, &layerBounds); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 284 | clipFlags = 0; // all clipping done by savelayer |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 285 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 286 | SkRect bounds = SkRect::MakeLTRB(layerBounds.left, layerBounds.top, layerBounds.right, |
| 287 | layerBounds.bottom); |
| 288 | canvas->saveLayerAlpha(&bounds, (int)(properties.getAlpha() * 255)); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | if (CC_UNLIKELY(ATRACE_ENABLED() && properties.promotedToLayer())) { |
| 292 | // pretend alpha always causes savelayer to warn about |
| 293 | // performance problem affecting old versions |
| 294 | ATRACE_FORMAT("alpha caused saveLayer %dx%d", properties.getWidth(), |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 295 | properties.getHeight()); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | const SkRect* pendingClip = nullptr; |
| 300 | SkRect clipRect; |
| 301 | |
| 302 | if (clipFlags) { |
| 303 | Rect tmpRect; |
| 304 | properties.getClippingRectForFlags(clipFlags, &tmpRect); |
| 305 | clipRect = tmpRect.toSkRect(); |
| 306 | pendingClip = &clipRect; |
| 307 | } |
| 308 | |
| 309 | if (properties.getRevealClip().willClip()) { |
Mike Reed | 6c67f1d | 2016-12-14 10:29:54 -0500 | [diff] [blame] | 310 | canvas->clipPath(*properties.getRevealClip().getPath(), SkClipOp::kIntersect, true); |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 311 | } else if (properties.getOutline().willClip()) { |
| 312 | clipOutline(properties.getOutline(), canvas, pendingClip); |
| 313 | pendingClip = nullptr; |
| 314 | } |
| 315 | |
| 316 | if (pendingClip) { |
| 317 | canvas->clipRect(*pendingClip); |
| 318 | } |
| 319 | } |
| 320 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 321 | }; // namespace skiapipeline |
| 322 | }; // namespace uirenderer |
| 323 | }; // namespace android |