blob: eab929b07065789397d1246081bb21eade1c16a1 [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 Reck293e8682014-06-17 10:34:02 -070033#include "utils/MathUtils.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) {
285 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleX, scaleX);
John Reckacb6f072014-03-12 16:11:23 -0700286 }
287
288 float getScaleX() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700289 return mPrimitiveFields.mScaleX;
John Reckacb6f072014-03-12 16:11:23 -0700290 }
291
John Reck79c7de72014-05-23 10:33:31 -0700292 bool setScaleY(float scaleY) {
293 return RP_SET_AND_DIRTY(mPrimitiveFields.mScaleY, scaleY);
John Reckacb6f072014-03-12 16:11:23 -0700294 }
295
296 float getScaleY() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700297 return mPrimitiveFields.mScaleY;
John Reckacb6f072014-03-12 16:11:23 -0700298 }
299
John Reck79c7de72014-05-23 10:33:31 -0700300 bool setPivotX(float pivotX) {
301 if (RP_SET(mPrimitiveFields.mPivotX, pivotX)
302 || !mPrimitiveFields.mPivotExplicitlySet) {
303 mPrimitiveFields.mMatrixOrPivotDirty = true;
304 mPrimitiveFields.mPivotExplicitlySet = true;
305 return true;
306 }
307 return false;
John Reckacb6f072014-03-12 16:11:23 -0700308 }
309
John Reckd0a0b2a2014-03-20 16:28:56 -0700310 /* Note that getPivotX and getPivotY are adjusted by updateMatrix(),
John Reck79c7de72014-05-23 10:33:31 -0700311 * so the value returned may be stale if the RenderProperties has been
312 * modified since the last call to updateMatrix()
John Reckd0a0b2a2014-03-20 16:28:56 -0700313 */
314 float getPivotX() const {
315 return mPrimitiveFields.mPivotX;
316 }
John Reckacb6f072014-03-12 16:11:23 -0700317
John Reck79c7de72014-05-23 10:33:31 -0700318 bool setPivotY(float pivotY) {
319 if (RP_SET(mPrimitiveFields.mPivotY, pivotY)
320 || !mPrimitiveFields.mPivotExplicitlySet) {
321 mPrimitiveFields.mMatrixOrPivotDirty = true;
322 mPrimitiveFields.mPivotExplicitlySet = true;
323 return true;
324 }
325 return false;
John Reckacb6f072014-03-12 16:11:23 -0700326 }
327
John Reckd0a0b2a2014-03-20 16:28:56 -0700328 float getPivotY() const {
329 return mPrimitiveFields.mPivotY;
330 }
John Reckacb6f072014-03-12 16:11:23 -0700331
Chris Craik49e6c7392014-03-31 12:34:11 -0700332 bool isPivotExplicitlySet() const {
333 return mPrimitiveFields.mPivotExplicitlySet;
334 }
335
John Reck79c7de72014-05-23 10:33:31 -0700336 bool setCameraDistance(float distance) {
Chris Craik49e6c7392014-03-31 12:34:11 -0700337 if (distance != getCameraDistance()) {
John Reckf7483e32014-04-11 08:54:47 -0700338 mPrimitiveFields.mMatrixOrPivotDirty = true;
Chris Craik49e6c7392014-03-31 12:34:11 -0700339 mComputedFields.mTransformCamera.setCameraLocation(0, 0, distance);
John Reck79c7de72014-05-23 10:33:31 -0700340 return true;
John Reckacb6f072014-03-12 16:11:23 -0700341 }
John Reck79c7de72014-05-23 10:33:31 -0700342 return false;
John Reckacb6f072014-03-12 16:11:23 -0700343 }
344
345 float getCameraDistance() const {
Chris Craik49e6c7392014-03-31 12:34:11 -0700346 // TODO: update getCameraLocationZ() to be const
347 return const_cast<Sk3DView*>(&mComputedFields.mTransformCamera)->getCameraLocationZ();
John Reckacb6f072014-03-12 16:11:23 -0700348 }
349
John Reck79c7de72014-05-23 10:33:31 -0700350 bool setLeft(int left) {
351 if (RP_SET(mPrimitiveFields.mLeft, left)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700352 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700353 if (!mPrimitiveFields.mPivotExplicitlySet) {
354 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700355 }
John Reck79c7de72014-05-23 10:33:31 -0700356 return true;
John Reckacb6f072014-03-12 16:11:23 -0700357 }
John Reck79c7de72014-05-23 10:33:31 -0700358 return false;
John Reckacb6f072014-03-12 16:11:23 -0700359 }
360
361 float getLeft() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700362 return mPrimitiveFields.mLeft;
John Reckacb6f072014-03-12 16:11:23 -0700363 }
364
John Reck79c7de72014-05-23 10:33:31 -0700365 bool setTop(int top) {
366 if (RP_SET(mPrimitiveFields.mTop, top)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700367 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700368 if (!mPrimitiveFields.mPivotExplicitlySet) {
369 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700370 }
John Reck79c7de72014-05-23 10:33:31 -0700371 return true;
John Reckacb6f072014-03-12 16:11:23 -0700372 }
John Reck79c7de72014-05-23 10:33:31 -0700373 return false;
John Reckacb6f072014-03-12 16:11:23 -0700374 }
375
376 float getTop() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700377 return mPrimitiveFields.mTop;
John Reckacb6f072014-03-12 16:11:23 -0700378 }
379
John Reck79c7de72014-05-23 10:33:31 -0700380 bool setRight(int right) {
381 if (RP_SET(mPrimitiveFields.mRight, right)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700382 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
John Reckf7483e32014-04-11 08:54:47 -0700383 if (!mPrimitiveFields.mPivotExplicitlySet) {
384 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700385 }
John Reck79c7de72014-05-23 10:33:31 -0700386 return true;
John Reckacb6f072014-03-12 16:11:23 -0700387 }
John Reck79c7de72014-05-23 10:33:31 -0700388 return false;
John Reckacb6f072014-03-12 16:11:23 -0700389 }
390
391 float getRight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700392 return mPrimitiveFields.mRight;
John Reckacb6f072014-03-12 16:11:23 -0700393 }
394
John Reck79c7de72014-05-23 10:33:31 -0700395 bool setBottom(int bottom) {
396 if (RP_SET(mPrimitiveFields.mBottom, bottom)) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700397 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700398 if (!mPrimitiveFields.mPivotExplicitlySet) {
399 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700400 }
John Reck79c7de72014-05-23 10:33:31 -0700401 return true;
John Reckacb6f072014-03-12 16:11:23 -0700402 }
John Reck79c7de72014-05-23 10:33:31 -0700403 return false;
John Reckacb6f072014-03-12 16:11:23 -0700404 }
405
406 float getBottom() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700407 return mPrimitiveFields.mBottom;
John Reckacb6f072014-03-12 16:11:23 -0700408 }
409
John Reck79c7de72014-05-23 10:33:31 -0700410 bool setLeftTop(int left, int top) {
411 bool leftResult = setLeft(left);
412 bool topResult = setTop(top);
413 return leftResult || topResult;
John Reckacb6f072014-03-12 16:11:23 -0700414 }
415
John Reck79c7de72014-05-23 10:33:31 -0700416 bool setLeftTopRightBottom(int left, int top, int right, int bottom) {
Chris Craikcc39e162014-04-25 18:34:11 -0700417 if (left != mPrimitiveFields.mLeft || top != mPrimitiveFields.mTop
418 || right != mPrimitiveFields.mRight || bottom != mPrimitiveFields.mBottom) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700419 mPrimitiveFields.mLeft = left;
420 mPrimitiveFields.mTop = top;
421 mPrimitiveFields.mRight = right;
422 mPrimitiveFields.mBottom = bottom;
423 mPrimitiveFields.mWidth = mPrimitiveFields.mRight - mPrimitiveFields.mLeft;
424 mPrimitiveFields.mHeight = mPrimitiveFields.mBottom - mPrimitiveFields.mTop;
John Reckf7483e32014-04-11 08:54:47 -0700425 if (!mPrimitiveFields.mPivotExplicitlySet) {
426 mPrimitiveFields.mMatrixOrPivotDirty = true;
John Reckacb6f072014-03-12 16:11:23 -0700427 }
John Reck79c7de72014-05-23 10:33:31 -0700428 return true;
John Reckacb6f072014-03-12 16:11:23 -0700429 }
John Reck79c7de72014-05-23 10:33:31 -0700430 return false;
John Reckacb6f072014-03-12 16:11:23 -0700431 }
432
John Reck79c7de72014-05-23 10:33:31 -0700433 bool offsetLeftRight(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700434 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700435 mPrimitiveFields.mLeft += offset;
436 mPrimitiveFields.mRight += offset;
John Reck79c7de72014-05-23 10:33:31 -0700437 return true;
John Reckacb6f072014-03-12 16:11:23 -0700438 }
John Reck79c7de72014-05-23 10:33:31 -0700439 return false;
John Reckacb6f072014-03-12 16:11:23 -0700440 }
441
John Reck79c7de72014-05-23 10:33:31 -0700442 bool offsetTopBottom(float offset) {
John Reckacb6f072014-03-12 16:11:23 -0700443 if (offset != 0) {
John Reckd0a0b2a2014-03-20 16:28:56 -0700444 mPrimitiveFields.mTop += offset;
445 mPrimitiveFields.mBottom += offset;
John Reck79c7de72014-05-23 10:33:31 -0700446 return true;
John Reckacb6f072014-03-12 16:11:23 -0700447 }
John Reck79c7de72014-05-23 10:33:31 -0700448 return false;
John Reckacb6f072014-03-12 16:11:23 -0700449 }
450
Chris Craikb49f4462014-03-20 12:44:20 -0700451 int getWidth() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700452 return mPrimitiveFields.mWidth;
John Reckacb6f072014-03-12 16:11:23 -0700453 }
454
Chris Craikb49f4462014-03-20 12:44:20 -0700455 int getHeight() const {
John Reckd0a0b2a2014-03-20 16:28:56 -0700456 return mPrimitiveFields.mHeight;
John Reckacb6f072014-03-12 16:11:23 -0700457 }
458
John Reckd0a0b2a2014-03-20 16:28:56 -0700459 const SkMatrix* getAnimationMatrix() const {
460 return mAnimationMatrix;
461 }
462
John Reckf7483e32014-04-11 08:54:47 -0700463 bool hasTransformMatrix() const {
464 return getTransformMatrix() && !getTransformMatrix()->isIdentity();
465 }
466
467 // May only call this if hasTransformMatrix() is true
468 bool isTransformTranslateOnly() const {
469 return getTransformMatrix()->getType() == SkMatrix::kTranslate_Mask;
John Reckd0a0b2a2014-03-20 16:28:56 -0700470 }
471
Chris Craik49e6c7392014-03-31 12:34:11 -0700472 const SkMatrix* getTransformMatrix() const {
John Reckf7483e32014-04-11 08:54:47 -0700473 LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mMatrixOrPivotDirty, "Cannot get a dirty matrix!");
John Reckd0a0b2a2014-03-20 16:28:56 -0700474 return mComputedFields.mTransformMatrix;
475 }
476
John Reckd0a0b2a2014-03-20 16:28:56 -0700477 bool getClipToBounds() const {
478 return mPrimitiveFields.mClipToBounds;
479 }
480
481 bool getHasOverlappingRendering() const {
482 return mPrimitiveFields.mHasOverlappingRendering;
483 }
484
485 const Outline& getOutline() const {
486 return mPrimitiveFields.mOutline;
487 }
488
Chris Craik8c271ca2014-03-25 10:33:01 -0700489 const RevealClip& getRevealClip() const {
490 return mPrimitiveFields.mRevealClip;
491 }
492
John Reckd0a0b2a2014-03-20 16:28:56 -0700493 bool getProjectBackwards() const {
494 return mPrimitiveFields.mProjectBackwards;
495 }
496
497 void debugOutputProperties(const int level) const;
498
John Reck25fbb3f2014-06-12 13:46:45 -0700499 void updateMatrix();
John Reckd0a0b2a2014-03-20 16:28:56 -0700500
Chris Craik8c271ca2014-03-25 10:33:01 -0700501 bool hasClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700502 return mPrimitiveFields.mRevealClip.willClip();
Chris Craik8c271ca2014-03-25 10:33:01 -0700503 }
504
505 const SkPath* getClippingPath() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700506 return mPrimitiveFields.mRevealClip.getPath();
Chris Craik8c271ca2014-03-25 10:33:01 -0700507 }
508
509 SkRegion::Op getClippingPathOp() const {
Chris Craik2bcad172014-05-14 18:11:23 -0700510 return mPrimitiveFields.mRevealClip.isInverseClip()
511 ? SkRegion::kDifference_Op : SkRegion::kIntersect_Op;
Chris Craik8c271ca2014-03-25 10:33:01 -0700512 }
513
John Reckd0a0b2a2014-03-20 16:28:56 -0700514 Outline& mutableOutline() {
515 return mPrimitiveFields.mOutline;
Chris Craikb49f4462014-03-20 12:44:20 -0700516 }
517
Chris Craik8c271ca2014-03-25 10:33:01 -0700518 RevealClip& mutableRevealClip() {
519 return mPrimitiveFields.mRevealClip;
520 }
521
John Reck25fbb3f2014-06-12 13:46:45 -0700522 const LayerProperties& layerProperties() const {
523 return mLayerProperties;
524 }
525
526 LayerProperties& mutateLayerProperties() {
527 return mLayerProperties;
528 }
529
John Reck293e8682014-06-17 10:34:02 -0700530 // Returns true if damage calculations should be clipped to bounds
531 // TODO: Figure out something better for getZ(), as children should still be
532 // clipped to this RP's bounds. But as we will damage -INT_MAX to INT_MAX
533 // for this RP's getZ() anyway, this can be optimized when we have a
534 // Z damage estimate instead of INT_MAX
535 bool getClipDamageToBounds() const {
536 return getClipToBounds() && (getZ() <= 0 || getOutline().isEmpty());
537 }
538
John Reckacb6f072014-03-12 16:11:23 -0700539private:
John Reckacb6f072014-03-12 16:11:23 -0700540
John Reckacb6f072014-03-12 16:11:23 -0700541 // Rendering properties
John Reckd0a0b2a2014-03-20 16:28:56 -0700542 struct PrimitiveFields {
543 PrimitiveFields();
John Reckacb6f072014-03-12 16:11:23 -0700544
John Reckd0a0b2a2014-03-20 16:28:56 -0700545 Outline mOutline;
Chris Craik8c271ca2014-03-25 10:33:01 -0700546 RevealClip mRevealClip;
John Reckd0a0b2a2014-03-20 16:28:56 -0700547 bool mClipToBounds;
548 bool mProjectBackwards;
549 bool mProjectionReceiver;
550 float mAlpha;
551 bool mHasOverlappingRendering;
Chris Craikcc39e162014-04-25 18:34:11 -0700552 float mElevation;
John Reckd0a0b2a2014-03-20 16:28:56 -0700553 float mTranslationX, mTranslationY, mTranslationZ;
554 float mRotation, mRotationX, mRotationY;
555 float mScaleX, mScaleY;
556 float mPivotX, mPivotY;
557 int mLeft, mTop, mRight, mBottom;
558 int mWidth, mHeight;
John Reckd0a0b2a2014-03-20 16:28:56 -0700559 bool mPivotExplicitlySet;
John Reckf7483e32014-04-11 08:54:47 -0700560 bool mMatrixOrPivotDirty;
John Reckd0a0b2a2014-03-20 16:28:56 -0700561 } mPrimitiveFields;
562
John Reckacb6f072014-03-12 16:11:23 -0700563 SkMatrix* mStaticMatrix;
564 SkMatrix* mAnimationMatrix;
John Reck25fbb3f2014-06-12 13:46:45 -0700565 LayerProperties mLayerProperties;
John Reckacb6f072014-03-12 16:11:23 -0700566
John Reckd0a0b2a2014-03-20 16:28:56 -0700567 /**
568 * These fields are all generated from other properties and are not set directly.
569 */
570 struct ComputedFields {
571 ComputedFields();
572 ~ComputedFields();
573
574 /**
575 * Stores the total transformation of the DisplayList based upon its scalar
576 * translate/rotate/scale properties.
577 *
Chris Craik49e6c7392014-03-31 12:34:11 -0700578 * In the common translation-only case, the matrix isn't necessarily allocated,
579 * and the mTranslation properties are used directly.
John Reckd0a0b2a2014-03-20 16:28:56 -0700580 */
Chris Craik49e6c7392014-03-31 12:34:11 -0700581 SkMatrix* mTransformMatrix;
582
583 Sk3DView mTransformCamera;
John Reckd0a0b2a2014-03-20 16:28:56 -0700584 } mComputedFields;
John Reckacb6f072014-03-12 16:11:23 -0700585};
586
587} /* namespace uirenderer */
588} /* namespace android */
589
Chris Craikb49f4462014-03-20 12:44:20 -0700590#endif /* RENDERNODEPROPERTIES_H */