Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 18 | #include <poll.h> |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 19 | #include <pthread.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | |
| 23 | #include <sys/ioctl.h> |
| 24 | #include <sys/mman.h> |
| 25 | #include <sys/time.h> |
| 26 | #include <sys/resource.h> |
| 27 | |
| 28 | #include <s3c-fb.h> |
| 29 | |
| 30 | #include <EGL/egl.h> |
| 31 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 32 | #define HWC_REMOVE_DEPRECATED_VERSIONS 1 |
| 33 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 34 | #include <cutils/log.h> |
| 35 | #include <hardware/gralloc.h> |
| 36 | #include <hardware/hardware.h> |
| 37 | #include <hardware/hwcomposer.h> |
| 38 | #include <hardware_legacy/uevent.h> |
| 39 | #include <utils/Vector.h> |
| 40 | |
Greg Hackmann | f4cc0c3 | 2012-05-30 09:28:52 -0700 | [diff] [blame] | 41 | #include <sync/sync.h> |
| 42 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 43 | #include "ion.h" |
| 44 | #include "gralloc_priv.h" |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 45 | #include "exynos_gscaler.h" |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 46 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 47 | struct hwc_callback_entry { |
| 48 | void (*callback)(void *, private_handle_t *); |
| 49 | void *data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 50 | }; |
| 51 | typedef android::Vector<struct hwc_callback_entry> hwc_callback_queue_t; |
| 52 | |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 53 | const size_t NUM_HW_WINDOWS = 5; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 54 | const size_t NO_FB_NEEDED = NUM_HW_WINDOWS + 1; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 55 | const size_t MAX_PIXELS = 2560 * 1600 * 2; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 56 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 57 | struct exynos5_hwc_composer_device_1_t; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 58 | |
| 59 | struct exynos5_hwc_post_data_t { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 60 | exynos5_hwc_composer_device_1_t *pdev; |
| 61 | int overlay_map[NUM_HW_WINDOWS]; |
| 62 | hwc_layer_1_t overlays[NUM_HW_WINDOWS]; |
| 63 | int num_overlays; |
| 64 | size_t fb_window; |
| 65 | int fence; |
| 66 | pthread_mutex_t completion_lock; |
| 67 | pthread_cond_t completion; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 70 | struct exynos5_hwc_composer_device_1_t { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 71 | hwc_composer_device_1_t base; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 72 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 73 | int fd; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 74 | int vsync_fd; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 75 | exynos5_hwc_post_data_t bufs; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 76 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 77 | const private_module_t *gralloc_module; |
| 78 | hwc_procs_t *procs; |
| 79 | pthread_t vsync_thread; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 80 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 81 | bool hdmi_hpd; |
| 82 | bool hdmi_mirroring; |
| 83 | void *hdmi_gsc; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 86 | static void dump_layer(hwc_layer_1_t const *l) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 87 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 88 | ALOGV("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, " |
| 89 | "{%d,%d,%d,%d}, {%d,%d,%d,%d}", |
| 90 | l->compositionType, l->flags, l->handle, l->transform, |
| 91 | l->blending, |
| 92 | l->sourceCrop.left, |
| 93 | l->sourceCrop.top, |
| 94 | l->sourceCrop.right, |
| 95 | l->sourceCrop.bottom, |
| 96 | l->displayFrame.left, |
| 97 | l->displayFrame.top, |
| 98 | l->displayFrame.right, |
| 99 | l->displayFrame.bottom); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static void dump_handle(private_handle_t *h) |
| 103 | { |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 104 | ALOGV("\t\tformat = %d, width = %u, height = %u, stride = %u", |
| 105 | h->format, h->width, h->height, h->stride); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static void dump_config(s3c_fb_win_config &c) |
| 109 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 110 | ALOGV("\tstate = %u", c.state); |
| 111 | if (c.state == c.S3C_FB_WIN_STATE_BUFFER) { |
| 112 | ALOGV("\t\tfd = %d, offset = %u, stride = %u, " |
| 113 | "x = %d, y = %d, w = %u, h = %u, " |
| 114 | "format = %u", |
| 115 | c.fd, c.offset, c.stride, |
| 116 | c.x, c.y, c.w, c.h, |
| 117 | c.format); |
| 118 | } |
| 119 | else if (c.state == c.S3C_FB_WIN_STATE_COLOR) { |
| 120 | ALOGV("\t\tcolor = %u", c.color); |
| 121 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | inline int WIDTH(const hwc_rect &rect) { return rect.right - rect.left; } |
| 125 | inline int HEIGHT(const hwc_rect &rect) { return rect.bottom - rect.top; } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 126 | template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; } |
| 127 | template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; } |
| 128 | |
| 129 | static bool is_transformed(const hwc_layer_1_t &layer) |
| 130 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 131 | return layer.transform != 0; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 132 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 133 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 134 | static bool is_scaled(const hwc_layer_1_t &layer) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 135 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 136 | return WIDTH(layer.displayFrame) != WIDTH(layer.sourceCrop) || |
| 137 | HEIGHT(layer.displayFrame) != HEIGHT(layer.sourceCrop); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static enum s3c_fb_pixel_format exynos5_format_to_s3c_format(int format) |
| 141 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 142 | switch (format) { |
| 143 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 144 | return S3C_FB_PIXEL_FORMAT_RGBA_8888; |
| 145 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 146 | return S3C_FB_PIXEL_FORMAT_RGBX_8888; |
| 147 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 148 | return S3C_FB_PIXEL_FORMAT_RGBA_5551; |
| 149 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 150 | return S3C_FB_PIXEL_FORMAT_RGBA_4444; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 151 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 152 | default: |
| 153 | return S3C_FB_PIXEL_FORMAT_MAX; |
| 154 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static bool exynos5_format_is_supported(int format) |
| 158 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 159 | return exynos5_format_to_s3c_format(format) < S3C_FB_PIXEL_FORMAT_MAX; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static bool exynos5_format_is_supported_by_gscaler(int format) |
| 163 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 164 | switch(format) { |
| 165 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 166 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 167 | case HAL_PIXEL_FORMAT_RGB_565: |
| 168 | case HAL_PIXEL_FORMAT_YV12: |
| 169 | return true; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 170 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 171 | default: |
| 172 | return false; |
| 173 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static uint8_t exynos5_format_to_bpp(int format) |
| 177 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 178 | switch (format) { |
| 179 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 180 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 181 | return 32; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 182 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 183 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 184 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 185 | return 16; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 186 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 187 | default: |
| 188 | ALOGW("unrecognized pixel format %u", format); |
| 189 | return 0; |
| 190 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 193 | static int hdmi_enable(struct exynos5_hwc_composer_device_1_t *dev) |
| 194 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 195 | if (dev->hdmi_mirroring) |
| 196 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 197 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 198 | exynos_gsc_img src_info; |
| 199 | exynos_gsc_img dst_info; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 200 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 201 | // TODO: Don't hardcode |
| 202 | int src_w = 2560; |
| 203 | int src_h = 1600; |
| 204 | int dst_w = 1920; |
| 205 | int dst_h = 1080; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 206 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 207 | dev->hdmi_gsc = exynos_gsc_create_exclusive(3, GSC_OUTPUT_MODE, GSC_OUT_TV); |
| 208 | if (!dev->hdmi_gsc) { |
| 209 | ALOGE("%s: exynos_gsc_create_exclusive failed", __func__); |
| 210 | return -ENODEV; |
| 211 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 212 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 213 | memset(&src_info, 0, sizeof(src_info)); |
| 214 | memset(&dst_info, 0, sizeof(dst_info)); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 215 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 216 | src_info.w = src_w; |
| 217 | src_info.h = src_h; |
| 218 | src_info.fw = src_w; |
| 219 | src_info.fh = src_h; |
| 220 | src_info.format = HAL_PIXEL_FORMAT_BGRA_8888; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 221 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 222 | dst_info.w = dst_w; |
| 223 | dst_info.h = dst_h; |
| 224 | dst_info.fw = dst_w; |
| 225 | dst_info.fh = dst_h; |
| 226 | dst_info.format = HAL_PIXEL_FORMAT_YV12; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 227 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 228 | int ret = exynos_gsc_config_exclusive(dev->hdmi_gsc, &src_info, &dst_info); |
| 229 | if (ret < 0) { |
| 230 | ALOGE("%s: exynos_gsc_config_exclusive failed %d", __func__, ret); |
| 231 | exynos_gsc_destroy(dev->hdmi_gsc); |
| 232 | dev->hdmi_gsc = NULL; |
| 233 | return ret; |
| 234 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 235 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 236 | dev->hdmi_mirroring = true; |
| 237 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void hdmi_disable(struct exynos5_hwc_composer_device_1_t *dev) |
| 241 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 242 | if (!dev->hdmi_mirroring) |
| 243 | return; |
| 244 | exynos_gsc_destroy(dev->hdmi_gsc); |
| 245 | dev->hdmi_gsc = NULL; |
| 246 | dev->hdmi_mirroring = false; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static int hdmi_output(struct exynos5_hwc_composer_device_1_t *dev, private_handle_t *fb) |
| 250 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 251 | exynos_gsc_img src_info; |
| 252 | exynos_gsc_img dst_info; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 253 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 254 | memset(&src_info, 0, sizeof(src_info)); |
| 255 | memset(&dst_info, 0, sizeof(dst_info)); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 256 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 257 | src_info.yaddr = fb->fd; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 258 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 259 | int ret = exynos_gsc_run_exclusive(dev->hdmi_gsc, &src_info, &dst_info); |
| 260 | if (ret < 0) { |
| 261 | ALOGE("%s: exynos_gsc_run_exclusive failed %d", __func__, ret); |
| 262 | return ret; |
| 263 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 264 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 265 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 268 | bool exynos5_supports_overlay(hwc_layer_1_t &layer, size_t i) |
| 269 | { |
| 270 | private_handle_t *handle = private_handle_t::dynamicCast(layer.handle); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 271 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 272 | if (!handle) { |
| 273 | ALOGV("\tlayer %u: handle is NULL", i); |
| 274 | return false; |
| 275 | } |
| 276 | if (!exynos5_format_is_supported(handle->format)) { |
| 277 | ALOGV("\tlayer %u: pixel format %u not supported", i, |
| 278 | handle->format); |
| 279 | return false; |
| 280 | } |
| 281 | if (is_scaled(layer)) { |
| 282 | ALOGV("\tlayer %u: scaling not supported", i); |
| 283 | return false; |
| 284 | } |
| 285 | if (is_transformed(layer)) { |
| 286 | ALOGV("\tlayer %u: transformations not supported", i); |
| 287 | return false; |
| 288 | } |
| 289 | if (layer.blending != HWC_BLENDING_NONE) { |
| 290 | // TODO: support this |
| 291 | ALOGV("\tlayer %u: blending not supported", i); |
| 292 | return false; |
| 293 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 294 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 295 | return true; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 298 | inline bool intersect(const hwc_rect &r1, const hwc_rect &r2) |
| 299 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 300 | return !(r1.left > r2.right || |
| 301 | r1.right < r2.left || |
| 302 | r1.top > r2.bottom || |
| 303 | r1.bottom < r2.top); |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | inline hwc_rect intersection(const hwc_rect &r1, const hwc_rect &r2) |
| 307 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 308 | hwc_rect i; |
| 309 | i.top = max(r1.top, r2.top); |
| 310 | i.bottom = min(r1.bottom, r2.bottom); |
| 311 | i.left = max(r1.left, r2.left); |
| 312 | i.right = min(r1.right, r2.right); |
| 313 | return i; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 316 | static int exynos5_prepare(hwc_composer_device_1_t *dev, hwc_layer_list_1_t* list) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 317 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 318 | if (!list) |
| 319 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 320 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 321 | ALOGV("preparing %u layers", list->numHwLayers); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 322 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 323 | exynos5_hwc_composer_device_1_t *pdev = |
| 324 | (exynos5_hwc_composer_device_1_t *)dev; |
| 325 | memset(pdev->bufs.overlays, 0, sizeof(pdev->bufs.overlays)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 326 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 327 | bool force_fb = false; |
| 328 | if (pdev->hdmi_hpd) { |
| 329 | hdmi_enable(pdev); |
| 330 | force_fb = true; |
| 331 | } else { |
| 332 | hdmi_disable(pdev); |
| 333 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 334 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 335 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) |
| 336 | pdev->bufs.overlay_map[i] = -1; |
| 337 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 338 | bool fb_needed = false; |
| 339 | size_t first_fb = 0, last_fb = 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 340 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 341 | // find unsupported overlays |
| 342 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 343 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 344 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 345 | if (layer.compositionType == HWC_BACKGROUND && !force_fb) { |
| 346 | ALOGV("\tlayer %u: background supported", i); |
| 347 | continue; |
| 348 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 349 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 350 | if (exynos5_supports_overlay(list->hwLayers[i], i) && !force_fb) { |
| 351 | ALOGV("\tlayer %u: overlay supported", i); |
| 352 | layer.compositionType = HWC_OVERLAY; |
| 353 | continue; |
| 354 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 355 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 356 | if (!fb_needed) { |
| 357 | first_fb = i; |
| 358 | fb_needed = true; |
| 359 | } |
| 360 | last_fb = i; |
| 361 | layer.compositionType = HWC_FRAMEBUFFER; |
| 362 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 363 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 364 | // can't composite overlays sandwiched between framebuffers |
| 365 | if (fb_needed) |
| 366 | for (size_t i = first_fb; i < last_fb; i++) |
| 367 | list->hwLayers[i].compositionType = HWC_FRAMEBUFFER; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 368 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 369 | // Incrementally try to add our supported layers to hardware windows. |
| 370 | // If adding a layer would violate a hardware constraint, force it |
| 371 | // into the framebuffer and try again. (Revisiting the entire list is |
| 372 | // necessary because adding a layer to the framebuffer can cause other |
| 373 | // windows to retroactively violate constraints.) |
| 374 | bool changed; |
| 375 | do { |
| 376 | android::Vector<hwc_rect> rects; |
| 377 | android::Vector<hwc_rect> overlaps; |
| 378 | size_t pixels_left, windows_left; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 379 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 380 | if (fb_needed) { |
| 381 | hwc_rect_t fb_rect; |
| 382 | fb_rect.top = fb_rect.left = 0; |
| 383 | fb_rect.right = pdev->gralloc_module->xres - 1; |
| 384 | fb_rect.bottom = pdev->gralloc_module->yres - 1; |
| 385 | pixels_left = MAX_PIXELS - pdev->gralloc_module->xres * |
| 386 | pdev->gralloc_module->yres; |
| 387 | windows_left = NUM_HW_WINDOWS - 1; |
| 388 | rects.push_back(fb_rect); |
| 389 | } |
| 390 | else { |
| 391 | pixels_left = MAX_PIXELS; |
| 392 | windows_left = NUM_HW_WINDOWS; |
| 393 | } |
| 394 | changed = false; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 395 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 396 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 397 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 398 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 399 | // we've already accounted for the framebuffer above |
| 400 | if (layer.compositionType == HWC_FRAMEBUFFER) |
| 401 | continue; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 402 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 403 | // only layer 0 can be HWC_BACKGROUND, so we can |
| 404 | // unconditionally allow it without extra checks |
| 405 | if (layer.compositionType == HWC_BACKGROUND) { |
| 406 | windows_left--; |
| 407 | continue; |
| 408 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 409 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 410 | size_t pixels_needed = WIDTH(layer.displayFrame) * |
| 411 | HEIGHT(layer.displayFrame); |
| 412 | bool can_compose = windows_left && pixels_needed <= pixels_left; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 413 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 414 | // hwc_rect_t right and bottom values are normally exclusive; |
| 415 | // the intersection logic is simpler if we make them inclusive |
| 416 | hwc_rect_t visible_rect = layer.displayFrame; |
| 417 | visible_rect.right--; visible_rect.bottom--; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 418 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 419 | // no more than 2 layers can overlap on a given pixel |
| 420 | for (size_t j = 0; can_compose && j < overlaps.size(); j++) { |
| 421 | if (intersect(visible_rect, overlaps.itemAt(j))) |
| 422 | can_compose = false; |
| 423 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 424 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 425 | if (!can_compose) { |
| 426 | layer.compositionType = HWC_FRAMEBUFFER; |
| 427 | if (!fb_needed) { |
| 428 | first_fb = last_fb = i; |
| 429 | fb_needed = true; |
| 430 | } |
| 431 | else { |
| 432 | first_fb = min(i, first_fb); |
| 433 | last_fb = max(i, last_fb); |
| 434 | } |
| 435 | changed = true; |
| 436 | break; |
| 437 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 438 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 439 | for (size_t j = 0; j < rects.size(); j++) { |
| 440 | const hwc_rect_t &other_rect = rects.itemAt(j); |
| 441 | if (intersect(visible_rect, other_rect)) |
| 442 | overlaps.push_back(intersection(visible_rect, other_rect)); |
| 443 | } |
| 444 | rects.push_back(visible_rect); |
| 445 | pixels_left -= pixels_needed; |
| 446 | windows_left--; |
| 447 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 448 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 449 | if (changed) |
| 450 | for (size_t i = first_fb; i < last_fb; i++) |
| 451 | list->hwLayers[i].compositionType = HWC_FRAMEBUFFER; |
| 452 | } while(changed); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 453 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 454 | unsigned int nextWindow = 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 455 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 456 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 457 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 458 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 459 | if (fb_needed && i == first_fb) { |
| 460 | ALOGV("assigning framebuffer to window %u\n", |
| 461 | nextWindow); |
| 462 | nextWindow++; |
| 463 | continue; |
| 464 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 465 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 466 | if (layer.compositionType != HWC_FRAMEBUFFER) { |
| 467 | ALOGV("assigning layer %u to window %u", i, nextWindow); |
| 468 | pdev->bufs.overlay_map[nextWindow] = i; |
| 469 | nextWindow++; |
| 470 | } |
| 471 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 472 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 473 | if (fb_needed) |
| 474 | pdev->bufs.fb_window = first_fb; |
| 475 | else |
| 476 | pdev->bufs.fb_window = NO_FB_NEEDED; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 477 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 478 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 479 | dump_layer(&list->hwLayers[i]); |
| 480 | if(list->hwLayers[i].handle) |
| 481 | dump_handle(private_handle_t::dynamicCast( |
| 482 | list->hwLayers[i].handle)); |
| 483 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 484 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 485 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void exynos5_config_handle(private_handle_t *handle, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 489 | hwc_rect_t &sourceCrop, hwc_rect_t &displayFrame, |
| 490 | s3c_fb_win_config &cfg) |
| 491 | { |
| 492 | cfg.state = cfg.S3C_FB_WIN_STATE_BUFFER; |
| 493 | cfg.fd = handle->fd; |
| 494 | cfg.x = displayFrame.left; |
| 495 | cfg.y = displayFrame.top; |
| 496 | cfg.w = WIDTH(displayFrame); |
| 497 | cfg.h = HEIGHT(displayFrame); |
| 498 | cfg.format = exynos5_format_to_s3c_format(handle->format); |
| 499 | uint8_t bpp = exynos5_format_to_bpp(handle->format); |
| 500 | cfg.offset = (sourceCrop.top * handle->stride + sourceCrop.left) * bpp / 8; |
| 501 | cfg.stride = handle->stride * bpp / 8; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 504 | static void exynos5_config_overlay(hwc_layer_1_t *layer, s3c_fb_win_config &cfg, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 505 | const private_module_t *gralloc_module) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 506 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 507 | if (layer->compositionType == HWC_BACKGROUND) { |
| 508 | hwc_color_t color = layer->backgroundColor; |
| 509 | cfg.state = cfg.S3C_FB_WIN_STATE_COLOR; |
| 510 | cfg.color = (color.r << 16) | (color.g << 8) | color.b; |
| 511 | cfg.x = 0; |
| 512 | cfg.y = 0; |
| 513 | cfg.w = gralloc_module->xres; |
| 514 | cfg.h = gralloc_module->yres; |
| 515 | return; |
| 516 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 517 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 518 | private_handle_t *handle = private_handle_t::dynamicCast(layer->handle); |
| 519 | exynos5_config_handle(handle, layer->sourceCrop, layer->displayFrame, cfg); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static void exynos5_post_callback(void *data, private_handle_t *fb) |
| 523 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 524 | exynos5_hwc_post_data_t *pdata = (exynos5_hwc_post_data_t *)data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 525 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 526 | struct s3c_fb_win_config_data win_data; |
| 527 | struct s3c_fb_win_config *config = win_data.config; |
| 528 | memset(config, 0, sizeof(win_data.config)); |
| 529 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 530 | if (i == pdata->fb_window) { |
| 531 | hwc_rect_t rect = { 0, 0, fb->width, fb->height }; |
| 532 | exynos5_config_handle(fb, rect, rect, config[i]); |
| 533 | } else if ( pdata->overlay_map[i] != -1) { |
| 534 | exynos5_config_overlay(&pdata->overlays[i], config[i], |
| 535 | pdata->pdev->gralloc_module); |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 536 | if (pdata->overlays[i].acquireFenceFd != -1) { |
| 537 | int err = sync_wait(pdata->overlays[i].acquireFenceFd, 100); |
| 538 | if (err != 0) |
| 539 | ALOGW("fence for layer %zu didn't signal in 100 ms: %s", |
| 540 | i, strerror(errno)); |
| 541 | close(pdata->overlays[i].acquireFenceFd); |
| 542 | } |
| 543 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 544 | dump_config(config[i]); |
| 545 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 546 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 547 | int ret = ioctl(pdata->pdev->fd, S3CFB_WIN_CONFIG, &win_data); |
| 548 | if (ret < 0) |
| 549 | ALOGE("ioctl S3CFB_WIN_CONFIG failed: %d", errno); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 550 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 551 | if (pdata->pdev->hdmi_mirroring) |
| 552 | hdmi_output(pdata->pdev, fb); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 553 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 554 | pthread_mutex_lock(&pdata->completion_lock); |
| 555 | pdata->fence = win_data.fence; |
| 556 | pthread_cond_signal(&pdata->completion); |
| 557 | pthread_mutex_unlock(&pdata->completion_lock); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 560 | static int exynos5_set(struct hwc_composer_device_1 *dev, hwc_display_t dpy, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 561 | hwc_surface_t sur, hwc_layer_list_1_t* list) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 562 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 563 | exynos5_hwc_composer_device_1_t *pdev = |
| 564 | (exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 565 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 566 | if (!dpy || !sur) |
| 567 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 568 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 569 | hwc_callback_queue_t *queue = NULL; |
| 570 | pthread_mutex_t *lock = NULL; |
| 571 | exynos5_hwc_post_data_t *data = NULL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 572 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 573 | if (list) { |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 574 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 575 | if (pdev->bufs.overlay_map[i] != -1) { |
| 576 | pdev->bufs.overlays[i] = |
| 577 | list->hwLayers[pdev->bufs.overlay_map[i]]; |
| 578 | } |
| 579 | } |
| 580 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 581 | data = (exynos5_hwc_post_data_t *) |
| 582 | malloc(sizeof(exynos5_hwc_post_data_t)); |
| 583 | memcpy(data, &pdev->bufs, sizeof(pdev->bufs)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 584 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 585 | data->fence = -1; |
| 586 | pthread_mutex_init(&data->completion_lock, NULL); |
| 587 | pthread_cond_init(&data->completion, NULL); |
| 588 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 589 | if (pdev->bufs.fb_window == NO_FB_NEEDED) { |
| 590 | exynos5_post_callback(data, NULL); |
| 591 | } else { |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 592 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 593 | struct hwc_callback_entry entry; |
| 594 | entry.callback = exynos5_post_callback; |
| 595 | entry.data = data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 596 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 597 | queue = reinterpret_cast<hwc_callback_queue_t *>( |
| 598 | pdev->gralloc_module->queue); |
| 599 | lock = const_cast<pthread_mutex_t *>( |
| 600 | &pdev->gralloc_module->queue_lock); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 601 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 602 | pthread_mutex_lock(lock); |
| 603 | queue->push_front(entry); |
| 604 | pthread_mutex_unlock(lock); |
| 605 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 606 | EGLBoolean success = eglSwapBuffers((EGLDisplay)dpy, |
| 607 | (EGLSurface)sur); |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 608 | if (!success) { |
| 609 | ALOGE("HWC_EGL_ERROR"); |
| 610 | if (list) { |
| 611 | pthread_mutex_lock(lock); |
| 612 | queue->removeAt(0); |
| 613 | pthread_mutex_unlock(lock); |
| 614 | free(data); |
| 615 | } |
| 616 | return HWC_EGL_ERROR; |
| 617 | } |
| 618 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 619 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 620 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 621 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 622 | pthread_mutex_lock(&data->completion_lock); |
| 623 | while (data->fence == -1) |
| 624 | pthread_cond_wait(&data->completion, &data->completion_lock); |
| 625 | pthread_mutex_unlock(&data->completion_lock); |
| 626 | |
| 627 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 628 | if (pdev->bufs.overlay_map[i] != -1) { |
| 629 | int dup_fd = dup(data->fence); |
| 630 | if (dup_fd < 0) |
| 631 | ALOGW("release fence dup failed: %s", strerror(errno)); |
| 632 | list->hwLayers[pdev->bufs.overlay_map[i]].releaseFenceFd = dup_fd; |
| 633 | } |
| 634 | } |
| 635 | close(data->fence); |
| 636 | free(data); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 637 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 640 | static void exynos5_registerProcs(struct hwc_composer_device_1* dev, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 641 | hwc_procs_t const* procs) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 642 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 643 | struct exynos5_hwc_composer_device_1_t* pdev = |
| 644 | (struct exynos5_hwc_composer_device_1_t*)dev; |
| 645 | pdev->procs = const_cast<hwc_procs_t *>(procs); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 648 | static int exynos5_query(struct hwc_composer_device_1* dev, int what, int *value) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 649 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 650 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 651 | (struct exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 652 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 653 | switch (what) { |
| 654 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 655 | // we support the background layer |
| 656 | value[0] = 1; |
| 657 | break; |
| 658 | case HWC_VSYNC_PERIOD: |
| 659 | // vsync period in nanosecond |
| 660 | value[0] = 1000000000.0 / pdev->gralloc_module->fps; |
| 661 | break; |
| 662 | default: |
| 663 | // unsupported query |
| 664 | return -EINVAL; |
| 665 | } |
| 666 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 669 | static int exynos5_eventControl(struct hwc_composer_device_1 *dev, int event, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 670 | int enabled) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 671 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 672 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 673 | (struct exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 674 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 675 | switch (event) { |
| 676 | case HWC_EVENT_VSYNC: |
| 677 | __u32 val = !!enabled; |
| 678 | int err = ioctl(pdev->fd, S3CFB_SET_VSYNC_INT, &val); |
| 679 | if (err < 0) { |
| 680 | ALOGE("vsync ioctl failed"); |
| 681 | return -errno; |
| 682 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 683 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 684 | return 0; |
| 685 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 686 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 687 | return -EINVAL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 690 | static void handle_hdmi_uevent(struct exynos5_hwc_composer_device_1_t *pdev, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 691 | const char *buff, int len) |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 692 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 693 | const char *s = buff; |
| 694 | s += strlen(s) + 1; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 695 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 696 | while (*s) { |
| 697 | if (!strncmp(s, "SWITCH_STATE=", strlen("SWITCH_STATE="))) |
| 698 | pdev->hdmi_hpd = atoi(s + strlen("SWITCH_STATE=")) == 1; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 699 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 700 | s += strlen(s) + 1; |
| 701 | if (s - buff >= len) |
| 702 | break; |
| 703 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 704 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 705 | ALOGV("HDMI HPD changed to %s", pdev->hdmi_hpd ? "enabled" : "disabled"); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 706 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 707 | if (pdev->procs && pdev->procs->invalidate) |
| 708 | pdev->procs->invalidate(pdev->procs); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 711 | static void handle_vsync_event(struct exynos5_hwc_composer_device_1_t *pdev) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 712 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 713 | if (!pdev->procs || !pdev->procs->vsync) |
| 714 | return; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 715 | |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame^] | 716 | int err = lseek(pdev->vsync_fd, 0, SEEK_SET); |
| 717 | if (err < 0) { |
| 718 | ALOGE("error seeking to vsync timestamp: %s", strerror(errno)); |
| 719 | return; |
| 720 | } |
| 721 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 722 | char buf[4096]; |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame^] | 723 | err = read(pdev->vsync_fd, buf, sizeof(buf)); |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 724 | if (err < 0) { |
| 725 | ALOGE("error reading vsync timestamp: %s", strerror(errno)); |
| 726 | return; |
Greg Hackmann | 3464b1d | 2012-07-24 09:46:23 -0700 | [diff] [blame] | 727 | } |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 728 | buf[sizeof(buf) - 1] = '\0'; |
Greg Hackmann | 3464b1d | 2012-07-24 09:46:23 -0700 | [diff] [blame] | 729 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 730 | errno = 0; |
| 731 | uint64_t timestamp = strtoull(buf, NULL, 0); |
| 732 | if (!errno) |
| 733 | pdev->procs->vsync(pdev->procs, 0, timestamp); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void *hwc_vsync_thread(void *data) |
| 737 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 738 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 739 | (struct exynos5_hwc_composer_device_1_t *)data; |
| 740 | char uevent_desc[4096]; |
| 741 | memset(uevent_desc, 0, sizeof(uevent_desc)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 742 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 743 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 744 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 745 | uevent_init(); |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 746 | |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame^] | 747 | char temp[4096]; |
| 748 | int err = read(pdev->vsync_fd, temp, sizeof(temp)); |
| 749 | if (err < 0) { |
| 750 | ALOGE("error reading vsync timestamp: %s", strerror(errno)); |
| 751 | return NULL; |
| 752 | } |
| 753 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 754 | struct pollfd fds[2]; |
| 755 | fds[0].fd = pdev->vsync_fd; |
| 756 | fds[0].events = POLLPRI; |
| 757 | fds[1].fd = uevent_get_fd(); |
| 758 | fds[1].events = POLLIN; |
| 759 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 760 | while (true) { |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 761 | int err = poll(fds, 2, -1); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 762 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 763 | if (err > 0) { |
| 764 | if (fds[0].revents & POLLPRI) { |
| 765 | handle_vsync_event(pdev); |
| 766 | } |
| 767 | else if (fds[1].revents & POLLIN) { |
| 768 | int len = uevent_next_event(uevent_desc, |
| 769 | sizeof(uevent_desc) - 2); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 770 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 771 | bool hdmi = !strcmp(uevent_desc, |
| 772 | "change@/devices/virtual/switch/hdmi"); |
| 773 | if (hdmi) |
| 774 | handle_hdmi_uevent(pdev, uevent_desc, len); |
| 775 | } |
| 776 | } |
| 777 | else if (err == -1) { |
| 778 | if (errno == EINTR) |
| 779 | break; |
| 780 | ALOGE("error in vsync thread: %s", strerror(errno)); |
| 781 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 782 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 783 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 784 | return NULL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Colin Cross | 00359a8 | 2012-07-12 17:54:17 -0700 | [diff] [blame] | 787 | static int exynos5_blank(struct hwc_composer_device_1 *dev, int blank) |
| 788 | { |
| 789 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 790 | (struct exynos5_hwc_composer_device_1_t *)dev; |
| 791 | |
| 792 | int fb_blank = blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK; |
| 793 | int err = ioctl(pdev->fd, FBIOBLANK, fb_blank); |
| 794 | if (err < 0) { |
| 795 | ALOGE("%sblank ioctl failed", blank ? "" : "un"); |
| 796 | return -errno; |
| 797 | } |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 802 | struct hwc_methods_1 exynos5_methods = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 803 | eventControl: exynos5_eventControl, |
Colin Cross | 00359a8 | 2012-07-12 17:54:17 -0700 | [diff] [blame] | 804 | blank: exynos5_blank, |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 805 | }; |
| 806 | |
| 807 | static int exynos5_close(hw_device_t* device); |
| 808 | |
| 809 | static int exynos5_open(const struct hw_module_t *module, const char *name, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 810 | struct hw_device_t **device) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 811 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 812 | int ret; |
| 813 | int sw_fd; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 814 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 815 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 816 | return -EINVAL; |
| 817 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 818 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 819 | struct exynos5_hwc_composer_device_1_t *dev; |
| 820 | dev = (struct exynos5_hwc_composer_device_1_t *)malloc(sizeof(*dev)); |
| 821 | memset(dev, 0, sizeof(*dev)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 822 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 823 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, |
| 824 | (const struct hw_module_t **)&dev->gralloc_module)) { |
| 825 | ALOGE("failed to get gralloc hw module"); |
| 826 | ret = -EINVAL; |
| 827 | goto err_get_module; |
| 828 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 829 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 830 | dev->fd = open("/dev/graphics/fb0", O_RDWR); |
| 831 | if (dev->fd < 0) { |
| 832 | ALOGE("failed to open framebuffer"); |
| 833 | ret = dev->fd; |
| 834 | goto err_get_module; |
| 835 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 836 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 837 | dev->vsync_fd = open("/sys/devices/platform/exynos5-fb.1/vsync", O_RDONLY); |
| 838 | if (dev->vsync_fd < 0) { |
| 839 | ALOGE("failed to open vsync attribute"); |
| 840 | ret = dev->vsync_fd; |
| 841 | goto err_ioctl; |
| 842 | } |
| 843 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 844 | sw_fd = open("/sys/class/switch/hdmi/state", O_RDONLY); |
| 845 | if (sw_fd) { |
| 846 | char val; |
| 847 | if (read(sw_fd, &val, 1) == 1 && val == '1') |
| 848 | dev->hdmi_hpd = true; |
| 849 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 850 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 851 | dev->base.common.tag = HARDWARE_DEVICE_TAG; |
| 852 | dev->base.common.version = HWC_DEVICE_API_VERSION_1_0; |
| 853 | dev->base.common.module = const_cast<hw_module_t *>(module); |
| 854 | dev->base.common.close = exynos5_close; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 855 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 856 | dev->base.prepare = exynos5_prepare; |
| 857 | dev->base.set = exynos5_set; |
| 858 | dev->base.registerProcs = exynos5_registerProcs; |
| 859 | dev->base.query = exynos5_query; |
| 860 | dev->base.methods = &exynos5_methods; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 861 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 862 | dev->bufs.pdev = dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 863 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 864 | *device = &dev->base.common; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 865 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 866 | ret = pthread_create(&dev->vsync_thread, NULL, hwc_vsync_thread, dev); |
| 867 | if (ret) { |
| 868 | ALOGE("failed to start vsync thread: %s", strerror(ret)); |
| 869 | ret = -ret; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 870 | goto err_vsync; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 871 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 872 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 873 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 874 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 875 | err_vsync: |
| 876 | close(dev->vsync_fd); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 877 | err_ioctl: |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 878 | close(dev->fd); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 879 | err_get_module: |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 880 | free(dev); |
| 881 | return ret; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static int exynos5_close(hw_device_t *device) |
| 885 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 886 | struct exynos5_hwc_composer_device_1_t *dev = |
| 887 | (struct exynos5_hwc_composer_device_1_t *)device; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 888 | pthread_kill(dev->vsync_thread, SIGTERM); |
| 889 | pthread_join(dev->vsync_thread, NULL); |
| 890 | close(dev->vsync_fd); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 891 | close(dev->fd); |
| 892 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | static struct hw_module_methods_t exynos5_hwc_module_methods = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 896 | open: exynos5_open, |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 897 | }; |
| 898 | |
| 899 | hwc_module_t HAL_MODULE_INFO_SYM = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 900 | common: { |
| 901 | tag: HARDWARE_MODULE_TAG, |
| 902 | module_api_version: HWC_MODULE_API_VERSION_0_1, |
| 903 | hal_api_version: HARDWARE_HAL_API_VERSION, |
| 904 | id: HWC_HARDWARE_MODULE_ID, |
| 905 | name: "Samsung exynos5 hwcomposer module", |
| 906 | author: "Google", |
| 907 | methods: &exynos5_hwc_module_methods, |
| 908 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 909 | }; |