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