sde: Move utility functions to common header file

Move utility functions to common header file accesible from
SDE and HWC modules.

Change-Id: Id5183bb8f41a223273c973960f653f155e3c4c05
This commit is contained in:
Tatenda Chipeperekwa
2015-02-10 12:18:34 -08:00
committed by Gerrit - the friendly Code Review server
parent f1f85ba397
commit 2ba9789b07
5 changed files with 55 additions and 49 deletions

View File

@@ -53,6 +53,24 @@
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b))
template <class T>
inline void Swap(T &a, T &b) {
T c(a);
a = b;
b = c;
}
// factor value should be in powers of 2(eg: 1, 2, 4, 8)
template <class T1, class T2>
inline T1 FloorToMultipleOf(const T1 &value, const T2 &factor) {
return (T1)(value & (~(factor - 1)));
}
template <class T1, class T2>
inline T1 CeilToMultipleOf(const T1 &value, const T2 &factor) {
return (T1)((value + (factor - 1)) & (~(factor - 1)));
}
namespace sde { namespace sde {
const int kThreadPriorityUrgent = -9; const int kThreadPriorityUrgent = -9;

View File

@@ -33,11 +33,14 @@
#include <stdint.h> #include <stdint.h>
#include <core/sde_types.h> #include <core/sde_types.h>
#include <core/layer_stack.h> #include <core/layer_stack.h>
#include <utils/debug.h>
namespace sde { namespace sde {
bool IsValidRect(const LayerRect &rect); bool IsValidRect(const LayerRect &rect);
LayerRect GetIntersection(const LayerRect &rect1, const LayerRect &rect2); LayerRect GetIntersection(const LayerRect &rect1, const LayerRect &rect2);
void LogRect(DebugTag debug_tag, const char *prefix, const LayerRect &roi);
void NormalizeRect(const uint32_t &factor, LayerRect *rect);
} // namespace sde } // namespace sde

View File

@@ -25,6 +25,7 @@
#include <math.h> #include <math.h>
#include <utils/constants.h> #include <utils/constants.h>
#include <utils/debug.h> #include <utils/debug.h>
#include <utils/rect.h>
#include "res_manager.h" #include "res_manager.h"
@@ -179,8 +180,8 @@ DisplayError ResManager::Config(DisplayResourceContext *display_resource_ctx, HW
float rot_scale_x = 1.0f, rot_scale_y = 1.0f; float rot_scale_x = 1.0f, rot_scale_y = 1.0f;
if (!IsValidDimension(layer.src_rect, layer.dst_rect)) { if (!IsValidDimension(layer.src_rect, layer.dst_rect)) {
DLOGV_IF(kTagResources, "Input is invalid"); DLOGV_IF(kTagResources, "Input is invalid");
LogRectVerbose("input layer src_rect", layer.src_rect); LogRect(kTagResources, "input layer src_rect", layer.src_rect);
LogRectVerbose("input layer dst_rect", layer.dst_rect); LogRect(kTagResources, "input layer dst_rect", layer.dst_rect);
return kErrorNotSupported; return kErrorNotSupported;
} }
@@ -239,21 +240,21 @@ DisplayError ResManager::Config(DisplayResourceContext *display_resource_ctx, HW
DLOGV_IF(kTagResources, "layer = %d, left pipe_id = %x", DLOGV_IF(kTagResources, "layer = %d, left pipe_id = %x",
i, layer_config->left_pipe.pipe_id); i, layer_config->left_pipe.pipe_id);
LogRectVerbose("input layer src_rect", layer.src_rect); LogRect(kTagResources, "input layer src_rect", layer.src_rect);
LogRectVerbose("input layer dst_rect", layer.dst_rect); LogRect(kTagResources, "input layer dst_rect", layer.dst_rect);
for (uint32_t k = 0; k < layer_config->num_rotate; k++) { for (uint32_t k = 0; k < layer_config->num_rotate; k++) {
DLOGV_IF(kTagResources, "rotate num = %d, scale_x = %.2f, scale_y = %.2f", DLOGV_IF(kTagResources, "rotate num = %d, scale_x = %.2f, scale_y = %.2f",
k, rot_scale_x, rot_scale_y); k, rot_scale_x, rot_scale_y);
LogRectVerbose("rotate src", layer_config->rotates[k].src_roi); LogRect(kTagResources, "rotate src", layer_config->rotates[k].src_roi);
LogRectVerbose("rotate dst", layer_config->rotates[k].dst_roi); LogRect(kTagResources, "rotate dst", layer_config->rotates[k].dst_roi);
} }
LogRectVerbose("cropped src_rect", src_rect); LogRect(kTagResources, "cropped src_rect", src_rect);
LogRectVerbose("cropped dst_rect", dst_rect); LogRect(kTagResources, "cropped dst_rect", dst_rect);
LogRectVerbose("left pipe src", layer_config->left_pipe.src_roi); LogRect(kTagResources, "left pipe src", layer_config->left_pipe.src_roi);
LogRectVerbose("left pipe dst", layer_config->left_pipe.dst_roi); LogRect(kTagResources, "left pipe dst", layer_config->left_pipe.dst_roi);
if (hw_layers->config[i].right_pipe.pipe_id) { if (hw_layers->config[i].right_pipe.pipe_id) {
LogRectVerbose("right pipe src", layer_config->right_pipe.src_roi); LogRect(kTagResources, "right pipe src", layer_config->right_pipe.src_roi);
LogRectVerbose("right pipe dst", layer_config->right_pipe.dst_roi); LogRect(kTagResources, "right pipe dst", layer_config->right_pipe.dst_roi);
} }
} }
@@ -529,21 +530,4 @@ void ResManager::SplitRect(bool flip_horizontal, const LayerRect &src_rect,
} }
} }
void ResManager::LogRectVerbose(const char *prefix, const LayerRect &roi) {
DLOGV_IF(kTagResources, "%s: left = %.0f, top = %.0f, right = %.0f, bottom = %.0f",
prefix, roi.left, roi.top, roi.right, roi.bottom);
}
void ResManager::NormalizeRect(const uint32_t &factor, LayerRect *rect) {
uint32_t left = UINT32(ceilf(rect->left));
uint32_t top = UINT32(ceilf(rect->top));
uint32_t right = UINT32(floorf(rect->right));
uint32_t bottom = UINT32(floorf(rect->bottom));
rect->left = FLOAT(CeilToMultipleOf(left, factor));
rect->top = FLOAT(CeilToMultipleOf(top, factor));
rect->right = FLOAT(FloorToMultipleOf(right, factor));
rect->bottom = FLOAT(FloorToMultipleOf(bottom, factor));
}
} // namespace sde } // namespace sde

