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