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