blob: 8c6cc9e967fc90c9a52d2a74bf7a1e4b1b8d27da [file] [log] [blame]
John Reckacb6f072014-03-12 16:11:23 -07001/*
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 Craikb49f4462014-03-20 12:44:20 -070016#ifndef RENDERNODEPROPERTIES_H
17#define RENDERNODEPROPERTIES_H
John Reckacb6f072014-03-12 16:11:23 -070018
John Recke45b1fd2014-04-15 09:50:16 -070019#include <algorithm>
John Reckacb6f072014-03-12 16:11:23 -070020#include <stddef.h>
John Recke45b1fd2014-04-15 09:50:16 -070021#include <vector>
John Reckacb6f072014-03-12 16:11:23 -070022#include <cutils/compiler.h>
23#include <androidfw/ResourceTypes.h>
24
25#include <SkCamera.h>
26#include <SkMatrix.h>
Chris Craik8c271ca2014-03-25 10:33:01 -070027#include <SkRegion.h>
Chris Craikb49f4462014-03-20 12:44:20 -070028
John Recke45b1fd2014-04-15 09:50:16 -070029#include "Animator.h"
Chris Craikb49f4462014-03-20 12:44:20 -070030#include "Rect.h"
Chris Craik8c271ca2014-03-25 10:33:01 -070031#include "RevealClip.h"
Chris Craikb49f4462014-03-20 12:44:20 -070032#include "Outline.h"
John Reckacb6f072014-03-12 16:11:23 -070033
John Reckacb6f072014-03-12 16:11:23 -070034class SkBitmap;
John Reck25fbb3f2014-06-12 13:46:45 -070035class SkColorFilter;
John Reckacb6f072014-03-12 16:11:23 -070036class SkPaint;
John Reckacb6f072014-03-12 16:11:23 -070037
38namespace android {
39namespace uirenderer {
40
41class Matrix4;
42class RenderNode;
John Reck25fbb3f2014-06-12 13:46:45 -070043class RenderProperties;
John Reckacb6f072014-03-12 16:11:23 -070044
John Reck79c7de72014-05-23 10:33:31 -070045// The __VA_ARGS__ will be executed if a & b are not equal
46#define RP_SET(a, b, ...) (a != b ? (a = b, ##__VA_ARGS__, true) : false)
47#define RP_SET_AND_DIRTY(a, b) RP_SET(a, b, mPrimitiveFields.mMatrixOrPivotDirty = true)
48
John Reck25fbb3f2014-06-12 13:46:45 -070049// Keep in sync with View.java:LAYER_TYPE_*
50enum LayerType {
51 kLayerTypeNone = 0,
52 // Although we cannot build the software layer directly (must be done at
53 // record time), this information is used when applying alpha.
54 kLayerTypeSoftware = 1,
55 kLayerTypeRenderLayer = 2,
56 // TODO: LayerTypeSurfaceTexture? Maybe?
57};
58
59class ANDROID_API LayerProperties {
60public:
61 bool setType(LayerType type) {
62 if (RP_SET(mType, type)) {
63 reset();
64 return true;
65 }
66 return false;
67 }
68
69 LayerType type() const {
70 return mType;
71 }
72
73 bool setOpaque(bool opaque) {
74 return RP_SET(mOpaque, opaque);
75 }
76
77 bool opaque() const {
78 return mOpaque;
79 }
80
81 bool setAlpha(uint8_t alpha) {
82 return RP_SET(mAlpha, alpha);
83 }
84
85 uint8_t alpha() const {
86 return mAlpha;
87 }
88
89 bool setXferMode(SkXfermode::Mode mode) {
90 return RP_SET(mMode, mode);
91 }
92
93 SkXfermode::Mode xferMode() const {
94 return mMode;
95 }
96
97 bool setColorFilter(SkColorFilter* filter);
98
99 SkColorFilter* colorFilter() const {
100 return mColorFilter;
101 }
102
103 // Sets alpha, xfermode, and colorfilter from an SkPaint
104 // paint may be NULL, in which case defaults will be set
105 bool setFromPaint(const SkPaint* paint);
106
107 bool needsBlending() const {
108 return !opaque() || alpha() < 255;
109 }
110
111 LayerProperties& operator=(const LayerProperties& other);
112
113private:
114 LayerProperties();
115 ~LayerProperties();
116 void reset();
117
118 friend class RenderProperties;
119
120 LayerType mType;
121 // Whether or not that Layer's content is opaque, doesn't include alpha
122 bool mOpaque;
123 uint8_t mAlpha;
124 SkXfermode::Mode mMode;
125 SkColorFilter* mColorFilter;
126};
127
John Reckacb6f072014-03-12 16:11:23 -0700128/*
129 * Data structure that holds the properties for a RenderNode
130 */
John Reck25fbb3f2014-06-12 13:46:45 -0700131class ANDROID_API RenderProperties {
John Reckacb6f072014-03-12 16:11:23 -0700132public:
133 RenderProperties();
134 virtual ~RenderProperties();
135
John Reckd0a0b2a2014-03-20 16:28:56 -0700136 RenderProperties& operator=(const RenderProperties& other);
137
John Reck79c7de72014-05-23 10:33:31 -0700138 bool setClipToBounds(bool clipToBounds) {
139 return RP_SET(mPrimitiveFields.mClipToBounds, clipToBounds);
John Reckacb6f072014-03-12 16:11:23 -0700140 }
141
John Reck79c7de72014-05-23 10:33:31 -0700142 bool setProjectBackwards(bool shouldProject) {
143 return RP_SET(mPrimitiveFields.mProjectBackwards, shouldProject);
John Reckacb6f072014-03-12 16:11:23 -0700144 }
145
John Reck79c7de72014-05-23 10:33:31 -0700146 bool setProjectionReceiver(bool shouldRecieve) {
147 return RP_SET(mPrimitiveFields.mProjectionReceiver, shouldRecieve);
John Reckacb6f072014-03-12 16:11:23 -0700148 }
149
John Reckd0a0b2a2014-03-20 16:28:56 -0700150 bool isProjectionReceiver() const {
151 return mPrimitiveFields.mProjectionReceiver;
John Reckacb6f072014-03-12 16:11:23 -0700152 }
153
John Reck79c7de72014-05-23 10:33:31 -0700154 bool setStaticMatrix(const SkMatrix* matrix) {
John Reckacb6f072014-03-12 16:11:23 -0700155 delete mStaticMatrix;
John Reckd0a0b2a2014-03-20 16:28:56 -0700156 if (matrix) {
157 mStaticMatrix = new SkMatrix(*matrix);
158 } else {
159 mStaticMatrix = NULL;
160 }
John Reck79c7de72014-05-23 10:33:31 -0700161 return true;
John Reckacb6f072014-03-12 16:11:23 -0700162 }
163
164 // Can return NULL
John Reckd0a0b2a2014-03-20 16:28:56 -0700165 const SkMatrix* getStaticMatrix() const {
John Reckacb6f072014-03-12 16:11:23 -0700166 return mStaticMatrix;
167 }
168
John Reck79c7de72014-05-23 10:33:31 -0700169 bool setAnimationMatrix(const SkMatrix* matrix) {
John Reckacb6f072014-03-12 16:11:23 -0700170 delete mAnimationMatrix;
171 if (matrix) {
172 mAnimationMatrix = new SkMatrix(*matrix);
173 } else {
174 mAnimationMatrix = NULL;
175 }
John Reck79c7de72014-05-23 10:33:31 -0700176 return true;
John Reckacb6f072014-03-12 16:11:23 -0700177 }
178
John Reck79c7de72014-05-23 10:33:31 -0700179 bool setAlpha(float alpha) {
John Reckacb6f072014-03-12 16:11:23 -0700180 alpha = fminf(1.0f, fmaxf(0.0f, alpha));
John Reck79c7de72014-05-23 10:33:31 -0700181 return RP_SET(mPrimitiveFields.mAlpha, alpha);
John Reckacb6f072014-03-12 16:11:23 -0700182 }
183
184 float getAlpha() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700185 return mPrimitiveFields.mAlpha;
John Reckacb6f072014-03-12 16:11:23 -0700186 }
187
John Reck79c7de72014-05-23 10:33:31 -0700188 bool setHasOverlappingRendering(bool hasOverlappingRendering) {
189 return RP_SET(mPrimitiveFields.mHasOverlappingRendering, hasOverlappingRendering);
John Reckacb6f072014-03-12 16:11:23 -0700190 }
191
192 bool hasOverlappingRendering() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700193 return mPrimitiveFields.mHasOverlappingRendering;
John Reckacb6f072014-03-12 16:11:23 -0700194 }
195
John Reck79c7de72014-05-23 10:33:31 -0700196 bool setElevation(float elevation) {
197 return RP_SET(mPrimitiveFields.mElevation, elevation);
198 // Don't dirty matrix/pivot, since they don't respect Z
Chris Craikcc39e162014-04-25 18:34:11 -0700199 }
200
201 float getElevation() const {
202 return mPrimitiveFields.mElevation;
203 }
204
John Reck79c7de72014-05-23 10:33:31 -0700205 bool setTranslationX(float translationX) {
206 return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationX, translationX);
John Reckacb6f072014-03-12 16:11:23 -0700207 }
208
209 float getTranslationX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700210 return mPrimitiveFields.mTranslationX;
John Reckacb6f072014-03-12 16:11:23 -0700211 }
212
John Reck79c7de72014-05-23 10:33:31 -0700213 bool setTranslationY(float translationY) {
214 return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationY, translationY);
John Reckacb6f072014-03-12 16:11:23 -0700215 }
216
217 float getTranslationY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700218 return mPrimitiveFields.mTranslationY;
John Reckacb6f072014-03-12 16:11:23 -0700219 }
220
John Reck79c7de72014-05-23 10:33:31 -0700221 bool setTranslationZ(float translationZ) {
222 return RP_SET(mPrimitiveFields.mTranslationZ, translationZ);
223 // mMatrixOrPivotDirty not set, since matrix doesn't respect Z
John Reckacb6f072014-03-12 16:11:23 -0700224 }
225
226 float getTranslationZ() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700227 return mPrimitiveFields.mTranslationZ;
John Reckacb6f072014-03-12 16:11:23 -0700228 }
229
John Recke45b1fd2014-04-15 09:50:16 -0700230 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700231 bool setX(float value) {
232 return setTranslationX(value - getLeft());
John Recke45b1fd2014-04-15 09:50:16 -0700233 }
234
235 // Animation helper
236 float getX() const {
237 return getLeft() + getTranslationX();
238 }
239
240 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700241 bool setY(float value) {
242 return setTranslationY(value - getTop());
John Recke45b1fd2014-04-15 09:50:16 -0700243 }
244
245 // Animation helper
246 float getY() const {
247 return getTop() + getTranslationY();
248 }
249
250 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700251 bool setZ(float value) {
252 return setTranslationZ(value - getElevation());
John Recke45b1fd2014-04-15 09:50:16 -0700253 }
254
Chris Craikcc39e162014-04-25 18:34:11 -0700255 float getZ() const {
256 return getElevation() + getTranslationZ();
257 }
258
John Reck79c7de72014-05-23 10:33:31 -0700259 bool setRotation(float rotation) {
260 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotation, rotation);
John Reckacb6f072014-03-12 16:11:23 -0700261 }
262
263 float getRotation() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700264 return mPrimitiveFields.mRotation;
John Reckacb6f072014-03-12 16:11:23 -0700265 }
266
John Reck79c7de72014-05-23 10:33:31 -0700267 bool setRotationX(float rotationX) {
268 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationX, rotationX);
John Reckacb6f072014-03-12 16:11:23 -0700269 }
270
271 float getRotationX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700272 return mPrimitiveFields.mRotationX;
John Reckacb6f072014-03-12 16:11:23 -0700273 }
274
John Reck79c7de72014-05-23 10:33:31 -0700275 bool setRotationY(float rotationY) {
276 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationY, rotationY);
John Reckacb6f072014-03-12 16:11:23 -0700277 }
278
279 float getRotationY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700280 return mPrimitiveFields.mRotationY;
John Reckacb6f072014-03-12 16:11:23 -0700281 }
282
John Reck79c7de72014-05-23 10:33:31 -0700283 bool setScaleX(float scaleX) {
284 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX);
John Reckacb6f072014-03-12 16:11:23 -0700285 }
286
287 float getScaleX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700288 return mPrimitiveFields.mScaleX;
John Reckacb6f072014-03-12 16:11:23 -0700289 }
290
John Reck79c7de72014-05-23 10:33:31 -0700291 bool setScaleY(float scaleY) {
292 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY);
John Reckacb6f072014-03-12 16:11:23 -0700293 }
294
295 float getScaleY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700296 return mPrimitiveFields.mScaleY;
John Reckacb6f072014-03-12 16:11:23 -0700297 }
298
John Reck79c7de72014-05-23 10:33:31 -0700299 bool setPivotX(float pivotX) {
300 if (RP_SET(mPrimitiveFields.mPivotX, pivotX)
301 || !mPrimitiveFields.mPivotExplicitlySet) {
302 mPrimitiveFields.mMatrixOrPivotDirty = true;
303 mPrimitiveFields.mPivotExplicitlySet = true;
304 return true;
305 }
306 return false;
John Reckacb6f072014-03-12 16:11:23 -0700307 }
308
John Reckd0a0b2a2014-03-20 16:28:56 -0700309 /* Note that getPivotX and getPivotY are adjusted by updateMatrix(),
John Reck79c7de72014-05-23 10:33:31 -0700310 * so the value returned may be stale if the RenderProperties has been
311 * modified since the last call to updateMatrix()
John Reckd0a0b2a2014-03-20 16:28:56 -0700312 */
313 float getPivotX() const {
314 return mPrimitiveFields.mPivotX;
315 }
John Reckacb6f072014-03-12 16:11:23 -0700316
John Reck79c7de72014-05-23 10:33:31 -0700317 bool setPivotY(float pivotY) {
318 if (RP_SET(mPrimitiveFields.mPivotY, pivotY)
319 || !mPrimitiveFields.mPivotExplicitlySet) {
320 mPrimitiveFields.mMatrixOrPivotDirty = true;
321 mPrimitiveFields.mPivotExplicitlySet = true;
322 return true;
323 }
324 return false;
John Reckacb6f072014-03-12 16:11:23 -0700325 }
326
John Reckd0a0b2a2014-03-20 16:28:56 -0700327 float getPivotY() const {
328 return mPrimitiveFields.mPivotY;
329 }
John Reckacb6f072014-03-12 16:11:23 -0700330
Chris Craik49e6c732014-03-31 12:34:11 -0700331 bool isPivotExplicitlySet() const {
332 return mPrimitiveFields.mPivotExplicitlySet;
333 }
334
John Reck79c7de72014-05-23 10:33:31 -0700335 bool setCameraDistance(float distance) {
Chris Craik49e6c732014-03-31 12:34:11 -0700336 if (distance != getCameraDistance()) {
John Reckf7483e32014-04-11 08:54:47 -0700337 mPrimitiveFields.mMatrixOrPivotDirty = true;
Chris Craik49e6c732014-03-31 12:34:11 -0700338 mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance);
John Reck79c7de72014-05-23 10:33:31 -0700339 return true;
John Reckacb6f072014-03-12 16:11:23 -0700340 }
John Reck79c7de72014-05-23 10:33:31 -0700341 return false;
John Reckacb6f072014-03-12 16:11:23 -0700342 }
343
344 float getCameraDistance() const {
Chris Craik49e6c732014-03-31 12:34:11 -0700345 // TODO: update getCameraLocationZ() to be const
346 return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ();
John Reckacb6f072014-03-12 16:11:23 -0700347 }
348
John Reck79c7de72014-05-23 10:33:31 -0700349 bool setLeft(int left) {
350 if (RP_SET(mPrimitiveFields.mLeft, left)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700351 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700352 if (!mPrimitiveFields.mPivotExplicitlySet) {
353 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700354 }
John Reck79c7de72014-05-23 10:33:31 -0700355 return true;
John Reckacb6f072014-03-12 16:11:23 -0700356 }
John Reck79c7de72014-05-23 10:33:31 -0700357 return false;
John Reckacb6f072014-03-12 16:11:23 -0700358 }
359
360 float getLeft() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700361 return mPrimitiveFields.mLeft;
John Reckacb6f072014-03-12 16:11:23 -0700362 }
363
John Reck79c7de72014-05-23 10:33:31 -0700364 bool setTop(int top) {
365 if (RP_SET(mPrimitiveFields.mTop, top)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700366 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700367 if (!mPrimitiveFields.mPivotExplicitlySet) {
368 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700369 }
John Reck79c7de72014-05-23 10:33:31 -0700370 return true;
John Reckacb6f072014-03-12 16:11:23 -0700371 }
John Reck79c7de72014-05-23 10:33:31 -0700372 return false;
John Reckacb6f072014-03-12 16:11:23 -0700373 }
374
375 float getTop() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700376 return mPrimitiveFields.mTop;
John Reckacb6f072014-03-12 16:11:23 -0700377 }
378
John Reck79c7de72014-05-23 10:33:31 -0700379 bool setRight(int right) {
380 if (RP_SET(mPrimitiveFields.mRight, right)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700381 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700382 if (!mPrimitiveFields.mPivotExplicitlySet) {
383 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700384 }
John Reck79c7de72014-05-23 10:33:31 -0700385 return true;
John Reckacb6f072014-03-12 16:11:23 -0700386 }
John Reck79c7de72014-05-23 10:33:31 -0700387 return false;
John Reckacb6f072014-03-12 16:11:23 -0700388 }
389
390 float getRight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700391 return mPrimitiveFields.mRight;
John Reckacb6f072014-03-12 16:11:23 -0700392 }
393
John Reck79c7de72014-05-23 10:33:31 -0700394 bool setBottom(int bottom) {
395 if (RP_SET(mPrimitiveFields.mBottom, bottom)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700396 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700397 if (!mPrimitiveFields.mPivotExplicitlySet) {
398 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700399 }
John Reck79c7de72014-05-23 10:33:31 -0700400 return true;
John Reckacb6f072014-03-12 16:11:23 -0700401 }
John Reck79c7de72014-05-23 10:33:31 -0700402 return false;
John Reckacb6f072014-03-12 16:11:23 -0700403 }
404
405 float getBottom() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700406 return mPrimitiveFields.mBottom;
John Reckacb6f072014-03-12 16:11:23 -0700407 }
408
John Reck79c7de72014-05-23 10:33:31 -0700409 bool setLeftTop(int left, int top) {
410 bool leftResult = setLeft(left);
411 bool topResult = setTop(top);
412 return leftResult || topResult;
John Reckacb6f072014-03-12 16:11:23 -0700413 }
414
John Reck79c7de72014-05-23 10:33:31 -0700415 bool setLeftTopRightBottom(int left, int top, int right, int bottom) {
Chris Craikcc39e162014-04-25 18:34:11 -0700416 if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop
417 || right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700418 mPrimitiveFields.mLeft = left;
419 mPrimitiveFields.mTop = top;
420 mPrimitiveFields.mRight = right;
421 mPrimitiveFields.mBottom = bottom;
422 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
423 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700424 if (!mPrimitiveFields.mPivotExplicitlySet) {
425 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700426 }
John Reck79c7de72014-05-23 10:33:31 -0700427 return true;
John Reckacb6f072014-03-12 16:11:23 -0700428 }
John Reck79c7de72014-05-23 10:33:31 -0700429 return false;
John Reckacb6f072014-03-12 16:11:23 -0700430 }
431
John Reck79c7de72014-05-23 10:33:31 -0700432 bool offsetLeftRight(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700433 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700434 mPrimitiveFields.mLeft += offset;
435 mPrimitiveFields.mRight += offset;
John Reck79c7de72014-05-23 10:33:31 -0700436 return true;
John Reckacb6f072014-03-12 16:11:23 -0700437 }
John Reck79c7de72014-05-23 10:33:31 -0700438 return false;
John Reckacb6f072014-03-12 16:11:23 -0700439 }
440
John Reck79c7de72014-05-23 10:33:31 -0700441 bool offsetTopBottom(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700442 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700443 mPrimitiveFields.mTop += offset;
444 mPrimitiveFields.mBottom += offset;
John Reck79c7de72014-05-23 10:33:31 -0700445 return true;
John Reckacb6f072014-03-12 16:11:23 -0700446 }
John Reck79c7de72014-05-23 10:33:31 -0700447 return false;
John Reckacb6f072014-03-12 16:11:23 -0700448 }
449
Chris Craikb49f4462014-03-20 12:44:20 -0700450 int getWidth() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700451 return mPrimitiveFields.mWidth;
John Reckacb6f072014-03-12 16:11:23 -0700452 }
453
Chris Craikb49f4462014-03-20 12:44:20 -0700454 int getHeight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700455 return mPrimitiveFields.mHeight;
John Reckacb6f072014-03-12 16:11:23 -0700456 }
457
John Reckd0a0b2a2014-03-20 16:28:56 -0700458 const SkMatrix* getAnimationMatrix() const {
459 return mAnimationMatrix;
460 }
461
John Reckf7483e32014-04-11 08:54:47 -0700462 bool hasTransformMatrix() const {
463 return getTransformMatrix() && !getTransformMatrix()->isIdentity();
464 }
465
466 // May only call this if hasTransformMatrix() is true
467 bool isTransformTranslateOnly() const {
468 return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask;
John Reckd0a0b2a2014-03-20 16:28:56 -0700469 }
470
Chris Craik49e6c732014-03-31 12:34:11 -0700471 const SkMatrix* getTransformMatrix() const {
John Reckf7483e32014-04-11 08:54:47 -0700472 LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!");
John Reckd0a0b2a2014-03-20 16:28:56 -0700473 return mComputedFields.mTransformMatrix;
474 }
475
John Reckd0a0b2a2014-03-20 16:28:56 -0700476 bool getClipToBounds() const {
477 return mPrimitiveFields.mClipToBounds;
478 }
479
480 bool getHasOverlappingRendering() const {
481 return mPrimitiveFields.mHasOverlappingRendering;
482 }
483
484 const Outline& getOutline() const {
485 return mPrimitiveFields.mOutline;
486 }
487
Chris Craik8c271ca2014-03-25 10:33:01 -0700488 const RevealClip& getRevealClip() const {
489 return mPrimitiveFields.mRevealClip;
490 }
491
John Reckd0a0b2a2014-03-20 16:28:56 -0700492 bool getProjectBackwards() const {
493 return mPrimitiveFields.mProjectBackwards;
494 }
495
496 void debugOutputProperties(const int level) const;
497
John Reck25fbb3f2014-06-12 13:46:45 -0700498 void updateMatrix();
John Reckd0a0b2a2014-03-20 16:28:56 -0700499
Chris Craik8c271ca2014-03-25 10:33:01 -0700500 bool hasClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700501 return mPrimitiveFields.mRevealClip.willClip();
Chris Craik8c271ca2014-03-25 10:33:01 -0700502 }
503
504 const SkPath* getClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700505 return mPrimitiveFields.mRevealClip.getPath();
Chris Craik8c271ca2014-03-25 10:33:01 -0700506 }
507
508 SkRegion::Op getClippingPathOp() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700509 return mPrimitiveFields.mRevealClip.isInverseClip()
510 ? SkRegion::kDifference_Op : SkRegion::kIntersect_Op;
Chris Craik8c271ca2014-03-25 10:33:01 -0700511 }
512
John Reckd0a0b2a2014-03-20 16:28:56 -0700513 Outline& mutableOutline() {
514 return mPrimitiveFields.mOutline;
Chris Craikb49f4462014-03-20 12:44:20 -0700515 }
516
Chris Craik8c271ca2014-03-25 10:33:01 -0700517 RevealClip& mutableRevealClip() {
518 return mPrimitiveFields.mRevealClip;
519 }
520
John Reck25fbb3f2014-06-12 13:46:45 -0700521 const LayerProperties& layerProperties() const {
522 return mLayerProperties;
523 }
524
525 LayerProperties& mutateLayerProperties() {
526 return mLayerProperties;
527 }
528
John Reckacb6f072014-03-12 16:11:23 -0700529private:
John Reckacb6f072014-03-12 16:11:23 -0700530
John Reckacb6f072014-03-12 16:11:23 -0700531 // Rendering properties
John Reckd0a0b2a2014-03-20 16:28:56 -0700532 struct PrimitiveFields {
533 PrimitiveFields();
John Reckacb6f072014-03-12 16:11:23 -0700534
John Reckd0a0b2a2014-03-20 16:28:56 -0700535 Outline mOutline;
Chris Craik8c271ca2014-03-25 10:33:01 -0700536 RevealClip mRevealClip;
John Reckd0a0b2a2014-03-20 16:28:56 -0700537 bool mClipToBounds;
538 bool mProjectBackwards;
539 bool mProjectionReceiver;
540 float mAlpha;
541 bool mHasOverlappingRendering;
Chris Craikcc39e162014-04-25 18:34:11 -0700542 float mElevation;
John Reckd0a0b2a2014-03-20 16:28:56 -0700543 float mTranslationX, mTranslationY, mTranslationZ;
544 float mRotation, mRotationX, mRotationY;
545 float mScaleX, mScaleY;
546 float mPivotX, mPivotY;
547 int mLeft, mTop, mRight, mBottom;
548 int mWidth, mHeight;
John Reckd0a0b2a2014-03-20 16:28:56 -0700549 bool mPivotExplicitlySet;
John Reckf7483e32014-04-11 08:54:47 -0700550 bool mMatrixOrPivotDirty;
John Reckd0a0b2a2014-03-20 16:28:56 -0700551 } mPrimitiveFields;
552
John Reckacb6f072014-03-12 16:11:23 -0700553 SkMatrix* mStaticMatrix;
554 SkMatrix* mAnimationMatrix;
John Reck25fbb3f2014-06-12 13:46:45 -0700555 LayerProperties mLayerProperties;
John Reckacb6f072014-03-12 16:11:23 -0700556
John Reckd0a0b2a2014-03-20 16:28:56 -0700557 /**
558 * These fields are all generated from other properties and are not set directly.
559 */
560 struct ComputedFields {
561 ComputedFields();
562 ~ComputedFields();
563
564 /**
565 * Stores the total transformation of the DisplayList based upon its scalar
566 * translate/rotate/scale properties.
567 *
Chris Craik49e6c732014-03-31 12:34:11 -0700568 * In the common translation-only case, the matrix isn't necessarily allocated,
569 * and the mTranslation properties are used directly.
John Reckd0a0b2a2014-03-20 16:28:56 -0700570 */
Chris Craik49e6c732014-03-31 12:34:11 -0700571 SkMatrix* mTransformMatrix;
572
573 Sk3DView mTransformCamera;
John Reckd0a0b2a2014-03-20 16:28:56 -0700574 } mComputedFields;
John Reckacb6f072014-03-12 16:11:23 -0700575};
576
577} /* namespace uirenderer */
578} /* namespace android */
579
Chris Craikb49f4462014-03-20 12:44:20 -0700580#endif /* RENDERNODEPROPERTIES_H */