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