From 51450039e2fd266b31f33dfd1b4353bc1b0b145a Mon Sep 17 00:00:00 2001 From: Pablo Ceballos Date: Wed, 3 Aug 2016 10:20:45 -0700 Subject: [PATCH] SF: Change rounding behavior in setGeometry - Add an option for a transform to round outwards instead of to the nearest pixel. - Use this new rounding behavior when converting the crop rectangle from display-space to layer-space. Otherwise a pixel that will partially be on the screen might be marked as transparent. Bug 30510632 Change-Id: I1aece177cc29c54ee0d4a2c919e47442eb455f30 --- services/surfaceflinger/Layer.cpp | 2 +- services/surfaceflinger/Transform.cpp | 17 ++++++++++++----- services/surfaceflinger/Transform.h | 3 ++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 2a3c229c35..2b899398be 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -559,7 +559,7 @@ void Layer::setGeometry( #endif activeCrop.clear(); } - activeCrop = s.active.transform.inverse().transform(activeCrop); + activeCrop = s.active.transform.inverse().transform(activeCrop, true); // This needs to be here as transform.transform(Rect) computes the // transformed rect and then takes the bounding box of the result before // returning. This means diff --git a/services/surfaceflinger/Transform.cpp b/services/surfaceflinger/Transform.cpp index c2be91df24..6be9ae2c5f 100644 --- a/services/surfaceflinger/Transform.cpp +++ b/services/surfaceflinger/Transform.cpp @@ -196,7 +196,7 @@ Rect Transform::makeBounds(int w, int h) const return transform( Rect(w, h) ); } -Rect Transform::transform(const Rect& bounds) const +Rect Transform::transform(const Rect& bounds, bool roundOutwards) const { Rect r; vec2 lt( bounds.left, bounds.top ); @@ -209,10 +209,17 @@ Rect Transform::transform(const Rect& bounds) const lb = transform(lb); rb = transform(rb); - r.left = floorf(min(lt[0], rt[0], lb[0], rb[0]) + 0.5f); - r.top = floorf(min(lt[1], rt[1], lb[1], rb[1]) + 0.5f); - r.right = floorf(max(lt[0], rt[0], lb[0], rb[0]) + 0.5f); - r.bottom = floorf(max(lt[1], rt[1], lb[1], rb[1]) + 0.5f); + if (roundOutwards) { + r.left = floorf(min(lt[0], rt[0], lb[0], rb[0])); + r.top = floorf(min(lt[1], rt[1], lb[1], rb[1])); + r.right = ceilf(max(lt[0], rt[0], lb[0], rb[0])); + r.bottom = ceilf(max(lt[1], rt[1], lb[1], rb[1])); + } else { + r.left = floorf(min(lt[0], rt[0], lb[0], rb[0]) + 0.5f); + r.top = floorf(min(lt[1], rt[1], lb[1], rb[1]) + 0.5f); + r.right = floorf(max(lt[0], rt[0], lb[0], rb[0]) + 0.5f); + r.bottom = floorf(max(lt[1], rt[1], lb[1], rb[1]) + 0.5f); + } return r; } diff --git a/services/surfaceflinger/Transform.h b/services/surfaceflinger/Transform.h index 90855da04d..66463a02e3 100644 --- a/services/surfaceflinger/Transform.h +++ b/services/surfaceflinger/Transform.h @@ -78,7 +78,8 @@ public: Rect makeBounds(int w, int h) const; vec2 transform(int x, int y) const; Region transform(const Region& reg) const; - Rect transform(const Rect& bounds) const; + Rect transform(const Rect& bounds, + bool roundOutwards = false) const; Transform operator * (const Transform& rhs) const; // assumes the last row is < 0 , 0 , 1 > vec2 transform(const vec2& v) const; -- 2.11.0