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