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 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 108 | void setElevation(float elevation) { |
| 109 | if (elevation != mPrimitiveFields.mElevation) { |
| 110 | mPrimitiveFields.mElevation = elevation; |
| 111 | // mMatrixOrPivotDirty not set, since matrix doesn't respect Z |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | float getElevation() const { |
| 116 | return mPrimitiveFields.mElevation; |
| 117 | } |
| 118 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 119 | void setTranslationX(float translationX) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 120 | if (translationX != mPrimitiveFields.mTranslationX) { |
| 121 | mPrimitiveFields.mTranslationX = translationX; |
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 getTranslationX() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 127 | return mPrimitiveFields.mTranslationX; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void setTranslationY(float translationY) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 131 | if (translationY != mPrimitiveFields.mTranslationY) { |
| 132 | mPrimitiveFields.mTranslationY = translationY; |
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 getTranslationY() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 138 | return mPrimitiveFields.mTranslationY; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void setTranslationZ(float translationZ) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 142 | if (translationZ != mPrimitiveFields.mTranslationZ) { |
| 143 | mPrimitiveFields.mTranslationZ = translationZ; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 144 | // mMatrixOrPivotDirty not set, since matrix doesn't respect Z |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | float getTranslationZ() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 149 | return mPrimitiveFields.mTranslationZ; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 152 | float getZ() const { |
| 153 | return getElevation() + getTranslationZ(); |
| 154 | } |
| 155 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 156 | void setRotation(float rotation) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 157 | if (rotation != mPrimitiveFields.mRotation) { |
| 158 | mPrimitiveFields.mRotation = rotation; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 159 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | float getRotation() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 164 | return mPrimitiveFields.mRotation; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void setRotationX(float rotationX) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 168 | if (rotationX != mPrimitiveFields.mRotationX) { |
| 169 | mPrimitiveFields.mRotationX = rotationX; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 170 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| 174 | float getRotationX() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 175 | return mPrimitiveFields.mRotationX; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void setRotationY(float rotationY) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 179 | if (rotationY != mPrimitiveFields.mRotationY) { |
| 180 | mPrimitiveFields.mRotationY = rotationY; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 181 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | float getRotationY() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 186 | return mPrimitiveFields.mRotationY; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void setScaleX(float scaleX) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 190 | if (scaleX != mPrimitiveFields.mScaleX) { |
| 191 | mPrimitiveFields.mScaleX = scaleX; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 192 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | float getScaleX() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 197 | return mPrimitiveFields.mScaleX; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void setScaleY(float scaleY) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 201 | if (scaleY != mPrimitiveFields.mScaleY) { |
| 202 | mPrimitiveFields.mScaleY = scaleY; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 203 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | float getScaleY() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 208 | return mPrimitiveFields.mScaleY; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void setPivotX(float pivotX) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 212 | mPrimitiveFields.mPivotX = pivotX; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 213 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 214 | mPrimitiveFields.mPivotExplicitlySet = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 215 | } |
| 216 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 217 | /* Note that getPivotX and getPivotY are adjusted by updateMatrix(), |
| 218 | * so the value returned mPrimitiveFields.may be stale if the RenderProperties has been |
| 219 | * mPrimitiveFields.modified since the last call to updateMatrix() |
| 220 | */ |
| 221 | float getPivotX() const { |
| 222 | return mPrimitiveFields.mPivotX; |
| 223 | } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 224 | |
| 225 | void setPivotY(float pivotY) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 226 | mPrimitiveFields.mPivotY = pivotY; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 227 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 228 | mPrimitiveFields.mPivotExplicitlySet = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 229 | } |
| 230 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 231 | float getPivotY() const { |
| 232 | return mPrimitiveFields.mPivotY; |
| 233 | } |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 234 | |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 235 | bool isPivotExplicitlySet() const { |
| 236 | return mPrimitiveFields.mPivotExplicitlySet; |
| 237 | } |
| 238 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 239 | void setCameraDistance(float distance) { |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 240 | if (distance != getCameraDistance()) { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 241 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 242 | mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | float getCameraDistance() const { |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 247 | // TODO: update getCameraLocationZ() to be const |
| 248 | return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ(); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void setLeft(int left) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 252 | if (left != mPrimitiveFields.mLeft) { |
| 253 | mPrimitiveFields.mLeft = left; |
| 254 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 255 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 256 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | float getLeft() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 262 | return mPrimitiveFields.mLeft; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void setTop(int top) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 266 | if (top != mPrimitiveFields.mTop) { |
| 267 | mPrimitiveFields.mTop = top; |
| 268 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 269 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 270 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | float getTop() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 276 | return mPrimitiveFields.mTop; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void setRight(int right) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 280 | if (right != mPrimitiveFields.mRight) { |
| 281 | mPrimitiveFields.mRight = right; |
| 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 getRight() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 290 | return mPrimitiveFields.mRight; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void setBottom(int bottom) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 294 | if (bottom != mPrimitiveFields.mBottom) { |
| 295 | mPrimitiveFields.mBottom = bottom; |
| 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 getBottom() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 304 | return mPrimitiveFields.mBottom; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void setLeftTop(int left, int top) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 308 | if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop) { |
| 309 | mPrimitiveFields.mLeft = left; |
| 310 | mPrimitiveFields.mTop = top; |
| 311 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 312 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 313 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 314 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void setLeftTopRightBottom(int left, int top, int right, int bottom) { |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 320 | if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop |
| 321 | || right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 322 | mPrimitiveFields.mLeft = left; |
| 323 | mPrimitiveFields.mTop = top; |
| 324 | mPrimitiveFields.mRight = right; |
| 325 | mPrimitiveFields.mBottom = bottom; |
| 326 | mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft; |
| 327 | mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 328 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 329 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void offsetLeftRight(float offset) { |
| 335 | if (offset != 0) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 336 | mPrimitiveFields.mLeft += offset; |
| 337 | mPrimitiveFields.mRight += offset; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 338 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 339 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void offsetTopBottom(float offset) { |
| 345 | if (offset != 0) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 346 | mPrimitiveFields.mTop += offset; |
| 347 | mPrimitiveFields.mBottom += offset; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 348 | if (!mPrimitiveFields.mPivotExplicitlySet) { |
| 349 | mPrimitiveFields.mMatrixOrPivotDirty = true; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | void setCaching(bool caching) { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 355 | mPrimitiveFields.mCaching = caching; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 358 | int getWidth() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 359 | return mPrimitiveFields.mWidth; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 362 | int getHeight() const { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 363 | return mPrimitiveFields.mHeight; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 364 | } |
| 365 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 366 | const SkMatrix* getAnimationMatrix() const { |
| 367 | return mAnimationMatrix; |
| 368 | } |
| 369 | |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 370 | bool hasTransformMatrix() const { |
| 371 | return getTransformMatrix() && !getTransformMatrix()->isIdentity(); |
| 372 | } |
| 373 | |
| 374 | // May only call this if hasTransformMatrix() is true |
| 375 | bool isTransformTranslateOnly() const { |
| 376 | return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 379 | const SkMatrix* getTransformMatrix() const { |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 380 | LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!"); |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 381 | return mComputedFields.mTransformMatrix; |
| 382 | } |
| 383 | |
| 384 | bool getCaching() const { |
| 385 | return mPrimitiveFields.mCaching; |
| 386 | } |
| 387 | |
| 388 | bool getClipToBounds() const { |
| 389 | return mPrimitiveFields.mClipToBounds; |
| 390 | } |
| 391 | |
| 392 | bool getHasOverlappingRendering() const { |
| 393 | return mPrimitiveFields.mHasOverlappingRendering; |
| 394 | } |
| 395 | |
| 396 | const Outline& getOutline() const { |
| 397 | return mPrimitiveFields.mOutline; |
| 398 | } |
| 399 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 400 | const RevealClip& getRevealClip() const { |
| 401 | return mPrimitiveFields.mRevealClip; |
| 402 | } |
| 403 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 404 | bool getProjectBackwards() const { |
| 405 | return mPrimitiveFields.mProjectBackwards; |
| 406 | } |
| 407 | |
| 408 | void debugOutputProperties(const int level) const; |
| 409 | |
| 410 | ANDROID_API void updateMatrix(); |
| 411 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 412 | ANDROID_API void updateClipPath(); |
| 413 | |
| 414 | // signals that mComputedFields.mClipPath is up to date, and should be used for clipping |
| 415 | bool hasClippingPath() const { |
| 416 | return mPrimitiveFields.mOutline.willClip() || mPrimitiveFields.mRevealClip.willClip(); |
| 417 | } |
| 418 | |
| 419 | const SkPath* getClippingPath() const { |
| 420 | return hasClippingPath() ? mComputedFields.mClipPath : NULL; |
| 421 | } |
| 422 | |
| 423 | SkRegion::Op getClippingPathOp() const { |
| 424 | return mComputedFields.mClipPathOp; |
| 425 | } |
| 426 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 427 | Outline& mutableOutline() { |
| 428 | return mPrimitiveFields.mOutline; |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 431 | RevealClip& mutableRevealClip() { |
| 432 | return mPrimitiveFields.mRevealClip; |
| 433 | } |
| 434 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 435 | private: |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 436 | |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 437 | // Rendering properties |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 438 | struct PrimitiveFields { |
| 439 | PrimitiveFields(); |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 440 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 441 | Outline mOutline; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 442 | RevealClip mRevealClip; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 443 | bool mClipToBounds; |
| 444 | bool mProjectBackwards; |
| 445 | bool mProjectionReceiver; |
| 446 | float mAlpha; |
| 447 | bool mHasOverlappingRendering; |
Chris Craik | cc39e16 | 2014-04-25 18:34:11 -0700 | [diff] [blame^] | 448 | float mElevation; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 449 | float mTranslationX, mTranslationY, mTranslationZ; |
| 450 | float mRotation, mRotationX, mRotationY; |
| 451 | float mScaleX, mScaleY; |
| 452 | float mPivotX, mPivotY; |
| 453 | int mLeft, mTop, mRight, mBottom; |
| 454 | int mWidth, mHeight; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 455 | bool mPivotExplicitlySet; |
John Reck | f7483e3 | 2014-04-11 08:54:47 -0700 | [diff] [blame] | 456 | bool mMatrixOrPivotDirty; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 457 | bool mCaching; |
| 458 | } mPrimitiveFields; |
| 459 | |
| 460 | // mCameraDistance isn't in mPrimitiveFields as it has a complex setter |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 461 | SkMatrix* mStaticMatrix; |
| 462 | SkMatrix* mAnimationMatrix; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 463 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 464 | /** |
| 465 | * These fields are all generated from other properties and are not set directly. |
| 466 | */ |
| 467 | struct ComputedFields { |
| 468 | ComputedFields(); |
| 469 | ~ComputedFields(); |
| 470 | |
| 471 | /** |
| 472 | * Stores the total transformation of the DisplayList based upon its scalar |
| 473 | * translate/rotate/scale properties. |
| 474 | * |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 475 | * In the common translation-only case, the matrix isn't necessarily allocated, |
| 476 | * and the mTranslation properties are used directly. |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 477 | */ |
Chris Craik | 49e6c739 | 2014-03-31 12:34:11 -0700 | [diff] [blame] | 478 | SkMatrix* mTransformMatrix; |
| 479 | |
| 480 | Sk3DView mTransformCamera; |
Chris Craik | 8c271ca | 2014-03-25 10:33:01 -0700 | [diff] [blame] | 481 | SkPath* mClipPath; // TODO: remove this, create new ops for efficient/special case clipping |
| 482 | SkRegion::Op mClipPathOp; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 483 | } mComputedFields; |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 484 | }; |
| 485 | |
| 486 | } /* namespace uirenderer */ |
| 487 | } /* namespace android */ |
| 488 | |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 489 | #endif /* RENDERNODEPROPERTIES_H */ |