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