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