exynos: reorganized and updated from insignal
Changes needed on exynos4210 devices:
libcsc -> libseccscapi
libswconverter -> remove
TARGET_HAL_PATH := hardware/samsung/exynos4/hal
TARGET_OMX_PATH := hardware/samsung/exynos/multimedia/openmax
$(call inherit-product, hardware/samsung/exynos4210.mk)
Change-Id: Ic59ef95b85ef37b3f38fb36cf6a364a5414685ee
diff --git a/exynos4/hal/libhwcomposer/Android.mk b/exynos4/hal/libhwcomposer/Android.mk
new file mode 100644
index 0000000..902a72f
--- /dev/null
+++ b/exynos4/hal/libhwcomposer/Android.mk
@@ -0,0 +1,88 @@
+# Copyright (C) 2008 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+LOCAL_PATH:= $(call my-dir)
+# HAL module implemenation, not prelinked and stored in
+# hw/<COPYPIX_HARDWARE_MODULE_ID>.<ro.product.board>.so
+
+include $(CLEAR_VARS)
+LOCAL_PRELINK_MODULE := false
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_SHARED_LIBRARIES := liblog libcutils libEGL \
+ libGLESv1_CM
+
+ifeq ($(BOARD_USE_V4L2_ION),true)
+LOCAL_SHARED_LIBRARIES += libion
+endif
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/../include
+
+LOCAL_SRC_FILES := SecHWCLog.cpp SecHWCUtils.cpp SecHWC.cpp
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/../libfimg
+
+ifeq ($(TARGET_SOC),exynos4210)
+LOCAL_CFLAGS += -DSAMSUNG_EXYNOS4210
+endif
+
+ifeq ($(TARGET_SOC),exynos4x12)
+LOCAL_CFLAGS += -DSAMSUNG_EXYNOS4x12
+endif
+
+ifeq ($(BOARD_USES_HDMI),true)
+LOCAL_C_INCLUDES += \
+ $(TARGET_HAL_PATH)/libhwcomposer \
+ $(TARGET_HAL_PATH)/include \
+ $(TARGET_HAL_PATH)/libhdmi/libhdmiservice
+
+LOCAL_SHARED_LIBRARIES += libhdmiclient libTVOut
+
+LOCAL_CFLAGS += -DBOARD_USES_HDMI
+LOCAL_CFLAGS += -DBOARD_HDMI_STD=$(BOARD_HDMI_STD)
+LOCAL_CFLAGS += -DVIDEO_DUAL_DISPLAY
+
+ifeq ($(BOARD_USES_HDMI_SUBTITLES),true)
+ LOCAL_CFLAGS += -DBOARD_USES_HDMI_SUBTITLES
+endif
+
+ifeq ($(BOARD_HDMI_STD), STD_NTSC_M)
+LOCAL_CFLAGS += -DSTD_NTSC_M
+endif
+
+ifeq ($(BOARD_HDMI_STD),STD_480P)
+LOCAL_CFLAGS += -DSTD_480P
+endif
+
+ifeq ($(BOARD_HDMI_STD),STD_720P)
+LOCAL_CFLAGS += -DSTD_720P
+endif
+
+ifeq ($(BOARD_HDMI_STD),STD_1080P)
+LOCAL_CFLAGS += -DSTD_1080P
+endif
+endif
+
+ifeq ($(BOARD_USE_V4L2),true)
+LOCAL_CFLAGS += -DBOARD_USE_V4L2
+endif
+
+ifeq ($(BOARD_USE_V4L2_ION),true)
+LOCAL_CFLAGS += -DBOARD_USE_V4L2_ION
+endif
+
+LOCAL_MODULE := hwcomposer.$(TARGET_BOARD_PLATFORM)
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_SHARED_LIBRARY)
diff --git a/exynos4/hal/libhwcomposer/SecHWC.cpp b/exynos4/hal/libhwcomposer/SecHWC.cpp
new file mode 100644
index 0000000..d2f3ecc
--- /dev/null
+++ b/exynos4/hal/libhwcomposer/SecHWC.cpp
@@ -0,0 +1,957 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Rama, Meka(v.meka@samsung.com)
+ Sangwoo, Park(sw5771.park@samsung.com)
+ Jamie Oh (jung-min.oh@samsung.com)
+ * @date 2011-03-11
+ *
+ */
+
+#include <cutils/log.h>
+#include <cutils/atomic.h>
+
+#include <EGL/egl.h>
+
+#include "SecHWCUtils.h"
+
+#include "gralloc_priv.h"
+#ifdef HWC_HWOVERLAY
+#include <GLES/gl.h>
+#endif
+#if defined(BOARD_USES_HDMI)
+#include "SecHdmiClient.h"
+#include "SecTVOutService.h"
+
+#include "SecHdmi.h"
+
+//#define CHECK_EGL_FPS
+#ifdef CHECK_EGL_FPS
+extern void check_fps();
+#endif
+
+static int lcd_width, lcd_height;
+static int prev_usage = 0;
+
+#define CHECK_TIME_DEBUG 0
+#define SUPPORT_AUTO_UI_ROTATE
+#endif
+int testRenderNum =0;
+
+static int hwc_device_open(const struct hw_module_t* module, const char* name,
+ struct hw_device_t** device);
+
+static struct hw_module_methods_t hwc_module_methods = {
+ open: hwc_device_open
+};
+
+hwc_module_t HAL_MODULE_INFO_SYM = {
+ common: {
+ tag: HARDWARE_MODULE_TAG,
+ version_major: 1,
+ version_minor: 0,
+ id: HWC_HARDWARE_MODULE_ID,
+ name: "Samsung S5PC21X hwcomposer module",
+ author: "SAMSUNG",
+ methods: &hwc_module_methods,
+ }
+};
+
+/*****************************************************************************/
+
+static void dump_layer(hwc_layer_t const* l) {
+ LOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, "
+ "{%d,%d,%d,%d}, {%d,%d,%d,%d}",
+ l->compositionType, l->flags, l->handle, l->transform, l->blending,
+ l->sourceCrop.left,
+ l->sourceCrop.top,
+ l->sourceCrop.right,
+ l->sourceCrop.bottom,
+ l->displayFrame.left,
+ l->displayFrame.top,
+ l->displayFrame.right,
+ l->displayFrame.bottom);
+}
+
+void calculate_rect(struct hwc_win_info_t *win, hwc_layer_t *cur,
+ sec_rect *rect)
+{
+ rect->x = cur->displayFrame.left;
+ rect->y = cur->displayFrame.top;
+ rect->w = cur->displayFrame.right - cur->displayFrame.left;
+ rect->h = cur->displayFrame.bottom - cur->displayFrame.top;
+
+ if (rect->x < 0) {
+ if (rect->w + rect->x > win->lcd_info.xres)
+ rect->w = win->lcd_info.xres;
+ else
+ rect->w = rect->w + rect->x;
+ rect->x = 0;
+ } else {
+ if (rect->w + rect->x > win->lcd_info.xres)
+ rect->w = win->lcd_info.xres - rect->x;
+ }
+ if (rect->y < 0) {
+ if (rect->h + rect->y > win->lcd_info.yres)
+ rect->h = win->lcd_info.yres;
+ else
+ rect->h = rect->h + rect->y;
+ rect->y = 0;
+ } else {
+ if (rect->h + rect->y > win->lcd_info.yres)
+ rect->h = win->lcd_info.yres - rect->y;
+ }
+}
+
+static int set_src_dst_img_rect(hwc_layer_t *cur,
+ struct hwc_win_info_t *win,
+ struct sec_img *src_img,
+ struct sec_img *dst_img,
+ struct sec_rect *src_rect,
+ struct sec_rect *dst_rect,
+ int win_idx)
+{
+ private_handle_t *prev_handle = (private_handle_t *)(cur->handle);
+ sec_rect rect;
+
+ /* 1. Set src_img from prev_handle */
+ src_img->f_w = prev_handle->width;
+ src_img->f_h = prev_handle->height;
+ src_img->w = prev_handle->width;
+ src_img->h = prev_handle->height;
+ src_img->format = prev_handle->format;
+ src_img->base = (uint32_t)prev_handle->base;
+ src_img->offset = prev_handle->offset;
+ src_img->mem_id = prev_handle->fd;
+ src_img->paddr = prev_handle->paddr;
+ src_img->usage = prev_handle->usage;
+ src_img->uoffset = prev_handle->uoffset;
+ src_img->voffset = prev_handle->voffset;
+
+ src_img->mem_type = HWC_VIRT_MEM_TYPE;
+
+ switch (src_img->format) {
+ case HAL_PIXEL_FORMAT_YV12: /* To support video editor */
+ case HAL_PIXEL_FORMAT_YCbCr_420_P: /* To support SW codec */
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I:
+ src_img->f_w = (src_img->f_w + 15) & ~15;
+ src_img->f_h = (src_img->f_h + 1) & ~1;
+ break;
+ default:
+ src_img->f_w = src_img->w;
+ src_img->f_h = src_img->h;
+ break;
+ }
+
+ /* 2. Set dst_img from window(lcd) */
+ calculate_rect(win, cur, &rect);
+ dst_img->f_w = win->lcd_info.xres;
+ dst_img->f_h = win->lcd_info.yres;
+ dst_img->w = rect.w;
+ dst_img->h = rect.h;
+
+ switch (win->lcd_info.bits_per_pixel) {
+ case 32:
+ dst_img->format = HAL_PIXEL_FORMAT_RGBX_8888;
+ break;
+ default:
+ dst_img->format = HAL_PIXEL_FORMAT_RGB_565;
+ break;
+ }
+
+ dst_img->base = win->addr[win->buf_index];
+ dst_img->offset = 0;
+ dst_img->mem_id = 0;
+ dst_img->mem_type = HWC_PHYS_MEM_TYPE;
+
+ /* 3. Set src_rect(crop rect) */
+ if (cur->displayFrame.left < 0) {
+ src_rect->x =
+ (0 - cur->displayFrame.left)
+ *(src_img->w)
+ /(cur->displayFrame.right - cur->displayFrame.left + 1);
+ if (cur->displayFrame.right + 1 > win->lcd_info.xres) {
+ src_rect->w =
+ (cur->sourceCrop.right - cur->sourceCrop.left + 1) -
+ src_rect->x -
+ (cur->displayFrame.right - win->lcd_info.xres)
+ *(src_img->w)
+ /(cur->displayFrame.right - cur->displayFrame.left + 1);
+ } else {
+ src_rect->w =
+ (cur->sourceCrop.right - cur->sourceCrop.left + 1) -
+ src_rect->x;
+ }
+ } else {
+ src_rect->x = cur->sourceCrop.left;
+ if (cur->displayFrame.right + 1 > win->lcd_info.xres) {
+ src_rect->w =
+ (cur->sourceCrop.right - cur->sourceCrop.left + 1) -
+ src_rect->x -
+ (cur->displayFrame.right - win->lcd_info.xres)
+ *(src_img->w)
+ /(cur->displayFrame.right - cur->displayFrame.left + 1);
+ } else {
+ src_rect->w =
+ (cur->sourceCrop.right - cur->sourceCrop.left + 1);
+ }
+ }
+ if (cur->displayFrame.top < 0) {
+ src_rect->y =
+ (0 - cur->displayFrame.top)
+ *(src_img->h)
+ /(cur->displayFrame.bottom - cur->displayFrame.top + 1);
+ if (cur->displayFrame.bottom + 1 > win->lcd_info.yres) {
+ src_rect->h =
+ (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) -
+ src_rect->y -
+ (cur->displayFrame.bottom - win->lcd_info.yres)
+ *(src_img->h)
+ /(cur->displayFrame.bottom - cur->displayFrame.top + 1);
+ } else {
+ src_rect->h =
+ (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) -
+ src_rect->y;
+ }
+ } else {
+ src_rect->y = cur->sourceCrop.top;
+ if (cur->displayFrame.bottom + 1 > win->lcd_info.yres) {
+ src_rect->h =
+ (cur->sourceCrop.bottom - cur->sourceCrop.top + 1) -
+ src_rect->y -
+ (cur->displayFrame.bottom - win->lcd_info.yres)
+ *(src_img->h)
+ /(cur->displayFrame.bottom - cur->displayFrame.top + 1);
+ } else {
+ src_rect->h =
+ (cur->sourceCrop.bottom - cur->sourceCrop.top + 1);
+ }
+ }
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "crop information()::"
+ "sourceCrop left(%d),top(%d),right(%d),bottom(%d),"
+ "src_rect x(%d),y(%d),w(%d),h(%d),"
+ "prev_handle w(%d),h(%d)",
+ cur->sourceCrop.left,
+ cur->sourceCrop.top,
+ cur->sourceCrop.right,
+ cur->sourceCrop.bottom,
+ src_rect->x, src_rect->y, src_rect->w, src_rect->h,
+ prev_handle->width, prev_handle->height);
+
+ src_rect->x = SEC_MAX(src_rect->x, 0);
+ src_rect->y = SEC_MAX(src_rect->y, 0);
+ src_rect->w = SEC_MAX(src_rect->w, 0);
+ src_rect->w = SEC_MIN(src_rect->w, prev_handle->width);
+ src_rect->h = SEC_MAX(src_rect->h, 0);
+ src_rect->h = SEC_MIN(src_rect->h, prev_handle->height);
+
+ /* 4. Set dst_rect(fb or lcd)
+ * fimc dst image will be stored from left top corner
+ */
+ dst_rect->x = 0;
+ dst_rect->y = 0;
+ dst_rect->w = win->rect_info.w;
+ dst_rect->h = win->rect_info.h;
+
+ /* Summery */
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "set_src_dst_img_rect()::"
+ "SRC w(%d),h(%d),f_w(%d),f_h(%d),fmt(0x%x),"
+ "base(0x%x),offset(%d),paddr(0x%X),mem_id(%d),mem_type(%d)=>\r\n"
+ " DST w(%d),h(%d),f(0x%x),base(0x%x),"
+ "offset(%d),mem_id(%d),mem_type(%d),"
+ "rot(%d),win_idx(%d)"
+ " SRC_RECT x(%d),y(%d),w(%d),h(%d)=>"
+ "DST_RECT x(%d),y(%d),w(%d),h(%d)",
+ src_img->w, src_img->h, src_img->f_w, src_img->f_h, src_img->format,
+ src_img->base, src_img->offset, src_img->paddr, src_img->mem_id, src_img->mem_type,
+ dst_img->w, dst_img->h, dst_img->format, dst_img->base,
+ dst_img->offset, dst_img->mem_id, dst_img->mem_type,
+ cur->transform, win_idx,
+ src_rect->x, src_rect->y, src_rect->w, src_rect->h,
+ dst_rect->x, dst_rect->y, dst_rect->w, dst_rect->h);
+
+ return 0;
+}
+
+static int get_hwc_compos_decision(hwc_layer_t* cur, int iter, int win_cnt)
+{
+ if(cur->flags & HWC_SKIP_LAYER || !cur->handle) {
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s::is_skip_layer %d cur->handle %x ",
+ __func__, cur->flags & HWC_SKIP_LAYER, cur->handle);
+
+ return HWC_FRAMEBUFFER;
+ }
+
+ private_handle_t *prev_handle = (private_handle_t *)(cur->handle);
+ int compositionType = HWC_FRAMEBUFFER;
+
+ if (iter == 0) {
+ /* check here....if we have any resolution constraints */
+ if (((cur->sourceCrop.right - cur->sourceCrop.left + 1) < 16) ||
+ ((cur->sourceCrop.bottom - cur->sourceCrop.top + 1) < 8))
+ return compositionType;
+
+ if ((cur->transform == HAL_TRANSFORM_ROT_90) ||
+ (cur->transform == HAL_TRANSFORM_ROT_270)) {
+ if (((cur->displayFrame.right - cur->displayFrame.left + 1) < 4) ||
+ ((cur->displayFrame.bottom - cur->displayFrame.top + 1) < 8))
+ return compositionType;
+ } else if (((cur->displayFrame.right - cur->displayFrame.left + 1) < 8) ||
+ ((cur->displayFrame.bottom - cur->displayFrame.top + 1) < 4)) {
+ return compositionType;
+ }
+
+ switch (prev_handle->format) {
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
+ compositionType = HWC_OVERLAY;
+ break;
+ case HAL_PIXEL_FORMAT_YV12: /* YCrCb_420_P */
+ case HAL_PIXEL_FORMAT_YCbCr_420_P:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ if ((prev_handle->usage & GRALLOC_USAGE_HWC_HWOVERLAY) &&
+ (cur->blending == HWC_BLENDING_NONE))
+ compositionType = HWC_OVERLAY;
+ else
+ compositionType = HWC_FRAMEBUFFER;
+ break;
+ default:
+ compositionType = HWC_FRAMEBUFFER;
+ break;
+ }
+ }
+
+#ifdef SUB_TITLES_HWC
+ else if ((win_cnt > 0) &&
+ (prev_handle->usage & GRALLOC_USAGE_EXTERNAL_DISP)) {
+ switch (prev_handle->format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ case HAL_PIXEL_FORMAT_RGB_888:
+ case HAL_PIXEL_FORMAT_RGB_565:
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ compositionType = HWC_OVERLAY;
+ break;
+ default:
+ compositionType = HWC_FRAMEBUFFER;
+ break;
+ }
+
+ SEC_HWC_Log(HWC_LOG_DEBUG, "2nd iter###%s:: compositionType %d bpp %d"
+ " format %x src[%d %d %d %d] dst[%d %d %d %d] srcImg[%d %d]",
+ __func__, compositionType, prev_handle->bpp,
+ prev_handle->format,
+ cur->sourceCrop.left, cur->sourceCrop.right,
+ cur->sourceCrop.top, cur->sourceCrop.bottom,
+ cur->displayFrame.left, cur->displayFrame.right,
+ cur->displayFrame.top, cur->displayFrame.bottom,
+ prev_handle->width, prev_handle->height);
+ }
+#endif
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "%s::compositionType(%d)=>0:FB,1:OVERLAY \r\n"
+ " format(0x%x),magic(0x%x),flags(%d),size(%d),offset(%d)"
+ "b_addr(0x%x),usage(%d),w(%d),h(%d),bpp(%d)",
+ "get_hwc_compos_decision()", compositionType,
+ prev_handle->format, prev_handle->magic, prev_handle->flags,
+ prev_handle->size, prev_handle->offset, prev_handle->base,
+ prev_handle->usage, prev_handle->width, prev_handle->height,
+ prev_handle->bpp);
+
+ return compositionType;
+}
+
+static void reset_win_rect_info(hwc_win_info_t *win)
+{
+ win->rect_info.x = 0;
+ win->rect_info.y = 0;
+ win->rect_info.w = 0;
+ win->rect_info.h = 0;
+ return;
+}
+
+
+static int assign_overlay_window(struct hwc_context_t *ctx, hwc_layer_t *cur,
+ int win_idx, int layer_idx)
+{
+ struct hwc_win_info_t *win;
+ sec_rect rect;
+ int ret = 0;
+
+ if (NUM_OF_WIN <= win_idx)
+ return -1;
+
+ win = &ctx->win[win_idx];
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "%s:: left(%d),top(%d),right(%d),bottom(%d),transform(%d)"
+ "lcd_info.xres(%d),lcd_info.yres(%d)",
+ "++assign_overlay_window()",
+ cur->displayFrame.left, cur->displayFrame.top,
+ cur->displayFrame.right, cur->displayFrame.bottom, cur->transform,
+ win->lcd_info.xres, win->lcd_info.yres);
+
+ calculate_rect(win, cur, &rect);
+
+ if ((rect.x != win->rect_info.x) || (rect.y != win->rect_info.y) ||
+ (rect.w != win->rect_info.w) || (rect.h != win->rect_info.h)){
+ win->rect_info.x = rect.x;
+ win->rect_info.y = rect.y;
+ win->rect_info.w = rect.w;
+ win->rect_info.h = rect.h;
+ //turnoff the window and set the window position with new conf...
+ if (window_set_pos(win) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_set_pos is failed : %s",
+ __func__, strerror(errno));
+ ret = -1;
+ }
+ ctx->layer_prev_buf[win_idx] = 0;
+ }
+
+ win->layer_index = layer_idx;
+ win->status = HWC_WIN_RESERVED;
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "%s:: win_x %d win_y %d win_w %d win_h %d lay_idx %d win_idx %d\n",
+ "--assign_overlay_window()",
+ win->rect_info.x, win->rect_info.y, win->rect_info.w,
+ win->rect_info.h, win->layer_index, win_idx );
+
+ return 0;
+}
+
+static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
+{
+ struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
+ int overlay_win_cnt = 0;
+ int compositionType = 0;
+ int ret;
+
+ //if geometry is not changed, there is no need to do any work here
+ if (!list || (!(list->flags & HWC_GEOMETRY_CHANGED)))
+ return 0;
+
+ //all the windows are free here....
+ for (int i = 0 ; i < NUM_OF_WIN; i++) {
+ ctx->win[i].status = HWC_WIN_FREE;
+ ctx->win[i].buf_index = 0;
+ }
+
+ ctx->num_of_hwc_layer = 0;
+ ctx->num_of_fb_layer = 0;
+ ctx->num_2d_blit_layer = 0;
+
+ for (int i = 0; i < list->numHwLayers ; i++) {
+ hwc_layer_t* cur = &list->hwLayers[i];
+
+ if (overlay_win_cnt < NUM_OF_WIN) {
+ compositionType = get_hwc_compos_decision(cur, 0, overlay_win_cnt);
+
+ if (compositionType == HWC_FRAMEBUFFER) {
+ cur->compositionType = HWC_FRAMEBUFFER;
+ ctx->num_of_fb_layer++;
+ } else {
+ ret = assign_overlay_window(ctx, cur, overlay_win_cnt, i);
+ if (ret != 0) {
+ LOGE("assign_overlay_window fail, change to frambuffer");
+ cur->compositionType = HWC_FRAMEBUFFER;
+ ctx->num_of_fb_layer++;
+ continue;
+ }
+
+ cur->compositionType = HWC_OVERLAY;
+ cur->hints = HWC_HINT_CLEAR_FB;
+ overlay_win_cnt++;
+ ctx->num_of_hwc_layer++;
+ }
+ } else {
+ cur->compositionType = HWC_FRAMEBUFFER;
+ ctx->num_of_fb_layer++;
+ }
+ }
+
+#ifdef SUB_TITLES_HWC
+ for (int i = 0; i < list->numHwLayers ; i++) {
+ if (overlay_win_cnt < NUM_OF_WIN) {
+ hwc_layer_t* cur = &list->hwLayers[i];
+ if (get_hwc_compos_decision(cur, 1, overlay_win_cnt) == HWC_OVERLAY) {
+ ret = assign_overlay_window(ctx, cur, overlay_win_cnt, i);
+ if (ret == 0) {
+ cur->compositionType = HWC_OVERLAY;
+ cur->hints = HWC_HINT_CLEAR_FB;
+ overlay_win_cnt++;
+ ctx->num_of_hwc_layer++;
+ ctx->num_of_fb_layer--;
+ ctx->num_2d_blit_layer = 1;
+ }
+ }
+ }
+ else
+ break;
+ }
+#endif
+
+#if defined(BOARD_USES_HDMI)
+ android::SecHdmiClient *mHdmiClient = android::SecHdmiClient::getInstance();
+ mHdmiClient->setHdmiHwcLayer(ctx->num_of_hwc_layer);
+#endif
+
+ if (list->numHwLayers != (ctx->num_of_fb_layer + ctx->num_of_hwc_layer))
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "%s:: numHwLayers %d num_of_fb_layer %d num_of_hwc_layer %d ",
+ __func__, list->numHwLayers, ctx->num_of_fb_layer,
+ ctx->num_of_hwc_layer);
+
+ if (overlay_win_cnt < NUM_OF_WIN) {
+ //turn off the free windows
+ for (int i = overlay_win_cnt; i < NUM_OF_WIN; i++) {
+ window_hide(&ctx->win[i]);
+ reset_win_rect_info(&ctx->win[i]);
+ }
+ }
+
+ return 0;
+}
+
+static int hwc_set(hwc_composer_device_t *dev,
+ hwc_display_t dpy,
+ hwc_surface_t sur,
+ hwc_layer_list_t* list)
+{
+ struct hwc_context_t *ctx = (struct hwc_context_t *)dev;
+ int skipped_window_mask = 0;
+ hwc_layer_t* cur;
+ struct hwc_win_info_t *win;
+ int ret;
+ int pmem_phyaddr;
+ static int egl_check;
+ int egl_run = 0;
+ struct sec_img src_img;
+ struct sec_img dst_img;
+ struct sec_rect src_work_rect;
+ struct sec_rect dst_work_rect;
+
+ memset(&src_img, 0, sizeof(src_img));
+ memset(&dst_img, 0, sizeof(dst_img));
+ memset(&src_work_rect, 0, sizeof(src_work_rect));
+ memset(&dst_work_rect, 0, sizeof(dst_work_rect));
+
+#if defined(BOARD_USES_HDMI)
+ int skip_hdmi_rendering = 0;
+ int rotVal = 0;
+#endif
+
+ if (!list) {
+ //turn off the all windows
+ for (int i = 0; i < NUM_OF_WIN; i++) {
+ window_hide(&ctx->win[i]);
+ reset_win_rect_info(&ctx->win[i]);
+ ctx->win[i].status = HWC_WIN_FREE;
+ }
+ ctx->num_of_hwc_layer = 0;
+
+ if (sur == NULL && dpy == NULL)
+ return HWC_EGL_ERROR;
+ }
+
+ if(ctx->num_of_hwc_layer > NUM_OF_WIN)
+ ctx->num_of_hwc_layer = NUM_OF_WIN;
+
+ //compose hardware layers here
+ for (int i = 0; i < ctx->num_of_hwc_layer - ctx->num_2d_blit_layer; i++) {
+ win = &ctx->win[i];
+ if (win->status == HWC_WIN_RESERVED) {
+ cur = &list->hwLayers[win->layer_index];
+
+ if (cur->compositionType == HWC_OVERLAY) {
+ if (ctx->layer_prev_buf[i] == (uint32_t)cur->handle) {
+ /*
+ * In android platform, all the graphic buffer are at least
+ * double buffered (2 or more) this buffer is already rendered.
+ * It is the redundant src buffer for FIMC rendering.
+ */
+ LOGD("SKIP FIMC rendering for Layer%d", win->layer_index);
+#if defined(BOARD_USES_HDMI)
+ skip_hdmi_rendering = 1;
+#endif
+ continue;
+ }
+ ctx->layer_prev_buf[i] = (uint32_t)cur->handle;
+ // initialize the src & dist context for fimc
+ set_src_dst_img_rect(cur, win, &src_img, &dst_img,
+ &src_work_rect, &dst_work_rect, i);
+
+ ret = runFimc(ctx,
+ &src_img, &src_work_rect,
+ &dst_img, &dst_work_rect,
+ cur->transform);
+
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::runFimc fail : ret=%d\n",
+ __func__, ret);
+ skipped_window_mask |= (1 << i);
+ continue;
+ }
+
+ window_pan_display(win);
+
+ win->buf_index = (win->buf_index + 1) % NUM_OF_WIN_BUF;
+ if (win->power_state == 0)
+ window_show(win);
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s:: error : layer %d compositionType should have been"
+ " HWC_OVERLAY ", __func__, win->layer_index);
+ skipped_window_mask |= (1 << i);
+ continue;
+ }
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s:: error : window status should have "
+ "been HWC_WIN_RESERVED by now... ", __func__);
+ skipped_window_mask |= (1 << i);
+ continue;
+ }
+ }
+
+#ifdef SUB_TITLES_HWC
+ if (ctx->num_2d_blit_layer) {
+ g2d_rect srcRect;
+ g2d_rect dstRect;
+
+ win = &ctx->win[ctx->num_of_hwc_layer - 1];
+ cur = &list->hwLayers[win->layer_index];
+ set_src_dst_g2d_rect(cur, win, &srcRect, &dstRect);
+ ret = runG2d(ctx, &srcRect, &dstRect,
+ cur->transform);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::runG2d fail : ret=%d\n",
+ __func__, ret);
+ skipped_window_mask |= (1 << (ctx->num_of_hwc_layer - 1));
+ goto g2d_error;
+ }
+
+ window_pan_display(win);
+
+ win->buf_index = (win->buf_index + 1) % NUM_OF_WIN_BUF;
+ if (win->power_state == 0)
+ window_show(win);
+ }
+
+g2d_error:
+#endif
+
+ if (skipped_window_mask) {
+ //turn off the free windows
+ for (int i = 0; i < NUM_OF_WIN; i++) {
+ if (skipped_window_mask & (1 << i)) {
+ window_hide(&ctx->win[i]);
+ reset_win_rect_info(&ctx->win[i]);
+ }
+ }
+ }
+
+ if (0 < ctx->num_of_fb_layer) {
+#ifdef CHECK_EGL_FPS
+ check_fps();
+#endif
+#ifdef HWC_HWOVERLAY
+ unsigned char pixels[4];
+ glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+#endif
+ egl_check = 1;
+ egl_run = 1;
+ } else {
+ if (egl_check == 1) {
+ egl_check = 0;
+ egl_run = 1;
+ }
+ }
+
+ if (egl_run == 1) {
+ EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
+ if (!sucess)
+ return HWC_EGL_ERROR;
+ }
+
+#if defined(BOARD_USES_HDMI)
+ android::SecHdmiClient *mHdmiClient = android::SecHdmiClient::getInstance();
+
+ if (skip_hdmi_rendering == 1)
+ return 0;
+
+ if (list == NULL) {
+ // Don't display unnecessary image
+ mHdmiClient->setHdmiEnable(0);
+ return 0;
+ } else {
+ mHdmiClient->setHdmiEnable(1);
+ }
+
+#ifdef SUPPORT_AUTO_UI_ROTATE
+ cur = &list->hwLayers[0];
+
+ if (cur->transform == HAL_TRANSFORM_ROT_90 || cur->transform == HAL_TRANSFORM_ROT_270)
+ mHdmiClient->setHdmiRotate(270, ctx->num_of_hwc_layer);
+ else
+ mHdmiClient->setHdmiRotate(0, ctx->num_of_hwc_layer);
+#endif
+
+ // To support S3D video playback (automatic TV mode change to 3D mode)
+ if (ctx->num_of_hwc_layer == 1) {
+ if (src_img.usage != prev_usage)
+ mHdmiClient->setHdmiResolution(DEFAULT_HDMI_RESOLUTION_VALUE); // V4L2_STD_1080P_60
+
+ if ((src_img.usage & GRALLOC_USAGE_PRIVATE_SBS_LR) ||
+ (src_img.usage & GRALLOC_USAGE_PRIVATE_SBS_RL))
+ mHdmiClient->setHdmiResolution(7209601); // V4L2_STD_TVOUT_720P_60_SBS_HALF
+ else if ((src_img.usage & GRALLOC_USAGE_PRIVATE_TB_LR) ||
+ (src_img.usage & GRALLOC_USAGE_PRIVATE_TB_RL))
+ mHdmiClient->setHdmiResolution(1080924); // V4L2_STD_TVOUT_1080P_24_TB
+
+ prev_usage = src_img.usage;
+ } else {
+ if ((prev_usage & GRALLOC_USAGE_PRIVATE_SBS_LR) ||
+ (prev_usage & GRALLOC_USAGE_PRIVATE_SBS_RL) ||
+ (prev_usage & GRALLOC_USAGE_PRIVATE_TB_LR) ||
+ (prev_usage & GRALLOC_USAGE_PRIVATE_TB_RL))
+ mHdmiClient->setHdmiResolution(DEFAULT_HDMI_RESOLUTION_VALUE); // V4L2_STD_1080P_60
+
+ prev_usage = 0;
+ }
+
+ if (ctx->num_of_hwc_layer == 1) {
+ if ((src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED)||
+ (src_img.format == HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP)) {
+ ADDRS * addr = (ADDRS *)(src_img.base);
+
+ mHdmiClient->blit2Hdmi(src_img.w, src_img.h,
+ src_img.format,
+ (unsigned int)addr->addr_y, (unsigned int)addr->addr_cbcr, (unsigned int)addr->addr_cbcr,
+ 0, 0,
+ android::SecHdmiClient::HDMI_MODE_VIDEO,
+ ctx->num_of_hwc_layer);
+ } else if ((src_img.format == HAL_PIXEL_FORMAT_YCbCr_420_SP) ||
+ (src_img.format == HAL_PIXEL_FORMAT_YCrCb_420_SP) ||
+ (src_img.format == HAL_PIXEL_FORMAT_YCbCr_420_P) ||
+ (src_img.format == HAL_PIXEL_FORMAT_YV12)) {
+ mHdmiClient->blit2Hdmi(src_img.w, src_img.h,
+ src_img.format,
+ (unsigned int)ctx->fimc.params.src.buf_addr_phy_rgb_y,
+ (unsigned int)ctx->fimc.params.src.buf_addr_phy_cb,
+ (unsigned int)ctx->fimc.params.src.buf_addr_phy_cr,
+ 0, 0,
+ android::SecHdmiClient::HDMI_MODE_VIDEO,
+ ctx->num_of_hwc_layer);
+ } else {
+ LOGE("%s: Unsupported format = %d", __func__, src_img.format);
+ }
+ }
+#endif
+ return 0;
+}
+
+static int hwc_device_close(struct hw_device_t *dev)
+{
+ struct hwc_context_t* ctx = (struct hwc_context_t*)dev;
+ int ret = 0;
+ int i;
+ if (ctx) {
+ if (destroyFimc(&ctx->fimc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyFimc fail", __func__);
+ ret = -1;
+ }
+#ifdef SUB_TITLES_HWC
+ if (destroyG2d(&ctx->g2d) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyG2d() fail", __func__);
+ ret = -1;
+ }
+#endif
+ if (destroyMem(&ctx->s3c_mem) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyMem fail", __func__);
+ ret = -1;
+ }
+
+#ifdef USE_HW_PMEM
+ if (destroyPmem(&ctx->sec_pmem) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyPmem fail", __func__);
+ ret = -1;
+ }
+#endif
+ for (i = 0; i < NUM_OF_WIN; i++) {
+ if (window_close(&ctx->win[i]) < 0)
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s::window_close() fail", __func__);
+ }
+
+ free(ctx);
+ }
+ return ret;
+}
+
+static int hwc_device_open(const struct hw_module_t* module, const char* name,
+ struct hw_device_t** device)
+{
+ int status = 0;
+ struct hwc_win_info_t *win;
+
+ if (strcmp(name, HWC_HARDWARE_COMPOSER))
+ return -EINVAL;
+
+ struct hwc_context_t *dev;
+ dev = (hwc_context_t*)malloc(sizeof(*dev));
+
+ /* initialize our state here */
+ memset(dev, 0, sizeof(*dev));
+
+ /* initialize the procs */
+ dev->device.common.tag = HARDWARE_DEVICE_TAG;
+ dev->device.common.version = 0;
+ dev->device.common.module = const_cast<hw_module_t*>(module);
+ dev->device.common.close = hwc_device_close;
+
+ dev->device.prepare = hwc_prepare;
+ dev->device.set = hwc_set;
+
+ *device = &dev->device.common;
+
+ //initializing
+ memset(&(dev->fimc), 0, sizeof(s5p_fimc_t));
+ memset(&(dev->s3c_mem), 0, sizeof(struct s3c_mem_t));
+#ifdef USE_HW_PMEM
+ memset(&(dev->sec_pmem), 0, sizeof(sec_pmem_t));
+#endif
+ /* open WIN0 & WIN1 here */
+ for (int i = 0; i < NUM_OF_WIN; i++) {
+ if (window_open(&(dev->win[i]), i) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s:: Failed to open window %d device ", __func__, i);
+ status = -EINVAL;
+ goto err;
+ }
+ }
+
+ if (window_get_global_lcd_info(dev->win[0].fd, &dev->lcd_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s::window_get_global_lcd_info is failed : %s",
+ __func__, strerror(errno));
+ status = -EINVAL;
+ goto err;
+ }
+
+#if defined(BOARD_USES_HDMI)
+ lcd_width = dev->lcd_info.xres;
+ lcd_height = dev->lcd_info.yres;
+#endif
+
+ /* initialize the window context */
+ for (int i = 0; i < NUM_OF_WIN; i++) {
+ win = &dev->win[i];
+ memcpy(&win->lcd_info, &dev->lcd_info, sizeof(struct fb_var_screeninfo));
+ memcpy(&win->var_info, &dev->lcd_info, sizeof(struct fb_var_screeninfo));
+
+ win->rect_info.x = 0;
+ win->rect_info.y = 0;
+ win->rect_info.w = win->var_info.xres;
+ win->rect_info.h = win->var_info.yres;
+
+ if (window_set_pos(win) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_set_pos is failed : %s",
+ __func__, strerror(errno));
+ status = -EINVAL;
+ goto err;
+ }
+
+ if (window_get_info(win, i) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::window_get_info is failed : %s",
+ __func__, strerror(errno));
+ status = -EINVAL;
+ goto err;
+ }
+
+ }
+
+#ifdef USE_HW_PMEM
+ if (createPmem(&dev->sec_pmem, PMEM_SIZE) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::initPmem(%d) fail", __func__, PMEM_SIZE);
+ }
+#endif
+
+ if (createMem(&dev->s3c_mem, 0, 0) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::createMem() fail (size=0)", __func__);
+ status = -EINVAL;
+ goto err;
+ }
+
+ //create PP
+ if (createFimc(&dev->fimc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::creatFimc() fail", __func__);
+ status = -EINVAL;
+ goto err;
+ }
+
+#ifdef SUB_TITLES_HWC
+ if (createG2d(&dev->g2d) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::createG2d() fail", __func__);
+ status = -EINVAL;
+ goto err;
+ }
+#endif
+
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s:: hwc_device_open: SUCCESS", __func__);
+
+ return 0;
+
+err:
+ if (destroyFimc(&dev->fimc) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyFimc() fail", __func__);
+#ifdef SUB_TITLES_HWC
+ if (destroyG2d(&dev->g2d) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyG2d() fail", __func__);
+#endif
+ if (destroyMem(&dev->s3c_mem) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyMem() fail", __func__);
+
+#ifdef USE_HW_PMEM
+ if (destroyPmem(&dev->sec_pmem) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::destroyPmem() fail", __func__);
+#endif
+
+ for (int i = 0; i < NUM_OF_WIN; i++) {
+ if (window_close(&dev->win[i]) < 0)
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s::window_close() fail", __func__);
+ }
+
+ return status;
+}
diff --git a/exynos4/hal/libhwcomposer/SecHWCLog.cpp b/exynos4/hal/libhwcomposer/SecHWCLog.cpp
new file mode 100644
index 0000000..6ad4283
--- /dev/null
+++ b/exynos4/hal/libhwcomposer/SecHWCLog.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Rama, Meka(v.meka@samsung.com)
+ Sangwoo, Park(sw5771.park@samsung.com)
+ Jamie Oh (jung-min.oh@samsung.com)
+ * @date 2011-03-11
+ *
+ */
+
+#include <utils/Log.h>
+
+#include "SecHWCUtils.h"
+
+void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...)
+{
+ va_list argptr;
+
+ va_start(argptr, msg);
+
+ switch (logLevel) {
+ case HWC_LOG_DEBUG:
+ __android_log_vprint(ANDROID_LOG_DEBUG, tag, msg, argptr);
+ break;
+ case HWC_LOG_WARNING:
+ __android_log_vprint(ANDROID_LOG_WARN, tag, msg, argptr);
+ break;
+ case HWC_LOG_ERROR:
+ __android_log_vprint(ANDROID_LOG_ERROR, tag, msg, argptr);
+ break;
+ default:
+ __android_log_vprint(ANDROID_LOG_VERBOSE, tag, msg, argptr);
+ }
+
+ va_end(argptr);
+}
diff --git a/exynos4/hal/libhwcomposer/SecHWCUtils.cpp b/exynos4/hal/libhwcomposer/SecHWCUtils.cpp
new file mode 100644
index 0000000..5214e40
--- /dev/null
+++ b/exynos4/hal/libhwcomposer/SecHWCUtils.cpp
@@ -0,0 +1,2077 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Revision History:
+ * - 2011/03/11 : Rama, Meka(v.meka@samsung.com)
+ * Initial version
+ *
+ * - 2011/12/07 : Jeonghee, Kim(jhhhh.kim@samsung.com)
+ * Add V4L2_PIX_FMT_YUV420M V4L2_PIX_FMT_NV12M
+ *
+ */
+
+#include "SecHWCUtils.h"
+
+#ifdef BOARD_USE_V4L2_ION
+#define V4L2_BUF_TYPE_OUTPUT V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE
+#define V4L2_BUF_TYPE_CAPTURE V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
+#else
+#define V4L2_BUF_TYPE_OUTPUT V4L2_BUF_TYPE_VIDEO_OUTPUT
+#define V4L2_BUF_TYPE_CAPTURE V4L2_BUF_TYPE_VIDEO_CAPTURE
+#endif
+
+#define EXYNOS4_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
+
+//#define CHECK_FPS
+#ifdef CHECK_FPS
+#include <sys/time.h>
+#include <unistd.h>
+#define CHK_FRAME_CNT 30
+
+void check_fps()
+{
+ static struct timeval tick, tick_old;
+ static int total = 0;
+ static int cnt = 0;
+ int FPS;
+ cnt++;
+ gettimeofday(&tick, NULL);
+ if (cnt > 10) {
+ if (tick.tv_sec > tick_old.tv_sec)
+ total += ((tick.tv_usec/1000) + (tick.tv_sec - tick_old.tv_sec)*1000 - (tick_old.tv_usec/1000));
+ else
+ total += ((tick.tv_usec - tick_old.tv_usec)/1000);
+
+ memcpy(&tick_old, &tick, sizeof(timeval));
+ if (cnt == (10 + CHK_FRAME_CNT)) {
+ FPS = 1000*CHK_FRAME_CNT/total;
+ LOGE("[FPS]:%d\n", FPS);
+ total = 0;
+ cnt = 10;
+ }
+ } else {
+ memcpy(&tick_old, &tick, sizeof(timeval));
+ total = 0;
+ }
+}
+#endif
+
+struct yuv_fmt_list yuv_list[] = {
+ { "V4L2_PIX_FMT_NV12", "YUV420/2P/LSB_CBCR", V4L2_PIX_FMT_NV12, 12, 2 },
+ { "V4L2_PIX_FMT_NV12T", "YUV420/2P/LSB_CBCR", V4L2_PIX_FMT_NV12T, 12, 2 },
+ { "V4L2_PIX_FMT_NV21", "YUV420/2P/LSB_CRCB", V4L2_PIX_FMT_NV21, 12, 2 },
+ { "V4L2_PIX_FMT_NV21X", "YUV420/2P/MSB_CBCR", V4L2_PIX_FMT_NV21X, 12, 2 },
+ { "V4L2_PIX_FMT_NV12X", "YUV420/2P/MSB_CRCB", V4L2_PIX_FMT_NV12X, 12, 2 },
+ { "V4L2_PIX_FMT_YUV420", "YUV420/3P", V4L2_PIX_FMT_YUV420, 12, 3 },
+#ifdef BOARD_USE_V4L2_ION
+ { "V4L2_PIX_FMT_YUV420M", "YUV420/3P", V4L2_PIX_FMT_YUV420M, 12, 3 },
+ { "V4L2_PIX_FMT_NV12M", "YUV420/2P", V4L2_PIX_FMT_NV12M, 12, 2 },
+#endif
+ { "V4L2_PIX_FMT_YUYV", "YUV422/1P/YCBYCR", V4L2_PIX_FMT_YUYV, 16, 1 },
+ { "V4L2_PIX_FMT_YVYU", "YUV422/1P/YCRYCB", V4L2_PIX_FMT_YVYU, 16, 1 },
+ { "V4L2_PIX_FMT_UYVY", "YUV422/1P/CBYCRY", V4L2_PIX_FMT_UYVY, 16, 1 },
+ { "V4L2_PIX_FMT_VYUY", "YUV422/1P/CRYCBY", V4L2_PIX_FMT_VYUY, 16, 1 },
+ { "V4L2_PIX_FMT_UV12", "YUV422/2P/LSB_CBCR", V4L2_PIX_FMT_NV16, 16, 2 },
+ { "V4L2_PIX_FMT_UV21", "YUV422/2P/LSB_CRCB", V4L2_PIX_FMT_NV61, 16, 2 },
+ { "V4L2_PIX_FMT_UV12X", "YUV422/2P/MSB_CBCR", V4L2_PIX_FMT_NV16X, 16, 2 },
+ { "V4L2_PIX_FMT_UV21X", "YUV422/2P/MSB_CRCB", V4L2_PIX_FMT_NV61X, 16, 2 },
+ { "V4L2_PIX_FMT_YUV422P", "YUV422/3P", V4L2_PIX_FMT_YUV422P, 16, 3 },
+};
+
+int window_open(struct hwc_win_info_t *win, int id)
+{
+ int fd = 0;
+ char name[64];
+ int vsync = 1;
+ int real_id = id;
+
+ char const * const device_template = "/dev/graphics/fb%u";
+ // window & FB maping
+ // fb0 -> win-id : 2
+ // fb1 -> win-id : 3
+ // fb2 -> win-id : 4
+ // fb3 -> win-id : 0
+ // fb4 -> win_id : 1
+ // it is pre assumed that ...win0 or win1 is used here..
+
+ switch (id) {
+ case 0:
+#ifdef BOARD_USE_V4L2_ION
+ real_id = 2;
+#else
+ real_id = 3;
+#endif
+ break;
+ case 1:
+#ifdef BOARD_USE_V4L2_ION
+ real_id = 1;
+#else
+ real_id = 4;
+#endif
+ break;
+ default:
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::id(%d) is weird", __func__, id);
+ goto error;
+}
+
+// 0/10
+// snprintf(name, 64, device_template, id + 3);
+// 5/10
+// snprintf(name, 64, device_template, id + 0);
+// 0/10
+// snprintf(name, 64, device_template, id + 1);
+ snprintf(name, 64, device_template, real_id);
+
+ win->fd = open(name, O_RDWR);
+ if (win->fd <= 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Failed to open window device (%s) : %s",
+ __func__, strerror(errno), name);
+ goto error;
+ }
+
+#ifdef ENABLE_FIMD_VSYNC
+ if (ioctl(win->fd, S3CFB_SET_VSYNC_INT, &vsync) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3CFB_SET_VSYNC_INT fail", __func__);
+ goto error;
+ }
+#endif
+
+ return 0;
+
+error:
+ if (0 < win->fd)
+ close(win->fd);
+ win->fd = 0;
+
+ return -1;
+}
+
+int window_close(struct hwc_win_info_t *win)
+{
+ int ret = 0;
+
+ if (0 < win->fd) {
+
+#ifdef BOARD_USE_V4L2_ION
+ ion_unmap((void *)win->addr[0], ALIGN(win->size * NUM_OF_WIN_BUF, PAGE_SIZE));
+ ion_free(win->ion_fd);
+#endif
+
+#ifdef ENABLE_FIMD_VSYNC
+ int vsync = 0;
+ if (ioctl(win->fd, S3CFB_SET_VSYNC_INT, &vsync) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3CFB_SET_VSYNC_INT fail", __func__);
+#endif
+ ret = close(win->fd);
+ }
+ win->fd = 0;
+
+ return ret;
+}
+
+int window_set_pos(struct hwc_win_info_t *win)
+{
+ struct s3cfb_user_window window;
+
+ //before changing the screen configuration...powerdown the window
+ if (window_hide(win) != 0)
+ return -1;
+
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s:: x(%d), y(%d)",
+ __func__, win->rect_info.x, win->rect_info.y);
+
+ win->var_info.xres_virtual = (win->lcd_info.xres + 15) & ~ 15;
+ win->var_info.yres_virtual = win->lcd_info.yres * NUM_OF_WIN_BUF;
+ win->var_info.xres = win->rect_info.w;
+ win->var_info.yres = win->rect_info.h;
+
+ win->var_info.activate &= ~FB_ACTIVATE_MASK;
+ win->var_info.activate |= FB_ACTIVATE_FORCE;
+
+ if (ioctl(win->fd, FBIOPUT_VSCREENINFO, &(win->var_info)) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIOPUT_VSCREENINFO(%d, %d) fail",
+ __func__, win->rect_info.w, win->rect_info.h);
+ return -1;
+ }
+
+ window.x = win->rect_info.x;
+ window.y = win->rect_info.y;
+
+ if (ioctl(win->fd, S3CFB_WIN_POSITION, &window) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3CFB_WIN_POSITION(%d, %d) fail",
+ __func__, window.x, window.y);
+ return -1;
+ }
+
+ return 0;
+}
+
+int window_get_info(struct hwc_win_info_t *win, int win_num)
+{
+ int temp_size = 0;
+
+ if (ioctl(win->fd, FBIOGET_FSCREENINFO, &win->fix_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "FBIOGET_FSCREENINFO failed : %s",
+ strerror(errno));
+ goto error;
+ }
+
+ win->size = win->fix_info.line_length * win->var_info.yres;
+
+#ifdef BOARD_USE_V4L2_ION
+ struct s3c_fb_user_ion_client ion_handle;
+ void *ion_start_addr;
+
+ if (ioctl(win->fd, S3CFB_GET_ION_USER_HANDLE, &ion_handle) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Get fb ion client is failed\n");
+ return -1;
+ }
+
+ win->ion_fd = ion_handle.fd;
+ ion_start_addr = ion_map(win->ion_fd, ALIGN(win->size * NUM_OF_WIN_BUF, PAGE_SIZE), 0);
+#endif
+
+ for (int j = 0; j < NUM_OF_WIN_BUF; j++) {
+ temp_size = win->size * j;
+#ifdef BOARD_USE_V4L2_ION
+ win->addr[j] = (uint32_t)ion_start_addr + temp_size;
+#else
+ win->addr[j] = win->fix_info.smem_start + temp_size;
+#endif
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s::win-%d add[%d] %x ",
+ __func__, win_num, j, win->addr[j]);
+ }
+ return 0;
+
+error:
+ win->fix_info.smem_start = 0;
+
+ return -1;
+}
+
+int window_pan_display(struct hwc_win_info_t *win)
+{
+ struct fb_var_screeninfo *lcd_info = &(win->lcd_info);
+
+#ifdef ENABLE_FIMD_VSYNC
+#ifdef BOARD_USE_V4L2_ION
+ int fimd_num = 0;
+ if (ioctl(win->fd, FBIO_WAITFORVSYNC, &fimd_num) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIO_WAITFORVSYNC fail(%s)",
+ __func__, strerror(errno));
+#else
+ if (ioctl(win->fd, FBIO_WAITFORVSYNC, 0) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIO_WAITFORVSYNC fail(%s)",
+ __func__, strerror(errno));
+#endif
+#endif
+
+ lcd_info->yoffset = lcd_info->yres * win->buf_index;
+
+ if (ioctl(win->fd, FBIOPAN_DISPLAY, lcd_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIOPAN_DISPLAY(%d / %d / %d) fail(%s)",
+ __func__,
+ lcd_info->yres,
+ win->buf_index, lcd_info->yres_virtual,
+ strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
+int window_show(struct hwc_win_info_t *win)
+{
+ if (win->power_state == 0) {
+ if (ioctl(win->fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIOBLANK failed : (%d:%s)",
+ __func__, win->fd, strerror(errno));
+ return -1;
+ }
+ win->power_state = 1;
+ }
+ return 0;
+}
+
+int window_hide(struct hwc_win_info_t *win)
+{
+ if (win->power_state == 1) {
+ if (ioctl(win->fd, FBIOBLANK, FB_BLANK_POWERDOWN) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FBIOBLANK failed : (%d:%s)",
+ __func__, win->fd, strerror(errno));
+ return -1;
+ }
+ win->power_state = 0;
+ }
+ return 0;
+}
+
+int window_get_global_lcd_info(int fd, struct fb_var_screeninfo *lcd_info)
+{
+ if (ioctl(fd, FBIOGET_VSCREENINFO, lcd_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "FBIOGET_VSCREENINFO failed : %s",
+ strerror(errno));
+ return -1;
+ }
+
+ SEC_HWC_Log(HWC_LOG_DEBUG, "%s:: Default LCD x(%d),y(%d)",
+ __func__, lcd_info->xres, lcd_info->yres);
+ return 0;
+}
+
+int fimc_v4l2_set_src(int fd, unsigned int hw_ver, s5p_fimc_img_info *src)
+{
+ struct v4l2_format fmt;
+ struct v4l2_cropcap cropcap;
+ struct v4l2_crop crop;
+ struct v4l2_requestbuffers req;
+
+#ifdef BOARD_USE_V4L2_ION
+ /* You MUST initialize structure for v4l2 */
+ memset(&fmt, 0, sizeof(fmt));
+ memset(&cropcap, 0, sizeof(cropcap));
+ memset(&crop, 0, sizeof(crop));
+ memset(&req, 0, sizeof(req));
+
+ /* To set size & format for source image (DMA-INPUT) */
+ fmt.fmt.pix_mp.num_planes = src->planes;
+ fmt.fmt.pix_mp.width = src->full_width;
+ fmt.fmt.pix_mp.height = src->full_height;
+ fmt.fmt.pix_mp.pixelformat = src->color_space;
+ fmt.fmt.pix_mp.field = V4L2_FIELD_ANY;
+#else
+ fmt.fmt.pix.width = src->full_width;
+ fmt.fmt.pix.height = src->full_height;
+ fmt.fmt.pix.pixelformat = src->color_space;
+ fmt.fmt.pix.field = V4L2_FIELD_NONE;
+#endif
+ fmt.type = V4L2_BUF_TYPE_OUTPUT;
+
+ if (ioctl(fd, VIDIOC_S_FMT, &fmt) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::VIDIOC_S_FMT failed : errno=%d (%s)"
+ " : fd=%d\n", __func__, errno, strerror(errno), fd);
+ return -1;
+ }
+
+ /* crop input size */
+ crop.type = V4L2_BUF_TYPE_OUTPUT;
+ crop.c.width = src->width;
+ crop.c.height = src->height;
+#ifdef BOARD_USE_V4L2_ION
+ crop.c.left = src->start_x;
+ crop.c.top = src->start_y;
+#else
+ if (0x50 <= hw_ver) {
+ crop.c.left = src->start_x;
+ crop.c.top = src->start_y;
+ } else {
+ crop.c.left = 0;
+ crop.c.top = 0;
+ }
+
+#endif
+
+ if (ioctl(fd, VIDIOC_S_CROP, &crop) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_S_CROP :"
+ "crop.c.left : (%d), crop.c.top : (%d), crop.c.width : (%d), crop.c.height : (%d)",
+ __func__, crop.c.left, crop.c.top, crop.c.width, crop.c.height);
+ return -1;
+ }
+
+ /* input buffer type */
+ req.count = 1;
+ req.memory = V4L2_MEMORY_USERPTR;
+ req.type = V4L2_BUF_TYPE_OUTPUT;
+
+ if (ioctl(fd, VIDIOC_REQBUFS, &req) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in VIDIOC_REQBUFS", __func__);
+ return -1;
+ }
+
+ return 0;
+}
+
+int fimc_v4l2_set_dst(int fd, s5p_fimc_img_info *dst,
+ int rotation, int hflip, int vflip, unsigned int addr)
+{
+ struct v4l2_format sFormat;
+ struct v4l2_control vc;
+ struct v4l2_framebuffer fbuf;
+#ifdef BOARD_USE_V4L2_ION
+ struct v4l2_crop crop;
+ struct v4l2_requestbuffers req;
+#endif
+ int ret;
+
+#ifdef BOARD_USE_V4L2_ION
+ /* You MUST initialize structure for v4l2 */
+ memset(&sFormat, 0, sizeof(sFormat));
+ memset(&vc, 0, sizeof(vc));
+ memset(&fbuf, 0, sizeof(fbuf));
+ memset(&crop, 0, sizeof(crop));
+ memset(&req, 0, sizeof(req));
+#endif
+
+ /* set rotation configuration */
+#ifdef BOARD_USE_V4L2_ION
+ vc.id = V4L2_CID_ROTATE;
+#else
+ vc.id = V4L2_CID_ROTATION;
+#endif
+ vc.value = rotation;
+
+ ret = ioctl(fd, VIDIOC_S_CTRL, &vc);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s::Error in video VIDIOC_S_CTRL - rotation (%d)"
+ "vc.id : (%d), vc.value : (%d)", __func__, ret, vc.id, vc.value);
+ return -1;
+ }
+
+ vc.id = V4L2_CID_HFLIP;
+ vc.value = hflip;
+
+ ret = ioctl(fd, VIDIOC_S_CTRL, &vc);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s::Error in video VIDIOC_S_CTRL - hflip (%d)"
+ "vc.id : (%d), vc.value : (%d)", __func__, ret, vc.id, vc.value);
+ return -1;
+ }
+
+ vc.id = V4L2_CID_VFLIP;
+ vc.value = vflip;
+
+ ret = ioctl(fd, VIDIOC_S_CTRL, &vc);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s::Error in video VIDIOC_S_CTRL - vflip (%d)"
+ "vc.id : (%d), vc.value : (%d)", __func__, ret, vc.id, vc.value);
+ return -1;
+ }
+
+#ifdef BOARD_USE_V4L2_ION
+ /* set destination */
+ sFormat.type = V4L2_BUF_TYPE_CAPTURE;
+ sFormat.fmt.pix_mp.width = dst->full_width;
+ sFormat.fmt.pix_mp.height = dst->full_height;
+ sFormat.fmt.pix_mp.pixelformat = dst->color_space;
+ sFormat.fmt.pix_mp.num_planes = dst->planes;
+ sFormat.fmt.pix.field = V4L2_FIELD_ANY;
+
+ ret = ioctl(fd, VIDIOC_S_FMT, &sFormat);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_S_FMT (%d)", __func__, ret);
+ return -1;
+ }
+
+ /* set destination window */
+ crop.type = V4L2_BUF_TYPE_CAPTURE;
+ crop.c.left = dst->start_x;
+ crop.c.top = dst->start_y;
+ crop.c.width = dst->width;
+ crop.c.height = dst->height;
+
+ ret = ioctl(fd, VIDIOC_S_CROP, &crop);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_S_CROP (%d)", __func__, ret);
+ return -1;
+ }
+
+ /* input buffer type */
+ req.count = 1;
+ req.type = V4L2_BUF_TYPE_CAPTURE;
+ req.memory = V4L2_MEMORY_USERPTR;
+
+ ret = ioctl (fd, VIDIOC_REQBUFS, &req);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in VIDIOC_REQBUFS (%d)", __func__, ret);
+ return -1;
+ }
+#else
+ /* set size, format & address for destination image (DMA-OUTPUT) */
+ ret = ioctl(fd, VIDIOC_G_FBUF, &fbuf);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_G_FBUF (%d)", __func__, ret);
+ return -1;
+ }
+
+ fbuf.base = (void *)addr;
+ fbuf.fmt.width = dst->full_width;
+ fbuf.fmt.height = dst->full_height;
+ fbuf.fmt.pixelformat = dst->color_space;
+
+ ret = ioctl(fd, VIDIOC_S_FBUF, &fbuf);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_S_FBUF (%d)", __func__, ret);
+ return -1;
+ }
+
+ /* set destination window */
+ sFormat.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
+ sFormat.fmt.win.w.left = dst->start_x;
+ sFormat.fmt.win.w.top = dst->start_y;
+ sFormat.fmt.win.w.width = dst->width;
+ sFormat.fmt.win.w.height = dst->height;
+
+ ret = ioctl(fd, VIDIOC_S_FMT, &sFormat);
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_S_FMT (%d)", __func__, ret);
+ return -1;
+ }
+#endif
+
+ return 0;
+}
+
+int fimc_v4l2_stream_on(int fd, enum v4l2_buf_type type)
+{
+ if (-1 == ioctl(fd, VIDIOC_STREAMON, &type)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_STREAMON\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int fimc_v4l2_queue(int fd, struct fimc_buf *fimc_buf, enum v4l2_buf_type type, int index)
+{
+#ifdef BOARD_USE_V4L2_ION
+ struct v4l2_plane plane[3];
+ int i;
+#endif
+ struct v4l2_buffer buf;
+ int ret;
+
+#ifdef BOARD_USE_V4L2_ION
+ buf.length = fimc_buf->planes;
+#else
+ buf.length = 0;
+ buf.m.userptr = (unsigned long)fimc_buf;
+#endif
+ buf.memory = V4L2_MEMORY_USERPTR;
+ buf.index = index;
+ buf.type = type;
+
+#ifdef BOARD_USE_V4L2_ION
+ if (buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
+ buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+ for (i = 0; i < buf.length; i++) {
+ plane[i].m.userptr = fimc_buf->base[i];
+ plane[i].length = fimc_buf->size[i];
+ }
+ }
+ buf.m.planes = plane;
+#endif
+
+ ret = ioctl(fd, VIDIOC_QBUF, &buf);
+ if (0 > ret) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_QBUF : (%d)", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+int fimc_v4l2_dequeue(int fd, struct fimc_buf *fimc_buf, enum v4l2_buf_type type)
+{
+ struct v4l2_buffer buf;
+#ifdef BOARD_USE_V4L2_ION
+ struct v4l2_plane plane[3];
+#endif
+
+#ifdef BOARD_USE_V4L2_ION
+ buf.m.planes = plane;
+ buf.length = fimc_buf->planes;
+#endif
+ buf.memory = V4L2_MEMORY_USERPTR;
+ buf.type = type;
+
+ if (-1 == ioctl(fd, VIDIOC_DQBUF, &buf)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_DQBUF\n");
+ return -1;
+ }
+
+ return buf.index;
+}
+
+int fimc_v4l2_stream_off(int fd, enum v4l2_buf_type type)
+{
+ if (-1 == ioctl(fd, VIDIOC_STREAMOFF, &type)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_STREAMOFF\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int fimc_v4l2_clr_buf(int fd, enum v4l2_buf_type type)
+{
+ struct v4l2_requestbuffers req;
+
+ req.count = 0;
+ req.memory = V4L2_MEMORY_USERPTR;
+ req.type = type;
+
+ if (ioctl(fd, VIDIOC_REQBUFS, &req) == -1) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_REQBUFS");
+ }
+
+ return 0;
+}
+
+int fimc_v4l2_S_ctrl(int fd)
+{
+ struct v4l2_control vc;
+
+ vc.id = V4L2_CID_CACHEABLE;
+ vc.value = 1;
+
+ if (ioctl(fd, VIDIOC_S_CTRL, &vc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Error in VIDIOC_S_CTRL");
+ return -1;
+ }
+
+ return 0;
+}
+
+int fimc_handle_oneshot(int fd, struct fimc_buf *fimc_src_buf, struct fimc_buf *fimc_dst_buf)
+{
+#ifdef CHECK_FPS
+ check_fps();
+#endif
+
+#ifdef BOARD_USE_V4L2_ION
+ if (fimc_v4l2_queue(fd, fimc_src_buf, V4L2_BUF_TYPE_OUTPUT, 0) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_queue()");
+ return -1;
+ }
+
+ if (fimc_v4l2_queue(fd, fimc_dst_buf, V4L2_BUF_TYPE_CAPTURE, 0) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : DST v4l2_queue()");
+ return -2;
+ }
+
+ if (fimc_v4l2_stream_on(fd, V4L2_BUF_TYPE_OUTPUT) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_stream_on()");
+ return -3;
+ }
+
+ if (fimc_v4l2_stream_on(fd, V4L2_BUF_TYPE_CAPTURE) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : DST v4l2_stream_on()");
+ return -4;
+ }
+#else
+ if (fimc_v4l2_stream_on(fd, V4L2_BUF_TYPE_OUTPUT) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_stream_on()");
+ return -5;
+ }
+
+ if (fimc_v4l2_queue(fd, fimc_src_buf, V4L2_BUF_TYPE_OUTPUT, 0) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_queue()");
+ goto STREAM_OFF;
+ }
+#endif
+ if (fimc_v4l2_dequeue(fd, fimc_src_buf, V4L2_BUF_TYPE_OUTPUT) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_dequeue()");
+ return -6;
+ }
+#ifdef BOARD_USE_V4L2_ION
+ if (fimc_v4l2_dequeue(fd, fimc_dst_buf, V4L2_BUF_TYPE_CAPTURE) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : DST v4l2_dequeue()");
+ return -7;
+ }
+#endif
+STREAM_OFF:
+ if (fimc_v4l2_stream_off(fd, V4L2_BUF_TYPE_OUTPUT) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_stream_off()");
+ return -8;
+ }
+#ifdef BOARD_USE_V4L2_ION
+ if (fimc_v4l2_stream_off(fd, V4L2_BUF_TYPE_CAPTURE) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : DST v4l2_stream_off()");
+ return -9;
+ }
+#endif
+ if (fimc_v4l2_clr_buf(fd, V4L2_BUF_TYPE_OUTPUT) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : SRC v4l2_clr_buf()");
+ return -10;
+ }
+#ifdef BOARD_USE_V4L2_ION
+ if (fimc_v4l2_clr_buf(fd, V4L2_BUF_TYPE_CAPTURE)< 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "Fail : DST v4l2_clr_buf()");
+ return -11;
+ }
+#endif
+ return 0;
+}
+
+static int memcpy_rect(void *dst, void *src, int fullW, int fullH, int realW, int realH, int format)
+{
+ unsigned char *srcCb, *srcCr;
+ unsigned char *dstCb, *dstCr;
+ unsigned char *srcY, *dstY;
+ int srcCbOffset, srcCrOffset;
+ int dstCbOffset, dstFrameOffset, dstCrOffset;
+ int cbFullW, cbRealW, cbFullH, cbRealH;
+ int ySrcFW, ySrcFH, ySrcRW, ySrcRH;
+ int planes;
+ int i;
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "++memcpy_rect()::"
+ "dst(0x%x),src(0x%x),f.w(%d),f.h(%d),r.w(%d),r.h(%d),format(0x%x)",
+ (unsigned int)dst, (unsigned int)src, fullW, fullH, realW, realH, format);
+
+// Set dst Y, Cb, Cr address for FIMC
+ {
+ cbFullW = fullW >> 1;
+ cbRealW = realW >> 1;
+ cbFullH = fullH >> 1;
+ cbRealH = realH >> 1;
+ dstFrameOffset = fullW * fullH;
+ dstCrOffset = cbFullW * cbFullH;
+ dstY = (unsigned char *)dst;
+ dstCb = (unsigned char *)dst + dstFrameOffset;
+ dstCr = (unsigned char *)dstCb + dstCrOffset;
+ }
+
+// Get src Y, Cb, Cr address for source buffer.
+// Each address is aligned by 16's multiple for GPU both width and height.
+ {
+ ySrcFW = fullW;
+ ySrcFH = fullH;
+ ySrcRW = realW;
+ ySrcRH = realH;
+ srcCbOffset = EXYNOS4_ALIGN(ySrcRW,16)* EXYNOS4_ALIGN(ySrcRH,16);
+ srcCrOffset = EXYNOS4_ALIGN(cbRealW,16)* EXYNOS4_ALIGN(cbRealH,16);
+ srcY = (unsigned char *)src;
+ srcCb = (unsigned char *)src + srcCbOffset;
+ srcCr = (unsigned char *)srcCb + srcCrOffset;
+ }
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "--memcpy_rect()::\n"
+ "dstY(0x%x),dstCb(0x%x),dstCr(0x%x) \n"
+ "srcY(0x%x),srcCb(0x%x),srcCr(0x%x) \n"
+ "cbRealW(%d),cbRealH(%d)",
+ (unsigned int)dstY,(unsigned int)dstCb,(unsigned int)dstCr,
+ (unsigned int)srcY,(unsigned int)srcCb,(unsigned int)srcCr,
+ cbRealW, cbRealH);
+
+ if (format == HAL_PIXEL_FORMAT_YV12) { //YV12(Y,Cr,Cv)
+ planes = 3;
+//This is code for VE, deleted temporory by SSONG 2011.09.22
+// This will be enabled later.
+/*
+ //as defined in hardware.h, cb & cr full_width should be aligned to 16. ALIGN(y_stride/2, 16).
+ ////Alignment is hard coded to 16.
+ ////for example...check frameworks/media/libvideoeditor/lvpp/VideoEditorTools.cpp file for UV stride cal
+ cbSrcFW = (cbSrcFW + 15) & (~15);
+ srcCbOffset = ySrcFW * fullH;
+ srcCrOffset = srcCbOffset + ((cbSrcFW * fullH) >> 1);
+ srcY = (unsigned char *)src;
+ srcCb = (unsigned char *)src + srcCbOffset;
+ srcCr = (unsigned char *)src + srcCrOffset;
+*/
+ } else if ((format == HAL_PIXEL_FORMAT_YCbCr_420_P)) {
+ planes = 3;
+ } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP || format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
+ planes = 2;
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR, "use default memcpy instead of memcpy_rect");
+ return -1;
+ }
+//#define CHECK_PERF
+#ifdef CHECK_PERF
+ struct timeval start, end;
+ gettimeofday(&start, NULL);
+#endif
+ for (i = 0; i < realH; i++)
+ memcpy(dstY + fullW * i, srcY + ySrcFW * i, ySrcRW);
+ if (planes == 2) {
+ for (i = 0; i < cbRealH; i++)
+ memcpy(dstCb + ySrcFW * i, srcCb + ySrcFW * i, ySrcRW);
+ } else if (planes == 3) {
+ for (i = 0; i < cbRealH; i++)
+ memcpy(dstCb + cbFullW * i, srcCb + cbFullW * i, cbRealW);
+ for (i = 0; i < cbRealH; i++)
+ memcpy(dstCr + cbFullW * i, srcCr + cbFullW * i, cbRealW);
+ }
+#ifdef CHECK_PERF
+ gettimeofday(&end, NULL);
+ SEC_HWC_Log(HWC_LOG_ERROR, "[COPY]=%d,",(end.tv_sec - start.tv_sec)*1000+(end.tv_usec - start.tv_usec)/1000);
+#endif
+
+ return 0;
+}
+
+/*****************************************************************************/
+static int get_src_phys_addr(struct hwc_context_t *ctx,
+ sec_img *src_img, sec_rect *src_rect)
+{
+ s5p_fimc_t *fimc = &ctx->fimc;
+ struct s3c_mem_alloc *ptr_mem_alloc = &ctx->s3c_mem.mem_alloc[0];
+ struct s3c_mem_dma_param s3c_mem_dma;
+#ifdef USE_HW_PMEM
+ sec_pmem_alloc_t *pm_alloc = &ctx->sec_pmem.sec_pmem_alloc[0];
+#endif
+
+ unsigned int src_virt_addr = 0;
+ unsigned int src_phys_addr = 0;
+ unsigned int src_frame_size = 0;
+
+ struct pmem_region region;
+ ADDRS * addr;
+
+ // error check routine
+ if (0 == src_img->base && !(src_img->usage & GRALLOC_USAGE_HW_FIMC1)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s invalid src image base\n", __func__);
+ return 0;
+ }
+
+ switch (src_img->mem_type) {
+ case HWC_PHYS_MEM_TYPE:
+ src_phys_addr = src_img->base + src_img->offset;
+ break;
+
+ case HWC_VIRT_MEM_TYPE:
+ case HWC_UNKNOWN_MEM_TYPE:
+ switch (src_img->format) {
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP:
+ addr = (ADDRS *)(src_img->base);
+ fimc->params.src.buf_addr_phy_rgb_y = addr->addr_y;
+ fimc->params.src.buf_addr_phy_cb = addr->addr_cbcr;
+
+ src_phys_addr = fimc->params.src.buf_addr_phy_rgb_y;
+ if (0 == src_phys_addr) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s address error "
+ "(format=CUSTOM_YCbCr/YCrCb_420_SP Y-addr=0x%x "
+ "CbCr-Addr=0x%x)",
+ __func__, fimc->params.src.buf_addr_phy_rgb_y,
+ fimc->params.src.buf_addr_phy_cb);
+ return 0;
+ }
+ break;
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I:
+ addr = (ADDRS *)(src_img->base + src_img->offset);
+ fimc->params.src.buf_addr_phy_rgb_y = addr->addr_y;
+ src_phys_addr = fimc->params.src.buf_addr_phy_rgb_y;
+ if (0 == src_phys_addr) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s address error "
+ "(format=CUSTOM_YCbCr/CbYCrY_422_I Y-addr=0x%x)",
+ __func__, fimc->params.src.buf_addr_phy_rgb_y);
+ return 0;
+ }
+ break;
+ default:
+#ifdef BOARD_USE_V4L2_ION
+ fimc->params.src.buf_addr_phy_rgb_y = src_img->base;
+ fimc->params.src.buf_addr_phy_cb = src_img->base + src_img->uoffset;
+ fimc->params.src.buf_addr_phy_cr = src_img->base + src_img->uoffset + src_img->voffset;
+ src_phys_addr = fimc->params.src.buf_addr_phy_rgb_y;
+ break;
+#endif
+ if (src_img->usage & GRALLOC_USAGE_HW_FIMC1) {
+ fimc->params.src.buf_addr_phy_rgb_y = src_img->paddr;
+ fimc->params.src.buf_addr_phy_cb = src_img->paddr + src_img->uoffset;
+ fimc->params.src.buf_addr_phy_cr = src_img->paddr + src_img->uoffset + src_img->voffset;
+ src_phys_addr = fimc->params.src.buf_addr_phy_rgb_y;
+ break;
+ }
+ // copy
+ src_frame_size = FRAME_SIZE(src_img->format, src_img->w, src_img->h);
+ if (src_frame_size == 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FRAME_SIZE fail", __func__);
+ return 0;
+ }
+
+#ifdef USE_HW_PMEM
+ if (0 <= checkPmem(&ctx->sec_pmem, 0, src_frame_size)) {
+ src_virt_addr = pm_alloc->virt_addr;
+ src_phys_addr = pm_alloc->phys_addr;
+ pm_alloc->size = src_frame_size;
+ } else
+#endif
+ if (0 <= checkMem(&ctx->s3c_mem, 0, src_frame_size)) {
+ src_virt_addr = ptr_mem_alloc->vir_addr;
+ src_phys_addr = ptr_mem_alloc->phy_addr;
+ ptr_mem_alloc->size = src_frame_size;
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::check_mem fail", __func__);
+ return 0;
+ }
+ if ((src_img->format == HAL_PIXEL_FORMAT_YCbCr_420_P) ||
+ (src_img->format == HAL_PIXEL_FORMAT_YV12) ||
+ (src_img->format == HAL_PIXEL_FORMAT_YCbCr_420_SP) ||
+ (src_img->format == HAL_PIXEL_FORMAT_YCrCb_420_SP)) {
+ if (memcpy_rect((void *)src_virt_addr, (void*)((unsigned int)src_img->base),
+ src_img->f_w, src_img->f_h, src_rect->w, src_rect->h, src_img->format) != 0)
+ return 0;
+ } else {
+ memcpy((void *)src_virt_addr, (void*)((unsigned int)src_img->base), src_frame_size);
+ }
+
+#ifdef USE_HW_PMEM
+ if (pm_alloc->size == src_frame_size) {
+ region.offset = 0;
+ region.len = src_frame_size;
+ if (ioctl(ctx->sec_pmem.pmem_master_fd, PMEM_CACHE_FLUSH, ®ion) < 0)
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::pmem cache flush fail ", __func__);
+ }
+#endif
+ break;
+ }
+ }
+
+ return src_phys_addr;
+}
+
+static int get_dst_phys_addr(struct hwc_context_t *ctx, sec_img *dst_img,
+ sec_rect *dst_rect, int *dst_memcpy_flag)
+{
+ unsigned int dst_phys_addr = 0;
+
+ if (HWC_PHYS_MEM_TYPE == dst_img->mem_type && 0 != dst_img->base)
+ dst_phys_addr = dst_img->base;
+ else
+ dst_phys_addr = dst_img->base;
+
+ return dst_phys_addr;
+}
+
+static inline int rotateValueHAL2PP(unsigned char transform)
+{
+ int rotate_flag = transform & 0x7;
+
+ switch (rotate_flag) {
+ case HAL_TRANSFORM_ROT_90: return 90;
+ case HAL_TRANSFORM_ROT_180: return 180;
+ case HAL_TRANSFORM_ROT_270: return 270;
+ case HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90: return 90;
+ case HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90: return 90;
+ case HAL_TRANSFORM_FLIP_H: return 0;
+ case HAL_TRANSFORM_FLIP_V: return 0;
+ }
+ return 0;
+}
+
+static inline int hflipValueHAL2PP(unsigned char transform)
+{
+ int flip_flag = transform & 0x7;
+ switch (flip_flag) {
+ case HAL_TRANSFORM_FLIP_H:
+ case HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90:
+ return 1;
+ case HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90:
+ case HAL_TRANSFORM_ROT_90:
+ case HAL_TRANSFORM_ROT_180:
+ case HAL_TRANSFORM_ROT_270:
+ case HAL_TRANSFORM_FLIP_V:
+ break;
+ }
+ return 0;
+}
+
+static inline int vflipValueHAL2PP(unsigned char transform)
+{
+ int flip_flag = transform & 0x7;
+ switch (flip_flag) {
+ case HAL_TRANSFORM_FLIP_V:
+ case HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_ROT_90:
+ return 1;
+ case HAL_TRANSFORM_FLIP_H | HAL_TRANSFORM_ROT_90:
+ case HAL_TRANSFORM_ROT_90:
+ case HAL_TRANSFORM_ROT_180:
+ case HAL_TRANSFORM_ROT_270:
+ case HAL_TRANSFORM_FLIP_H:
+ break;
+ }
+ return 0;
+}
+
+static inline int multipleOf2(int number)
+{
+ if (number % 2 == 1)
+ return (number - 1);
+ else
+ return number;
+}
+
+static inline int multipleOf4(int number)
+{
+ int remain_number = number % 4;
+
+ if (remain_number != 0)
+ return (number - remain_number);
+ else
+ return number;
+}
+
+static inline int multipleOf8(int number)
+{
+ int remain_number = number % 8;
+
+ if (remain_number != 0)
+ return (number - remain_number);
+ else
+ return number;
+}
+
+static inline int multipleOf16(int number)
+{
+ int remain_number = number % 16;
+
+ if (remain_number != 0)
+ return (number - remain_number);
+ else
+ return number;
+}
+
+static inline int widthOfPP(unsigned int ver, int pp_color_format, int number)
+{
+#ifdef BOARD_USE_V4L2_ION
+ if (1) {
+#else
+ if (0x50 <= ver) {
+#endif
+ switch (pp_color_format) {
+ /* 422 1/2/3 plane */
+ case V4L2_PIX_FMT_YUYV:
+ case V4L2_PIX_FMT_UYVY:
+ case V4L2_PIX_FMT_NV61:
+ case V4L2_PIX_FMT_NV16:
+ case V4L2_PIX_FMT_YUV422P:
+
+ /* 420 2/3 plane */
+ case V4L2_PIX_FMT_NV21:
+ case V4L2_PIX_FMT_NV12:
+ case V4L2_PIX_FMT_NV12T:
+ case V4L2_PIX_FMT_YUV420:
+ return multipleOf2(number);
+
+ default :
+ return number;
+ }
+ } else {
+ switch (pp_color_format) {
+ case V4L2_PIX_FMT_RGB565:
+ return multipleOf8(number);
+
+ case V4L2_PIX_FMT_RGB32:
+ return multipleOf4(number);
+
+ case V4L2_PIX_FMT_YUYV:
+ case V4L2_PIX_FMT_UYVY:
+ return multipleOf4(number);
+
+ case V4L2_PIX_FMT_NV61:
+ case V4L2_PIX_FMT_NV16:
+ return multipleOf8(number);
+
+ case V4L2_PIX_FMT_YUV422P:
+ return multipleOf16(number);
+
+ case V4L2_PIX_FMT_NV21:
+ case V4L2_PIX_FMT_NV12:
+ case V4L2_PIX_FMT_NV12T:
+ return multipleOf8(number);
+
+ case V4L2_PIX_FMT_YUV420:
+ return multipleOf16(number);
+
+ default :
+ return number;
+ }
+ }
+ return number;
+}
+
+static inline int heightOfPP(int pp_color_format, int number)
+{
+ switch (pp_color_format) {
+ case V4L2_PIX_FMT_NV21:
+ case V4L2_PIX_FMT_NV12:
+ case V4L2_PIX_FMT_NV12T:
+ case V4L2_PIX_FMT_YUV420:
+ return multipleOf2(number);
+
+ default :
+ return number;
+ break;
+ }
+ return number;
+}
+
+static unsigned int get_yuv_bpp(unsigned int fmt)
+{
+ int i, sel = -1;
+
+ for (i = 0; i < (int)(sizeof(yuv_list) / sizeof(struct yuv_fmt_list)); i++) {
+ if (yuv_list[i].fmt == fmt) {
+ sel = i;
+ break;
+ }
+ }
+
+ if (sel == -1)
+ return sel;
+ else
+ return yuv_list[sel].bpp;
+}
+
+static unsigned int get_yuv_planes(unsigned int fmt)
+{
+ int i, sel = -1;
+
+ for (i = 0; i < (int)(sizeof(yuv_list) / sizeof(struct yuv_fmt_list)); i++) {
+ if (yuv_list[i].fmt == fmt) {
+ sel = i;
+ break;
+ }
+ }
+
+ if (sel == -1)
+ return sel;
+ else
+ return yuv_list[sel].planes;
+}
+
+static int runcFimcCore(struct hwc_context_t *ctx,
+ unsigned int src_phys_addr, sec_img *src_img, sec_rect *src_rect,
+ uint32_t src_color_space,
+ unsigned int dst_phys_addr, sec_img *dst_img, sec_rect *dst_rect,
+ uint32_t dst_color_space, int transform)
+{
+ s5p_fimc_t * fimc = &ctx->fimc;
+ s5p_fimc_params_t * params = &(fimc->params);
+
+ struct fimc_buf fimc_src_buf;
+ int src_bpp, src_planes;
+
+#ifdef BOARD_USE_V4L2_ION
+ struct fimc_buf fimc_dst_buf;
+ int dst_bpp, dst_planes;
+ unsigned int src_frame_size = 0;
+ unsigned int dst_frame_size = 0;
+#endif
+ unsigned int frame_size = 0;
+
+ bool src_cbcr_order = true;
+ int rotate_value = rotateValueHAL2PP(transform);
+ int hflip = hflipValueHAL2PP(transform);
+ int vflip = vflipValueHAL2PP(transform);
+
+ /* 1. param(fimc config)->src information
+ * - src_img,src_rect => s_fw,s_fh,s_w,s_h,s_x,s_y
+ */
+ params->src.full_width = src_img->f_w;
+ params->src.full_height = src_img->f_h;
+ params->src.width = src_rect->w;
+ params->src.height = src_rect->h;
+ params->src.start_x = src_rect->x;
+ params->src.start_y = src_rect->y;
+ params->src.color_space = src_color_space;
+ params->src.buf_addr_phy_rgb_y = src_phys_addr;
+
+#ifdef BOARD_USE_V4L2_ION
+ params->dst.full_width = dst_img->f_w;
+ params->dst.full_height = dst_img->f_h;
+ params->dst.width = widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->w);
+ params->dst.height = heightOfPP(dst_color_space, dst_rect->h);
+ params->dst.start_x = dst_rect->x;
+ params->dst.start_y = dst_rect->y;
+ params->dst.color_space = dst_color_space;
+ params->dst.buf_addr_phy_rgb_y = dst_phys_addr;
+#endif
+
+ /* check src minimum */
+ if (src_rect->w < 16 || src_rect->h < 8) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s src size is not supported by fimc : f_w=%d f_h=%d "
+ "x=%d y=%d w=%d h=%d (ow=%d oh=%d) format=0x%x", __func__,
+ params->src.full_width, params->src.full_height,
+ params->src.start_x, params->src.start_y,
+ params->src.width, params->src.height,
+ src_rect->w, src_rect->h,
+ params->src.color_space);
+ return -1;
+ }
+
+#ifdef BOARD_USE_V4L2_ION
+#else
+ /* 2. param(fimc config)->dst information
+ * - dst_img,dst_rect,rot => d_fw,d_fh,d_w,d_h,d_x,d_y
+ */
+ switch (rotate_value) {
+ case 0:
+ params->dst.full_width = dst_img->f_w;
+ params->dst.full_height = dst_img->f_h;
+
+ params->dst.start_x = dst_rect->x;
+ params->dst.start_y = dst_rect->y;
+
+ params->dst.width =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->w);
+ params->dst.height = heightOfPP(dst_color_space, dst_rect->h);
+ break;
+ case 90:
+ params->dst.full_width = dst_img->f_h;
+ params->dst.full_height = dst_img->f_w;
+
+ params->dst.start_x = dst_rect->y;
+ params->dst.start_y = dst_img->f_w - (dst_rect->x + dst_rect->w);
+
+ params->dst.width =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->h);
+ params->dst.height =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->w);
+
+ if (0x50 > fimc->hw_ver)
+ params->dst.start_y += (dst_rect->w - params->dst.height);
+ break;
+ case 180:
+ params->dst.full_width = dst_img->f_w;
+ params->dst.full_height = dst_img->f_h;
+
+ params->dst.start_x = dst_img->f_w - (dst_rect->x + dst_rect->w);
+ params->dst.start_y = dst_img->f_h - (dst_rect->y + dst_rect->h);
+
+ params->dst.width =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->w);
+ params->dst.height = heightOfPP(dst_color_space, dst_rect->h);
+ break;
+ case 270:
+ params->dst.full_width = dst_img->f_h;
+ params->dst.full_height = dst_img->f_w;
+
+ params->dst.start_x = dst_img->f_h - (dst_rect->y + dst_rect->h);
+ params->dst.start_y = dst_rect->x;
+
+ params->dst.width =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->h);
+ params->dst.height =
+ widthOfPP(fimc->hw_ver, dst_color_space, dst_rect->w);
+
+ if (0x50 > fimc->hw_ver)
+ params->dst.start_y += (dst_rect->w - params->dst.height);
+ break;
+ }
+ params->dst.color_space = dst_color_space;
+#endif
+
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "runcFimcCore()::"
+ "SRC f.w(%d),f.h(%d),x(%d),y(%d),w(%d),h(%d)=>"
+ "DST f.w(%d),f.h(%d),x(%d),y(%d),w(%d),h(%d)",
+ params->src.full_width, params->src.full_height,
+ params->src.start_x, params->src.start_y,
+ params->src.width, params->src.height,
+ params->dst.full_width, params->dst.full_height,
+ params->dst.start_x, params->dst.start_y,
+ params->dst.width, params->dst.height);
+
+ /* check dst minimum */
+ if (dst_rect->w < 8 || dst_rect->h < 4) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s dst size is not supported by fimc : f_w=%d f_h=%d "
+ "x=%d y=%d w=%d h=%d (ow=%d oh=%d) format=0x%x", __func__,
+ params->dst.full_width, params->dst.full_height,
+ params->dst.start_x, params->dst.start_y,
+ params->dst.width, params->dst.height,
+ dst_rect->w, dst_rect->h, params->dst.color_space);
+ return -1;
+ }
+ /* check scaling limit
+ * the scaling limie must not be more than MAX_RESIZING_RATIO_LIMIT
+ */
+ if (((src_rect->w > dst_rect->w) &&
+ ((src_rect->w / dst_rect->w) > MAX_RESIZING_RATIO_LIMIT)) ||
+ ((dst_rect->w > src_rect->w) &&
+ ((dst_rect->w / src_rect->w) > MAX_RESIZING_RATIO_LIMIT))) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "%s over scaling limit : src.w=%d dst.w=%d (limit=%d)",
+ __func__, src_rect->w, dst_rect->w, MAX_RESIZING_RATIO_LIMIT);
+ return -1;
+ }
+
+ /* 3. Set configuration related to destination (DMA-OUT)
+ * - set input format & size
+ * - crop input size
+ * - set input buffer
+ * - set buffer type (V4L2_MEMORY_USERPTR)
+ */
+#ifdef BOARD_USE_V4L2_ION
+ switch (dst_img->format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ case HAL_PIXEL_FORMAT_RGB_888:
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ dst_planes = 1;
+ dst_bpp = 32;
+ break;
+
+ case HAL_PIXEL_FORMAT_RGB_565:
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ dst_planes = 1;
+ dst_bpp = 16;
+ break;
+ }
+
+ dst_frame_size = params->dst.width * params->dst.height ;
+ params->dst.planes = dst_planes;
+
+ if (dst_planes == 1) {
+ fimc_dst_buf.base[0] = params->dst.buf_addr_phy_rgb_y;
+ if (dst_bpp == 32)
+ fimc_dst_buf.size[0] = dst_frame_size * 4;
+ else if (dst_bpp == 16)
+ fimc_dst_buf.size[0] = dst_frame_size * 2;
+ }
+#endif
+
+ if (fimc_v4l2_set_dst(fimc->dev_fd, ¶ms->dst, rotate_value, hflip, vflip, dst_phys_addr) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "fimc_v4l2_set_dst is failed\n");
+ return -1;
+ }
+
+ /* 4. Set configuration related to source (DMA-INPUT)
+ * - set input format & size
+ * - crop input size
+ * - set input buffer
+ * - set buffer type (V4L2_MEMORY_USERPTR)
+ */
+#ifndef BOARD_USE_V4L2_ION
+ if (fimc_v4l2_set_src(fimc->dev_fd, fimc->hw_ver, ¶ms->src) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "fimc_v4l2_set_src is failed\n");
+ return -1;
+ }
+#endif
+
+ /* 5. Set input dma address (Y/RGB, Cb, Cr)
+ * - zero copy : mfc, camera
+ * - memcpy to pmem : SW dec(420P), video editor(YV12)
+ */
+ switch (src_img->format) {
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP:
+ /* for video contents zero copy case */
+ fimc_src_buf.base[0] = params->src.buf_addr_phy_rgb_y;
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cb;
+ break;
+
+ case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I:
+ case HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I:
+ case HAL_PIXEL_FORMAT_RGB_565:
+ case HAL_PIXEL_FORMAT_YV12:
+ default:
+ if (src_img->format == HAL_PIXEL_FORMAT_YV12)
+ src_cbcr_order = false;
+
+#ifdef BOARD_USE_V4L2_ION
+ fimc_src_buf.base[0] = params->src.buf_addr_phy_rgb_y;
+ if (src_cbcr_order == true) {
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cb;
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cr;
+ } else {
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cr;
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cb;
+ }
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "runFimcCore - Y=0x%X, U=0x%X, V=0x%X\n",
+ fimc_src_buf.base[0], fimc_src_buf.base[1],fimc_src_buf.base[2]);
+ src_frame_size = params->src.full_width * params->src.full_height;
+ fimc_src_buf.size[0] = src_frame_size;
+ fimc_src_buf.size[1] = src_frame_size >> 2;
+ fimc_src_buf.size[2] = src_frame_size >> 2;
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "runFimcCore - Y_length=%d, U_length=%d, V_length=%d\n",
+ fimc_src_buf.size[0], fimc_src_buf.size[1],fimc_src_buf.size[2]);
+ src_planes = get_yuv_planes(src_color_space);
+
+ break;
+#endif
+
+ if (src_img->usage & GRALLOC_USAGE_HW_FIMC1) {
+ fimc_src_buf.base[0] = params->src.buf_addr_phy_rgb_y;
+ if (src_cbcr_order == true) {
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cb;
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cr;
+ }
+ else {
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cb;
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cr;
+ }
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "runFimcCore - Y=0x%X, U=0x%X, V=0x%X\n",
+ fimc_src_buf.base[0], fimc_src_buf.base[1],fimc_src_buf.base[2]);
+ break;
+ }
+
+ /* set source Y image */
+ fimc_src_buf.base[0] = params->src.buf_addr_phy_rgb_y;
+ /* set source Cb,Cr images for 2 or 3 planes */
+ src_bpp = get_yuv_bpp(src_color_space);
+ src_planes = get_yuv_planes(src_color_space);
+ if (2 == src_planes) { /* 2 planes */
+ frame_size = params->src.full_width * params->src.full_height;
+ params->src.buf_addr_phy_cb =
+ params->src.buf_addr_phy_rgb_y + frame_size;
+ /* CbCr */
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cb;
+ } else if (3 == src_planes) { /* 3 planes */
+ frame_size = params->src.full_width * params->src.full_height;
+ params->src.buf_addr_phy_cb =
+ params->src.buf_addr_phy_rgb_y + frame_size;
+ if (12 == src_bpp)
+ params->src.buf_addr_phy_cr =
+ params->src.buf_addr_phy_cb + (frame_size >> 2);
+ else
+ params->src.buf_addr_phy_cr =
+ params->src.buf_addr_phy_cb + (frame_size >> 1);
+ /* Cb, Cr */
+ if (src_cbcr_order == true) {
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cb;
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cr;
+ }
+ else {
+ fimc_src_buf.base[2] = params->src.buf_addr_phy_cb;
+ fimc_src_buf.base[1] = params->src.buf_addr_phy_cr;
+ }
+ }
+ break;
+ }
+
+ /* 6. Run FIMC
+ * - stream on => queue => dequeue => stream off => clear buf
+ */
+#ifdef BOARD_USE_V4L2_ION
+ int ret = 0;
+ params->src.planes = src_planes;
+
+ if (fimc_v4l2_set_src(fimc->dev_fd, fimc->hw_ver, ¶ms->src) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "fimc_v4l2_set_src is failed\n");
+ return -1;
+ }
+
+ fimc_src_buf.planes = src_planes;
+ fimc_dst_buf.planes = dst_planes;
+
+ ret = fimc_handle_oneshot(fimc->dev_fd, &fimc_src_buf, &fimc_dst_buf);
+
+ if (ret < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR,"fimc_handle_oneshot = %d\n",ret);
+ if (ret == -2) {
+ fimc_v4l2_clr_buf(fimc->dev_fd, V4L2_BUF_TYPE_OUTPUT);
+ } else if (ret == -3) {
+ fimc_v4l2_clr_buf(fimc->dev_fd, V4L2_BUF_TYPE_OUTPUT);
+ fimc_v4l2_clr_buf(fimc->dev_fd, V4L2_BUF_TYPE_CAPTURE);
+ }
+ return ret;
+ }
+#else
+ if (fimc_handle_oneshot(fimc->dev_fd, &fimc_src_buf, NULL) < 0) {
+ fimc_v4l2_clr_buf(fimc->dev_fd, V4L2_BUF_TYPE_OUTPUT);
+ return -1;
+ }
+#endif
+
+ return 0;
+}
+
+#ifdef SUB_TITLES_HWC
+int createG2d(sec_g2d_t *g2d)
+{
+ g2d->dev_fd = open(SEC_G2D_DEV_NAME, O_RDWR);
+
+ if (g2d->dev_fd <= 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::G2d open error (%d)", __func__, errno);
+ goto err;
+ }
+
+ return 0;
+err:
+ if (0 < g2d->dev_fd)
+ close(g2d->dev_fd);
+ g2d->dev_fd =0;
+
+ return -1;
+}
+
+int destroyG2d(sec_g2d_t *g2d)
+{
+ // close
+ if (0 < g2d->dev_fd)
+ close(g2d->dev_fd);
+ g2d->dev_fd = 0;
+
+ return 0;
+}
+#endif
+
+int createFimc(s5p_fimc_t *fimc)
+{
+ struct v4l2_capability cap;
+ struct v4l2_format fmt;
+ struct v4l2_control vc;
+
+ // open device file
+ if (fimc->dev_fd <= 0)
+ fimc->dev_fd = open(PP_DEVICE_DEV_NAME, O_RDWR);
+
+ if (fimc->dev_fd <= 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Post processor open error (%d)",
+ __func__, errno);
+ goto err;
+ }
+
+ // check capability
+ if (ioctl(fimc->dev_fd, VIDIOC_QUERYCAP, &cap) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "VIDIOC_QUERYCAP failed");
+ goto err;
+ }
+
+ if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%d has no streaming support", fimc->dev_fd);
+ goto err;
+ }
+
+ if (!(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%d is no video output", fimc->dev_fd);
+ goto err;
+ }
+
+ /*
+ * malloc fimc_outinfo structure
+ */
+ fmt.type = V4L2_BUF_TYPE_OUTPUT;
+ if (ioctl(fimc->dev_fd, VIDIOC_G_FMT, &fmt) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_G_FMT", __func__);
+ goto err;
+ }
+
+#ifdef BOARD_USE_V4L2_ION
+#else
+ vc.id = V4L2_CID_FIMC_VERSION;
+ vc.value = 0;
+
+ if (ioctl(fimc->dev_fd, VIDIOC_G_CTRL, &vc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::Error in video VIDIOC_G_CTRL", __func__);
+ goto err;
+ }
+ fimc->hw_ver = vc.value;
+#endif
+
+ return 0;
+
+err:
+ if (0 < fimc->dev_fd)
+ close(fimc->dev_fd);
+ fimc->dev_fd =0;
+
+ return -1;
+}
+
+int destroyFimc(s5p_fimc_t *fimc)
+{
+ if (fimc->out_buf.virt_addr != NULL) {
+ fimc->out_buf.virt_addr = NULL;
+ fimc->out_buf.length = 0;
+ }
+
+ // close
+ if (0 < fimc->dev_fd)
+ close(fimc->dev_fd);
+ fimc->dev_fd = 0;
+
+ return 0;
+}
+
+int runFimc(struct hwc_context_t *ctx,
+ struct sec_img *src_img, struct sec_rect *src_rect,
+ struct sec_img *dst_img, struct sec_rect *dst_rect,
+ uint32_t transform)
+{
+ s5p_fimc_t * fimc = &ctx->fimc;
+
+ unsigned int src_phys_addr = 0;
+ unsigned int dst_phys_addr = 0;
+ int rotate_value = 0;
+ int flag_force_memcpy = 0;
+ int32_t src_color_space;
+ int32_t dst_color_space;
+
+ /* 1. source address and size */
+ src_phys_addr = get_src_phys_addr(ctx, src_img, src_rect);
+ if (0 == src_phys_addr)
+ return -1;
+
+ /* 2. destination address and size */
+ dst_phys_addr = get_dst_phys_addr(ctx, dst_img, dst_rect, &flag_force_memcpy);
+ if (0 == dst_phys_addr)
+ return -2;
+
+ /* 3. check whether fimc supports the src format */
+ src_color_space = HAL_PIXEL_FORMAT_2_V4L2_PIX(src_img->format);
+ if (0 > src_color_space)
+ return -3;
+ dst_color_space = HAL_PIXEL_FORMAT_2_V4L2_PIX(dst_img->format);
+ if (0 > dst_color_space)
+ return -4;
+
+ /* 4. FIMC: src_rect of src_img => dst_rect of dst_img */
+ if (runcFimcCore(ctx, src_phys_addr, src_img, src_rect,
+ (uint32_t)src_color_space, dst_phys_addr, dst_img, dst_rect,
+ (uint32_t)dst_color_space, transform) < 0)
+ return -5;
+
+ if (flag_force_memcpy == 1) {
+#ifdef USE_HW_PMEM
+ if (0 != ctx->sec_pmem.sec_pmem_alloc[1].size) {
+ struct s3c_mem_dma_param s3c_mem_dma;
+
+ s3c_mem_dma.src_addr =
+ (unsigned long)(ctx->sec_pmem.sec_pmem_alloc[1].virt_addr);
+ s3c_mem_dma.size = ctx->sec_pmem.sec_pmem_alloc[1].size;
+
+ ioctl(ctx->s3c_mem.fd, S3C_MEM_CACHE_INVAL, &s3c_mem_dma);
+
+ memcpy((void*)((unsigned int)dst_img->base),
+ (void *)(ctx->sec_pmem.sec_pmem_alloc[1].virt_addr),
+ ctx->sec_pmem.sec_pmem_alloc[1].size);
+ } else
+#endif
+ {
+ struct s3c_mem_alloc *ptr_mem_alloc = &ctx->s3c_mem.mem_alloc[1];
+ struct s3c_mem_dma_param s3c_mem_dma;
+
+ s3c_mem_dma.src_addr = (unsigned long)ptr_mem_alloc->vir_addr;
+ s3c_mem_dma.size = ptr_mem_alloc->size;
+
+ ioctl(ctx->s3c_mem.fd, S3C_MEM_CACHE_INVAL, &s3c_mem_dma);
+
+ memcpy((void*)((unsigned int)dst_img->base),
+ (void *)ptr_mem_alloc->vir_addr, ptr_mem_alloc->size);
+ }
+ }
+
+ return 0;
+}
+
+#ifdef SUB_TITLES_HWC
+static int get_g2d_src_phys_addr(struct hwc_context_t *ctx, g2d_rect *src_rect)
+{
+ sec_g2d_t *g2d = &ctx->g2d;
+ struct s3c_mem_alloc *ptr_mem_alloc = &ctx->s3c_mem.mem_alloc[0];
+#ifdef USE_HW_PMEM
+ sec_pmem_alloc_t *pm_alloc = &ctx->sec_pmem.sec_pmem_alloc[0];
+#endif
+
+ unsigned int src_virt_addr = 0;
+ unsigned int src_phys_addr = 0;
+ unsigned int src_frame_size = 0;
+
+ struct pmem_region region;
+
+ // error check routine
+ if (0 == src_rect->virt_addr) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s invalid src address\n", __func__);
+ return 0;
+ }
+
+ src_frame_size = FRAME_SIZE(src_rect->color_format,
+ src_rect->full_w, src_rect->full_h);
+ if (src_frame_size == 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::FRAME_SIZE fail", __func__);
+ return 0;
+ }
+
+#ifdef USE_HW_PMEM
+ if (0 <= checkPmem(&ctx->sec_pmem, 0, src_frame_size)) {
+ src_virt_addr = pm_alloc->virt_addr;
+ src_phys_addr = pm_alloc->phys_addr;
+ pm_alloc->size = src_frame_size;
+ } else
+#endif
+ if (0 <= checkMem(&ctx->s3c_mem, 0, src_frame_size)) {
+ src_virt_addr = ptr_mem_alloc->vir_addr;
+ src_phys_addr = ptr_mem_alloc->phy_addr;
+ ptr_mem_alloc->size = src_frame_size;
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::check_mem fail", __func__);
+ return 0;
+ }
+ memcpy((void *)src_virt_addr, (void*)((unsigned int)src_rect->virt_addr), src_frame_size);
+
+ return src_phys_addr;
+}
+
+int get_HAL_2_G2D_FORMAT(int format)
+{
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888: return G2D_ABGR_8888;
+ case HAL_PIXEL_FORMAT_RGBX_8888: return G2D_XBGR_8888;
+ case HAL_PIXEL_FORMAT_BGRA_8888: return G2D_ARGB_8888;
+ case HAL_PIXEL_FORMAT_RGB_888: return G2D_PACKED_BGR_888;
+ case HAL_PIXEL_FORMAT_RGB_565: return G2D_RGB_565;
+ case HAL_PIXEL_FORMAT_RGBA_5551: return G2D_RGBA_5551;
+ case HAL_PIXEL_FORMAT_RGBA_4444: return G2D_RGBA_4444;
+ default:
+ return -1;
+ }
+}
+
+static inline int rotateValueHAL2G2D(unsigned char transform)
+{
+ int rotate_flag = transform & 0x7;
+
+ switch (rotate_flag) {
+ case HAL_TRANSFORM_ROT_90: return G2D_ROT_90;
+ case HAL_TRANSFORM_ROT_180: return G2D_ROT_180;
+ case HAL_TRANSFORM_ROT_270: return G2D_ROT_270;
+ default:
+ return G2D_ROT_0;
+ }
+}
+
+int runG2d(struct hwc_context_t *ctx, g2d_rect *src_rect, g2d_rect *dst_rect,
+ uint32_t transform)
+{
+ sec_g2d_t * g2d = &ctx->g2d;
+ g2d_flag flag = {G2D_ROT_0, G2D_ALPHA_BLENDING_OPAQUE, 0, 0, 0, 0, 0, 0};
+ int rotate_value = 0;
+
+ // 1 : source address and size
+ src_rect->phys_addr = get_g2d_src_phys_addr(ctx, src_rect);
+ if (0 == src_rect->phys_addr)
+ return -1;
+
+ // 2 : destination address and size
+ if (0 == dst_rect->phys_addr)
+ return -2;
+
+ // check whether g2d supports the src format
+ src_rect->color_format = get_HAL_2_G2D_FORMAT(src_rect->color_format);
+ if (0 > src_rect->color_format)
+ return -3;
+
+ dst_rect->color_format = get_HAL_2_G2D_FORMAT(dst_rect->color_format);
+ if (0 > dst_rect->color_format)
+ return -4;
+
+ flag.rotate_val = rotateValueHAL2G2D(transform);
+
+ // scale and rotate and alpha with FIMG
+ if(stretchSecFimg(src_rect, dst_rect, &flag) < 0)
+ return -5;
+
+ return 0;
+}
+#endif
+
+int createMem(struct s3c_mem_t *mem, unsigned int index, unsigned int size)
+{
+ struct s3c_mem_alloc *ptr_mem_alloc;
+ struct s3c_mem_alloc mem_alloc_info;
+
+ if (index >= NUM_OF_MEM_OBJ) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::invalid index (%d >= %d)",
+ __func__, index, NUM_OF_MEM_OBJ);
+ goto err;
+ }
+
+ ptr_mem_alloc = &mem->mem_alloc[index];
+
+ if (mem->fd <= 0) {
+ mem->fd = open(S3C_MEM_DEV_NAME, O_RDWR);
+ if (mem->fd <= 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::open(%s) fail(%s)",
+ __func__, S3C_MEM_DEV_NAME, strerror(errno));
+ goto err;
+ }
+ }
+
+ // kcoolsw : what the hell of this line??
+ if (0 == size)
+ return 0;
+
+ mem_alloc_info.size = size;
+
+ if (ioctl(mem->fd, S3C_MEM_CACHEABLE_ALLOC, &mem_alloc_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3C_MEM_ALLOC(size : %d) fail",
+ __func__, mem_alloc_info.size);
+ goto err;
+ }
+
+ ptr_mem_alloc->phy_addr = mem_alloc_info.phy_addr;
+ ptr_mem_alloc->vir_addr = mem_alloc_info.vir_addr;
+ ptr_mem_alloc->size = mem_alloc_info.size;
+
+ return 0;
+
+err:
+ if (0 < mem->fd)
+ close(mem->fd);
+ mem->fd = 0;
+
+ return 0;
+}
+
+int destroyMem(struct s3c_mem_t *mem)
+{
+ int i;
+ struct s3c_mem_alloc *ptr_mem_alloc;
+
+ if (mem->fd <= 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::invalied fd(%d) fail", __func__, mem->fd);
+ return -1;
+ }
+
+ for (i = 0; i < NUM_OF_MEM_OBJ; i++) {
+ ptr_mem_alloc = &mem->mem_alloc[i];
+
+ if (0 != ptr_mem_alloc->vir_addr) {
+ if (ioctl(mem->fd, S3C_MEM_FREE, ptr_mem_alloc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3C_MEM_FREE fail", __func__);
+ return -1;
+ }
+
+ ptr_mem_alloc->phy_addr = 0;
+ ptr_mem_alloc->vir_addr = 0;
+ ptr_mem_alloc->size = 0;
+ }
+ }
+
+ close(mem->fd);
+ mem->fd = 0;
+
+ return 0;
+}
+
+int checkMem(struct s3c_mem_t *mem, unsigned int index, unsigned int size)
+{
+ int ret;
+ struct s3c_mem_alloc *ptr_mem_alloc;
+ struct s3c_mem_alloc mem_alloc_info;
+
+ if (index >= NUM_OF_MEM_OBJ) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::invalid index (%d >= %d)", __func__,
+ index, NUM_OF_MEM_OBJ);
+ return -1;
+ }
+
+ if (mem->fd <= 0) {
+ ret = createMem(mem, index, size);
+ return ret;
+ }
+
+ ptr_mem_alloc = &mem->mem_alloc[index];
+
+ if (ptr_mem_alloc->size < (int)size) {
+ if (0 < ptr_mem_alloc->size) {
+ // free allocated mem
+ if (ioctl(mem->fd, S3C_MEM_FREE, ptr_mem_alloc) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3C_MEM_FREE fail", __func__);
+ return -1;
+ }
+ }
+
+ // allocate mem with requested size
+ mem_alloc_info.size = size;
+ if (ioctl(mem->fd, S3C_MEM_CACHEABLE_ALLOC, &mem_alloc_info) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::S3C_MEM_ALLOC(size : %d) fail",
+ __func__, mem_alloc_info.size);
+ return -1;
+ }
+
+ ptr_mem_alloc->phy_addr = mem_alloc_info.phy_addr;
+ ptr_mem_alloc->vir_addr = mem_alloc_info.vir_addr;
+ ptr_mem_alloc->size = mem_alloc_info.size;
+ }
+
+ return 0;
+}
+
+#ifdef USE_HW_PMEM
+int createPmem(sec_pmem_t *pm, unsigned int buf_size)
+{
+ int master_fd, err = 0, i;
+ void *base;
+ unsigned int phys_base;
+ size_t size, sub_size[NUM_OF_MEM_OBJ];
+ struct pmem_region region;
+
+ master_fd = open(PMEM_DEVICE_DEV_NAME, O_RDWR, 0);
+ if (master_fd < 0) {
+ pm->pmem_master_fd = -1;
+ if (EACCES == errno) {
+ return 0;
+ } else {
+ SEC_HWC_Log(HWC_LOG_ERROR, "%s::open(%s) fail(%s)",
+ __func__, PMEM_DEVICE_DEV_NAME, strerror(errno));
+ return -errno;
+ }
+ }
+
+ if (ioctl(master_fd, PMEM_GET_TOTAL_SIZE, ®ion) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "PMEM_GET_TOTAL_SIZE failed, default mode");
+ size = 8<<20; // 8 MiB
+ } else {
+ size = region.len;
+ }
+
+ base = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, master_fd, 0);
+ if (base == MAP_FAILED) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "[%s] mmap failed : %d (%s)", __func__,
+ errno, strerror(errno));
+ base = 0;
+ close(master_fd);
+ master_fd = -1;
+ return -errno;
+ }
+
+ if (ioctl(master_fd, PMEM_GET_PHYS, ®ion) < 0) {
+ SEC_HWC_Log(HWC_LOG_ERROR, "PMEM_GET_PHYS failed, limp mode");
+ region.offset = 0;
+ }
+
+ pm->pmem_master_fd = master_fd;
+ pm->pmem_master_base = base;
+ pm->pmem_total_size = size;
+ //pm->pmem_master_phys_base = region.offset;
+ phys_base = region.offset;
+
+ // sec_pmem_alloc[0] for temporary buffer for source
+ sub_size[0] = buf_size;
+ sub_size[0] = roundUpToPageSize(sub_size[0]);
+
+ for (i = 0; i < NUM_OF_MEM_OBJ; i++) {
+ sec_pmem_alloc_t *pm_alloc = &(pm->sec_pmem_alloc[i]);
+ int fd, ret;
+ int offset = i ? sub_size[i-1] : 0;
+ struct pmem_region sub = { offset, sub_size[i] };
+
+ // create the "sub-heap"
+ if (0 > (fd = open(PMEM_DEVICE_DEV_NAME, O_RDWR, 0))) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "[%s][index=%d] open failed (%dL) : %d (%s)",
+ __func__, i, __LINE__, errno, strerror(errno));
+ return -errno;
+ }
+
+ // connect to it
+ if (0 != (ret = ioctl(fd, PMEM_CONNECT, pm->pmem_master_fd))) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "[%s][index=%d] ioctl(PMEM_CONNECT) failed : %d (%s)",
+ __func__, i, errno, strerror(errno));
+ close(fd);
+ return -errno;
+ }
+
+ // make it available to the client process
+ if (0 != (ret = ioctl(fd, PMEM_MAP, &sub))) {
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "[%s][index=%d] ioctl(PMEM_MAP) failed : %d (%s)",
+ __func__, i, errno, strerror(errno));
+ close(fd);
+ return -errno;
+ }
+
+ pm_alloc->fd = fd;
+ pm_alloc->total_size = sub_size[i];
+ pm_alloc->offset = offset;
+ pm_alloc->virt_addr = (unsigned int)base + (unsigned int)offset;
+ pm_alloc->phys_addr = (unsigned int)phys_base + (unsigned int)offset;
+
+#if defined (PMEM_DEBUG)
+ SEC_HWC_Log(HWC_LOG_DEBUG, "[%s] pm_alloc[%d] fd=%d total_size=%d "
+ "offset=0x%x virt_addr=0x%x phys_addr=0x%x",
+ __func__, i, pm_alloc->fd, pm_alloc->total_size,
+ pm_alloc->offset, pm_alloc->virt_addr, pm_alloc->phys_addr);
+#endif
+ }
+
+ return err;
+}
+
+int destroyPmem(sec_pmem_t *pm)
+{
+ int i, err;
+
+ for (i=0; i<NUM_OF_MEM_OBJ; i++) {
+ sec_pmem_alloc_t *pm_alloc = &(pm->sec_pmem_alloc[i]);
+
+ if (0 <= pm_alloc->fd) {
+ struct pmem_region sub = { pm_alloc->offset, pm_alloc->total_size };
+
+ if (0 > (err = ioctl(pm_alloc->fd, PMEM_UNMAP, &sub)))
+ SEC_HWC_Log(HWC_LOG_ERROR,
+ "[%s][index=%d] ioctl(PMEM_UNMAP) failed : %d (%s)",
+ __func__, i, errno, strerror(errno));
+#if defined (PMEM_DEBUG)
+ else
+ SEC_HWC_Log(HWC_LOG_DEBUG,
+ "[%s] pm_alloc[%d] unmap fd=%d total_size=%d offset=0x%x",
+ __func__, i, pm_alloc->fd, pm_alloc->total_size,
+ pm_alloc->offset);
+#endif
+ close(pm_alloc->fd);
+
+ pm_alloc->fd = -1;
+ pm_alloc->total_size = 0;
+ pm_alloc->offset = 0;
+ pm_alloc->virt_addr = 0;
+ pm_alloc->phys_addr = 0;
+ }
+ }
+
+ if (0 <= pm->pmem_master_fd) {
+ munmap(pm->pmem_master_base, pm->pmem_total_size);
+ close(pm->pmem_master_fd);
+ pm->pmem_master_fd = -1;
+ }
+
+ pm->pmem_master_base = 0;
+ pm->pmem_total_size = 0;
+
+ return 0;
+}
+
+int checkPmem(sec_pmem_t *pm, unsigned int index, unsigned int requested_size)
+{
+ sec_pmem_alloc_t *pm_alloc = &(pm->sec_pmem_alloc[index]);
+
+ if (0 < pm_alloc->virt_addr &&
+ requested_size <= (unsigned int)(pm_alloc->total_size))
+ return 0;
+
+ pm_alloc->size = 0;
+ return -1;
+}
+
+#endif
diff --git a/exynos4/hal/libhwcomposer/SecHWCUtils.h b/exynos4/hal/libhwcomposer/SecHWCUtils.h
new file mode 100644
index 0000000..005b694
--- /dev/null
+++ b/exynos4/hal/libhwcomposer/SecHWCUtils.h
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *
+ * @author Rama, Meka(v.meka@samsung.com)
+ Sangwoo, Park(sw5771.park@samsung.com)
+ Jamie, Oh (jung-min.oh@samsung.com)
+ * @date 2011-03-11
+ *
+ */
+
+#ifndef ANDROID_SEC_HWC_UTILS_H_
+#define ANDROID_SEC_HWC_UTILS_H_
+
+#include <stdlib.h>
+#include <hardware/hardware.h>
+#include <hardware/hwcomposer.h>
+
+#include <fcntl.h>
+#include <errno.h>
+#include <cutils/log.h>
+
+#ifdef BOARD_USE_V4L2_ION
+#include <ion.h>
+#include "s5p_fimc_v4l2.h"
+#include "sec_utils_v4l2.h"
+#else
+#include <linux/videodev.h>
+#include "s5p_fimc.h"
+#include "sec_utils.h"
+#endif
+
+#include <linux/android_pmem.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <hardware/gralloc.h>
+
+#include "linux/fb.h"
+
+#include "s3c_lcd.h"
+#include "s3c_mem.h"
+#include "sec_format.h"
+
+//#define HWC_DEBUG
+#if defined(BOARD_USES_FIMGAPI)
+#include "sec_g2d.h"
+//#define SUB_TITLES_HWC
+#endif
+
+#define NUM_OF_WIN (2)
+#define NUM_OF_WIN_BUF (2)
+#define NUM_OF_MEM_OBJ (1)
+
+#if (NUM_OF_WIN_BUF < 2)
+ #define ENABLE_FIMD_VSYNC
+#endif
+
+#define MAX_RESIZING_RATIO_LIMIT (63)
+
+#ifdef SAMSUNG_EXYNOS4x12
+#ifdef BOARD_USE_V4L2_ION
+#define PP_DEVICE_DEV_NAME "/dev/video4"
+#else
+#define PP_DEVICE_DEV_NAME "/dev/video3"
+#endif
+#endif
+
+#ifdef SAMSUNG_EXYNOS4210
+#define PP_DEVICE_DEV_NAME "/dev/video1"
+#endif
+
+#define S3C_MEM_DEV_NAME "/dev/s3c-mem"
+#define PMEM_DEVICE_DEV_NAME "/dev/pmem_gpu1"
+
+#ifdef BOARD_USE_V4L2_ION
+#undef USE_HW_PMEM
+#else
+#define USE_HW_PMEM
+#endif
+
+#define PMEM_SIZE (1920 * 1280 * 2)
+
+struct sec_rect {
+ int32_t x;
+ int32_t y;
+ int32_t w;
+ int32_t h;
+};
+
+struct sec_img {
+ uint32_t f_w;
+ uint32_t f_h;
+ uint32_t w;
+ uint32_t h;
+ uint32_t format;
+ uint32_t base;
+ uint32_t offset;
+ uint32_t paddr;
+ uint32_t uoffset;
+ uint32_t voffset;
+ int usage;
+ int mem_id;
+ int mem_type;
+};
+
+inline int SEC_MIN(int x, int y)
+{
+ return ((x < y) ? x : y);
+}
+
+inline int SEC_MAX(int x, int y)
+{
+ return ((x > y) ? x : y);
+}
+
+struct s3c_mem_t {
+ int fd;
+ struct s3c_mem_alloc mem_alloc[NUM_OF_MEM_OBJ];
+};
+
+#ifdef USE_HW_PMEM
+typedef struct __sec_pmem_alloc {
+ int fd;
+ int total_size;
+ int offset;
+ int size;
+ unsigned int virt_addr;
+ unsigned int phys_addr;
+} sec_pmem_alloc_t;
+
+typedef struct __sec_pmem {
+ int pmem_master_fd;
+ void *pmem_master_base;
+ int pmem_total_size;
+ sec_pmem_alloc_t sec_pmem_alloc[NUM_OF_MEM_OBJ];
+} sec_pmem_t;
+
+inline size_t roundUpToPageSize(size_t x)
+{
+ return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
+}
+#endif
+
+struct hwc_win_info_t {
+ int fd;
+ int size;
+ sec_rect rect_info;
+ uint32_t addr[NUM_OF_WIN_BUF];
+ int buf_index;
+
+ int power_state;
+ int blending;
+ int layer_index;
+ int status;
+ int vsync;
+#ifdef BOARD_USE_V4L2_ION
+ int ion_fd;
+#endif
+
+ struct fb_fix_screeninfo fix_info;
+ struct fb_var_screeninfo var_info;
+ struct fb_var_screeninfo lcd_info;
+};
+
+enum {
+ HWC_WIN_FREE = 0,
+ HWC_WIN_RESERVED,
+};
+
+enum {
+ HWC_UNKNOWN_MEM_TYPE = 0,
+ HWC_PHYS_MEM_TYPE,
+ HWC_VIRT_MEM_TYPE,
+};
+
+struct hwc_context_t {
+ hwc_composer_device_t device;
+
+ /* our private state goes below here */
+ struct hwc_win_info_t win[NUM_OF_WIN];
+ struct fb_var_screeninfo lcd_info;
+ s5p_fimc_t fimc;
+#ifdef SUB_TITLES_HWC
+ sec_g2d_t g2d;
+#endif
+ struct s3c_mem_t s3c_mem;
+#ifdef USE_HW_PMEM
+ sec_pmem_t sec_pmem;
+#endif
+ int num_of_fb_layer;
+ int num_of_hwc_layer;
+ int num_2d_blit_layer;
+ uint32_t layer_prev_buf[NUM_OF_WIN];
+};
+
+typedef enum _LOG_LEVEL {
+ HWC_LOG_DEBUG,
+ HWC_LOG_WARNING,
+ HWC_LOG_ERROR,
+} HWC_LOG_LEVEL;
+
+#define SEC_HWC_LOG_TAG "SECHWC_LOG"
+
+#ifdef HWC_DEBUG
+#define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__))
+#else
+#define SEC_HWC_Log(a, ...) \
+ do { \
+ if (a == HWC_LOG_ERROR) \
+ ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
+ } while (0)
+#endif
+
+extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
+
+/* copied from gralloc module ..*/
+typedef struct {
+ native_handle_t base;
+
+ /* These fields can be sent cross process. They are also valid
+ * to duplicate within the same process.
+ *
+ * A table is stored within psPrivateData on gralloc_module_t (this
+ * is obviously per-process) which maps stamps to a mapped
+ * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
+ * count associated with it, satisfying the requirements of the
+ * Android API. This also prevents us from leaking maps/allocations.
+ *
+ * This table has entries inserted either by alloc()
+ * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
+ * by free() (alloc_device_t) and unmap() (gralloc_module_t).
+ *
+ * As a special case for framebuffer_device_t, framebuffer_open()
+ * will add and framebuffer_close() will remove from this table.
+ */
+
+#define IMG_NATIVE_HANDLE_NUMFDS 1
+ /* The `fd' field is used to "export" a meminfo to another process.
+ * Therefore, it is allocated by alloc_device_t, and consumed by
+ * gralloc_module_t. The framebuffer_device_t does not need a handle,
+ * and the special value IMG_FRAMEBUFFER_FD is used instead.
+ */
+ int fd;
+
+#if 1
+ int format;
+ int magic;
+ int flags;
+ int size;
+ int offset;
+ int base_addr;
+#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6)
+#else
+#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4)
+#endif
+ /* A KERNEL unique identifier for any exported kernel meminfo. Each
+ * exported kernel meminfo will have a unique stamp, but note that in
+ * userspace, several meminfos across multiple processes could have
+ * the same stamp. As the native_handle can be dup(2)'d, there could be
+ * multiple handles with the same stamp but different file descriptors.
+ */
+ uint64_t ui64Stamp;
+
+ /* We could live without this, but it lets us perform some additional
+ * validation on the client side. Normally, we'd have no visibility
+ * of the allocated usage, just the lock usage.
+ */
+ int usage;
+
+ /* In order to do efficient cache flushes we need the buffer dimensions
+ * and format. These are available on the android_native_buffer_t,
+ * but the platform doesn't pass them down to the graphics HAL.
+ *
+ * TODO: Ideally the platform would be modified to not require this.
+ */
+ int width;
+ int height;
+ int bpp;
+}
+__attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t;
+
+int window_open (struct hwc_win_info_t *win, int id);
+int window_close (struct hwc_win_info_t *win);
+int window_set_pos (struct hwc_win_info_t *win);
+int window_get_info (struct hwc_win_info_t *win, int win_num);
+int window_pan_display(struct hwc_win_info_t *win);
+int window_show (struct hwc_win_info_t *win);
+int window_hide (struct hwc_win_info_t *win);
+int window_get_global_lcd_info(int fd, struct fb_var_screeninfo *lcd_info);
+
+int createFimc (s5p_fimc_t *fimc);
+int destroyFimc(s5p_fimc_t *fimc);
+int runFimc(struct hwc_context_t *ctx,
+ struct sec_img *src_img, struct sec_rect *src_rect,
+ struct sec_img *dst_img, struct sec_rect *dst_rect,
+ uint32_t transform);
+
+#ifdef SUB_TITLES_HWC
+int runG2d(struct hwc_context_t *ctx,
+ g2d_rect *src_rect, g2d_rect *dst_rect,
+ uint32_t transform);
+
+int destroyG2d(sec_g2d_t *g2d);
+int createG2d(sec_g2d_t *g2d);
+#endif
+
+int createMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
+int destroyMem(struct s3c_mem_t *mem);
+int checkMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
+
+#ifdef USE_HW_PMEM
+int createPmem (sec_pmem_t *pm, unsigned int size);
+int destroyPmem(sec_pmem_t *pm);
+int checkPmem (sec_pmem_t *pm, unsigned int index, unsigned int size);
+#endif
+
+#endif /* ANDROID_SEC_HWC_UTILS_H_*/