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