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