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