reformat Rect.{cpp|h}
Change-Id: I45b1f6646541a1abacce1e70df00a770e47b820e
This commit is contained in:
parent
b6df7d0e4c
commit
6c7f25afb7
@ -35,14 +35,25 @@ public:
|
|||||||
|
|
||||||
inline Rect() {
|
inline Rect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rect(int32_t w, int32_t h) {
|
inline Rect(int32_t w, int32_t h) {
|
||||||
left = top = 0; right = w; bottom = h;
|
left = top = 0;
|
||||||
|
right = w;
|
||||||
|
bottom = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) {
|
inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) {
|
||||||
left = l; top = t; right = r; bottom = b;
|
left = l;
|
||||||
|
top = t;
|
||||||
|
right = r;
|
||||||
|
bottom = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rect(const Point& lt, const Point& rb) {
|
inline Rect(const Point& lt, const Point& rb) {
|
||||||
left = lt.x; top = lt.y; right = rb.x; bottom = rb.y;
|
left = lt.x;
|
||||||
|
top = lt.y;
|
||||||
|
right = rb.x;
|
||||||
|
bottom = rb.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void makeInvalid();
|
void makeInvalid();
|
||||||
@ -53,43 +64,36 @@ public:
|
|||||||
|
|
||||||
// a valid rectangle has a non negative width and height
|
// a valid rectangle has a non negative width and height
|
||||||
inline bool isValid() const {
|
inline bool isValid() const {
|
||||||
return (width()>=0) && (height()>=0);
|
return (getWidth() >= 0) && (getHeight() >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// an empty rect has a zero width or height, or is invalid
|
// an empty rect has a zero width or height, or is invalid
|
||||||
inline bool isEmpty() const {
|
inline bool isEmpty() const {
|
||||||
return (width()<=0) || (height()<=0);
|
return (getWidth() <= 0) || (getHeight() <= 0);
|
||||||
}
|
|
||||||
|
|
||||||
inline void set(const Rect& rhs) {
|
|
||||||
operator = (rhs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// rectangle's width
|
// rectangle's width
|
||||||
inline int32_t getWidth() const {
|
inline int32_t getWidth() const {
|
||||||
return right-left;
|
return right - left;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rectangle's height
|
// rectangle's height
|
||||||
inline int32_t getHeight() const {
|
inline int32_t getHeight() const {
|
||||||
return bottom-top;
|
return bottom - top;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rect getBounds() const {
|
inline Rect getBounds() const {
|
||||||
return Rect(right-left, bottom-top);
|
return Rect(right - left, bottom - top);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32_t width() const { return getWidth(); }
|
|
||||||
inline int32_t height() const { return getHeight(); }
|
|
||||||
|
|
||||||
void setLeftTop(const Point& lt) {
|
void setLeftTop(const Point& lt) {
|
||||||
left = lt.x;
|
left = lt.x;
|
||||||
top = lt.y;
|
top = lt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRightBottom(const Point& rb) {
|
void setRightBottom(const Point& rb) {
|
||||||
right = rb.x;
|
right = rb.x;
|
||||||
bottom = rb.y;
|
bottom = rb.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the following 4 functions return the 4 corners of the rect as Point
|
// the following 4 functions return the 4 corners of the rect as Point
|
||||||
@ -120,6 +124,16 @@ public:
|
|||||||
// vectors.
|
// vectors.
|
||||||
bool operator < (const Rect& rhs) const;
|
bool operator < (const Rect& rhs) const;
|
||||||
|
|
||||||
|
const Rect operator + (const Point& rhs) const;
|
||||||
|
const Rect operator - (const Point& rhs) const;
|
||||||
|
|
||||||
|
Rect& operator += (const Point& rhs) {
|
||||||
|
return offsetBy(rhs.x, rhs.y);
|
||||||
|
}
|
||||||
|
Rect& operator -= (const Point& rhs) {
|
||||||
|
return offsetBy(-rhs.x, -rhs.y);
|
||||||
|
}
|
||||||
|
|
||||||
Rect& offsetToOrigin() {
|
Rect& offsetToOrigin() {
|
||||||
right -= left;
|
right -= left;
|
||||||
bottom -= top;
|
bottom -= top;
|
||||||
@ -132,22 +146,11 @@ public:
|
|||||||
Rect& offsetBy(const Point& dp) {
|
Rect& offsetBy(const Point& dp) {
|
||||||
return offsetBy(dp.x, dp.y);
|
return offsetBy(dp.x, dp.y);
|
||||||
}
|
}
|
||||||
Rect& operator += (const Point& rhs) {
|
|
||||||
return offsetBy(rhs.x, rhs.y);
|
|
||||||
}
|
|
||||||
Rect& operator -= (const Point& rhs) {
|
|
||||||
return offsetBy(-rhs.x, -rhs.y);
|
|
||||||
}
|
|
||||||
const Rect operator + (const Point& rhs) const;
|
|
||||||
const Rect operator - (const Point& rhs) const;
|
|
||||||
|
|
||||||
void translate(int32_t dx, int32_t dy) { // legacy, don't use.
|
Rect& offsetTo(int32_t x, int32_t y);
|
||||||
offsetBy(dx, dy);
|
Rect& offsetBy(int32_t x, int32_t y);
|
||||||
}
|
|
||||||
|
|
||||||
Rect& offsetTo(int32_t x, int32_t y);
|
bool intersect(const Rect& with, Rect* result) const;
|
||||||
Rect& offsetBy(int32_t x, int32_t y);
|
|
||||||
bool intersect(const Rect& with, Rect* result) const;
|
|
||||||
|
|
||||||
// Create a new Rect by transforming this one using a graphics HAL
|
// Create a new Rect by transforming this one using a graphics HAL
|
||||||
// transform. This rectangle is defined in a coordinate space starting at
|
// transform. This rectangle is defined in a coordinate space starting at
|
||||||
@ -156,6 +159,11 @@ public:
|
|||||||
// (height, width). Otherwise the output rectangle is in the same space as
|
// (height, width). Otherwise the output rectangle is in the same space as
|
||||||
// the input.
|
// the input.
|
||||||
Rect transform(uint32_t xform, int32_t width, int32_t height) const;
|
Rect transform(uint32_t xform, int32_t width, int32_t height) const;
|
||||||
|
|
||||||
|
// for backward compatibility
|
||||||
|
inline int32_t width() const { return getWidth(); }
|
||||||
|
inline int32_t height() const { return getHeight(); }
|
||||||
|
inline void set(const Rect& rhs) { operator = (rhs); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ANDROID_BASIC_TYPES_TRAITS(Rect)
|
ANDROID_BASIC_TYPES_TRAITS(Rect)
|
||||||
|
@ -20,11 +20,11 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
static inline int32_t min(int32_t a, int32_t b) {
|
static inline int32_t min(int32_t a, int32_t b) {
|
||||||
return (a<b) ? a : b;
|
return (a < b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t max(int32_t a, int32_t b) {
|
static inline int32_t max(int32_t a, int32_t b) {
|
||||||
return (a>b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rect::makeInvalid() {
|
void Rect::makeInvalid() {
|
||||||
@ -34,18 +34,17 @@ void Rect::makeInvalid() {
|
|||||||
bottom = -1;
|
bottom = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rect::operator < (const Rect& rhs) const
|
bool Rect::operator <(const Rect& rhs) const {
|
||||||
{
|
if (top < rhs.top) {
|
||||||
if (top<rhs.top) {
|
|
||||||
return true;
|
return true;
|
||||||
} else if (top == rhs.top) {
|
} else if (top == rhs.top) {
|
||||||
if (left < rhs.left) {
|
if (left < rhs.left) {
|
||||||
return true;
|
return true;
|
||||||
} else if (left == rhs.left) {
|
} else if (left == rhs.left) {
|
||||||
if (bottom<rhs.bottom) {
|
if (bottom < rhs.bottom) {
|
||||||
return true;
|
return true;
|
||||||
} else if (bottom == rhs.bottom) {
|
} else if (bottom == rhs.bottom) {
|
||||||
if (right<rhs.right) {
|
if (right < rhs.right) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,8 +53,7 @@ bool Rect::operator < (const Rect& rhs) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect& Rect::offsetTo(int32_t x, int32_t y)
|
Rect& Rect::offsetTo(int32_t x, int32_t y) {
|
||||||
{
|
|
||||||
right -= left - x;
|
right -= left - x;
|
||||||
bottom -= top - y;
|
bottom -= top - y;
|
||||||
left = x;
|
left = x;
|
||||||
@ -63,45 +61,41 @@ Rect& Rect::offsetTo(int32_t x, int32_t y)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect& Rect::offsetBy(int32_t x, int32_t y)
|
Rect& Rect::offsetBy(int32_t x, int32_t y) {
|
||||||
{
|
|
||||||
left += x;
|
left += x;
|
||||||
top += y;
|
top += y;
|
||||||
right+= x;
|
right += x;
|
||||||
bottom+=y;
|
bottom += y;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rect Rect::operator + (const Point& rhs) const
|
const Rect Rect::operator +(const Point& rhs) const {
|
||||||
{
|
const Rect result(left + rhs.x, top + rhs.y, right + rhs.x, bottom + rhs.y);
|
||||||
const Rect result(left+rhs.x, top+rhs.y, right+rhs.x, bottom+rhs.y);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rect Rect::operator - (const Point& rhs) const
|
const Rect Rect::operator -(const Point& rhs) const {
|
||||||
{
|
const Rect result(left - rhs.x, top - rhs.y, right - rhs.x, bottom - rhs.y);
|
||||||
const Rect result(left-rhs.x, top-rhs.y, right-rhs.x, bottom-rhs.y);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rect::intersect(const Rect& with, Rect* result) const
|
bool Rect::intersect(const Rect& with, Rect* result) const {
|
||||||
{
|
result->left = max(left, with.left);
|
||||||
result->left = max(left, with.left);
|
result->top = max(top, with.top);
|
||||||
result->top = max(top, with.top);
|
result->right = min(right, with.right);
|
||||||
result->right = min(right, with.right);
|
result->bottom = min(bottom, with.bottom);
|
||||||
result->bottom = min(bottom, with.bottom);
|
|
||||||
return !(result->isEmpty());
|
return !(result->isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) const {
|
Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) const {
|
||||||
Rect result(*this);
|
Rect result(*this);
|
||||||
if (xform & HAL_TRANSFORM_FLIP_H) {
|
if (xform & HAL_TRANSFORM_FLIP_H) {
|
||||||
result = Rect(width - result.right, result.top,
|
result = Rect(width - result.right, result.top, width - result.left,
|
||||||
width - result.left, result.bottom);
|
result.bottom);
|
||||||
}
|
}
|
||||||
if (xform & HAL_TRANSFORM_FLIP_V) {
|
if (xform & HAL_TRANSFORM_FLIP_V) {
|
||||||
result = Rect(result.left, height - result.bottom,
|
result = Rect(result.left, height - result.bottom, result.right,
|
||||||
result.right, height - result.top);
|
height - result.top);
|
||||||
}
|
}
|
||||||
if (xform & HAL_TRANSFORM_ROT_90) {
|
if (xform & HAL_TRANSFORM_ROT_90) {
|
||||||
int left = height - result.bottom;
|
int left = height - result.bottom;
|
||||||
|
@ -697,7 +697,7 @@ void Region::translate(Region& reg, int dx, int dy)
|
|||||||
size_t count = reg.mStorage.size();
|
size_t count = reg.mStorage.size();
|
||||||
Rect* rects = reg.mStorage.editArray();
|
Rect* rects = reg.mStorage.editArray();
|
||||||
while (count) {
|
while (count) {
|
||||||
rects->translate(dx, dy);
|
rects->offsetBy(dx, dy);
|
||||||
rects++;
|
rects++;
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ void DisplayDevice::setProjection(int orientation,
|
|||||||
|
|
||||||
mScissor = mGlobalTransform.transform(viewport);
|
mScissor = mGlobalTransform.transform(viewport);
|
||||||
if (mScissor.isEmpty()) {
|
if (mScissor.isEmpty()) {
|
||||||
mScissor.set(getBounds());
|
mScissor = getBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
mOrientation = orientation;
|
mOrientation = orientation;
|
||||||
|
@ -276,6 +276,8 @@ Rect Layer::computeBounds() const {
|
|||||||
if (!s.active.crop.isEmpty()) {
|
if (!s.active.crop.isEmpty()) {
|
||||||
win.intersect(s.active.crop, &win);
|
win.intersect(s.active.crop, &win);
|
||||||
}
|
}
|
||||||
|
// subtract the transparent region and snap to the bounds
|
||||||
|
win = Region(win).subtract(s.activeTransparentRegion).getBounds();
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,6 +668,8 @@ void Layer::computeGeometry(const sp<const DisplayDevice>& hw, LayerMesh* mesh)
|
|||||||
if (!s.active.crop.isEmpty()) {
|
if (!s.active.crop.isEmpty()) {
|
||||||
win.intersect(s.active.crop, &win);
|
win.intersect(s.active.crop, &win);
|
||||||
}
|
}
|
||||||
|
// subtract the transparent region and snap to the bounds
|
||||||
|
win = Region(win).subtract(s.activeTransparentRegion).getBounds();
|
||||||
if (mesh) {
|
if (mesh) {
|
||||||
tr.transform(mesh->mVertices[0], win.left, win.top);
|
tr.transform(mesh->mVertices[0], win.left, win.top);
|
||||||
tr.transform(mesh->mVertices[1], win.left, win.bottom);
|
tr.transform(mesh->mVertices[1], win.left, win.bottom);
|
||||||
|
Loading…
Reference in New Issue
Block a user