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