libhwcomposer: Make Rect utils generic.

Changes rect utility functions more generic.
Adds more sanity checks.

Change-Id: Ie935302592ac8eb5f7cfaffe03ac49da077a290d
This commit is contained in:
Jeykumar Sankaran
2013-10-03 11:30:55 -07:00
committed by Gerrit - the friendly Code Review server
parent d214b2c843
commit 6a58579603
2 changed files with 48 additions and 24 deletions

View File

@@ -917,26 +917,51 @@ void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
crop_b -= crop_h * bottomCutRatio; crop_b -= crop_h * bottomCutRatio;
} }
bool isValidRect(hwc_rect_t& rect) { bool isValidRect(const hwc_rect& rect)
{
return ((rect.bottom > rect.top) && (rect.right > rect.left)) ; return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
} }
/* computes intersection of two rects into 3rd arg/rect */ /* computes the intersection of two rects */
void getIntersection(hwc_rect_t& rect1, hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
hwc_rect_t& rect2, hwc_rect_t& irect) { {
irect.left = max(rect1.left, rect2.left); hwc_rect_t res;
irect.top = max(rect1.top, rect2.top);
irect.right = min(rect1.right, rect2.right); if(!isValidRect(rect1) || !isValidRect(rect2)){
irect.bottom = min(rect1.bottom, rect2.bottom); return (hwc_rect_t){0, 0, 0, 0};
} }
/* get union of two rects into 3rd rect */
void getUnion(hwc_rect_t& rect1, res.left = max(rect1.left, rect2.left);
hwc_rect_t& rect2, hwc_rect_t& irect) { res.top = max(rect1.top, rect2.top);
irect.left = min(rect1.left, rect2.left); res.right = min(rect1.right, rect2.right);
irect.top = min(rect1.top, rect2.top); res.bottom = min(rect1.bottom, rect2.bottom);
irect.right = max(rect1.right, rect2.right);
irect.bottom = max(rect1.bottom, rect2.bottom); if(!isValidRect(res))
return (hwc_rect_t){0, 0, 0, 0};
return res;
}
/* computes the union of two rects */
hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
{
hwc_rect_t res;
if(!isValidRect(rect1)){
return rect2;
}
if(!isValidRect(rect2)){
return rect1;
}
res.left = min(rect1.left, rect2.left);
res.top = min(rect1.top, rect2.top);
res.right = max(rect1.right, rect2.right);
res.bottom = max(rect1.bottom, rect2.bottom);
return res;
} }
/* deducts given rect from layers display-frame and source crop. /* deducts given rect from layers display-frame and source crop.
@@ -987,7 +1012,8 @@ void optimizeLayerRects(hwc_context_t *ctx,
if(!needsScaling(ctx, &list->hwLayers[j], dpy)) { if(!needsScaling(ctx, &list->hwLayers[j], dpy)) {
hwc_rect_t& bottomframe = hwc_rect_t& bottomframe =
(hwc_rect_t&)list->hwLayers[j].displayFrame; (hwc_rect_t&)list->hwLayers[j].displayFrame;
getIntersection(bottomframe, topframe, (hwc_rect_t&)irect);
hwc_rect_t irect = getIntersection(bottomframe, topframe);
if(isValidRect(irect)) { if(isValidRect(irect)) {
//if intersection is valid rect, deduct it //if intersection is valid rect, deduct it
deductRect(&list->hwLayers[j], irect); deductRect(&list->hwLayers[j], irect);
@@ -1013,11 +1039,11 @@ void getNonWormholeRegion(hwc_display_contents_1_t* list,
for (uint32_t i = 1; i < last; i++) { for (uint32_t i = 1; i < last; i++) {
hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
getUnion(nwr, displayFrame, nwr); nwr = getUnion(nwr, displayFrame);
} }
//Intersect with the framebuffer //Intersect with the framebuffer
getIntersection(nwr, fbDisplayFrame, nwr); nwr = getIntersection(nwr, fbDisplayFrame);
} }
bool isExternalActive(hwc_context_t* ctx) { bool isExternalActive(hwc_context_t* ctx) {

View File

@@ -185,12 +185,10 @@ void dumpsys_log(android::String8& buf, const char* fmt, ...);
int getExtOrientation(hwc_context_t* ctx); int getExtOrientation(hwc_context_t* ctx);
bool isValidRect(hwc_rect_t& rect); bool isValidRect(const hwc_rect_t& rect);
void deductRect(const hwc_layer_1_t* layer, hwc_rect_t& irect); void deductRect(const hwc_layer_1_t* layer, hwc_rect_t& irect);
void getIntersection(hwc_rect_t& rect1, hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
hwc_rect_t& rect2, hwc_rect_t& irect); hwc_rect_t getUnion(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
void getUnion(hwc_rect_t& rect1,
hwc_rect_t& rect2, hwc_rect_t& irect);
void optimizeLayerRects(hwc_context_t *ctx, void optimizeLayerRects(hwc_context_t *ctx,
const hwc_display_contents_1_t *list, const int& dpy); const hwc_display_contents_1_t *list, const int& dpy);