Skip to content

Commit 196a7da

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Sanitize display list properties" into jb-dev
2 parents 4b51e29 + f26c8be commit 196a7da

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

libs/hwui/DisplayListRenderer.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ class DisplayList {
170170
}
171171

172172
void setAlpha(float alpha) {
173+
alpha = fminf(1.0f, fmaxf(0.0f, alpha));
173174
if (alpha != mAlpha) {
174175
mAlpha = alpha;
175-
mMultipliedAlpha = (int)(255 * alpha);
176+
mMultipliedAlpha = (int) (255 * alpha);
176177
}
177178
}
178179

@@ -184,7 +185,7 @@ class DisplayList {
184185
if (translationX != mTranslationX) {
185186
mTranslationX = translationX;
186187
mMatrixDirty = true;
187-
if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) {
188+
if (mTranslationX == 0.0f && mTranslationY == 0.0f) {
188189
mMatrixFlags &= ~TRANSLATION;
189190
} else {
190191
mMatrixFlags |= TRANSLATION;
@@ -196,7 +197,7 @@ class DisplayList {
196197
if (translationY != mTranslationY) {
197198
mTranslationY = translationY;
198199
mMatrixDirty = true;
199-
if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) {
200+
if (mTranslationX == 0.0f && mTranslationY == 0.0f) {
200201
mMatrixFlags &= ~TRANSLATION;
201202
} else {
202203
mMatrixFlags |= TRANSLATION;
@@ -208,7 +209,7 @@ class DisplayList {
208209
if (rotation != mRotation) {
209210
mRotation = rotation;
210211
mMatrixDirty = true;
211-
if (ALMOST_EQUAL(mRotation, 0)) {
212+
if (mRotation == 0.0f) {
212213
mMatrixFlags &= ~ROTATION;
213214
} else {
214215
mMatrixFlags |= ROTATION;
@@ -220,7 +221,7 @@ class DisplayList {
220221
if (rotationX != mRotationX) {
221222
mRotationX = rotationX;
222223
mMatrixDirty = true;
223-
if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) {
224+
if (mRotationX == 0.0f && mRotationY == 0.0f) {
224225
mMatrixFlags &= ~ROTATION_3D;
225226
} else {
226227
mMatrixFlags |= ROTATION_3D;
@@ -232,7 +233,7 @@ class DisplayList {
232233
if (rotationY != mRotationY) {
233234
mRotationY = rotationY;
234235
mMatrixDirty = true;
235-
if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) {
236+
if (mRotationX == 0.0f && mRotationY == 0.0f) {
236237
mMatrixFlags &= ~ROTATION_3D;
237238
} else {
238239
mMatrixFlags |= ROTATION_3D;
@@ -244,7 +245,7 @@ class DisplayList {
244245
if (scaleX != mScaleX) {
245246
mScaleX = scaleX;
246247
mMatrixDirty = true;
247-
if (ALMOST_EQUAL(mScaleX, 1) && ALMOST_EQUAL(mScaleY, 1)) {
248+
if (mScaleX == 1.0f && mScaleY == 1.0f) {
248249
mMatrixFlags &= ~SCALE;
249250
} else {
250251
mMatrixFlags |= SCALE;
@@ -267,7 +268,7 @@ class DisplayList {
267268
void setPivotX(float pivotX) {
268269
mPivotX = pivotX;
269270
mMatrixDirty = true;
270-
if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) {
271+
if (mPivotX == 0.0f && mPivotY == 0.0f) {
271272
mMatrixFlags &= ~PIVOT;
272273
} else {
273274
mMatrixFlags |= PIVOT;
@@ -278,7 +279,7 @@ class DisplayList {
278279
void setPivotY(float pivotY) {
279280
mPivotY = pivotY;
280281
mMatrixDirty = true;
281-
if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) {
282+
if (mPivotX == 0.0f && mPivotY == 0.0f) {
282283
mMatrixFlags &= ~PIVOT;
283284
} else {
284285
mMatrixFlags |= PIVOT;

libs/hwui/OpenGLRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class OpenGLRenderer {
9090
virtual int saveLayerAlpha(float left, float top, float right, float bottom,
9191
int alpha, int flags);
9292

93-
virtual void setAlpha(float alpha) {
93+
void setAlpha(float alpha) {
9494
mSnapshot->alpha = alpha;
9595
}
9696

libs/hwui/utils/Compare.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020
#include <cmath>
2121

22-
#define EPSILON 0.00001f
23-
24-
#define ALMOST_EQUAL(u, v) (fabs((u) - (v)) < EPSILON)
25-
2622
/**
2723
* Compare floats.
2824
*/

0 commit comments

Comments
 (0)