From 8da83f0059683464f8ca978aff31bbe0b64b856d Mon Sep 17 00:00:00 2001 From: Naomi Luis Date: Thu, 22 Sep 2011 15:58:27 -0700 Subject: [PATCH] liboverlay: Use even crop values The overlay hardware requires the values to be even. Calculate the ROI to ensure that the crop rectangle is correct after making the parameters even. CRs-fixed: 302916 Change-Id: I7316a65efe2b72c5392a3d2adbb95070662dced9 --- liboverlay/overlayLib.cpp | 23 +++++++++++++++++++++++ liboverlay/overlayLib.h | 1 + 2 files changed, 24 insertions(+) diff --git a/liboverlay/overlayLib.cpp b/liboverlay/overlayLib.cpp index 7a97063..186ea97 100644 --- a/liboverlay/overlayLib.cpp +++ b/liboverlay/overlayLib.cpp @@ -81,6 +81,26 @@ int overlay::get_mdp_orientation(int rotation, int flip) { return -1; } +// This function normalizes the crop values to be all even +void overlay::normalize_crop(uint32_t& xy, uint32_t& wh) { + + if (xy & 0x0001) { + // x or y is odd, increment it's value + xy += 1; + // Since we've incremented x(y), we need to decrement + // w(h) accordingly + if (wh & 0x0001) { + // w or h is odd, decrement it by 1, to make it even + EVEN_OUT(wh); + } else { + // w(h) is already even, hence we decrement by 2 + wh -=2; + } + } else { + EVEN_OUT(wh); + } +} + #define LOG_TAG "OverlayLIB" static void reportError(const char* message) { LOGE( "%s", message); @@ -1673,6 +1693,9 @@ bool OverlayDataChannel::setCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h) (ov.src_rect.h == h)) return true; + normalize_crop(x, w); + normalize_crop(y, h); + ov.src_rect.x = x; ov.src_rect.y = y; ov.src_rect.w = w; diff --git a/liboverlay/overlayLib.h b/liboverlay/overlayLib.h index aeee828..87a697c 100644 --- a/liboverlay/overlayLib.h +++ b/liboverlay/overlayLib.h @@ -126,6 +126,7 @@ unsigned int getOverlayConfig (unsigned int format3D, bool poll = true, int get_mdp_format(int format); int get_size(int format, int w, int h); int get_mdp_orientation(int rotation, int flip); +void normalize_crop(uint32_t& xy, uint32_t& wh); /* Print values being sent to driver in case of ioctl failures These logs are enabled only if DEBUG_OVERLAY is true */