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