summaryrefslogtreecommitdiffstats
path: root/hwc
diff options
context:
space:
mode:
authorTony Lofthouse <a0741364@ti.com>2012-11-13 10:02:42 -0600
committerDaniel Levin <dendy@ti.com>2012-11-28 21:16:26 +0200
commit368038a14d5fd94184751a167a63af0c559be82f (patch)
treecf0775f8d8eeab9fc12c96dfdc530bf6a9517906 /hwc
parentdc2e4aafa6b02b6a16eb29c73e84fd45781bb09c (diff)
downloadhardware_ti_omap4-368038a14d5fd94184751a167a63af0c559be82f.zip
hardware_ti_omap4-368038a14d5fd94184751a167a63af0c559be82f.tar.gz
hardware_ti_omap4-368038a14d5fd94184751a167a63af0c559be82f.tar.bz2
hwc: Move dock image into a separate file
Change-Id: I01582535beb22f7f4de493f74b4671ee59cdcadd Signed-off-by: Mykola Ostrovskyy <mykola@ti.com> Signed-off-by: Tony Lofthouse <a0741364@ti.com>
Diffstat (limited to 'hwc')
-rw-r--r--hwc/Android.mk2
-rw-r--r--hwc/dock_image.c196
-rw-r--r--hwc/dock_image.h38
-rw-r--r--hwc/hwc.c153
-rw-r--r--hwc/hwc_dev.h3
5 files changed, 242 insertions, 150 deletions
diff --git a/hwc/Android.mk b/hwc/Android.mk
index 60b421d..b48bffa 100644
--- a/hwc/Android.mk
+++ b/hwc/Android.mk
@@ -8,7 +8,7 @@ LOCAL_ARM_MODE := arm
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/../vendor/lib/hw
LOCAL_SHARED_LIBRARIES := liblog libEGL libcutils libutils libhardware libhardware_legacy libz \
libion
-LOCAL_SRC_FILES := hwc.c rgz_2d.c
+LOCAL_SRC_FILES := hwc.c rgz_2d.c dock_image.c
LOCAL_STATIC_LIBRARIES := libpng
LOCAL_MODULE_TAGS := optional
diff --git a/hwc/dock_image.c b/hwc/dock_image.c
new file mode 100644
index 0000000..b74a17e
--- /dev/null
+++ b/hwc/dock_image.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * 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.
+ */
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
+#include <cutils/log.h>
+#include <cutils/properties.h>
+#include <png.h>
+
+#include <linux/fb.h>
+
+#include "hwc_dev.h"
+#include "dock_image.h"
+
+static struct dock_image_state {
+ void *buffer; /* start of fb for hdmi */
+ uint32_t buffer_size; /* size of fb for hdmi */
+
+ uint32_t max_width;
+ uint32_t max_height;
+
+ image_info_t image;
+} dock_image;
+
+static void free_png_image(image_info_t *img)
+{
+ memset(img, 0, sizeof(*img));
+}
+
+static int load_png_image(char *path, image_info_t *img)
+{
+ void *ptr = NULL;
+ png_bytepp row_pointers = NULL;
+
+ FILE *fd = fopen(path, "rb");
+ if (!fd) {
+ ALOGE("failed to open PNG file %s: (%d)", path, errno);
+ return -EINVAL;
+ }
+
+ const int SIZE_PNG_HEADER = 8;
+ uint8_t header[SIZE_PNG_HEADER];
+ fread(header, 1, SIZE_PNG_HEADER, fd);
+ if (png_sig_cmp(header, 0, SIZE_PNG_HEADER)) {
+ ALOGE("%s is not a PNG file", path);
+ goto fail;
+ }
+
+ png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr)
+ goto fail_alloc;
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ goto fail_alloc;
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ goto fail_alloc;
+
+ png_init_io(png_ptr, fd);
+ png_set_sig_bytes(png_ptr, SIZE_PNG_HEADER);
+ png_set_user_limits(png_ptr, dock_image.max_width, dock_image.max_height);
+ png_read_info(png_ptr, info_ptr);
+
+ uint8_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
+ uint32_t width = png_get_image_width(png_ptr, info_ptr);
+ uint32_t height = png_get_image_height(png_ptr, info_ptr);
+ uint8_t color_type = png_get_color_type(png_ptr, info_ptr);
+
+ switch (color_type) {
+ case PNG_COLOR_TYPE_PALETTE:
+ png_set_palette_to_rgb(png_ptr);
+ png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
+ break;
+ case PNG_COLOR_TYPE_GRAY:
+ if (bit_depth < 8) {
+ png_set_expand_gray_1_2_4_to_8(png_ptr);
+ if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(png_ptr);
+ } else {
+ png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
+ }
+ /* fall through */
+ case PNG_COLOR_TYPE_GRAY_ALPHA:
+ png_set_gray_to_rgb(png_ptr);
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
+ /* fall through */
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ png_set_bgr(png_ptr);
+ break;
+ default:
+ ALOGE("unsupported PNG color: %x", color_type);
+ goto fail_alloc;
+ }
+
+ if (bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+ const uint32_t bpp = 4;
+ img->size = ALIGN(width * height * bpp, 4096);
+ if ((uint32_t)img->size > dock_image.buffer_size) {
+ ALOGE("image does not fit into framebuffer area (%d > %d)", img->size, dock_image.buffer_size);
+ goto fail_alloc;
+ }
+ img->ptr = dock_image.buffer;
+
+ row_pointers = calloc(height, sizeof(*row_pointers));
+ if (!row_pointers) {
+ ALOGE("failed to allocate row pointers");
+ goto fail_alloc;
+ }
+ uint32_t i;
+ for (i = 0; i < height; i++)
+ row_pointers[i] = img->ptr + i * width * bpp;
+ png_set_rows(png_ptr, info_ptr, row_pointers);
+ png_read_update_info(png_ptr, info_ptr);
+ img->rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
+ png_read_image(png_ptr, row_pointers);
+ png_read_end(png_ptr, NULL);
+ free(row_pointers);
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+ fclose(fd);
+ img->width = width;
+ img->height = height;
+ return 0;
+
+fail_alloc:
+ free_png_image(img);
+ free(row_pointers);
+ if (!png_ptr || !info_ptr)
+ ALOGE("failed to allocate PNG structures");
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+fail:
+ fclose(fd);
+ return -EINVAL;
+}
+
+int init_dock_image(omap_hwc_device_t *hwc_dev, uint32_t max_width, uint32_t max_height)
+{
+ int err = 0;
+
+ struct fb_fix_screeninfo fix;
+ if (ioctl(hwc_dev->fb_fd, FBIOGET_FSCREENINFO, &fix)) {
+ ALOGE("failed to get fb info (%d)", errno);
+ err = -errno;
+ goto done;
+ }
+
+ dock_image.buffer_size = fix.smem_len;
+ dock_image.buffer = mmap(NULL, fix.smem_len, PROT_WRITE, MAP_SHARED, hwc_dev->fb_fd, 0);
+ if (dock_image.buffer == MAP_FAILED) {
+ ALOGE("failed to map fb memory");
+ err = -errno;
+ goto done;
+ }
+
+ dock_image.max_width = max_width;
+ dock_image.max_height = max_height;
+
+ done:
+ return err;
+}
+
+void load_dock_image()
+{
+ if (!dock_image.image.rowbytes) {
+ char value[PROPERTY_VALUE_MAX];
+ property_get("persist.hwc.dock_image", value, "/vendor/res/images/dock/dock.png");
+ load_png_image(value, &dock_image.image);
+ }
+}
+
+image_info_t *get_dock_image()
+{
+ return &dock_image.image;
+}
+
diff --git a/hwc/dock_image.h b/hwc/dock_image.h
new file mode 100644
index 0000000..44a3271
--- /dev/null
+++ b/hwc/dock_image.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * 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.
+ */
+
+#ifndef __DOCK_IMAGE__
+#define __DOCK_IMAGE__
+
+#include <stdint.h>
+
+/* ARGB image */
+struct image_info {
+ int width;
+ int height;
+ int rowbytes;
+ int size;
+ uint8_t *ptr;
+};
+typedef struct image_info image_info_t;
+
+typedef struct omap_hwc_device omap_hwc_device_t;
+
+int init_dock_image(omap_hwc_device_t *hwc_dev, uint32_t max_width, uint32_t max_height);
+void load_dock_image();
+image_info_t *get_dock_image();
+
+#endif
diff --git a/hwc/hwc.c b/hwc/hwc.c
index d187675..9b0965e 100644
--- a/hwc/hwc.c
+++ b/hwc/hwc.c
@@ -22,7 +22,6 @@
#include <fcntl.h>
#include <poll.h>
#include <sys/ioctl.h>
-#include <sys/mman.h>
#include <sys/resource.h>
#include <cutils/properties.h>
@@ -35,7 +34,6 @@
#include <ui/S3DFormat.h>
#include <utils/Timers.h>
#include <EGL/egl.h>
-#include <png.h>
#include <edid_parser.h>
#include <linux/fb.h>
@@ -43,6 +41,7 @@
#include <ion/ion.h>
#include "hwc_dev.h"
+#include "dock_image.h"
#define min(a, b) ( { typeof(a) __a = (a), __b = (b); __a < __b ? __a : __b; } )
#define max(a, b) ( { typeof(a) __a = (a), __b = (b); __a > __b ? __a : __b; } )
@@ -65,15 +64,6 @@ enum {
EXT_HFLIP = (1 << 2), /* flip l-r on output (after rotation) */
};
-/* ARGB image */
-struct image_info {
- int width;
- int height;
- int rowbytes;
- int size;
- uint8_t *ptr;
-} dock_image = { .rowbytes = 0 };
-
#define HAL_FMT(f) ((f) == HAL_PIXEL_FORMAT_TI_NV12 ? "NV12" : \
(f) == HAL_PIXEL_FORMAT_TI_NV12_1D ? "NV12" : \
(f) == HAL_PIXEL_FORMAT_YV12 ? "YV12" : \
@@ -1764,9 +1754,10 @@ static int hwc_prepare(struct hwc_composer_device *dev, hwc_layer_list_t* list)
} else if (ext->current.docking && ix_docking < 0 && ext->force_dock) {
ix_docking = dsscomp->num_ovls;
struct dss2_ovl_info *oi = &dsscomp->ovls[ix_docking];
+ image_info_t *dock_image = get_dock_image();
setup_layer_base(&oi->cfg, 0, HAL_PIXEL_FORMAT_BGRA_8888, 1,
- dock_image.width, dock_image.height);
- oi->cfg.stride = dock_image.rowbytes;
+ dock_image->width, dock_image->height);
+ oi->cfg.stride = dock_image->rowbytes;
if (clone_external_layer(hwc_dev, ix_docking) == 0) {
oi->addressing = OMAP_DSS_BUFADDR_FB;
oi->ba = 0;
@@ -2005,122 +1996,6 @@ static void hwc_dump(struct hwc_composer_device *dev, char *buff, int buff_len)
dump_printf(&log, "\n");
}
-static void free_png_image(omap_hwc_device_t *hwc_dev, struct image_info *img)
-{
- memset(img, 0, sizeof(*img));
-}
-
-static int load_png_image(omap_hwc_device_t *hwc_dev, char *path, struct image_info *img)
-{
- void *ptr = NULL;
- png_bytepp row_pointers = NULL;
-
- FILE *fd = fopen(path, "rb");
- if (!fd) {
- ALOGE("failed to open PNG file %s: (%d)", path, errno);
- return -EINVAL;
- }
-
- const int SIZE_PNG_HEADER = 8;
- uint8_t header[SIZE_PNG_HEADER];
- fread(header, 1, SIZE_PNG_HEADER, fd);
- if (png_sig_cmp(header, 0, SIZE_PNG_HEADER)) {
- ALOGE("%s is not a PNG file", path);
- goto fail;
- }
-
- png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr)
- goto fail_alloc;
- png_infop info_ptr = png_create_info_struct(png_ptr);
- if (!info_ptr)
- goto fail_alloc;
-
- if (setjmp(png_jmpbuf(png_ptr)))
- goto fail_alloc;
-
- png_init_io(png_ptr, fd);
- png_set_sig_bytes(png_ptr, SIZE_PNG_HEADER);
- png_set_user_limits(png_ptr, limits.max_width, limits.max_height);
- png_read_info(png_ptr, info_ptr);
-
- uint8_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
- uint32_t width = png_get_image_width(png_ptr, info_ptr);
- uint32_t height = png_get_image_height(png_ptr, info_ptr);
- uint8_t color_type = png_get_color_type(png_ptr, info_ptr);
-
- switch (color_type) {
- case PNG_COLOR_TYPE_PALETTE:
- png_set_palette_to_rgb(png_ptr);
- png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
- break;
- case PNG_COLOR_TYPE_GRAY:
- if (bit_depth < 8) {
- png_set_expand_gray_1_2_4_to_8(png_ptr);
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
- png_set_tRNS_to_alpha(png_ptr);
- } else {
- png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
- }
- /* fall through */
- case PNG_COLOR_TYPE_GRAY_ALPHA:
- png_set_gray_to_rgb(png_ptr);
- break;
- case PNG_COLOR_TYPE_RGB:
- png_set_filler(png_ptr, 128, PNG_FILLER_AFTER);
- /* fall through */
- case PNG_COLOR_TYPE_RGB_ALPHA:
- png_set_bgr(png_ptr);
- break;
- default:
- ALOGE("unsupported PNG color: %x", color_type);
- goto fail_alloc;
- }
-
- if (bit_depth == 16)
- png_set_strip_16(png_ptr);
-
- const uint32_t bpp = 4;
- img->size = ALIGN(width * height * bpp, 4096);
- if (img->size > hwc_dev->img_mem_size) {
- ALOGE("image does not fit into framebuffer area (%d > %d)", img->size, hwc_dev->img_mem_size);
- goto fail_alloc;
- }
- img->ptr = hwc_dev->img_mem_ptr;
-
- row_pointers = calloc(height, sizeof(*row_pointers));
- if (!row_pointers) {
- ALOGE("failed to allocate row pointers");
- goto fail_alloc;
- }
- uint32_t i;
- for (i = 0; i < height; i++)
- row_pointers[i] = img->ptr + i * width * bpp;
- png_set_rows(png_ptr, info_ptr, row_pointers);
- png_read_update_info(png_ptr, info_ptr);
- img->rowbytes = png_get_rowbytes(png_ptr, info_ptr);
-
- png_read_image(png_ptr, row_pointers);
- png_read_end(png_ptr, NULL);
- free(row_pointers);
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
- fclose(fd);
- img->width = width;
- img->height = height;
- return 0;
-
-fail_alloc:
- free_png_image(hwc_dev, img);
- free(row_pointers);
- if (!png_ptr || !info_ptr)
- ALOGE("failed to allocate PNG structures");
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
-fail:
- fclose(fd);
- return -EINVAL;
-}
-
-
static int hwc_device_close(hw_device_t* device)
{
omap_hwc_device_t *hwc_dev = (omap_hwc_device_t *) device;;
@@ -2290,10 +2165,7 @@ static void handle_hotplug(omap_hwc_device_t *hwc_dev)
ext->dock.rotation = 0;
ext->dock.hflip = 0;
- if (!dock_image.rowbytes) {
- property_get("persist.hwc.dock_image", value, "/vendor/res/images/dock/dock.png");
- load_png_image(hwc_dev, value, &dock_image);
- }
+ load_dock_image();
}
/* select best mode for mirroring */
@@ -2576,20 +2448,9 @@ static int hwc_device_open(const hw_module_t* module, const char* name, hw_devic
goto done;
}
- struct fb_fix_screeninfo fix;
- if (ioctl(hwc_dev->fb_fd, FBIOGET_FSCREENINFO, &fix)) {
- ALOGE("failed to get fb info (%d)", errno);
- err = -errno;
- goto done;
- }
-
- hwc_dev->img_mem_size = fix.smem_len;
- hwc_dev->img_mem_ptr = mmap(NULL, fix.smem_len, PROT_WRITE, MAP_SHARED, hwc_dev->fb_fd, 0);
- if (hwc_dev->img_mem_ptr == MAP_FAILED) {
- ALOGE("failed to map fb memory");
- err = -errno;
+ err = init_dock_image(hwc_dev, limits.max_width, limits.max_height);
+ if (err)
goto done;
- }
/* Allocate the maximum buffers that we can receive from HWC */
hwc_dev->buffers = malloc(sizeof(buffer_handle_t) * MAX_HWC_LAYERS);
diff --git a/hwc/hwc_dev.h b/hwc/hwc_dev.h
index 2cd1ca0..c63c1c5 100644
--- a/hwc/hwc_dev.h
+++ b/hwc/hwc_dev.h
@@ -122,9 +122,6 @@ struct omap_hwc_device {
int hdmi_fb_fd; /* file descriptor for /dev/fb1 */
int pipe_fds[2]; /* pipe to event thread */
- int img_mem_size; /* size of fb for hdmi */
- void *img_mem_ptr; /* start of fb for hdmi */
-
int flags_rgb_order;
int flags_nv12_only;
float upscaled_nv12_limit;