hwc: utils: Include orientation while screen-fitting.
MDP doesn't like out-of-screen-bounds parameters. So based on the position of
the layer, we adjust the portion of layer the MDP should pick.
However, this did not factor in orientation, so far. This patch does that and
allows panning to work in other orientations, without having to use GPU.
Bug: 7313955
Change-Id: Ice17ad144abcd60279c2ef9ad87fc617a1bd3621
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index d5266c2..6cab545 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -231,7 +231,7 @@
ALOGD_IF(isDebug(),"%s: Destination has negative coordinates",
__FUNCTION__);
- qhwc::calculate_crop_rects(crop, dst, hw_w, hw_h);
+ qhwc::calculate_crop_rects(crop, dst, hw_w, hw_h, 0);
//Update calulated width and height
crop_w = crop.right - crop.left;
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 9e7da37..0398a17 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -148,60 +148,65 @@
}
}
+static inline void calc_cut(float& leftCut, float& topCut, float& rightCut,
+ float& bottomCut, int orient) {
+ if(orient & HAL_TRANSFORM_FLIP_H) {
+ swap(leftCut, rightCut);
+ }
+ if(orient & HAL_TRANSFORM_FLIP_V) {
+ swap(topCut, bottomCut);
+ }
+ if(orient & HAL_TRANSFORM_ROT_90) {
+ //Anti clock swapping
+ float tmpCut = leftCut;
+ leftCut = topCut;
+ topCut = rightCut;
+ rightCut = bottomCut;
+ bottomCut = tmpCut;
+ }
+}
+
//Crops source buffer against destination and FB boundaries
void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
- const int fbWidth, const int fbHeight) {
-
- int& crop_x = crop.left;
- int& crop_y = crop.top;
+ const int fbWidth, const int fbHeight, int orient) {
+ int& crop_l = crop.left;
+ int& crop_t = crop.top;
int& crop_r = crop.right;
int& crop_b = crop.bottom;
int crop_w = crop.right - crop.left;
int crop_h = crop.bottom - crop.top;
- int& dst_x = dst.left;
- int& dst_y = dst.top;
+ int& dst_l = dst.left;
+ int& dst_t = dst.top;
int& dst_r = dst.right;
int& dst_b = dst.bottom;
- int dst_w = dst.right - dst.left;
- int dst_h = dst.bottom - dst.top;
+ int dst_w = abs(dst.right - dst.left);
+ int dst_h = abs(dst.bottom - dst.top);
- if(dst_x < 0) {
- float scale_x = crop_w * 1.0f / dst_w;
- float diff_factor = (scale_x * abs(dst_x));
- crop_x = crop_x + (int)diff_factor;
- crop_w = crop_r - crop_x;
+ float leftCut = 0.0f, rightCut = 0.0f, topCut = 0.0f, bottomCut = 0.0f;
- dst_x = 0;
- dst_w = dst_r - dst_x;;
+ if(dst_l < 0) {
+ leftCut = (float)(0.0f - dst_l) / (float)dst_w;
+ dst_l = 0;
}
if(dst_r > fbWidth) {
- float scale_x = crop_w * 1.0f / dst_w;
- float diff_factor = scale_x * (dst_r - fbWidth);
- crop_r = crop_r - diff_factor;
- crop_w = crop_r - crop_x;
-
+ rightCut = (float)(dst_r - fbWidth) / (float)dst_w;
dst_r = fbWidth;
- dst_w = dst_r - dst_x;
}
- if(dst_y < 0) {
- float scale_y = crop_h * 1.0f / dst_h;
- float diff_factor = scale_y * abs(dst_y);
- crop_y = crop_y + diff_factor;
- crop_h = crop_b - crop_y;
-
- dst_y = 0;
- dst_h = dst_b - dst_y;
+ if(dst_t < 0) {
+ topCut = (float)(0 - dst_t) / (float)dst_h;
+ dst_t = 0;
}
if(dst_b > fbHeight) {
- float scale_y = crop_h * 1.0f / dst_h;
- float diff_factor = scale_y * (dst_b - fbHeight);
- crop_b = crop_b - diff_factor;
- crop_h = crop_b - crop_y;
-
+ bottomCut = (float)(dst_b - fbHeight) / (float)dst_h;
dst_b = fbHeight;
- dst_h = dst_b - dst_y;
}
+
+ calc_cut(leftCut, topCut, rightCut, bottomCut, orient);
+ crop_l += crop_w * leftCut;
+ crop_t += crop_h * topCut;
+ crop_r -= crop_w * rightCut;
+ crop_b -= crop_h * bottomCut;
}
bool isExternalActive(hwc_context_t* ctx) {
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 0307e10..9193540 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -91,7 +91,7 @@
void closeContext(hwc_context_t *ctx);
//Crops source buffer against destination and FB boundaries
void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
- const int fbWidth, const int fbHeight);
+ const int fbWidth, const int fbHeight, int orient);
bool isExternalActive(hwc_context_t* ctx);
@@ -154,6 +154,13 @@
return fd;
}
+template <class T>
+inline void swap(T& a, T& b) {
+ T tmp = a;
+ a = b;
+ b = tmp;
+}
+
}; //qhwc namespace
struct vsync_state {
diff --git a/libhwcomposer/hwc_video.cpp b/libhwcomposer/hwc_video.cpp
index cb5cf1e..77c9328 100644
--- a/libhwcomposer/hwc_video.cpp
+++ b/libhwcomposer/hwc_video.cpp
@@ -143,6 +143,10 @@
ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
ov.setSource(pargs, ovutils::OV_PIPE0);
+ int transform = layer->transform & FINAL_TRANSFORM_MASK;
+ ovutils::eTransform orient =
+ static_cast<ovutils::eTransform>(transform);
+
hwc_rect_t sourceCrop = layer->sourceCrop;
hwc_rect_t displayFrame = layer->displayFrame;
@@ -157,7 +161,8 @@
displayFrame.top < 0 ||
displayFrame.right > fbWidth ||
displayFrame.bottom > fbHeight) {
- calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight);
+ calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight,
+ transform);
}
// source crop x,y,w,h
@@ -167,9 +172,6 @@
//Only for Primary
ov.setCrop(dcrop, ovutils::OV_PIPE0);
- int transform = layer->transform;
- ovutils::eTransform orient =
- static_cast<ovutils::eTransform>(transform);
ov.setTransform(orient, ovutils::OV_PIPE0);
// position x,y,w,h