blob: 0cece005a46b0972cc0291f08627a2e3d5d4849a [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>
Chris Craikfe02b4b2014-06-16 16:34:29 -070024#include <utils/Log.h>
John Reckacb6f072014-03-12 16:11:23 -070025
26#include <SkCamera.h>
27#include <SkMatrix.h>
Chris Craik8c271ca2014-03-25 10:33:01 -070028#include <SkRegion.h>
Chris Craikb49f4462014-03-20 12:44:20 -070029
John Recke45b1fd2014-04-15 09:50:16 -070030#include "Animator.h"
Chris Craikb49f4462014-03-20 12:44:20 -070031#include "Rect.h"
Chris Craik8c271ca2014-03-25 10:33:01 -070032#include "RevealClip.h"
Chris Craikb49f4462014-03-20 12:44:20 -070033#include "Outline.h"
John Reckacb6f072014-03-12 16:11:23 -070034
John Reckacb6f072014-03-12 16:11:23 -070035class SkBitmap;
John Reck25fbb3f2014-06-12 13:46:45 -070036class SkColorFilter;
John Reckacb6f072014-03-12 16:11:23 -070037class SkPaint;
John Reckacb6f072014-03-12 16:11:23 -070038
39namespace android {
40namespace uirenderer {
41
42class Matrix4;
43class RenderNode;
John Reck25fbb3f2014-06-12 13:46:45 -070044class RenderProperties;
John Reckacb6f072014-03-12 16:11:23 -070045
John Reck79c7de72014-05-23 10:33:31 -070046// The __VA_ARGS__ will be executed if a & b are not equal
47#define RP_SET(a, b, ...) (a != b ? (a = b, ##__VA_ARGS__, true) : false)
48#define RP_SET_AND_DIRTY(a, b) RP_SET(a, b, mPrimitiveFields.mMatrixOrPivotDirty = true)
49
John Reck25fbb3f2014-06-12 13:46:45 -070050// Keep in sync with View.java:LAYER_TYPE_*
51enum LayerType {
52 kLayerTypeNone = 0,
53 // Although we cannot build the software layer directly (must be done at
54 // record time), this information is used when applying alpha.
55 kLayerTypeSoftware = 1,
56 kLayerTypeRenderLayer = 2,
57 // TODO: LayerTypeSurfaceTexture? Maybe?
58};
59
60class ANDROID_API LayerProperties {
61public:
62 bool setType(LayerType type) {
63 if (RP_SET(mType, type)) {
64 reset();
65 return true;
66 }
67 return false;
68 }
69
70 LayerType type() const {
71 return mType;
72 }
73
74 bool setOpaque(bool opaque) {
75 return RP_SET(mOpaque, opaque);
76 }
77
78 bool opaque() const {
79 return mOpaque;
80 }
81
82 bool setAlpha(uint8_t alpha) {
83 return RP_SET(mAlpha, alpha);
84 }
85
86 uint8_t alpha() const {
87 return mAlpha;
88 }
89
90 bool setXferMode(SkXfermode::Mode mode) {
91 return RP_SET(mMode, mode);
92 }
93
94 SkXfermode::Mode xferMode() const {
95 return mMode;
96 }
97
98 bool setColorFilter(SkColorFilter* filter);
99
100 SkColorFilter* colorFilter() const {
101 return mColorFilter;
102 }
103
104 // Sets alpha, xfermode, and colorfilter from an SkPaint
105 // paint may be NULL, in which case defaults will be set
106 bool setFromPaint(const SkPaint* paint);
107
108 bool needsBlending() const {
109 return !opaque() || alpha() < 255;
110 }
111
112 LayerProperties& operator=(const LayerProperties& other);
113
114private:
115 LayerProperties();
116 ~LayerProperties();
117 void reset();
118
119 friend class RenderProperties;
120
121 LayerType mType;
122 // Whether or not that Layer's content is opaque, doesn't include alpha
123 bool mOpaque;
124 uint8_t mAlpha;
125 SkXfermode::Mode mMode;
126 SkColorFilter* mColorFilter;
127};
128
John Reckacb6f072014-03-12 16:11:23 -0700129/*
130 * Data structure that holds the properties for a RenderNode
131 */
John Reck25fbb3f2014-06-12 13:46:45 -0700132class ANDROID_API RenderProperties {
John Reckacb6f072014-03-12 16:11:23 -0700133public:
134 RenderProperties();
135 virtual ~RenderProperties();
136
John Reckd0a0b2a2014-03-20 16:28:56 -0700137 RenderProperties& operator=(const RenderProperties& other);
138
John Reck79c7de72014-05-23 10:33:31 -0700139 bool setClipToBounds(bool clipToBounds) {
140 return RP_SET(mPrimitiveFields.mClipToBounds, clipToBounds);
John Reckacb6f072014-03-12 16:11:23 -0700141 }
142
John Reck79c7de72014-05-23 10:33:31 -0700143 bool setProjectBackwards(bool shouldProject) {
144 return RP_SET(mPrimitiveFields.mProjectBackwards, shouldProject);
John Reckacb6f072014-03-12 16:11:23 -0700145 }
146
John Reck79c7de72014-05-23 10:33:31 -0700147 bool setProjectionReceiver(bool shouldRecieve) {
148 return RP_SET(mPrimitiveFields.mProjectionReceiver, shouldRecieve);
John Reckacb6f072014-03-12 16:11:23 -0700149 }
150
John Reckd0a0b2a2014-03-20 16:28:56 -0700151 bool isProjectionReceiver() const {
152 return mPrimitiveFields.mProjectionReceiver;
John Reckacb6f072014-03-12 16:11:23 -0700153 }
154
John Reck79c7de72014-05-23 10:33:31 -0700155 bool setStaticMatrix(const SkMatrix* matrix) {
John Reckacb6f072014-03-12 16:11:23 -0700156 delete mStaticMatrix;
John Reckd0a0b2a2014-03-20 16:28:56 -0700157 if (matrix) {
158 mStaticMatrix = new SkMatrix(*matrix);
159 } else {
160 mStaticMatrix = NULL;
161 }
John Reck79c7de72014-05-23 10:33:31 -0700162 return true;
John Reckacb6f072014-03-12 16:11:23 -0700163 }
164
165 // Can return NULL
John Reckd0a0b2a2014-03-20 16:28:56 -0700166 const SkMatrix* getStaticMatrix() const {
John Reckacb6f072014-03-12 16:11:23 -0700167 return mStaticMatrix;
168 }
169
John Reck79c7de72014-05-23 10:33:31 -0700170 bool setAnimationMatrix(const SkMatrix* matrix) {
John Reckacb6f072014-03-12 16:11:23 -0700171 delete mAnimationMatrix;
172 if (matrix) {
173 mAnimationMatrix = new SkMatrix(*matrix);
174 } else {
175 mAnimationMatrix = NULL;
176 }
John Reck79c7de72014-05-23 10:33:31 -0700177 return true;
John Reckacb6f072014-03-12 16:11:23 -0700178 }
179
John Reck79c7de72014-05-23 10:33:31 -0700180 bool setAlpha(float alpha) {
John Reckacb6f072014-03-12 16:11:23 -0700181 alpha = fminf(1.0f, fmaxf(0.0f, alpha));
John Reck79c7de72014-05-23 10:33:31 -0700182 return RP_SET(mPrimitiveFields.mAlpha, alpha);
John Reckacb6f072014-03-12 16:11:23 -0700183 }
184
185 float getAlpha() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700186 return mPrimitiveFields.mAlpha;
John Reckacb6f072014-03-12 16:11:23 -0700187 }
188
John Reck79c7de72014-05-23 10:33:31 -0700189 bool setHasOverlappingRendering(bool hasOverlappingRendering) {
190 return RP_SET(mPrimitiveFields.mHasOverlappingRendering, hasOverlappingRendering);
John Reckacb6f072014-03-12 16:11:23 -0700191 }
192
193 bool hasOverlappingRendering() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700194 return mPrimitiveFields.mHasOverlappingRendering;
John Reckacb6f072014-03-12 16:11:23 -0700195 }
196
John Reck79c7de72014-05-23 10:33:31 -0700197 bool setElevation(float elevation) {
198 return RP_SET(mPrimitiveFields.mElevation, elevation);
199 // Don't dirty matrix/pivot, since they don't respect Z
Chris Craikcc39e162014-04-25 18:34:11 -0700200 }
201
202 float getElevation() const {
203 return mPrimitiveFields.mElevation;
204 }
205
John Reck79c7de72014-05-23 10:33:31 -0700206 bool setTranslationX(float translationX) {
207 return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationX, translationX);
John Reckacb6f072014-03-12 16:11:23 -0700208 }
209
210 float getTranslationX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700211 return mPrimitiveFields.mTranslationX;
John Reckacb6f072014-03-12 16:11:23 -0700212 }
213
John Reck79c7de72014-05-23 10:33:31 -0700214 bool setTranslationY(float translationY) {
215 return RP_SET_AND_DIRTY(mPrimitiveFields.mTranslationY, translationY);
John Reckacb6f072014-03-12 16:11:23 -0700216 }
217
218 float getTranslationY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700219 return mPrimitiveFields.mTranslationY;
John Reckacb6f072014-03-12 16:11:23 -0700220 }
221
John Reck79c7de72014-05-23 10:33:31 -0700222 bool setTranslationZ(float translationZ) {
223 return RP_SET(mPrimitiveFields.mTranslationZ, translationZ);
224 // mMatrixOrPivotDirty not set, since matrix doesn't respect Z
John Reckacb6f072014-03-12 16:11:23 -0700225 }
226
227 float getTranslationZ() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700228 return mPrimitiveFields.mTranslationZ;
John Reckacb6f072014-03-12 16:11:23 -0700229 }
230
John Recke45b1fd2014-04-15 09:50:16 -0700231 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700232 bool setX(float value) {
233 return setTranslationX(value - getLeft());
John Recke45b1fd2014-04-15 09:50:16 -0700234 }
235
236 // Animation helper
237 float getX() const {
238 return getLeft() + getTranslationX();
239 }
240
241 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700242 bool setY(float value) {
243 return setTranslationY(value - getTop());
John Recke45b1fd2014-04-15 09:50:16 -0700244 }
245
246 // Animation helper
247 float getY() const {
248 return getTop() + getTranslationY();
249 }
250
251 // Animation helper
John Reck79c7de72014-05-23 10:33:31 -0700252 bool setZ(float value) {
253 return setTranslationZ(value - getElevation());
John Recke45b1fd2014-04-15 09:50:16 -0700254 }
255
Chris Craikcc39e162014-04-25 18:34:11 -0700256 float getZ() const {
257 return getElevation() + getTranslationZ();
258 }
259
John Reck79c7de72014-05-23 10:33:31 -0700260 bool setRotation(float rotation) {
261 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotation, rotation);
John Reckacb6f072014-03-12 16:11:23 -0700262 }
263
264 float getRotation() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700265 return mPrimitiveFields.mRotation;
John Reckacb6f072014-03-12 16:11:23 -0700266 }
267
John Reck79c7de72014-05-23 10:33:31 -0700268 bool setRotationX(float rotationX) {
269 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationX, rotationX);
John Reckacb6f072014-03-12 16:11:23 -0700270 }
271
272 float getRotationX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700273 return mPrimitiveFields.mRotationX;
John Reckacb6f072014-03-12 16:11:23 -0700274 }
275
John Reck79c7de72014-05-23 10:33:31 -0700276 bool setRotationY(float rotationY) {
277 return RP_SET_AND_DIRTY(mPrimitiveFields.mRotationY, rotationY);
John Reckacb6f072014-03-12 16:11:23 -0700278 }
279
280 float getRotationY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700281 return mPrimitiveFields.mRotationY;
John Reckacb6f072014-03-12 16:11:23 -0700282 }
283
John Reck79c7de72014-05-23 10:33:31 -0700284 bool setScaleX(float scaleX) {
Chris Craikfe02b4b2014-06-16 16:34:29 -0700285 LOG_ALWAYS_FATAL_IF(scaleX > 1000000, "invalid scaleX %e", scaleX);
John Reck79c7de72014-05-23 10:33:31 -0700286 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX);
John Reckacb6f072014-03-12 16:11:23 -0700287 }
288
289 float getScaleX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700290 return mPrimitiveFields.mScaleX;
John Reckacb6f072014-03-12 16:11:23 -0700291 }
292
John Reck79c7de72014-05-23 10:33:31 -0700293 bool setScaleY(float scaleY) {
Chris Craikfe02b4b2014-06-16 16:34:29 -0700294 LOG_ALWAYS_FATAL_IF(scaleY > 1000000, "invalid scaleY %e", scaleY);
John Reck79c7de72014-05-23 10:33:31 -0700295 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY);
John Reckacb6f072014-03-12 16:11:23 -0700296 }
297
298 float getScaleY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700299 return mPrimitiveFields.mScaleY;
John Reckacb6f072014-03-12 16:11:23 -0700300 }
301
John Reck79c7de72014-05-23 10:33:31 -0700302 bool setPivotX(float pivotX) {
303 if (RP_SET(mPrimitiveFields.mPivotX, pivotX)
304 || !mPrimitiveFields.mPivotExplicitlySet) {
305 mPrimitiveFields.mMatrixOrPivotDirty = true;
306 mPrimitiveFields.mPivotExplicitlySet = true;
307 return true;
308 }
309 return false;
John Reckacb6f072014-03-12 16:11:23 -0700310 }
311
John Reckd0a0b2a2014-03-20 16:28:56 -0700312 /* Note that getPivotX and getPivotY are adjusted by updateMatrix(),
John Reck79c7de72014-05-23 10:33:31 -0700313 * so the value returned may be stale if the RenderProperties has been
314 * modified since the last call to updateMatrix()
John Reckd0a0b2a2014-03-20 16:28:56 -0700315 */
316 float getPivotX() const {
317 return mPrimitiveFields.mPivotX;
318 }
John Reckacb6f072014-03-12 16:11:23 -0700319
John Reck79c7de72014-05-23 10:33:31 -0700320 bool setPivotY(float pivotY) {
321 if (RP_SET(mPrimitiveFields.mPivotY, pivotY)
322 || !mPrimitiveFields.mPivotExplicitlySet) {
323 mPrimitiveFields.mMatrixOrPivotDirty = true;
324 mPrimitiveFields.mPivotExplicitlySet = true;
325 return true;
326 }
327 return false;
John Reckacb6f072014-03-12 16:11:23 -0700328 }
329
John Reckd0a0b2a2014-03-20 16:28:56 -0700330 float getPivotY() const {
331 return mPrimitiveFields.mPivotY;
332 }
John Reckacb6f072014-03-12 16:11:23 -0700333
Chris Craik49e6c732014-03-31 12:34:11 -0700334 bool isPivotExplicitlySet() const {
335 return mPrimitiveFields.mPivotExplicitlySet;
336 }
337
John Reck79c7de72014-05-23 10:33:31 -0700338 bool setCameraDistance(float distance) {
Chris Craik49e6c732014-03-31 12:34:11 -0700339 if (distance != getCameraDistance()) {
John Reckf7483e32014-04-11 08:54:47 -0700340 mPrimitiveFields.mMatrixOrPivotDirty = true;
Chris Craik49e6c732014-03-31 12:34:11 -0700341 mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance);
John Reck79c7de72014-05-23 10:33:31 -0700342 return true;
John Reckacb6f072014-03-12 16:11:23 -0700343 }
John Reck79c7de72014-05-23 10:33:31 -0700344 return false;
John Reckacb6f072014-03-12 16:11:23 -0700345 }
346
347 float getCameraDistance() const {
Chris Craik49e6c732014-03-31 12:34:11 -0700348 // TODO: update getCameraLocationZ() to be const
349 return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ();
John Reckacb6f072014-03-12 16:11:23 -0700350 }
351
John Reck79c7de72014-05-23 10:33:31 -0700352 bool setLeft(int left) {
353 if (RP_SET(mPrimitiveFields.mLeft, left)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700354 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700355 if (!mPrimitiveFields.mPivotExplicitlySet) {
356 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700357 }
John Reck79c7de72014-05-23 10:33:31 -0700358 return true;
John Reckacb6f072014-03-12 16:11:23 -0700359 }
John Reck79c7de72014-05-23 10:33:31 -0700360 return false;
John Reckacb6f072014-03-12 16:11:23 -0700361 }
362
363 float getLeft() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700364 return mPrimitiveFields.mLeft;
John Reckacb6f072014-03-12 16:11:23 -0700365 }
366
John Reck79c7de72014-05-23 10:33:31 -0700367 bool setTop(int top) {
368 if (RP_SET(mPrimitiveFields.mTop, top)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700369 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700370 if (!mPrimitiveFields.mPivotExplicitlySet) {
371 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700372 }
John Reck79c7de72014-05-23 10:33:31 -0700373 return true;
John Reckacb6f072014-03-12 16:11:23 -0700374 }
John Reck79c7de72014-05-23 10:33:31 -0700375 return false;
John Reckacb6f072014-03-12 16:11:23 -0700376 }
377
378 float getTop() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700379 return mPrimitiveFields.mTop;
John Reckacb6f072014-03-12 16:11:23 -0700380 }
381
John Reck79c7de72014-05-23 10:33:31 -0700382 bool setRight(int right) {
383 if (RP_SET(mPrimitiveFields.mRight, right)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700384 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700385 if (!mPrimitiveFields.mPivotExplicitlySet) {
386 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700387 }
John Reck79c7de72014-05-23 10:33:31 -0700388 return true;
John Reckacb6f072014-03-12 16:11:23 -0700389 }
John Reck79c7de72014-05-23 10:33:31 -0700390 return false;
John Reckacb6f072014-03-12 16:11:23 -0700391 }
392
393 float getRight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700394 return mPrimitiveFields.mRight;
John Reckacb6f072014-03-12 16:11:23 -0700395 }
396
John Reck79c7de72014-05-23 10:33:31 -0700397 bool setBottom(int bottom) {
398 if (RP_SET(mPrimitiveFields.mBottom, bottom)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700399 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700400 if (!mPrimitiveFields.mPivotExplicitlySet) {
401 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700402 }
John Reck79c7de72014-05-23 10:33:31 -0700403 return true;
John Reckacb6f072014-03-12 16:11:23 -0700404 }
John Reck79c7de72014-05-23 10:33:31 -0700405 return false;
John Reckacb6f072014-03-12 16:11:23 -0700406 }
407
408 float getBottom() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700409 return mPrimitiveFields.mBottom;
John Reckacb6f072014-03-12 16:11:23 -0700410 }
411
John Reck79c7de72014-05-23 10:33:31 -0700412 bool setLeftTop(int left, int top) {
413 bool leftResult = setLeft(left);
414 bool topResult = setTop(top);
415 return leftResult || topResult;
John Reckacb6f072014-03-12 16:11:23 -0700416 }
417
John Reck79c7de72014-05-23 10:33:31 -0700418 bool setLeftTopRightBottom(int left, int top, int right, int bottom) {
Chris Craikcc39e162014-04-25 18:34:11 -0700419 if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop
420 || right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700421 mPrimitiveFields.mLeft = left;
422 mPrimitiveFields.mTop = top;
423 mPrimitiveFields.mRight = right;
424 mPrimitiveFields.mBottom = bottom;
425 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
426 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700427 if (!mPrimitiveFields.mPivotExplicitlySet) {
428 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700429 }
John Reck79c7de72014-05-23 10:33:31 -0700430 return true;
John Reckacb6f072014-03-12 16:11:23 -0700431 }
John Reck79c7de72014-05-23 10:33:31 -0700432 return false;
John Reckacb6f072014-03-12 16:11:23 -0700433 }
434
John Reck79c7de72014-05-23 10:33:31 -0700435 bool offsetLeftRight(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700436 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700437 mPrimitiveFields.mLeft += offset;
438 mPrimitiveFields.mRight += offset;
John Reck79c7de72014-05-23 10:33:31 -0700439 return true;
John Reckacb6f072014-03-12 16:11:23 -0700440 }
John Reck79c7de72014-05-23 10:33:31 -0700441 return false;
John Reckacb6f072014-03-12 16:11:23 -0700442 }
443
John Reck79c7de72014-05-23 10:33:31 -0700444 bool offsetTopBottom(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700445 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700446 mPrimitiveFields.mTop += offset;
447 mPrimitiveFields.mBottom += offset;
John Reck79c7de72014-05-23 10:33:31 -0700448 return true;
John Reckacb6f072014-03-12 16:11:23 -0700449 }
John Reck79c7de72014-05-23 10:33:31 -0700450 return false;
John Reckacb6f072014-03-12 16:11:23 -0700451 }
452
Chris Craikb49f4462014-03-20 12:44:20 -0700453 int getWidth() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700454 return mPrimitiveFields.mWidth;
John Reckacb6f072014-03-12 16:11:23 -0700455 }
456
Chris Craikb49f4462014-03-20 12:44:20 -0700457 int getHeight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700458 return mPrimitiveFields.mHeight;
John Reckacb6f072014-03-12 16:11:23 -0700459 }
460
John Reckd0a0b2a2014-03-20 16:28:56 -0700461 const SkMatrix* getAnimationMatrix() const {
462 return mAnimationMatrix;
463 }
464
John Reckf7483e32014-04-11 08:54:47 -0700465 bool hasTransformMatrix() const {
466 return getTransformMatrix() && !getTransformMatrix()->isIdentity();
467 }
468
469 // May only call this if hasTransformMatrix() is true
470 bool isTransformTranslateOnly() const {
471 return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask;
John Reckd0a0b2a2014-03-20 16:28:56 -0700472 }
473
Chris Craik49e6c732014-03-31 12:34:11 -0700474 const SkMatrix* getTransformMatrix() const {
John Reckf7483e32014-04-11 08:54:47 -0700475 LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!");
John Reckd0a0b2a2014-03-20 16:28:56 -0700476 return mComputedFields.mTransformMatrix;
477 }
478
John Reckd0a0b2a2014-03-20 16:28:56 -0700479 bool getClipToBounds() const {
480 return mPrimitiveFields.mClipToBounds;
481 }
482
483 bool getHasOverlappingRendering() const {
484 return mPrimitiveFields.mHasOverlappingRendering;
485 }
486
487 const Outline& getOutline() const {
488 return mPrimitiveFields.mOutline;
489 }
490
Chris Craik8c271ca2014-03-25 10:33:01 -0700491 const RevealClip& getRevealClip() const {
492 return mPrimitiveFields.mRevealClip;
493 }
494
John Reckd0a0b2a2014-03-20 16:28:56 -0700495 bool getProjectBackwards() const {
496 return mPrimitiveFields.mProjectBackwards;
497 }
498
499 void debugOutputProperties(const int level) const;
500
John Reck25fbb3f2014-06-12 13:46:45 -0700501 void updateMatrix();
John Reckd0a0b2a2014-03-20 16:28:56 -0700502
Chris Craik8c271ca2014-03-25 10:33:01 -0700503 bool hasClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700504 return mPrimitiveFields.mRevealClip.willClip();
Chris Craik8c271ca2014-03-25 10:33:01 -0700505 }
506
507 const SkPath* getClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700508 return mPrimitiveFields.mRevealClip.getPath();
Chris Craik8c271ca2014-03-25 10:33:01 -0700509 }
510
511 SkRegion::Op getClippingPathOp() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700512 return mPrimitiveFields.mRevealClip.isInverseClip()
513 ? SkRegion::kDifference_Op : SkRegion::kIntersect_Op;
Chris Craik8c271ca2014-03-25 10:33:01 -0700514 }
515
John Reckd0a0b2a2014-03-20 16:28:56 -0700516 Outline& mutableOutline() {
517 return mPrimitiveFields.mOutline;
Chris Craikb49f4462014-03-20 12:44:20 -0700518 }
519
Chris Craik8c271ca2014-03-25 10:33:01 -0700520 RevealClip& mutableRevealClip() {
521 return mPrimitiveFields.mRevealClip;
522 }
523
John Reck25fbb3f2014-06-12 13:46:45 -0700524 const LayerProperties& layerProperties() const {
525 return mLayerProperties;
526 }
527
528 LayerProperties& mutateLayerProperties() {
529 return mLayerProperties;
530 }
531
John Reckacb6f072014-03-12 16:11:23 -0700532private:
John Reckacb6f072014-03-12 16:11:23 -0700533
John Reckacb6f072014-03-12 16:11:23 -0700534 // Rendering properties
John Reckd0a0b2a2014-03-20 16:28:56 -0700535 struct PrimitiveFields {
536 PrimitiveFields();
John Reckacb6f072014-03-12 16:11:23 -0700537
John Reckd0a0b2a2014-03-20 16:28:56 -0700538 Outline mOutline;
Chris Craik8c271ca2014-03-25 10:33:01 -0700539 RevealClip mRevealClip;
John Reckd0a0b2a2014-03-20 16:28:56 -0700540 bool mClipToBounds;
541 bool mProjectBackwards;
542 bool mProjectionReceiver;
543 float mAlpha;
544 bool mHasOverlappingRendering;
Chris Craikcc39e162014-04-25 18:34:11 -0700545 float mElevation;
John Reckd0a0b2a2014-03-20 16:28:56 -0700546 float mTranslationX, mTranslationY, mTranslationZ;
547 float mRotation, mRotationX, mRotationY;
548 float mScaleX, mScaleY;
549 float mPivotX, mPivotY;
550 int mLeft, mTop, mRight, mBottom;
551 int mWidth, mHeight;
John Reckd0a0b2a2014-03-20 16:28:56 -0700552 bool mPivotExplicitlySet;
John Reckf7483e32014-04-11 08:54:47 -0700553 bool mMatrixOrPivotDirty;
John Reckd0a0b2a2014-03-20 16:28:56 -0700554 } mPrimitiveFields;
555
John Reckacb6f072014-03-12 16:11:23 -0700556 SkMatrix* mStaticMatrix;
557 SkMatrix* mAnimationMatrix;
John Reck25fbb3f2014-06-12 13:46:45 -0700558 LayerProperties mLayerProperties;
John Reckacb6f072014-03-12 16:11:23 -0700559
John Reckd0a0b2a2014-03-20 16:28:56 -0700560 /**
561 * These fields are all generated from other properties and are not set directly.
562 */
563 struct ComputedFields {
564 ComputedFields();
565 ~ComputedFields();
566
567 /**
568 * Stores the total transformation of the DisplayList based upon its scalar
569 * translate/rotate/scale properties.
570 *
Chris Craik49e6c732014-03-31 12:34:11 -0700571 * In the common translation-only case, the matrix isn't necessarily allocated,
572 * and the mTranslation properties are used directly.
John Reckd0a0b2a2014-03-20 16:28:56 -0700573 */
Chris Craik49e6c732014-03-31 12:34:11 -0700574 SkMatrix* mTransformMatrix;
575
576 Sk3DView mTransformCamera;
John Reckd0a0b2a2014-03-20 16:28:56 -0700577 } mComputedFields;
John Reckacb6f072014-03-12 16:11:23 -0700578};
579
580} /* namespace uirenderer */
581} /* namespace android */
582
Chris Craikb49f4462014-03-20 12:44:20 -0700583#endif /* RENDERNODEPROPERTIES_H */