summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Riddle Hsu <riddlehsu@google.com> 2018-11-30 20:46:53 +0800
committer Riddle Hsu <riddlehsu@google.com> 2018-11-30 12:49:00 +0000
commit39d4aa5bb18a14680347f6f6d1a34eed918e274b (patch)
tree40d06173e8d45207ad57cf3fae1c4d72bd8f4c8e
parent75cc36e4924601444c75b24a59fac117ead00ee2 (diff)
Fix empty region if the scale is smaller than 1
It may be used by Layer of SurfaceFlinger to calculate touchable region. It should be able to scale a window to a smaller size. Bug: 111440400 Test: manual - An input-associated surface with a scaling matrix that has dsdx, dsdy < 1. Use "dumpsys input" to observe its touchable region. Change-Id: I495bd16acec77f913fd39dcac90404eddc71cabb
-rw-r--r--libs/ui/Region.cpp10
-rw-r--r--libs/ui/include/ui/Region.h2
-rw-r--r--services/inputflinger/InputDispatcher.cpp2
-rw-r--r--services/surfaceflinger/Layer.cpp11
4 files changed, 14 insertions, 11 deletions
diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp
index 815093174c..618c7d62b1 100644
--- a/libs/ui/Region.cpp
+++ b/libs/ui/Region.cpp
@@ -325,14 +325,14 @@ Region& Region::translateSelf(int x, int y) {
return *this;
}
-Region& Region::scaleSelf(int sx, int sy) {
+Region& Region::scaleSelf(float sx, float sy) {
size_t count = mStorage.size();
Rect* rects = mStorage.editArray();
while (count) {
- rects->left *= sx;
- rects->right *= sx;
- rects->top *= sy;
- rects->bottom *= sy;
+ rects->left = static_cast<int32_t>(rects->left * sx + 0.5f);
+ rects->right = static_cast<int32_t>(rects->right * sx + 0.5f);
+ rects->top = static_cast<int32_t>(rects->top * sy + 0.5f);
+ rects->bottom = static_cast<int32_t>(rects->bottom * sy + 0.5f);
rects++;
count--;
}
diff --git a/libs/ui/include/ui/Region.h b/libs/ui/include/ui/Region.h
index c5e31c56f1..0a09960994 100644
--- a/libs/ui/include/ui/Region.h
+++ b/libs/ui/include/ui/Region.h
@@ -89,7 +89,7 @@ public:
// these translate rhs first
Region& translateSelf(int dx, int dy);
- Region& scaleSelf(int sx, int sy);
+ Region& scaleSelf(float sx, float sy);
Region& orSelf(const Region& rhs, int dx, int dy);
Region& xorSelf(const Region& rhs, int dx, int dy);
Region& andSelf(const Region& rhs, int dx, int dy);
diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp
index bea4f911d9..0e258c8eb9 100644
--- a/services/inputflinger/InputDispatcher.cpp
+++ b/services/inputflinger/InputDispatcher.cpp
@@ -3518,7 +3518,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) {
dump += StringPrintf(INDENT3 "%zu: name='%s', displayId=%d, "
"paused=%s, hasFocus=%s, hasWallpaper=%s, "
"visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
- "frame=[%d,%d][%d,%d], globalScale=%f, windowScale=%f,%f"
+ "frame=[%d,%d][%d,%d], globalScale=%f, windowScale=(%f,%f), "
"touchableRegion=",
i, windowInfo->name.c_str(), windowInfo->displayId,
toString(windowInfo->paused),
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 81456dfea9..58fd86618e 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2069,10 +2069,13 @@ InputWindowInfo Layer::fillInputInfo(const Rect& screenBounds) {
info.frameBottom = screenBounds.bottom - info.surfaceInset;
ui::Transform t = getTransform();
- info.windowXScale *= 1.0f / t.sx();
- info.windowYScale *= 1.0f / t.sy();
-
- info.touchableRegion.scaleSelf(t.sx(), t.sy());
+ const float xScale = t.sx();
+ const float yScale = t.sy();
+ if (xScale != 1.0f || yScale != 1.0f) {
+ info.windowXScale *= 1.0f / xScale;
+ info.windowYScale *= 1.0f / yScale;
+ info.touchableRegion.scaleSelf(xScale, yScale);
+ }
info.touchableRegion = info.touchableRegion.translate(
screenBounds.left,