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