From f3e85d432749ca77ad707bec523b67d741d43e6e Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 10 May 2013 18:01:12 -0700 Subject: take the "transparent region" into account for blending until now it was only used to discard a layer entirely. we're now reducing the size of the layer if it is still visible, if possible. this works for instance when a surfaceView is used and only the menu bar is displayed over it. Change-Id: I3f5527c5cd1e69ecc968272c8948f1513ada8c55 --- libs/ui/Rect.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libs/ui/Rect.cpp') diff --git a/libs/ui/Rect.cpp b/libs/ui/Rect.cpp index 365ea13f8a..b480f3a62b 100644 --- a/libs/ui/Rect.cpp +++ b/libs/ui/Rect.cpp @@ -107,4 +107,35 @@ Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) const { return result; } +Rect Rect::reduce(const Rect& exclude) const { + Rect result; + + uint32_t mask = 0; + mask |= (exclude.left > left) ? 1 : 0; + mask |= (exclude.top > top) ? 2 : 0; + mask |= (exclude.right < right) ? 4 : 0; + mask |= (exclude.bottom < bottom) ? 8 : 0; + + if (mask == 0) { + // crop entirely covers us + result.clear(); + } else { + result = *this; + if (!(mask & (mask - 1))) { + // power-of-2, i.e.: just one bit is set + if (mask & 1) { + result.right = exclude.left; + } else if (mask & 2) { + result.bottom = exclude.top; + } else if (mask & 4) { + result.left = exclude.right; + } else if (mask & 8) { + result.top = exclude.bottom; + } + } + } + + return result; +} + }; // namespace android -- cgit v1.2.3-59-g8ed1b