1bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy/*
2bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * Copyright (C) 2010 The Android Open Source Project
3bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy *
4bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * you may not use this file except in compliance with the License.
6bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * You may obtain a copy of the License at
7bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy *
8bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy *
10bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * Unless required by applicable law or agreed to in writing, software
11bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * See the License for the specific language governing permissions and
14bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy * limitations under the License.
15bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy */
16bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_RECT_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_RECT_H
195b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
205b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#include <cmath>
21af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui#include <SkRect.h>
22bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
235cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include <utils/Log.h>
245cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2532f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik#include "Vertex.h"
2632f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik
27bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guynamespace android {
289d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
29bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
3062d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik#define RECT_STRING "%5.2f %5.2f %5.2f %5.2f"
3128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik#define RECT_ARGS(r) \
3228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    (r).left, (r).top, (r).right, (r).bottom
333f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik#define SK_RECT_ARGS(r) \
343f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    (r).left(), (r).top(), (r).right(), (r).bottom()
3528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik
36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy///////////////////////////////////////////////////////////////////////////////
37bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy// Structs
38bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy///////////////////////////////////////////////////////////////////////////////
39bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
4083b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopianclass Rect {
4183b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopianpublic:
427ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    float left;
437ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    float top;
447ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    float right;
457ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    float bottom;
467ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    // Used by Region
485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    typedef float value_type;
495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5083b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian    // we don't provide copy-ctor and operator= on purpose
5183b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian    // because we want the compiler generated versions
5283b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian
535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline Rect():
547ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            left(0),
557ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            top(0),
567ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            right(0),
577ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            bottom(0) {
587ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
597ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline Rect(float left, float top, float right, float bottom):
617ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            left(left),
627ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            top(top),
637ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            right(right),
647ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            bottom(bottom) {
657ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
667ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline Rect(float width, float height):
685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            left(0.0f),
695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            top(0.0f),
705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            right(width),
715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bottom(height) {
725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    }
735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
74af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui    inline Rect(const SkRect& rect):
75af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui            left(rect.fLeft),
76af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui            top(rect.fTop),
77af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui            right(rect.fRight),
78af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui            bottom(rect.fBottom) {
79af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui    }
80af6f7ed8dd4288a41d0a07a1f0f0be7d6d035b33ztenghui
817ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    friend int operator==(const Rect& a, const Rect& b) {
827ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return !memcmp(&a, &b, sizeof(a));
837ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
847ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
857ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    friend int operator!=(const Rect& a, const Rect& b) {
867ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return memcmp(&a, &b, sizeof(a));
877ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
887ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
895b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline void clear() {
905b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        left = top = right = bottom = 0.0f;
915b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    }
925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
935b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline bool isEmpty() const {
9483b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian        // this is written in such way this it'll handle NANs to return
9583b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian        // true (empty)
9683b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian        return !((left < right) && (top < bottom));
977ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
987ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
995b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline void setEmpty() {
1005b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        left = top = right = bottom = 0.0f;
1017ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1027ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline void set(float left, float top, float right, float bottom) {
1047ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        this->left = left;
1057ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        this->right = right;
1067ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        this->top = top;
1077ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        this->bottom = bottom;
1087ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1097ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1105b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    inline void set(const Rect& r) {
1117ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        set(r.left, r.top, r.right, r.bottom);
1127ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1137ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1148aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    inline float getWidth() const {
1157ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return right - left;
1167ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1177ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1188aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    inline float getHeight() const {
1197ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return bottom - top;
1207ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1217ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
12283b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian    bool intersects(float l, float t, float r, float b) const {
123a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy        return !intersectWith(l, t, r, b).isEmpty();
1247ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1257ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1267ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    bool intersects(const Rect& r) const {
1277ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return intersects(r.left, r.top, r.right, r.bottom);
1287ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1297ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
13083b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian    bool intersect(float l, float t, float r, float b) {
1318f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        Rect tmp(l, t, r, b);
1328f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy        intersectWith(tmp);
13383b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian        if (!tmp.isEmpty()) {
13483b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian            set(tmp);
1357ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy            return true;
1367ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        }
1377ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return false;
1387ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1397ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1407ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    bool intersect(const Rect& r) {
1417ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy        return intersect(r.left, r.top, r.right, r.bottom);
1427ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
1437ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy
1442db5e993b626794eb07a0ff354269f9a77da81b3Romain Guy    inline bool contains(float l, float t, float r, float b) const {
145ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy        return l >= left && t >= top && r <= right && b <= bottom;
146ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy    }
147ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy
1482db5e993b626794eb07a0ff354269f9a77da81b3Romain Guy    inline bool contains(const Rect& r) const {
149ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy        return contains(r.left, r.top, r.right, r.bottom);
150ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy    }
151ec31f83bd3af1f900d1ee9116b15f56904c66dcdRomain Guy
152079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy    bool unionWith(const Rect& r) {
153079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy        if (r.left < r.right && r.top < r.bottom) {
154079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy            if (left < right && top < bottom) {
155079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                if (left > r.left) left = r.left;
156079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                if (top > r.top) top = r.top;
157079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                if (right < r.right) right = r.right;
158079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                if (bottom < r.bottom) bottom = r.bottom;
159079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                return true;
160079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy            } else {
161079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                left = r.left;
162079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                top = r.top;
163079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                right = r.right;
164079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                bottom = r.bottom;
165079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy                return true;
166079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy            }
167079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy        }
168079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy        return false;
169079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy    }
170079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy
1715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void translate(float dx, float dy) {
1725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        left += dx;
1735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        right += dx;
1745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        top += dy;
1755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy        bottom += dy;
1765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    }
1775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
178e4aa95e3627226bcb0d8cc3e42dca6e4df8f421cChris Craik    void inset(float delta) {
179e4aa95e3627226bcb0d8cc3e42dca6e4df8f421cChris Craik        outset(-delta);
180e4aa95e3627226bcb0d8cc3e42dca6e4df8f421cChris Craik    }
181e4aa95e3627226bcb0d8cc3e42dca6e4df8f421cChris Craik
182c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    void outset(float delta) {
183c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik        left -= delta;
184c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik        top -= delta;
185c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik        right += delta;
186c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik        bottom += delta;
187c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    }
188c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
18905f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    void outset(float xdelta, float ydelta) {
19005f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik        left -= xdelta;
19105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik        top -= ydelta;
19205f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik        right += xdelta;
19305f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik        bottom += ydelta;
19405f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    }
19505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik
1965e49b307eb99269db2db257760508b8efd7bb97dChris Craik    /**
19732f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik     * Similar to snapToPixelBoundaries, but estimates bounds conservatively to handle GL rounding
19832f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik     * errors.
1995e49b307eb99269db2db257760508b8efd7bb97dChris Craik     *
20032f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik     * This function should be used whenever estimating the damage rect of geometry already mapped
20132f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik     * into layer space.
2025e49b307eb99269db2db257760508b8efd7bb97dChris Craik     */
20332f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik    void snapGeometryToPixelBoundaries(bool snapOut) {
20432f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik        if (snapOut) {
20532f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik            /* For AA geometry with a ramp perimeter, don't snap by rounding - AA geometry will have
20632f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * a 0.5 pixel perimeter not accounted for in its bounds. Instead, snap by
20732f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * conservatively rounding out the bounds with floor/ceil.
20832f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             *
20932f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * In order to avoid changing integer bounds with floor/ceil due to rounding errors
21032f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * inset the bounds first by the fudge factor. Very small fraction-of-a-pixel errors
21132f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * from this inset will only incur similarly small errors in output, due to transparency
21232f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * in extreme outside of the geometry.
21332f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             */
214564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            left = floorf(left + Vertex::GeometryFudgeFactor());
215564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            top = floorf(top + Vertex::GeometryFudgeFactor());
216564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            right = ceilf(right - Vertex::GeometryFudgeFactor());
217564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            bottom = ceilf(bottom - Vertex::GeometryFudgeFactor());
21832f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik        } else {
21932f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik            /* For other geometry, we do the regular rounding in order to snap, but also outset the
22032f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * bounds by a fudge factor. This ensures that ambiguous geometry (e.g. a non-AA Rect
22132f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             * with top left at (0.5, 0.5)) will err on the side of a larger damage rect.
22232f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik             */
223564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            left = floorf(left + 0.5f - Vertex::GeometryFudgeFactor());
224564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            top = floorf(top + 0.5f - Vertex::GeometryFudgeFactor());
225564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            right = floorf(right + 0.5f + Vertex::GeometryFudgeFactor());
226564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik            bottom = floorf(bottom + 0.5f + Vertex::GeometryFudgeFactor());
22732f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik        }
2285e49b307eb99269db2db257760508b8efd7bb97dChris Craik    }
2295e49b307eb99269db2db257760508b8efd7bb97dChris Craik
230bf434114cbf55b216fdc76fc8d65a75e84c9dab5Romain Guy    void snapToPixelBoundaries() {
231ae88e5e8e9cb6c9539314c4360c5b20f8ec1fefcRomain Guy        left = floorf(left + 0.5f);
232ae88e5e8e9cb6c9539314c4360c5b20f8ec1fefcRomain Guy        top = floorf(top + 0.5f);
233ae88e5e8e9cb6c9539314c4360c5b20f8ec1fefcRomain Guy        right = floorf(right + 0.5f);
234ae88e5e8e9cb6c9539314c4360c5b20f8ec1fefcRomain Guy        bottom = floorf(bottom + 0.5f);
235bf434114cbf55b216fdc76fc8d65a75e84c9dab5Romain Guy    }
236bf434114cbf55b216fdc76fc8d65a75e84c9dab5Romain Guy
237f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    void roundOut() {
238f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        left = floorf(left);
239f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        top = floorf(top);
240f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        right = ceilf(right);
241f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        bottom = ceilf(bottom);
242f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    }
243f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik
244c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik    void expandToCoverVertex(float x, float y) {
245c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik        left = fminf(left, x);
246c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik        top = fminf(top, y);
247c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik        right = fmaxf(right, x);
248c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik        bottom = fmaxf(bottom, y);
249c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik    }
250c93e45cf045f41aea95f856173e4043d988a5a5cChris Craik
251deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    void dump(const char* label = NULL) const {
252e4aa95e3627226bcb0d8cc3e42dca6e4df8f421cChris Craik        ALOGD("%s[l=%f t=%f r=%f b=%f]", label ? label : "Rect", left, top, right, bottom);
2537ae7ac48aa2b53453c9805075171ecd5bcafd7deRomain Guy    }
254bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
255a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guyprivate:
2568f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy    void intersectWith(Rect& tmp) const {
2572af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.left = fmaxf(left, tmp.left);
2582af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.top = fmaxf(top, tmp.top);
2592af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.right = fminf(right, tmp.right);
2602af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.bottom = fminf(bottom, tmp.bottom);
2618f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy    }
2628f85e80b64b89fd38cc23b129f61ec36ddde7f15Romain Guy
263a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    Rect intersectWith(float l, float t, float r, float b) const {
264a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy        Rect tmp;
2652af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.left = fmaxf(left, l);
2662af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.top = fmaxf(top, t);
2672af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.right = fminf(right, r);
2682af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        tmp.bottom = fminf(bottom, b);
269a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy        return tmp;
270a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy    }
271a1d3c91afbd52c7e8b01f4a9060c5459f02ae7a5Romain Guy
27283b186a246e8ffd52b91a17c0019dd8c9c9d21b1Mathias Agopian}; // class Rect
273bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2749d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
275bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // namespace android
276bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_RECT_H
278