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