View File

@@ -187,7 +187,6 @@ class ResManager : public DumpImpl {
bool IsYuvFormat(LayerBufferFormat format) { return (format >= kFormatYCbCr420Planar); } bool IsYuvFormat(LayerBufferFormat format) { return (format >= kFormatYCbCr420Planar); }
bool IsRotationNeeded(float rotation) bool IsRotationNeeded(float rotation)
{ return (UINT32(rotation) == 90 || UINT32(rotation) == 270); } { return (UINT32(rotation) == 90 || UINT32(rotation) == 270); }
void LogRectVerbose(const char *prefix, const LayerRect &roi);
void RotationConfig(const LayerTransform &transform, const float &scale_x, void RotationConfig(const LayerTransform &transform, const float &scale_x,
const float &scale_y, LayerRect *src_rect, const float &scale_y, LayerRect *src_rect,
struct HWLayerConfig *layer_config, uint32_t *rotate_count); struct HWLayerConfig *layer_config, uint32_t *rotate_count);
@@ -195,29 +194,10 @@ class ResManager : public DumpImpl {
const uint32_t roate_cnt); const uint32_t roate_cnt);
void AssignRotator(HWRotateInfo *rotate, uint32_t *rotate_cnt); void AssignRotator(HWRotateInfo *rotate, uint32_t *rotate_cnt);
void ClearRotator(DisplayResourceContext *display_resource_ctx); void ClearRotator(DisplayResourceContext *display_resource_ctx);
void NormalizeRect(const uint32_t &factor, LayerRect *rect);
DisplayError AllocRotatorBuffer(Handle display_ctx, HWLayers *hw_layers); DisplayError AllocRotatorBuffer(Handle display_ctx, HWLayers *hw_layers);
void SetRotatorOutputFormat(const LayerBufferFormat &input_format, bool bwc, bool rot90, void SetRotatorOutputFormat(const LayerBufferFormat &input_format, bool bwc, bool rot90,
LayerBufferFormat *output_format); LayerBufferFormat *output_format);
template <class T>
inline void Swap(T &a, T &b) {
T c(a);
a = b;
b = c;
}
// factor value should be in powers of 2(eg: 1, 2, 4, 8)
template <class T1, class T2>
inline T1 FloorToMultipleOf(const T1 &value, const T2 &factor) {
return (T1)(value & (~(factor - 1)));
}
template <class T1, class T2>
inline T1 CeilToMultipleOf(const T1 &value, const T2 &factor) {
return (T1)((value + (factor - 1)) & (~(factor - 1)));
}
Locker locker_; Locker locker_;
HWResourceInfo hw_res_info_; HWResourceInfo hw_res_info_;
HWBlockContext hw_block_ctx_[kHWBlockMax]; HWBlockContext hw_block_ctx_[kHWBlockMax];

View File

@@ -27,7 +27,11 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <math.h>
#include <utils/rect.h> #include <utils/rect.h>
#include <utils/constants.h>
#define __CLASS__ "RectUtils"
namespace sde { namespace sde {
@@ -55,5 +59,22 @@ LayerRect GetIntersection(const LayerRect &rect1, const LayerRect &rect2) {
return res; return res;
} }
void LogRect(DebugTag debug_tag, const char *prefix, const LayerRect &roi) {
DLOGV_IF(debug_tag, "%s: left = %.0f, top = %.0f, right = %.0f, bottom = %.0f",
prefix, roi.left, roi.top, roi.right, roi.bottom);
}
void NormalizeRect(const uint32_t &factor, LayerRect *rect) {
uint32_t left = UINT32(ceilf(rect->left));
uint32_t top = UINT32(ceilf(rect->top));
uint32_t right = UINT32(floorf(rect->right));
uint32_t bottom = UINT32(floorf(rect->bottom));
rect->left = FLOAT(CeilToMultipleOf(left, factor));
rect->top = FLOAT(CeilToMultipleOf(top, factor));
rect->right = FLOAT(FloorToMultipleOf(right, factor));
rect->bottom = FLOAT(FloorToMultipleOf(bottom, factor));
}
} // namespace sde } // namespace sde