Loading libs/ui/include/ui/FloatRect.h +11 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,17 @@ public: float getWidth() const { return right - left; } float getHeight() const { return bottom - top; } FloatRect intersect(const FloatRect& other) const { return { // Inline to avoid tromping on other min/max defines or adding a // dependency on STL (left > other.left) ? left : other.left, (top > other.top) ? top : other.top, (right < other.right) ? right : other.right, (bottom < other.bottom) ? bottom : other.bottom }; } float left = 0.0f; float top = 0.0f; float right = 0.0f; Loading libs/ui/include/ui/Rect.h +9 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,15 @@ public: bottom = rb.y; } inline explicit Rect(const FloatRect& floatRect) { // Ideally we would use std::round, but we don't want to add an STL // dependency here, so we use an approximation left = static_cast<int32_t>(floatRect.left + 0.5f); top = static_cast<int32_t>(floatRect.top + 0.5f); right = static_cast<int32_t>(floatRect.right + 0.5f); bottom = static_cast<int32_t>(floatRect.bottom + 0.5f); } void makeInvalid(); inline void clear() { Loading services/surfaceflinger/Layer.cpp +23 −10 Original line number Diff line number Diff line Loading @@ -447,6 +447,14 @@ static Rect reduce(const Rect& win, const Region& exclude) { return Region(win).subtract(exclude).getBounds(); } static FloatRect reduce(const FloatRect& win, const Region& exclude) { if (CC_LIKELY(exclude.isEmpty())) { return win; } // Convert through Rect (by rounding) for lack of FloatRegion return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); } Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const { const Layer::State& s(getDrawingState()); Rect win(s.active.w, s.active.h); Loading Loading @@ -485,12 +493,12 @@ Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const { return win; } Rect Layer::computeBounds() const { FloatRect Layer::computeBounds() const { const Layer::State& s(getDrawingState()); return computeBounds(s.activeTransparentRegion); } Rect Layer::computeBounds(const Region& activeTransparentRegion) const { FloatRect Layer::computeBounds(const Region& activeTransparentRegion) const { const Layer::State& s(getDrawingState()); Rect win(s.active.w, s.active.h); Loading @@ -507,14 +515,16 @@ Rect Layer::computeBounds(const Region& activeTransparentRegion) const { } Transform t = getTransform(); FloatRect floatWin = win.toFloatRect(); if (p != nullptr) { win = t.transform(win); win.intersect(bounds, &win); win = t.inverse().transform(win); floatWin = t.transform(floatWin); floatWin = floatWin.intersect(bounds.toFloatRect()); floatWin = t.inverse().transform(floatWin); } // subtract the transparent region and snap to the bounds return reduce(win, activeTransparentRegion); return reduce(floatWin, activeTransparentRegion); } Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const { Loading Loading @@ -723,7 +733,9 @@ void Layer::setGeometry( s.active.w, activeCrop.bottom)); } Rect frame(t.transform(computeBounds(activeTransparentRegion))); // computeBounds returns a FloatRect to provide more accuracy during the // transformation. We then round upon constructing 'frame'. Rect frame{t.transform(computeBounds(activeTransparentRegion))}; if (!s.finalCrop.isEmpty()) { if(!frame.intersect(s.finalCrop, &frame)) { frame.clear(); Loading Loading @@ -1225,16 +1237,17 @@ void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw, * minimal value)? Or, we could make GL behave like HWC -- but this feel * like more of a hack. */ Rect win(computeBounds()); const Rect bounds{computeBounds()}; // Rounds from FloatRect Transform t = getTransform(); Rect win = bounds; if (!s.finalCrop.isEmpty()) { win = t.transform(win); if (!win.intersect(s.finalCrop, &win)) { win.clear(); } win = t.inverse().transform(win); if (!win.intersect(computeBounds(), &win)) { if (!win.intersect(bounds, &win)) { win.clear(); } } Loading Loading @@ -1440,7 +1453,7 @@ void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, const Layer::State& s(getDrawingState()); const Transform hwTransform(hw->getTransform()); const uint32_t hw_h = hw->getHeight(); Rect win = computeBounds(); FloatRect win = computeBounds(); vec2 lt = vec2(win.left, win.top); vec2 lb = vec2(win.left, win.bottom); Loading services/surfaceflinger/Layer.h +3 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <utils/String8.h> #include <utils/Timers.h> #include <ui/FloatRect.h> #include <ui/FrameStats.h> #include <ui/GraphicBuffer.h> #include <ui/PixelFormat.h> Loading Loading @@ -258,8 +259,8 @@ public: void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, bool useIdentityTransform) const; Rect computeBounds(const Region& activeTransparentRegion) const; Rect computeBounds() const; FloatRect computeBounds(const Region& activeTransparentRegion) const; FloatRect computeBounds() const; int32_t getSequence() const { return sequence; } Loading services/surfaceflinger/Transform.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,27 @@ Rect Transform::transform(const Rect& bounds, bool roundOutwards) const return r; } FloatRect Transform::transform(const FloatRect& bounds) const { vec2 lt(bounds.left, bounds.top); vec2 rt(bounds.right, bounds.top); vec2 lb(bounds.left, bounds.bottom); vec2 rb(bounds.right, bounds.bottom); lt = transform(lt); rt = transform(rt); lb = transform(lb); rb = transform(rb); FloatRect r; r.left = min(lt[0], rt[0], lb[0], rb[0]); r.top = min(lt[1], rt[1], lb[1], rb[1]); r.right = max(lt[0], rt[0], lb[0], rb[0]); r.bottom = max(lt[1], rt[1], lb[1], rb[1]); return r; } Region Transform::transform(const Region& reg) const { Region out; Loading Loading
libs/ui/include/ui/FloatRect.h +11 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,17 @@ public: float getWidth() const { return right - left; } float getHeight() const { return bottom - top; } FloatRect intersect(const FloatRect& other) const { return { // Inline to avoid tromping on other min/max defines or adding a // dependency on STL (left > other.left) ? left : other.left, (top > other.top) ? top : other.top, (right < other.right) ? right : other.right, (bottom < other.bottom) ? bottom : other.bottom }; } float left = 0.0f; float top = 0.0f; float right = 0.0f; Loading
libs/ui/include/ui/Rect.h +9 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,15 @@ public: bottom = rb.y; } inline explicit Rect(const FloatRect& floatRect) { // Ideally we would use std::round, but we don't want to add an STL // dependency here, so we use an approximation left = static_cast<int32_t>(floatRect.left + 0.5f); top = static_cast<int32_t>(floatRect.top + 0.5f); right = static_cast<int32_t>(floatRect.right + 0.5f); bottom = static_cast<int32_t>(floatRect.bottom + 0.5f); } void makeInvalid(); inline void clear() { Loading
services/surfaceflinger/Layer.cpp +23 −10 Original line number Diff line number Diff line Loading @@ -447,6 +447,14 @@ static Rect reduce(const Rect& win, const Region& exclude) { return Region(win).subtract(exclude).getBounds(); } static FloatRect reduce(const FloatRect& win, const Region& exclude) { if (CC_LIKELY(exclude.isEmpty())) { return win; } // Convert through Rect (by rounding) for lack of FloatRegion return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); } Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const { const Layer::State& s(getDrawingState()); Rect win(s.active.w, s.active.h); Loading Loading @@ -485,12 +493,12 @@ Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const { return win; } Rect Layer::computeBounds() const { FloatRect Layer::computeBounds() const { const Layer::State& s(getDrawingState()); return computeBounds(s.activeTransparentRegion); } Rect Layer::computeBounds(const Region& activeTransparentRegion) const { FloatRect Layer::computeBounds(const Region& activeTransparentRegion) const { const Layer::State& s(getDrawingState()); Rect win(s.active.w, s.active.h); Loading @@ -507,14 +515,16 @@ Rect Layer::computeBounds(const Region& activeTransparentRegion) const { } Transform t = getTransform(); FloatRect floatWin = win.toFloatRect(); if (p != nullptr) { win = t.transform(win); win.intersect(bounds, &win); win = t.inverse().transform(win); floatWin = t.transform(floatWin); floatWin = floatWin.intersect(bounds.toFloatRect()); floatWin = t.inverse().transform(floatWin); } // subtract the transparent region and snap to the bounds return reduce(win, activeTransparentRegion); return reduce(floatWin, activeTransparentRegion); } Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const { Loading Loading @@ -723,7 +733,9 @@ void Layer::setGeometry( s.active.w, activeCrop.bottom)); } Rect frame(t.transform(computeBounds(activeTransparentRegion))); // computeBounds returns a FloatRect to provide more accuracy during the // transformation. We then round upon constructing 'frame'. Rect frame{t.transform(computeBounds(activeTransparentRegion))}; if (!s.finalCrop.isEmpty()) { if(!frame.intersect(s.finalCrop, &frame)) { frame.clear(); Loading Loading @@ -1225,16 +1237,17 @@ void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw, * minimal value)? Or, we could make GL behave like HWC -- but this feel * like more of a hack. */ Rect win(computeBounds()); const Rect bounds{computeBounds()}; // Rounds from FloatRect Transform t = getTransform(); Rect win = bounds; if (!s.finalCrop.isEmpty()) { win = t.transform(win); if (!win.intersect(s.finalCrop, &win)) { win.clear(); } win = t.inverse().transform(win); if (!win.intersect(computeBounds(), &win)) { if (!win.intersect(bounds, &win)) { win.clear(); } } Loading Loading @@ -1440,7 +1453,7 @@ void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, const Layer::State& s(getDrawingState()); const Transform hwTransform(hw->getTransform()); const uint32_t hw_h = hw->getHeight(); Rect win = computeBounds(); FloatRect win = computeBounds(); vec2 lt = vec2(win.left, win.top); vec2 lb = vec2(win.left, win.bottom); Loading
services/surfaceflinger/Layer.h +3 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <utils/String8.h> #include <utils/Timers.h> #include <ui/FloatRect.h> #include <ui/FrameStats.h> #include <ui/GraphicBuffer.h> #include <ui/PixelFormat.h> Loading Loading @@ -258,8 +259,8 @@ public: void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, bool useIdentityTransform) const; Rect computeBounds(const Region& activeTransparentRegion) const; Rect computeBounds() const; FloatRect computeBounds(const Region& activeTransparentRegion) const; FloatRect computeBounds() const; int32_t getSequence() const { return sequence; } Loading
services/surfaceflinger/Transform.cpp +21 −0 Original line number Diff line number Diff line Loading @@ -224,6 +224,27 @@ Rect Transform::transform(const Rect& bounds, bool roundOutwards) const return r; } FloatRect Transform::transform(const FloatRect& bounds) const { vec2 lt(bounds.left, bounds.top); vec2 rt(bounds.right, bounds.top); vec2 lb(bounds.left, bounds.bottom); vec2 rb(bounds.right, bounds.bottom); lt = transform(lt); rt = transform(rt); lb = transform(lb); rb = transform(rb); FloatRect r; r.left = min(lt[0], rt[0], lb[0], rb[0]); r.top = min(lt[1], rt[1], lb[1], rb[1]); r.right = max(lt[0], rt[0], lb[0], rb[0]); r.bottom = max(lt[1], rt[1], lb[1], rb[1]); return r; } Region Transform::transform(const Region& reg) const { Region out; Loading