John Reck | acb6f07 | 2014-03-12 16:11:23 -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 | */ |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 18 | |
Jerome Gaillard | 8f6d6e0 | 2024-02-26 18:56:00 +0000 | [diff] [blame] | 19 | #include <SkBlendMode.h> |
| 20 | #include <SkCamera.h> |
| 21 | #include <SkColor.h> |
| 22 | #include <SkImageFilter.h> |
| 23 | #include <SkMatrix.h> |
| 24 | #include <SkRegion.h> |
| 25 | #include <androidfw/ResourceTypes.h> |
| 26 | #include <cutils/compiler.h> |
| 27 | #include <stddef.h> |
| 28 | #include <utils/Log.h> |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 29 | |
Jerome Gaillard | 8f6d6e0 | 2024-02-26 18:56:00 +0000 | [diff] [blame] | 30 | #include <algorithm> |
| 31 | #include <ostream> |
| 32 | #include <vector> |
| 33 | |
| 34 | #include "DeviceInfo.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 35 | #include "Outline.h" |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 36 | #include "Rect.h" |
| 37 | #include "RevealClip.h" |
John Reck | 5cb290b | 2021-02-01 13:47:31 -0500 | [diff] [blame] | 38 | #include "effects/StretchEffect.h" |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 39 | #include "utils/MathUtils.h" |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 40 | #include "utils/PaintUtils.h" |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 41 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 42 | class SkBitmap; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 43 | class SkColorFilter; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 44 | class SkPaint; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 45 | |
| 46 | namespace android { |
| 47 | namespace uirenderer { |
| 48 | |
| 49 | class Matrix4; |
| 50 | class RenderNode; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 51 | class RenderProperties; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 52 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 53 | // The __VA_ARGS__ will be executed if a & b are not equal |
Chih-Hung Hsieh | cef190d | 2016-05-19 15:25:50 -0700 | [diff] [blame] | 54 | #define RP_SET(a, b, ...) ((a) != (b) ? ((a) = (b), ##__VA_ARGS__, true) : false) |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 55 | #define RP_SET_AND_DIRTY(a, b) RP_SET(a, b, mPrimitiveFields.mMatrixOrPivotDirty = true) |
| 56 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 57 | // Keep in sync with View.java:LAYER_TYPE_* |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 58 | enum class LayerType { |
| 59 | None = 0, |
Derek Sollenberger | 52230bc | 2018-02-16 12:24:13 -0500 | [diff] [blame] | 60 | // We cannot build the software layer directly (must be done at record time) and all management |
| 61 | // of software layers is handled in Java. |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 62 | Software = 1, |
| 63 | RenderLayer = 2, |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 66 | enum ClippingFlags { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 67 | CLIP_TO_BOUNDS = 0x1 << 0, |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 68 | CLIP_TO_CLIP_BOUNDS = 0x1 << 1, |
| 69 | }; |
| 70 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 71 | class LayerProperties { |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 72 | public: |
| 73 | bool setType(LayerType type) { |
| 74 | if (RP_SET(mType, type)) { |
| 75 | reset(); |
| 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 81 | bool setOpaque(bool opaque) { return RP_SET(mOpaque, opaque); } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 82 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 83 | bool opaque() const { return mOpaque; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 84 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 85 | bool setAlpha(uint8_t alpha) { return RP_SET(mAlpha, alpha); } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 86 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 87 | uint8_t alpha() const { return mAlpha; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 88 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 89 | bool setXferMode(SkBlendMode mode) { return RP_SET(mMode, mode); } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 90 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 91 | SkBlendMode xferMode() const { return mMode; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 92 | |
Ben Wagner | c1a8a46 | 2018-07-12 12:41:28 -0400 | [diff] [blame] | 93 | SkColorFilter* getColorFilter() const { return mColorFilter.get(); } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 94 | |
Nader Jawad | 390d6e8 | 2020-09-24 21:35:03 -0700 | [diff] [blame] | 95 | bool setImageFilter(SkImageFilter* imageFilter); |
| 96 | |
Dongya Jiang | e2b9938 | 2022-02-28 21:35:57 +0800 | [diff] [blame] | 97 | bool setBackdropImageFilter(SkImageFilter* imageFilter); |
| 98 | |
Nader Jawad | 390d6e8 | 2020-09-24 21:35:03 -0700 | [diff] [blame] | 99 | SkImageFilter* getImageFilter() const { return mImageFilter.get(); } |
| 100 | |
Dongya Jiang | e2b9938 | 2022-02-28 21:35:57 +0800 | [diff] [blame] | 101 | SkImageFilter* getBackdropImageFilter() const { return mBackdropImageFilter.get(); } |
| 102 | |
John Reck | 5cb290b | 2021-02-01 13:47:31 -0500 | [diff] [blame] | 103 | const StretchEffect& getStretchEffect() const { return mStretchEffect; } |
| 104 | |
| 105 | StretchEffect& mutableStretchEffect() { return mStretchEffect; } |
| 106 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 107 | // Sets alpha, xfermode, and colorfilter from an SkPaint |
| 108 | // paint may be NULL, in which case defaults will be set |
| 109 | bool setFromPaint(const SkPaint* paint); |
| 110 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 111 | bool needsBlending() const { return !opaque() || alpha() < 255; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 112 | |
| 113 | LayerProperties& operator=(const LayerProperties& other); |
| 114 | |
John Reck | 470a919 | 2018-12-17 10:55:54 -0800 | [diff] [blame] | 115 | // Strongly recommend using effectiveLayerType instead |
| 116 | LayerType type() const { return mType; } |
| 117 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 118 | private: |
| 119 | LayerProperties(); |
| 120 | ~LayerProperties(); |
| 121 | void reset(); |
Ben Wagner | c1a8a46 | 2018-07-12 12:41:28 -0400 | [diff] [blame] | 122 | bool setColorFilter(SkColorFilter* filter); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 123 | |
| 124 | friend class RenderProperties; |
| 125 | |
Chris Craik | 182952f | 2015-03-09 14:17:29 -0700 | [diff] [blame] | 126 | LayerType mType = LayerType::None; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 127 | // Whether or not that Layer's content is opaque, doesn't include alpha |
| 128 | bool mOpaque; |
| 129 | uint8_t mAlpha; |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 130 | SkBlendMode mMode; |
Ben Wagner | c1a8a46 | 2018-07-12 12:41:28 -0400 | [diff] [blame] | 131 | sk_sp<SkColorFilter> mColorFilter; |
Nader Jawad | 390d6e8 | 2020-09-24 21:35:03 -0700 | [diff] [blame] | 132 | sk_sp<SkImageFilter> mImageFilter; |
Dongya Jiang | e2b9938 | 2022-02-28 21:35:57 +0800 | [diff] [blame] | 133 | sk_sp<SkImageFilter> mBackdropImageFilter; |
John Reck | 5cb290b | 2021-02-01 13:47:31 -0500 | [diff] [blame] | 134 | StretchEffect mStretchEffect; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 137 | /* |
| 138 | * Data structure that holds the properties for a RenderNode |
| 139 | */ |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 140 | class RenderProperties { |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 141 | public: |
| 142 | RenderProperties(); |
| 143 | virtual ~RenderProperties(); |
| 144 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 145 | static bool setFlag(int flag, bool newValue, int* outFlags) { |
| 146 | if (newValue) { |
| 147 | if (!(flag & *outFlags)) { |
| 148 | *outFlags |= flag; |
| 149 | return true; |
| 150 | } |
| 151 | return false; |
| 152 | } else { |
| 153 | if (flag & *outFlags) { |
| 154 | *outFlags &= ~flag; |
| 155 | return true; |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | } |
| 160 | |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 161 | /** |
| 162 | * Set internal layer state based on whether this layer |
| 163 | * |
| 164 | * Additionally, returns true if child RenderNodes with functors will need to use a layer |
| 165 | * to support clipping. |
| 166 | */ |
| 167 | bool prepareForFunctorPresence(bool willHaveFunctor, bool ancestorDictatesFunctorsNeedLayer) { |
| 168 | // parent may have already dictated that a descendant layer is needed |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 169 | bool functorsNeedLayer = |
Chet Haase | 33c1ea7 | 2021-09-27 20:56:08 +0000 | [diff] [blame] | 170 | ancestorDictatesFunctorsNeedLayer || |
| 171 | CC_UNLIKELY(isClipMayBeComplex()) |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 172 | |
| 173 | // Round rect clipping forces layer for functors |
Chet Haase | 33c1ea7 | 2021-09-27 20:56:08 +0000 | [diff] [blame] | 174 | || CC_UNLIKELY(getOutline().willComplexClip()) || |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 175 | CC_UNLIKELY(getRevealClip().willClip()) |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 176 | |
| 177 | // Complex matrices forces layer, due to stencil clipping |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 178 | || CC_UNLIKELY(getTransformMatrix() && !getTransformMatrix()->isScaleTranslate()) || |
| 179 | CC_UNLIKELY(getAnimationMatrix() && !getAnimationMatrix()->isScaleTranslate()) || |
| 180 | CC_UNLIKELY(getStaticMatrix() && !getStaticMatrix()->isScaleTranslate()); |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 181 | |
| 182 | mComputedFields.mNeedLayerForFunctors = (willHaveFunctor && functorsNeedLayer); |
| 183 | |
| 184 | // If on a layer, will have consumed the need for isolating functors from stencil. |
| 185 | // Thus, it's safe to reset the flag until some descendent sets it. |
| 186 | return CC_LIKELY(effectiveLayerType() == LayerType::None) && functorsNeedLayer; |
| 187 | } |
| 188 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 189 | RenderProperties& operator=(const RenderProperties& other); |
| 190 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 191 | bool setClipToBounds(bool clipToBounds) { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 192 | return setFlag(CLIP_TO_BOUNDS, clipToBounds, &mPrimitiveFields.mClippingFlags); |
| 193 | } |
| 194 | |
| 195 | bool setClipBounds(const Rect& clipBounds) { |
| 196 | bool ret = setFlag(CLIP_TO_CLIP_BOUNDS, true, &mPrimitiveFields.mClippingFlags); |
| 197 | return RP_SET(mPrimitiveFields.mClipBounds, clipBounds) || ret; |
| 198 | } |
| 199 | |
| 200 | bool setClipBoundsEmpty() { |
| 201 | return setFlag(CLIP_TO_CLIP_BOUNDS, false, &mPrimitiveFields.mClippingFlags); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 202 | } |
| 203 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 204 | bool setProjectBackwards(bool shouldProject) { |
| 205 | return RP_SET(mPrimitiveFields.mProjectBackwards, shouldProject); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 208 | bool setProjectionReceiver(bool shouldReceive) { |
| 209 | return RP_SET(mPrimitiveFields.mProjectionReceiver, shouldReceive); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 210 | } |
| 211 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 212 | bool isProjectionReceiver() const { return mPrimitiveFields.mProjectionReceiver; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 213 | |
Stan Iliev | f09ee58 | 2018-11-06 17:35:50 -0500 | [diff] [blame] | 214 | bool setClipMayBeComplex(bool isClipMayBeComplex) { |
| 215 | return RP_SET(mPrimitiveFields.mClipMayBeComplex, isClipMayBeComplex); |
| 216 | } |
| 217 | |
| 218 | bool isClipMayBeComplex() const { return mPrimitiveFields.mClipMayBeComplex; } |
| 219 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 220 | bool setStaticMatrix(const SkMatrix* matrix) { |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 221 | delete mStaticMatrix; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 222 | if (matrix) { |
| 223 | mStaticMatrix = new SkMatrix(*matrix); |
| 224 | } else { |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 225 | mStaticMatrix = nullptr; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 226 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 227 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // Can return NULL |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 231 | const SkMatrix* getStaticMatrix() const { return mStaticMatrix; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 232 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 233 | bool setAnimationMatrix(const SkMatrix* matrix) { |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 234 | delete mAnimationMatrix; |
| 235 | if (matrix) { |
| 236 | mAnimationMatrix = new SkMatrix(*matrix); |
| 237 | } else { |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 238 | mAnimationMatrix = nullptr; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 239 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 240 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 241 | } |
| 242 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 243 | bool setAlpha(float alpha) { |
John Reck | 3b52c03 | 2014-08-06 10:19:32 -0700 | [diff] [blame] | 244 | alpha = MathUtils::clampAlpha(alpha); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 245 | return RP_SET(mPrimitiveFields.mAlpha, alpha); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 246 | } |
| 247 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 248 | float getAlpha() const { return mPrimitiveFields.mAlpha; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 249 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 250 | bool setHasOverlappingRendering(bool hasOverlappingRendering) { |
| 251 | return RP_SET(mPrimitiveFields.mHasOverlappingRendering, hasOverlappingRendering); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 252 | } |
| 253 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 254 | bool hasOverlappingRendering() const { return mPrimitiveFields.mHasOverlappingRendering; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 255 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 256 | bool setElevation(float elevation) { |
| 257 | return RP_SET(mPrimitiveFields.mElevation, elevation); |
| 258 | // Don't dirty matrix/pivot, since they don't respect Z |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 259 | } |
| 260 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 261 | float getElevation() const { return mPrimitiveFields.mElevation; } |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 262 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 263 | bool setTranslationX(float translationX) { |
| 264 | return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationX, translationX); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 265 | } |
| 266 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 267 | float getTranslationX() const { return mPrimitiveFields.mTranslationX; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 268 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 269 | bool setTranslationY(float translationY) { |
| 270 | return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationY, translationY); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 271 | } |
| 272 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 273 | float getTranslationY() const { return mPrimitiveFields.mTranslationY; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 274 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 275 | bool setTranslationZ(float translationZ) { |
| 276 | return RP_SET(mPrimitiveFields.mTranslationZ, translationZ); |
| 277 | // mMatrixOrPivotDirty not set, since matrix doesn't respect Z |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 278 | } |
| 279 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 280 | float getTranslationZ() const { return mPrimitiveFields.mTranslationZ; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 281 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 282 | // Animation helper |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 283 | bool setX(float value) { return setTranslationX(value - getLeft()); } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 284 | |
| 285 | // Animation helper |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 286 | float getX() const { return getLeft() + getTranslationX(); } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 287 | |
| 288 | // Animation helper |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 289 | bool setY(float value) { return setTranslationY(value - getTop()); } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 290 | |
| 291 | // Animation helper |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 292 | float getY() const { return getTop() + getTranslationY(); } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 293 | |
| 294 | // Animation helper |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 295 | bool setZ(float value) { return setTranslationZ(value - getElevation()); } |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 296 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 297 | float getZ() const { return getElevation() + getTranslationZ(); } |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame] | 298 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 299 | bool setRotation(float rotation) { |
| 300 | return RP_SET_AND_DIRTY(mPrimitiveFields.mRotation, rotation); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 301 | } |
| 302 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 303 | float getRotation() const { return mPrimitiveFields.mRotation; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 304 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 305 | bool setRotationX(float rotationX) { |
| 306 | return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationX, rotationX); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 307 | } |
| 308 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 309 | float getRotationX() const { return mPrimitiveFields.mRotationX; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 310 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 311 | bool setRotationY(float rotationY) { |
| 312 | return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationY, rotationY); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 313 | } |
| 314 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 315 | float getRotationY() const { return mPrimitiveFields.mRotationY; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 316 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 317 | bool setScaleX(float scaleX) { return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX); } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 318 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 319 | float getScaleX() const { return mPrimitiveFields.mScaleX; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 320 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 321 | bool setScaleY(float scaleY) { return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY); } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 322 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 323 | float getScaleY() const { return mPrimitiveFields.mScaleY; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 324 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 325 | bool setPivotX(float pivotX) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 326 | if (RP_SET(mPrimitiveFields.mPivotX, pivotX) || !mPrimitiveFields.mPivotExplicitlySet) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 327 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 328 | mPrimitiveFields.mPivotExplicitlySet = true; |
| 329 | return true; |
| 330 | } |
| 331 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 332 | } |
| 333 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 334 | /* Note that getPivotX and getPivotY are adjusted by updateMatrix(), |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 335 | * so the value returned may be stale if the RenderProperties has been |
| 336 | * modified since the last call to updateMatrix() |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 337 | */ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 338 | float getPivotX() const { return mPrimitiveFields.mPivotX; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 339 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 340 | bool setPivotY(float pivotY) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 341 | if (RP_SET(mPrimitiveFields.mPivotY, pivotY) || !mPrimitiveFields.mPivotExplicitlySet) { |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 342 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
| 343 | mPrimitiveFields.mPivotExplicitlySet = true; |
| 344 | return true; |
| 345 | } |
| 346 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 347 | } |
| 348 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 349 | float getPivotY() const { return mPrimitiveFields.mPivotY; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 350 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 351 | bool isPivotExplicitlySet() const { return mPrimitiveFields.mPivotExplicitlySet; } |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 352 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 353 | bool resetPivot() { return RP_SET_AND_DIRTY(mPrimitiveFields.mPivotExplicitlySet, false); } |
John Reck | 8686e1f | 2018-03-21 16:31:21 -0700 | [diff] [blame] | 354 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 355 | bool setCameraDistance(float distance) { |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 356 | if (distance != getCameraDistance()) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 357 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 358 | mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance); |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 359 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 360 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 361 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | float getCameraDistance() const { |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 365 | // TODO: update getCameraLocationZ() to be const |
| 366 | return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ(); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 367 | } |
| 368 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 369 | bool setLeft(int left) { |
| 370 | if (RP_SET(mPrimitiveFields.mLeft, left)) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 371 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 372 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 373 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 374 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 375 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 376 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 377 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 378 | } |
| 379 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 380 | int getLeft() const { return mPrimitiveFields.mLeft; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 381 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 382 | bool setTop(int top) { |
| 383 | if (RP_SET(mPrimitiveFields.mTop, top)) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 384 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 385 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 386 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 387 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 388 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 389 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 390 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 391 | } |
| 392 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 393 | int getTop() const { return mPrimitiveFields.mTop; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 394 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 395 | bool setRight(int right) { |
| 396 | if (RP_SET(mPrimitiveFields.mRight, right)) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 397 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 398 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 399 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 400 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 401 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 402 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 403 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 404 | } |
| 405 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 406 | int getRight() const { return mPrimitiveFields.mRight; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 407 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 408 | bool setBottom(int bottom) { |
| 409 | if (RP_SET(mPrimitiveFields.mBottom, bottom)) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 410 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 411 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 412 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 413 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 414 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 415 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 416 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 417 | } |
| 418 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 419 | int getBottom() const { return mPrimitiveFields.mBottom; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 420 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 421 | bool setLeftTop(int left, int top) { |
| 422 | bool leftResult = setLeft(left); |
| 423 | bool topResult = setTop(top); |
| 424 | return leftResult || topResult; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 425 | } |
| 426 | |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 427 | bool setLeftTopRightBottom(int left, int top, int right, int bottom) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 428 | if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop || |
| 429 | right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 430 | mPrimitiveFields.mLeft = left; |
| 431 | mPrimitiveFields.mTop = top; |
| 432 | mPrimitiveFields.mRight = right; |
| 433 | mPrimitiveFields.mBottom = bottom; |
| 434 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 435 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 436 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 437 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 438 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 439 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 440 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 441 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 444 | bool offsetLeftRight(int offset) { |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 445 | if (offset != 0) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 446 | mPrimitiveFields.mLeft += offset; |
| 447 | mPrimitiveFields.mRight += offset; |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 448 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 449 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 450 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 453 | bool offsetTopBottom(int offset) { |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 454 | if (offset != 0) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 455 | mPrimitiveFields.mTop += offset; |
| 456 | mPrimitiveFields.mBottom += offset; |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 457 | return true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 458 | } |
John Reck | 79c7de7 | 2014-05-23 10:33:31 -0700 | [diff] [blame] | 459 | return false; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 460 | } |
| 461 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 462 | int getWidth() const { return mPrimitiveFields.mWidth; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 463 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 464 | int getHeight() const { return mPrimitiveFields.mHeight; } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 465 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 466 | const SkMatrix* getAnimationMatrix() const { return mAnimationMatrix; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 467 | |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 468 | bool hasTransformMatrix() const { |
| 469 | return getTransformMatrix() && !getTransformMatrix()->isIdentity(); |
| 470 | } |
| 471 | |
| 472 | // May only call this if hasTransformMatrix() is true |
| 473 | bool isTransformTranslateOnly() const { |
| 474 | return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 477 | const SkMatrix* getTransformMatrix() const { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 478 | LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!"); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 479 | return mComputedFields.mTransformMatrix; |
| 480 | } |
| 481 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 482 | int getClippingFlags() const { return mPrimitiveFields.mClippingFlags; } |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 483 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 484 | bool getClipToBounds() const { return mPrimitiveFields.mClippingFlags & CLIP_TO_BOUNDS; } |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 485 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 486 | const Rect& getClipBounds() const { return mPrimitiveFields.mClipBounds; } |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 487 | |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 488 | void getClippingRectForFlags(uint32_t flags, Rect* outRect) const { |
| 489 | if (flags & CLIP_TO_BOUNDS) { |
| 490 | outRect->set(0, 0, getWidth(), getHeight()); |
| 491 | if (flags & CLIP_TO_CLIP_BOUNDS) { |
Chris Craik | ac02eb9 | 2015-10-05 12:23:46 -0700 | [diff] [blame] | 492 | outRect->doIntersect(mPrimitiveFields.mClipBounds); |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 493 | } |
| 494 | } else { |
| 495 | outRect->set(mPrimitiveFields.mClipBounds); |
| 496 | } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 497 | } |
| 498 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 499 | bool getHasOverlappingRendering() const { return mPrimitiveFields.mHasOverlappingRendering; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 500 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 501 | const Outline& getOutline() const { return mPrimitiveFields.mOutline; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 502 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 503 | const RevealClip& getRevealClip() const { return mPrimitiveFields.mRevealClip; } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 504 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 505 | bool getProjectBackwards() const { return mPrimitiveFields.mProjectBackwards; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 506 | |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 507 | void debugOutputProperties(std::ostream& output, const int level) const; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 508 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 509 | void updateMatrix(); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 510 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 511 | Outline& mutableOutline() { return mPrimitiveFields.mOutline; } |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 512 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 513 | RevealClip& mutableRevealClip() { return mPrimitiveFields.mRevealClip; } |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 514 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 515 | const LayerProperties& layerProperties() const { return mLayerProperties; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 516 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 517 | LayerProperties& mutateLayerProperties() { return mLayerProperties; } |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 518 | |
John Reck | 293e868 | 2014-06-17 10:34:02 -0700 | [diff] [blame] | 519 | // Returns true if damage calculations should be clipped to bounds |
| 520 | // TODO: Figure out something better for getZ(), as children should still be |
| 521 | // clipped to this RP's bounds. But as we will damage -INT_MAX to INT_MAX |
| 522 | // for this RP's getZ() anyway, this can be optimized when we have a |
| 523 | // Z damage estimate instead of INT_MAX |
| 524 | bool getClipDamageToBounds() const { |
| 525 | return getClipToBounds() && (getZ() <= 0 || getOutline().isEmpty()); |
| 526 | } |
| 527 | |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 528 | bool hasShadow() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 529 | return getZ() > 0.0f && getOutline().getPath() != nullptr && |
| 530 | getOutline().getAlpha() != 0.0f; |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 531 | } |
| 532 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 533 | SkColor getSpotShadowColor() const { return mPrimitiveFields.mSpotShadowColor; } |
John Reck | 3c0369b | 2017-11-13 16:47:35 -0800 | [diff] [blame] | 534 | |
John Reck | d8be4a0 | 2017-11-17 15:06:24 -0800 | [diff] [blame] | 535 | bool setSpotShadowColor(SkColor shadowColor) { |
| 536 | return RP_SET(mPrimitiveFields.mSpotShadowColor, shadowColor); |
| 537 | } |
| 538 | |
John Reck | e170fb6 | 2018-05-07 08:12:07 -0700 | [diff] [blame] | 539 | SkColor getAmbientShadowColor() const { return mPrimitiveFields.mAmbientShadowColor; } |
John Reck | d8be4a0 | 2017-11-17 15:06:24 -0800 | [diff] [blame] | 540 | |
| 541 | bool setAmbientShadowColor(SkColor shadowColor) { |
| 542 | return RP_SET(mPrimitiveFields.mAmbientShadowColor, shadowColor); |
John Reck | 3c0369b | 2017-11-13 16:47:35 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 545 | bool fitsOnLayer() const { |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 546 | const DeviceInfo* deviceInfo = DeviceInfo::get(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 547 | return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() && |
John Reck | 1895e2e | 2024-11-13 11:48:29 -0500 | [diff] [blame] | 548 | mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize() && |
| 549 | mPrimitiveFields.mWidth > 0 && mPrimitiveFields.mHeight > 0; |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | bool promotedToLayer() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 553 | return mLayerProperties.mType == LayerType::None && fitsOnLayer() && |
Nader Jawad | 6701a60 | 2021-02-23 18:14:22 -0800 | [diff] [blame] | 554 | (mComputedFields.mNeedLayerForFunctors || mLayerProperties.mImageFilter != nullptr || |
John Reck | 09d9cca | 2021-05-10 19:34:58 -0400 | [diff] [blame] | 555 | mLayerProperties.getStretchEffect().requiresLayer() || |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 556 | (!MathUtils::isZero(mPrimitiveFields.mAlpha) && mPrimitiveFields.mAlpha < 1 && |
| 557 | mPrimitiveFields.mHasOverlappingRendering)); |
Chris Craik | 1a0808e | 2015-05-13 16:33:04 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | LayerType effectiveLayerType() const { |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 561 | return CC_UNLIKELY(promotedToLayer()) ? LayerType::RenderLayer : mLayerProperties.mType; |
Chris Craik | 856f0cc | 2015-04-21 15:13:29 -0700 | [diff] [blame] | 562 | } |
| 563 | |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 564 | bool setAllowForceDark(bool allow) { |
| 565 | return RP_SET(mPrimitiveFields.mAllowForceDark, allow); |
| 566 | } |
| 567 | |
| 568 | bool getAllowForceDark() const { |
| 569 | return mPrimitiveFields.mAllowForceDark; |
| 570 | } |
| 571 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 572 | private: |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 573 | // Rendering properties |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 574 | struct PrimitiveFields { |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 575 | int mLeft = 0, mTop = 0, mRight = 0, mBottom = 0; |
| 576 | int mWidth = 0, mHeight = 0; |
| 577 | int mClippingFlags = CLIP_TO_BOUNDS; |
John Reck | d8be4a0 | 2017-11-17 15:06:24 -0800 | [diff] [blame] | 578 | SkColor mSpotShadowColor = SK_ColorBLACK; |
| 579 | SkColor mAmbientShadowColor = SK_ColorBLACK; |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 580 | float mAlpha = 1; |
| 581 | float mTranslationX = 0, mTranslationY = 0, mTranslationZ = 0; |
| 582 | float mElevation = 0; |
| 583 | float mRotation = 0, mRotationX = 0, mRotationY = 0; |
| 584 | float mScaleX = 1, mScaleY = 1; |
| 585 | float mPivotX = 0, mPivotY = 0; |
| 586 | bool mHasOverlappingRendering = false; |
| 587 | bool mPivotExplicitlySet = false; |
| 588 | bool mMatrixOrPivotDirty = false; |
| 589 | bool mProjectBackwards = false; |
| 590 | bool mProjectionReceiver = false; |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 591 | bool mAllowForceDark = true; |
Stan Iliev | f09ee58 | 2018-11-06 17:35:50 -0500 | [diff] [blame] | 592 | bool mClipMayBeComplex = false; |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 593 | Rect mClipBounds; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 594 | Outline mOutline; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 595 | RevealClip mRevealClip; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 596 | } mPrimitiveFields; |
| 597 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 598 | SkMatrix* mStaticMatrix; |
| 599 | SkMatrix* mAnimationMatrix; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 600 | LayerProperties mLayerProperties; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 601 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 602 | /** |
| 603 | * These fields are all generated from other properties and are not set directly. |
| 604 | */ |
| 605 | struct ComputedFields { |
| 606 | ComputedFields(); |
| 607 | ~ComputedFields(); |
| 608 | |
| 609 | /** |
| 610 | * Stores the total transformation of the DisplayList based upon its scalar |
| 611 | * translate/rotate/scale properties. |
| 612 | * |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 613 | * In the common translation-only case, the matrix isn't necessarily allocated, |
| 614 | * and the mTranslation properties are used directly. |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 615 | */ |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 616 | SkMatrix* mTransformMatrix; |
| 617 | |
| 618 | Sk3DView mTransformCamera; |
Chris Craik | a766cb2 | 2015-06-08 16:49:43 -0700 | [diff] [blame] | 619 | |
| 620 | // Force layer on for functors to enable render features they don't yet support (clipping) |
| 621 | bool mNeedLayerForFunctors = false; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 622 | } mComputedFields; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | } /* namespace uirenderer */ |
| 626 | } /* namespace android */ |