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 | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 46 | #include "exynos_format.h" |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 47 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 48 | struct hwc_callback_entry { |
| 49 | void (*callback)(void *, private_handle_t *); |
| 50 | void *data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 51 | }; |
| 52 | typedef android::Vector<struct hwc_callback_entry> hwc_callback_queue_t; |
| 53 | |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 54 | const size_t NUM_HW_WINDOWS = 5; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 55 | const size_t NO_FB_NEEDED = NUM_HW_WINDOWS + 1; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 56 | const size_t MAX_PIXELS = 2560 * 1600 * 2; |
Greg Hackmann | 49e5108 | 2012-07-31 09:50:38 -0700 | [diff] [blame] | 57 | const size_t NUM_GSC_UNITS = 3; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 58 | const size_t GSC_W_ALIGNMENT = 16; |
| 59 | const size_t GSC_H_ALIGNMENT = 16; |
Greg Hackmann | 49e5108 | 2012-07-31 09:50:38 -0700 | [diff] [blame] | 60 | const int CAMERA_GSC_IDX = 2; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 61 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 62 | struct exynos5_hwc_composer_device_1_t; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 63 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 64 | struct exynos5_gsc_map_t { |
| 65 | enum { |
| 66 | GSC_NONE = 0, |
| 67 | GSC_M2M, |
| 68 | // TODO: GSC_LOCAL_PATH |
| 69 | } mode; |
| 70 | int idx; |
| 71 | }; |
| 72 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 73 | struct exynos5_hwc_post_data_t { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 74 | exynos5_hwc_composer_device_1_t *pdev; |
| 75 | int overlay_map[NUM_HW_WINDOWS]; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 76 | exynos5_gsc_map_t gsc_map[NUM_HW_WINDOWS]; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 77 | hwc_layer_1_t overlays[NUM_HW_WINDOWS]; |
| 78 | int num_overlays; |
| 79 | size_t fb_window; |
| 80 | int fence; |
| 81 | pthread_mutex_t completion_lock; |
| 82 | pthread_cond_t completion; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 85 | const size_t NUM_GSC_DST_BUFS = 2; |
| 86 | struct exynos5_gsc_data_t { |
| 87 | void *gsc; |
| 88 | exynos_gsc_img src_cfg; |
| 89 | exynos_gsc_img dst_cfg; |
| 90 | buffer_handle_t dst_buf[NUM_GSC_DST_BUFS]; |
| 91 | size_t current_buf; |
| 92 | }; |
| 93 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 94 | struct exynos5_hwc_composer_device_1_t { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 95 | hwc_composer_device_1_t base; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 96 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 97 | int fd; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 98 | int vsync_fd; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 99 | exynos5_hwc_post_data_t bufs; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 100 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 101 | const private_module_t *gralloc_module; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 102 | alloc_device_t *alloc_device; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 103 | hwc_procs_t *procs; |
| 104 | pthread_t vsync_thread; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 105 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 106 | bool hdmi_hpd; |
| 107 | bool hdmi_mirroring; |
| 108 | void *hdmi_gsc; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 109 | |
| 110 | exynos5_gsc_data_t gsc[NUM_GSC_UNITS]; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 113 | static void dump_handle(private_handle_t *h) |
| 114 | { |
| 115 | ALOGV("\t\tformat = %d, width = %u, height = %u, stride = %u", |
| 116 | h->format, h->width, h->height, h->stride); |
| 117 | } |
| 118 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 119 | static void dump_layer(hwc_layer_1_t const *l) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 120 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 121 | ALOGV("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, " |
| 122 | "{%d,%d,%d,%d}, {%d,%d,%d,%d}", |
| 123 | l->compositionType, l->flags, l->handle, l->transform, |
| 124 | l->blending, |
| 125 | l->sourceCrop.left, |
| 126 | l->sourceCrop.top, |
| 127 | l->sourceCrop.right, |
| 128 | l->sourceCrop.bottom, |
| 129 | l->displayFrame.left, |
| 130 | l->displayFrame.top, |
| 131 | l->displayFrame.right, |
| 132 | l->displayFrame.bottom); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 133 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 134 | if(l->handle && !(l->flags & HWC_SKIP_LAYER)) |
| 135 | dump_handle(private_handle_t::dynamicCast(l->handle)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void dump_config(s3c_fb_win_config &c) |
| 139 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 140 | ALOGV("\tstate = %u", c.state); |
| 141 | if (c.state == c.S3C_FB_WIN_STATE_BUFFER) { |
| 142 | ALOGV("\t\tfd = %d, offset = %u, stride = %u, " |
| 143 | "x = %d, y = %d, w = %u, h = %u, " |
| 144 | "format = %u", |
| 145 | c.fd, c.offset, c.stride, |
| 146 | c.x, c.y, c.w, c.h, |
| 147 | c.format); |
| 148 | } |
| 149 | else if (c.state == c.S3C_FB_WIN_STATE_COLOR) { |
| 150 | ALOGV("\t\tcolor = %u", c.color); |
| 151 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 154 | static void dump_gsc_img(exynos_gsc_img &c) |
| 155 | { |
| 156 | ALOGV("\tx = %u, y = %u, w = %u, h = %u, fw = %u, fh = %u", |
| 157 | c.x, c.y, c.w, c.h, c.fw, c.fh); |
| 158 | ALOGV("\taddr = {%u, %u, %u}, rot = %u, cacheable = %u, drmMode = %u", |
| 159 | c.yaddr, c.uaddr, c.vaddr, c.rot, c.cacheable, c.drmMode); |
| 160 | } |
| 161 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 162 | inline int WIDTH(const hwc_rect &rect) { return rect.right - rect.left; } |
| 163 | inline int HEIGHT(const hwc_rect &rect) { return rect.bottom - rect.top; } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 164 | template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; } |
| 165 | template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; } |
| 166 | |
| 167 | static bool is_transformed(const hwc_layer_1_t &layer) |
| 168 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 169 | return layer.transform != 0; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 170 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 171 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 172 | static bool is_rotated(const hwc_layer_1_t &layer) |
| 173 | { |
| 174 | return (layer.transform & HAL_TRANSFORM_ROT_90) || |
| 175 | (layer.transform & HAL_TRANSFORM_ROT_180); |
| 176 | } |
| 177 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 178 | static bool is_scaled(const hwc_layer_1_t &layer) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 179 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 180 | return WIDTH(layer.displayFrame) != WIDTH(layer.sourceCrop) || |
| 181 | HEIGHT(layer.displayFrame) != HEIGHT(layer.sourceCrop); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static enum s3c_fb_pixel_format exynos5_format_to_s3c_format(int format) |
| 185 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 186 | switch (format) { |
| 187 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 188 | return S3C_FB_PIXEL_FORMAT_RGBA_8888; |
| 189 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 190 | return S3C_FB_PIXEL_FORMAT_RGBX_8888; |
| 191 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 192 | return S3C_FB_PIXEL_FORMAT_RGBA_5551; |
| 193 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 194 | return S3C_FB_PIXEL_FORMAT_RGBA_4444; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 195 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 196 | default: |
| 197 | return S3C_FB_PIXEL_FORMAT_MAX; |
| 198 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static bool exynos5_format_is_supported(int format) |
| 202 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 203 | return exynos5_format_to_s3c_format(format) < S3C_FB_PIXEL_FORMAT_MAX; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static bool exynos5_format_is_supported_by_gscaler(int format) |
| 207 | { |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 208 | switch (format) { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 209 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 210 | case HAL_PIXEL_FORMAT_RGB_565: |
| 211 | case HAL_PIXEL_FORMAT_YV12: |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 212 | case HAL_PIXEL_FORMAT_YCbCr_420_P: |
| 213 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 214 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_SP: |
| 215 | case HAL_PIXEL_FORMAT_YCbCr_420_SP: |
| 216 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP: |
| 217 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 218 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_422_I: |
| 219 | case HAL_PIXEL_FORMAT_YCbCr_422_P: |
| 220 | case HAL_PIXEL_FORMAT_CbYCrY_422_I: |
| 221 | case HAL_PIXEL_FORMAT_CUSTOM_CbYCrY_422_I: |
| 222 | case HAL_PIXEL_FORMAT_YCrCb_422_SP: |
| 223 | case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_SP: |
| 224 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 225 | case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_420_SP: |
| 226 | case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: |
| 227 | case HAL_PIXEL_FORMAT_CUSTOM_YCbCr_420_SP_TILED: |
| 228 | case HAL_PIXEL_FORMAT_CUSTOM_YCrCb_422_I: |
| 229 | case HAL_PIXEL_FORMAT_CUSTOM_CrYCbY_422_I: |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 230 | return true; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 231 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 232 | default: |
| 233 | return false; |
| 234 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 237 | static bool exynos5_format_requires_gscaler(int format) |
| 238 | { |
| 239 | return exynos5_format_is_supported_by_gscaler(format) && |
| 240 | format != HAL_PIXEL_FORMAT_RGBX_8888; |
| 241 | } |
| 242 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 243 | static uint8_t exynos5_format_to_bpp(int format) |
| 244 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 245 | switch (format) { |
| 246 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 247 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 248 | return 32; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 249 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 250 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 251 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 252 | return 16; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 253 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 254 | default: |
| 255 | ALOGW("unrecognized pixel format %u", format); |
| 256 | return 0; |
| 257 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Greg Hackmann | 227ae8a | 2012-08-03 16:16:58 -0700 | [diff] [blame^] | 260 | static bool exynos5_supports_gscaler(hwc_layer_1_t &layer, int format, |
| 261 | bool local_path) |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 262 | { |
| 263 | private_handle_t *handle = private_handle_t::dynamicCast(layer.handle); |
| 264 | |
| 265 | int max_w = is_rotated(layer) ? 2048 : 4800; |
| 266 | int max_h = is_rotated(layer) ? 2048 : 3344; |
| 267 | |
| 268 | bool rot90or270 = !!(layer.transform & HAL_TRANSFORM_ROT_90); |
| 269 | // n.b.: HAL_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_90 | |
| 270 | // HAL_TRANSFORM_ROT_180 |
| 271 | |
Greg Hackmann | 227ae8a | 2012-08-03 16:16:58 -0700 | [diff] [blame^] | 272 | int src_w = WIDTH(layer.sourceCrop), src_h = HEIGHT(layer.sourceCrop); |
| 273 | int dest_w, dest_h; |
| 274 | if (rot90or270) { |
| 275 | dest_w = HEIGHT(layer.displayFrame); |
| 276 | dest_h = WIDTH(layer.displayFrame); |
| 277 | } else { |
| 278 | dest_w = WIDTH(layer.displayFrame); |
| 279 | dest_h = HEIGHT(layer.displayFrame); |
| 280 | } |
| 281 | int max_downscale = local_path ? 4 : 16; |
| 282 | const int max_upscale = 8; |
| 283 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 284 | return exynos5_format_is_supported_by_gscaler(format) && |
| 285 | handle->stride <= max_w && |
| 286 | handle->stride % GSC_W_ALIGNMENT == 0 && |
Greg Hackmann | 227ae8a | 2012-08-03 16:16:58 -0700 | [diff] [blame^] | 287 | src_w <= dest_w * max_downscale && |
| 288 | dest_w <= src_w * max_upscale && |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 289 | handle->height <= max_h && |
| 290 | handle->height % GSC_H_ALIGNMENT == 0 && |
Greg Hackmann | 227ae8a | 2012-08-03 16:16:58 -0700 | [diff] [blame^] | 291 | src_h <= dest_h * max_downscale && |
| 292 | dest_h <= src_h * max_upscale && |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 293 | // per 46.2 |
| 294 | (!rot90or270 || layer.sourceCrop.top % 2 == 0) && |
| 295 | (!rot90or270 || layer.sourceCrop.left % 2 == 0); |
| 296 | // per 46.3.1.6 |
| 297 | } |
| 298 | |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 299 | static int hdmi_enable(struct exynos5_hwc_composer_device_1_t *dev) |
| 300 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 301 | if (dev->hdmi_mirroring) |
| 302 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 303 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 304 | exynos_gsc_img src_info; |
| 305 | exynos_gsc_img dst_info; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 306 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 307 | // TODO: Don't hardcode |
| 308 | int src_w = 2560; |
| 309 | int src_h = 1600; |
| 310 | int dst_w = 1920; |
| 311 | int dst_h = 1080; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 312 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 313 | dev->hdmi_gsc = exynos_gsc_create_exclusive(3, GSC_OUTPUT_MODE, GSC_OUT_TV); |
| 314 | if (!dev->hdmi_gsc) { |
| 315 | ALOGE("%s: exynos_gsc_create_exclusive failed", __func__); |
| 316 | return -ENODEV; |
| 317 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 318 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 319 | memset(&src_info, 0, sizeof(src_info)); |
| 320 | memset(&dst_info, 0, sizeof(dst_info)); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 321 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 322 | src_info.w = src_w; |
| 323 | src_info.h = src_h; |
| 324 | src_info.fw = src_w; |
| 325 | src_info.fh = src_h; |
| 326 | src_info.format = HAL_PIXEL_FORMAT_BGRA_8888; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 327 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 328 | dst_info.w = dst_w; |
| 329 | dst_info.h = dst_h; |
| 330 | dst_info.fw = dst_w; |
| 331 | dst_info.fh = dst_h; |
| 332 | dst_info.format = HAL_PIXEL_FORMAT_YV12; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 333 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 334 | int ret = exynos_gsc_config_exclusive(dev->hdmi_gsc, &src_info, &dst_info); |
| 335 | if (ret < 0) { |
| 336 | ALOGE("%s: exynos_gsc_config_exclusive failed %d", __func__, ret); |
| 337 | exynos_gsc_destroy(dev->hdmi_gsc); |
| 338 | dev->hdmi_gsc = NULL; |
| 339 | return ret; |
| 340 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 341 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 342 | dev->hdmi_mirroring = true; |
| 343 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static void hdmi_disable(struct exynos5_hwc_composer_device_1_t *dev) |
| 347 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 348 | if (!dev->hdmi_mirroring) |
| 349 | return; |
| 350 | exynos_gsc_destroy(dev->hdmi_gsc); |
| 351 | dev->hdmi_gsc = NULL; |
| 352 | dev->hdmi_mirroring = false; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static int hdmi_output(struct exynos5_hwc_composer_device_1_t *dev, private_handle_t *fb) |
| 356 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 357 | exynos_gsc_img src_info; |
| 358 | exynos_gsc_img dst_info; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 359 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 360 | memset(&src_info, 0, sizeof(src_info)); |
| 361 | memset(&dst_info, 0, sizeof(dst_info)); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 362 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 363 | src_info.yaddr = fb->fd; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 364 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 365 | int ret = exynos_gsc_run_exclusive(dev->hdmi_gsc, &src_info, &dst_info); |
| 366 | if (ret < 0) { |
| 367 | ALOGE("%s: exynos_gsc_run_exclusive failed %d", __func__, ret); |
| 368 | return ret; |
| 369 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 370 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 371 | return 0; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 374 | bool exynos5_supports_overlay(hwc_layer_1_t &layer, size_t i) |
| 375 | { |
Greg Hackmann | d82ad20 | 2012-07-24 13:49:47 -0700 | [diff] [blame] | 376 | if (layer.flags & HWC_SKIP_LAYER) { |
| 377 | ALOGV("\tlayer %u: skipping", i); |
| 378 | return false; |
| 379 | } |
| 380 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 381 | private_handle_t *handle = private_handle_t::dynamicCast(layer.handle); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 382 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 383 | if (!handle) { |
| 384 | ALOGV("\tlayer %u: handle is NULL", i); |
| 385 | return false; |
| 386 | } |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 387 | if (exynos5_format_requires_gscaler(handle->format)) { |
Greg Hackmann | 227ae8a | 2012-08-03 16:16:58 -0700 | [diff] [blame^] | 388 | if (!exynos5_supports_gscaler(layer, handle->format, false)) { |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 389 | ALOGV("\tlayer %u: gscaler required but not supported", i); |
| 390 | return false; |
| 391 | } |
| 392 | } else { |
| 393 | if (!exynos5_format_is_supported(handle->format)) { |
| 394 | ALOGV("\tlayer %u: pixel format %u not supported", i, handle->format); |
| 395 | return false; |
| 396 | } |
| 397 | if (is_scaled(layer)) { |
| 398 | ALOGV("\tlayer %u: scaling not supported", i); |
| 399 | return false; |
| 400 | } |
| 401 | if (is_transformed(layer)) { |
| 402 | ALOGV("\tlayer %u: transformations not supported", i); |
| 403 | return false; |
| 404 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 405 | } |
| 406 | if (layer.blending != HWC_BLENDING_NONE) { |
| 407 | // TODO: support this |
| 408 | ALOGV("\tlayer %u: blending not supported", i); |
| 409 | return false; |
| 410 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 411 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 412 | return true; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 415 | inline bool intersect(const hwc_rect &r1, const hwc_rect &r2) |
| 416 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 417 | return !(r1.left > r2.right || |
| 418 | r1.right < r2.left || |
| 419 | r1.top > r2.bottom || |
| 420 | r1.bottom < r2.top); |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | inline hwc_rect intersection(const hwc_rect &r1, const hwc_rect &r2) |
| 424 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 425 | hwc_rect i; |
| 426 | i.top = max(r1.top, r2.top); |
| 427 | i.bottom = min(r1.bottom, r2.bottom); |
| 428 | i.left = max(r1.left, r2.left); |
| 429 | i.right = min(r1.right, r2.right); |
| 430 | return i; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 433 | 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] | 434 | { |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 435 | if (!list) |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 436 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 437 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 438 | ALOGV("preparing %u layers", list->numHwLayers); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 439 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 440 | exynos5_hwc_composer_device_1_t *pdev = |
| 441 | (exynos5_hwc_composer_device_1_t *)dev; |
| 442 | memset(pdev->bufs.overlays, 0, sizeof(pdev->bufs.overlays)); |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 443 | memset(pdev->bufs.gsc_map, 0, sizeof(pdev->bufs.gsc_map)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 444 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 445 | bool force_fb = false; |
| 446 | if (pdev->hdmi_hpd) { |
| 447 | hdmi_enable(pdev); |
| 448 | force_fb = true; |
| 449 | } else { |
| 450 | hdmi_disable(pdev); |
| 451 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 452 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 453 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) |
| 454 | pdev->bufs.overlay_map[i] = -1; |
| 455 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 456 | bool fb_needed = false; |
| 457 | size_t first_fb = 0, last_fb = 0; |
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 | // find unsupported overlays |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 460 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 461 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 462 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 463 | if (layer.compositionType == HWC_BACKGROUND && !force_fb) { |
| 464 | ALOGV("\tlayer %u: background supported", i); |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 465 | dump_layer(&list->hwLayers[i]); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 466 | continue; |
| 467 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 468 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 469 | if (exynos5_supports_overlay(list->hwLayers[i], i) && !force_fb) { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 470 | ALOGV("\tlayer %u: overlay supported", i); |
| 471 | layer.compositionType = HWC_OVERLAY; |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 472 | dump_layer(&list->hwLayers[i]); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 473 | continue; |
| 474 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 475 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 476 | if (!fb_needed) { |
| 477 | first_fb = i; |
| 478 | fb_needed = true; |
| 479 | } |
| 480 | last_fb = i; |
| 481 | layer.compositionType = HWC_FRAMEBUFFER; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 482 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 483 | dump_layer(&list->hwLayers[i]); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 484 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 485 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 486 | // can't composite overlays sandwiched between framebuffers |
| 487 | if (fb_needed) |
| 488 | for (size_t i = first_fb; i < last_fb; i++) |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 489 | list->hwLayers[i].compositionType = HWC_FRAMEBUFFER; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 490 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 491 | // Incrementally try to add our supported layers to hardware windows. |
| 492 | // If adding a layer would violate a hardware constraint, force it |
| 493 | // into the framebuffer and try again. (Revisiting the entire list is |
| 494 | // necessary because adding a layer to the framebuffer can cause other |
| 495 | // windows to retroactively violate constraints.) |
| 496 | bool changed; |
| 497 | do { |
| 498 | android::Vector<hwc_rect> rects; |
| 499 | android::Vector<hwc_rect> overlaps; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 500 | size_t pixels_left, windows_left, gsc_left = NUM_GSC_UNITS; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 501 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 502 | if (fb_needed) { |
| 503 | hwc_rect_t fb_rect; |
| 504 | fb_rect.top = fb_rect.left = 0; |
| 505 | fb_rect.right = pdev->gralloc_module->xres - 1; |
| 506 | fb_rect.bottom = pdev->gralloc_module->yres - 1; |
| 507 | pixels_left = MAX_PIXELS - pdev->gralloc_module->xres * |
| 508 | pdev->gralloc_module->yres; |
| 509 | windows_left = NUM_HW_WINDOWS - 1; |
| 510 | rects.push_back(fb_rect); |
| 511 | } |
| 512 | else { |
| 513 | pixels_left = MAX_PIXELS; |
| 514 | windows_left = NUM_HW_WINDOWS; |
| 515 | } |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 516 | if (pdev->hdmi_mirroring) |
| 517 | gsc_left--; |
| 518 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 519 | changed = false; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 520 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 521 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 522 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 523 | if (layer.flags & HWC_SKIP_LAYER) |
| 524 | continue; |
| 525 | |
| 526 | private_handle_t *handle = private_handle_t::dynamicCast( |
| 527 | layer.handle); |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 528 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 529 | // we've already accounted for the framebuffer above |
| 530 | if (layer.compositionType == HWC_FRAMEBUFFER) |
| 531 | continue; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 532 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 533 | // only layer 0 can be HWC_BACKGROUND, so we can |
| 534 | // unconditionally allow it without extra checks |
| 535 | if (layer.compositionType == HWC_BACKGROUND) { |
| 536 | windows_left--; |
| 537 | continue; |
| 538 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 539 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 540 | size_t pixels_needed = WIDTH(layer.displayFrame) * |
| 541 | HEIGHT(layer.displayFrame); |
| 542 | bool can_compose = windows_left && pixels_needed <= pixels_left; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 543 | bool gsc_required = exynos5_format_requires_gscaler(handle->format); |
| 544 | if (gsc_required) |
| 545 | can_compose = can_compose && gsc_left; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 546 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 547 | // hwc_rect_t right and bottom values are normally exclusive; |
| 548 | // the intersection logic is simpler if we make them inclusive |
| 549 | hwc_rect_t visible_rect = layer.displayFrame; |
| 550 | visible_rect.right--; visible_rect.bottom--; |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 551 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 552 | // no more than 2 layers can overlap on a given pixel |
| 553 | for (size_t j = 0; can_compose && j < overlaps.size(); j++) { |
| 554 | if (intersect(visible_rect, overlaps.itemAt(j))) |
| 555 | can_compose = false; |
| 556 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 557 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 558 | if (!can_compose) { |
| 559 | layer.compositionType = HWC_FRAMEBUFFER; |
| 560 | if (!fb_needed) { |
| 561 | first_fb = last_fb = i; |
| 562 | fb_needed = true; |
| 563 | } |
| 564 | else { |
| 565 | first_fb = min(i, first_fb); |
| 566 | last_fb = max(i, last_fb); |
| 567 | } |
| 568 | changed = true; |
| 569 | break; |
| 570 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 571 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 572 | for (size_t j = 0; j < rects.size(); j++) { |
| 573 | const hwc_rect_t &other_rect = rects.itemAt(j); |
| 574 | if (intersect(visible_rect, other_rect)) |
| 575 | overlaps.push_back(intersection(visible_rect, other_rect)); |
| 576 | } |
| 577 | rects.push_back(visible_rect); |
| 578 | pixels_left -= pixels_needed; |
| 579 | windows_left--; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 580 | if (gsc_required) |
| 581 | gsc_left--; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 582 | } |
Greg Hackmann | 31991d5 | 2012-07-13 13:23:11 -0700 | [diff] [blame] | 583 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 584 | if (changed) |
| 585 | for (size_t i = first_fb; i < last_fb; i++) |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 586 | list->hwLayers[i].compositionType = HWC_FRAMEBUFFER; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 587 | } while(changed); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 588 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 589 | unsigned int nextWindow = 0; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 590 | int nextGsc = 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 591 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 592 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 593 | hwc_layer_1_t &layer = list->hwLayers[i]; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 594 | if (layer.flags & HWC_SKIP_LAYER) |
| 595 | continue; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 596 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 597 | if (fb_needed && i == first_fb) { |
| 598 | ALOGV("assigning framebuffer to window %u\n", |
| 599 | nextWindow); |
| 600 | nextWindow++; |
| 601 | continue; |
| 602 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 603 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 604 | if (layer.compositionType != HWC_FRAMEBUFFER) { |
| 605 | ALOGV("assigning layer %u to window %u", i, nextWindow); |
| 606 | pdev->bufs.overlay_map[nextWindow] = i; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 607 | if (layer.compositionType == HWC_OVERLAY) { |
| 608 | private_handle_t *handle = |
| 609 | private_handle_t::dynamicCast(layer.handle); |
| 610 | if (exynos5_format_requires_gscaler(handle->format)) { |
| 611 | ALOGV("\tusing gscaler %u", nextGsc); |
| 612 | pdev->bufs.gsc_map[i].mode = |
| 613 | exynos5_gsc_map_t::GSC_M2M; |
| 614 | pdev->bufs.gsc_map[i].idx = nextGsc++; |
Greg Hackmann | 49e5108 | 2012-07-31 09:50:38 -0700 | [diff] [blame] | 615 | if (nextGsc == CAMERA_GSC_IDX) |
| 616 | nextGsc++; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 619 | nextWindow++; |
| 620 | } |
| 621 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 622 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 623 | for (size_t i = nextGsc; i < NUM_GSC_UNITS; i++) { |
| 624 | for (size_t j = 0; j < NUM_GSC_DST_BUFS; j++) |
| 625 | if (pdev->gsc[i].dst_buf[j]) |
| 626 | pdev->alloc_device->free(pdev->alloc_device, |
| 627 | pdev->gsc[i].dst_buf[j]); |
| 628 | memset(&pdev->gsc[i], 0, sizeof(pdev->gsc[i])); |
| 629 | } |
| 630 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 631 | if (fb_needed) |
| 632 | pdev->bufs.fb_window = first_fb; |
| 633 | else |
| 634 | pdev->bufs.fb_window = NO_FB_NEEDED; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 635 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | static inline bool gsc_dst_cfg_changed(exynos_gsc_img &c1, exynos_gsc_img &c2) |
| 640 | { |
| 641 | return c1.x != c2.x || |
| 642 | c1.y != c2.y || |
| 643 | c1.w != c2.w || |
| 644 | c1.h != c2.h || |
| 645 | c1.format != c2.format || |
| 646 | c1.rot != c2.rot || |
| 647 | c1.cacheable != c2.cacheable || |
| 648 | c1.drmMode != c2.drmMode; |
| 649 | } |
| 650 | |
| 651 | static inline bool gsc_src_cfg_changed(exynos_gsc_img &c1, exynos_gsc_img &c2) |
| 652 | { |
| 653 | return gsc_dst_cfg_changed(c1, c2) || |
| 654 | c1.fw != c2.fw || |
| 655 | c1.fh != c2.fh; |
| 656 | } |
| 657 | |
| 658 | static int exynos5_config_gsc_m2m(hwc_layer_1_t &layer, |
| 659 | alloc_device_t* alloc_device, exynos5_gsc_data_t *gsc_data, |
| 660 | int gsc_idx) |
| 661 | { |
| 662 | ALOGV("configuring gscaler %u for memory-to-memory", gsc_idx); |
| 663 | |
| 664 | private_handle_t *src_handle = private_handle_t::dynamicCast(layer.handle); |
| 665 | buffer_handle_t dst_buf; |
| 666 | private_handle_t *dst_handle; |
| 667 | int ret = 0; |
| 668 | |
| 669 | exynos_gsc_img src_cfg, dst_cfg; |
| 670 | memset(&src_cfg, 0, sizeof(src_cfg)); |
| 671 | memset(&dst_cfg, 0, sizeof(dst_cfg)); |
| 672 | |
| 673 | src_cfg.x = layer.sourceCrop.left; |
| 674 | src_cfg.y = layer.sourceCrop.top; |
| 675 | src_cfg.w = WIDTH(layer.sourceCrop); |
| 676 | src_cfg.fw = src_handle->stride; |
| 677 | src_cfg.h = HEIGHT(layer.sourceCrop); |
| 678 | src_cfg.fh = src_handle->height; |
| 679 | src_cfg.yaddr = src_handle->fd; |
| 680 | src_cfg.uaddr = src_handle->fd1; |
| 681 | src_cfg.vaddr = src_handle->fd2; |
| 682 | src_cfg.format = src_handle->format; |
| 683 | |
| 684 | dst_cfg.x = 0; |
| 685 | dst_cfg.y = 0; |
| 686 | dst_cfg.w = WIDTH(layer.displayFrame); |
| 687 | dst_cfg.h = HEIGHT(layer.displayFrame); |
Greg Hackmann | a00c043 | 2012-07-31 15:20:00 -0700 | [diff] [blame] | 688 | dst_cfg.format = HAL_PIXEL_FORMAT_BGRA_8888; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 689 | dst_cfg.rot = layer.transform; |
| 690 | |
| 691 | ALOGV("source configuration:"); |
| 692 | dump_gsc_img(src_cfg); |
| 693 | |
| 694 | if (gsc_src_cfg_changed(src_cfg, gsc_data->src_cfg) || |
| 695 | gsc_dst_cfg_changed(dst_cfg, gsc_data->dst_cfg)) { |
| 696 | int dst_stride; |
| 697 | int usage = GRALLOC_USAGE_SW_READ_NEVER | |
| 698 | GRALLOC_USAGE_SW_WRITE_NEVER | |
| 699 | GRALLOC_USAGE_HW_COMPOSER; |
| 700 | // TODO: add GRALLOC_USAGE_PROTECTED if source buffer is also protected |
| 701 | |
| 702 | int w = ALIGN(WIDTH(layer.displayFrame), GSC_W_ALIGNMENT); |
| 703 | int h = ALIGN(HEIGHT(layer.displayFrame), GSC_H_ALIGNMENT); |
| 704 | |
| 705 | for (size_t i = 0; i < NUM_GSC_DST_BUFS; i++) { |
| 706 | if (gsc_data->dst_buf[i]) { |
| 707 | alloc_device->free(alloc_device, gsc_data->dst_buf[i]); |
| 708 | gsc_data->dst_buf[i] = NULL; |
| 709 | } |
| 710 | |
| 711 | int ret = alloc_device->alloc(alloc_device, w, h, |
| 712 | HAL_PIXEL_FORMAT_RGBX_8888, usage, &gsc_data->dst_buf[i], |
| 713 | &dst_stride); |
| 714 | if (ret < 0) { |
| 715 | ALOGE("failed to allocate destination buffer: %s", |
| 716 | strerror(-ret)); |
| 717 | goto err_alloc; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | gsc_data->current_buf = 0; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 722 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 723 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 724 | dst_buf = gsc_data->dst_buf[gsc_data->current_buf]; |
| 725 | dst_handle = private_handle_t::dynamicCast(dst_buf); |
| 726 | |
| 727 | dst_cfg.fw = dst_handle->stride; |
| 728 | dst_cfg.fh = dst_handle->height; |
| 729 | dst_cfg.yaddr = dst_handle->fd; |
| 730 | |
| 731 | ALOGV("destination configuration:"); |
| 732 | dump_gsc_img(dst_cfg); |
| 733 | |
| 734 | gsc_data->gsc = exynos_gsc_create_exclusive(gsc_idx, GSC_M2M_MODE, |
| 735 | GSC_DUMMY); |
| 736 | if (!gsc_data->gsc) { |
| 737 | ALOGE("failed to create gscaler handle"); |
| 738 | ret = -1; |
| 739 | goto err_alloc; |
| 740 | } |
| 741 | |
| 742 | ret = exynos_gsc_config_exclusive(gsc_data->gsc, &src_cfg, &dst_cfg); |
| 743 | if (ret < 0) { |
| 744 | ALOGE("failed to configure gscaler %u", gsc_idx); |
| 745 | goto err_gsc_config; |
| 746 | } |
| 747 | |
| 748 | ret = exynos_gsc_run_exclusive(gsc_data->gsc, &src_cfg, &dst_cfg); |
| 749 | if (ret < 0) { |
| 750 | ALOGE("failed to run gscaler %u", gsc_idx); |
| 751 | goto err_gsc_config; |
| 752 | } |
| 753 | |
| 754 | gsc_data->src_cfg = src_cfg; |
| 755 | gsc_data->dst_cfg = dst_cfg; |
| 756 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 757 | return 0; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 758 | |
| 759 | err_gsc_config: |
| 760 | exynos_gsc_destroy(gsc_data->gsc); |
| 761 | gsc_data->gsc = NULL; |
| 762 | err_alloc: |
| 763 | for (size_t i = 0; i < NUM_GSC_DST_BUFS; i++) { |
| 764 | if (gsc_data->dst_buf[i]) { |
| 765 | alloc_device->free(alloc_device, gsc_data->dst_buf[i]); |
| 766 | gsc_data->dst_buf[i] = NULL; |
| 767 | } |
| 768 | } |
| 769 | return ret; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static void exynos5_config_handle(private_handle_t *handle, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 773 | hwc_rect_t &sourceCrop, hwc_rect_t &displayFrame, |
| 774 | s3c_fb_win_config &cfg) |
| 775 | { |
| 776 | cfg.state = cfg.S3C_FB_WIN_STATE_BUFFER; |
| 777 | cfg.fd = handle->fd; |
| 778 | cfg.x = displayFrame.left; |
| 779 | cfg.y = displayFrame.top; |
| 780 | cfg.w = WIDTH(displayFrame); |
| 781 | cfg.h = HEIGHT(displayFrame); |
| 782 | cfg.format = exynos5_format_to_s3c_format(handle->format); |
| 783 | uint8_t bpp = exynos5_format_to_bpp(handle->format); |
| 784 | cfg.offset = (sourceCrop.top * handle->stride + sourceCrop.left) * bpp / 8; |
| 785 | cfg.stride = handle->stride * bpp / 8; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 788 | 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] | 789 | const private_module_t *gralloc_module) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 790 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 791 | if (layer->compositionType == HWC_BACKGROUND) { |
| 792 | hwc_color_t color = layer->backgroundColor; |
| 793 | cfg.state = cfg.S3C_FB_WIN_STATE_COLOR; |
| 794 | cfg.color = (color.r << 16) | (color.g << 8) | color.b; |
| 795 | cfg.x = 0; |
| 796 | cfg.y = 0; |
| 797 | cfg.w = gralloc_module->xres; |
| 798 | cfg.h = gralloc_module->yres; |
| 799 | return; |
| 800 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 801 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 802 | private_handle_t *handle = private_handle_t::dynamicCast(layer->handle); |
| 803 | exynos5_config_handle(handle, layer->sourceCrop, layer->displayFrame, cfg); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static void exynos5_post_callback(void *data, private_handle_t *fb) |
| 807 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 808 | exynos5_hwc_post_data_t *pdata = (exynos5_hwc_post_data_t *)data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 809 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 810 | struct s3c_fb_win_config_data win_data; |
| 811 | struct s3c_fb_win_config *config = win_data.config; |
| 812 | memset(config, 0, sizeof(win_data.config)); |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 813 | |
| 814 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 815 | if ( pdata->overlay_map[i] != -1) { |
| 816 | hwc_layer_1_t &layer = pdata->overlays[i]; |
| 817 | private_handle_t *handle = |
| 818 | private_handle_t::dynamicCast(layer.handle); |
| 819 | |
| 820 | if (layer.acquireFenceFd != -1) { |
| 821 | int err = sync_wait(layer.acquireFenceFd, 100); |
| 822 | if (err != 0) |
| 823 | ALOGW("fence for layer %zu didn't signal in 100 ms: %s", |
| 824 | i, strerror(errno)); |
| 825 | close(layer.acquireFenceFd); |
| 826 | } |
| 827 | |
| 828 | if (pdata->gsc_map[i].mode == exynos5_gsc_map_t::GSC_M2M) { |
| 829 | int gsc_idx = pdata->gsc_map[i].idx; |
| 830 | exynos5_config_gsc_m2m(layer, pdata->pdev->alloc_device, |
| 831 | &pdata->pdev->gsc[gsc_idx], gsc_idx); |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 836 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 837 | if (i == pdata->fb_window) { |
| 838 | hwc_rect_t rect = { 0, 0, fb->width, fb->height }; |
| 839 | exynos5_config_handle(fb, rect, rect, config[i]); |
| 840 | } else if ( pdata->overlay_map[i] != -1) { |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 841 | hwc_layer_1_t &layer = pdata->overlays[i]; |
| 842 | private_handle_t *handle = |
| 843 | private_handle_t::dynamicCast(layer.handle); |
| 844 | |
| 845 | if (pdata->gsc_map[i].mode == exynos5_gsc_map_t::GSC_M2M) { |
| 846 | int gsc_idx = pdata->gsc_map[i].idx; |
| 847 | exynos5_gsc_data_t &gsc = pdata->pdev->gsc[gsc_idx]; |
| 848 | |
| 849 | if (!gsc.gsc) { |
| 850 | ALOGE("failed to queue gscaler %u input for layer %u", |
| 851 | gsc_idx, i); |
| 852 | continue; |
| 853 | } |
| 854 | |
| 855 | int err = exynos_gsc_stop_exclusive(gsc.gsc); |
| 856 | exynos_gsc_destroy(gsc.gsc); |
| 857 | gsc.gsc = NULL; |
| 858 | if (err < 0) { |
| 859 | ALOGE("failed to dequeue gscaler output for layer %u", i); |
| 860 | continue; |
| 861 | } |
| 862 | |
| 863 | buffer_handle_t dst_buf = gsc.dst_buf[gsc.current_buf]; |
| 864 | gsc.current_buf = (gsc.current_buf + 1) % NUM_GSC_DST_BUFS; |
| 865 | private_handle_t *dst_handle = |
| 866 | private_handle_t::dynamicCast(dst_buf); |
| 867 | exynos5_config_handle(dst_handle, layer.sourceCrop, |
| 868 | layer.displayFrame, config[i]); |
| 869 | } |
| 870 | else { |
| 871 | exynos5_config_overlay(&layer, config[i], |
| 872 | pdata->pdev->gralloc_module); |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 873 | } |
| 874 | } |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 875 | ALOGV("window %u configuration:", i); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 876 | dump_config(config[i]); |
| 877 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 878 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 879 | int ret = ioctl(pdata->pdev->fd, S3CFB_WIN_CONFIG, &win_data); |
| 880 | if (ret < 0) |
| 881 | ALOGE("ioctl S3CFB_WIN_CONFIG failed: %d", errno); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 882 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 883 | if (pdata->pdev->hdmi_mirroring) |
| 884 | hdmi_output(pdata->pdev, fb); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 885 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 886 | pthread_mutex_lock(&pdata->completion_lock); |
| 887 | pdata->fence = win_data.fence; |
| 888 | pthread_cond_signal(&pdata->completion); |
| 889 | pthread_mutex_unlock(&pdata->completion_lock); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 892 | static int exynos5_set(struct hwc_composer_device_1 *dev, hwc_display_t dpy, |
| 893 | hwc_surface_t sur, hwc_layer_list_1_t* list) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 894 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 895 | exynos5_hwc_composer_device_1_t *pdev = |
| 896 | (exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 897 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 898 | if (!dpy || !sur) |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 899 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 900 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 901 | hwc_callback_queue_t *queue = NULL; |
| 902 | pthread_mutex_t *lock = NULL; |
| 903 | exynos5_hwc_post_data_t *data = NULL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 904 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 905 | if (list) { |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 906 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 907 | if (pdev->bufs.overlay_map[i] != -1) { |
| 908 | pdev->bufs.overlays[i] = |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 909 | list->hwLayers[pdev->bufs.overlay_map[i]]; |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 913 | data = (exynos5_hwc_post_data_t *) |
| 914 | malloc(sizeof(exynos5_hwc_post_data_t)); |
| 915 | memcpy(data, &pdev->bufs, sizeof(pdev->bufs)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 916 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 917 | data->fence = -1; |
| 918 | pthread_mutex_init(&data->completion_lock, NULL); |
| 919 | pthread_cond_init(&data->completion, NULL); |
| 920 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 921 | if (pdev->bufs.fb_window == NO_FB_NEEDED) { |
| 922 | exynos5_post_callback(data, NULL); |
| 923 | } else { |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 924 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 925 | struct hwc_callback_entry entry; |
| 926 | entry.callback = exynos5_post_callback; |
| 927 | entry.data = data; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 928 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 929 | queue = reinterpret_cast<hwc_callback_queue_t *>( |
| 930 | pdev->gralloc_module->queue); |
| 931 | lock = const_cast<pthread_mutex_t *>( |
| 932 | &pdev->gralloc_module->queue_lock); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 933 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 934 | pthread_mutex_lock(lock); |
| 935 | queue->push_front(entry); |
| 936 | pthread_mutex_unlock(lock); |
| 937 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 938 | EGLBoolean success = eglSwapBuffers((EGLDisplay)dpy, |
| 939 | (EGLSurface)sur); |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 940 | if (!success) { |
| 941 | ALOGE("HWC_EGL_ERROR"); |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 942 | if (list) { |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 943 | pthread_mutex_lock(lock); |
| 944 | queue->removeAt(0); |
| 945 | pthread_mutex_unlock(lock); |
| 946 | free(data); |
| 947 | } |
| 948 | return HWC_EGL_ERROR; |
| 949 | } |
| 950 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 951 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 952 | |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 953 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 954 | pthread_mutex_lock(&data->completion_lock); |
| 955 | while (data->fence == -1) |
| 956 | pthread_cond_wait(&data->completion, &data->completion_lock); |
| 957 | pthread_mutex_unlock(&data->completion_lock); |
| 958 | |
| 959 | for (size_t i = 0; i < NUM_HW_WINDOWS; i++) { |
| 960 | if (pdev->bufs.overlay_map[i] != -1) { |
| 961 | int dup_fd = dup(data->fence); |
| 962 | if (dup_fd < 0) |
| 963 | ALOGW("release fence dup failed: %s", strerror(errno)); |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 964 | list->hwLayers[pdev->bufs.overlay_map[i]].releaseFenceFd = dup_fd; |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | close(data->fence); |
| 968 | free(data); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 969 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 972 | static void exynos5_registerProcs(struct hwc_composer_device_1* dev, |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 973 | hwc_procs_t const* procs) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 974 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 975 | struct exynos5_hwc_composer_device_1_t* pdev = |
| 976 | (struct exynos5_hwc_composer_device_1_t*)dev; |
| 977 | pdev->procs = const_cast<hwc_procs_t *>(procs); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 980 | 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] | 981 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 982 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 983 | (struct exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 984 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 985 | switch (what) { |
| 986 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 987 | // we support the background layer |
| 988 | value[0] = 1; |
| 989 | break; |
| 990 | case HWC_VSYNC_PERIOD: |
| 991 | // vsync period in nanosecond |
| 992 | value[0] = 1000000000.0 / pdev->gralloc_module->fps; |
| 993 | break; |
| 994 | default: |
| 995 | // unsupported query |
| 996 | return -EINVAL; |
| 997 | } |
| 998 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 1001 | static int exynos5_eventControl(struct hwc_composer_device_1 *dev, int event, |
| 1002 | int enabled) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1003 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1004 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 1005 | (struct exynos5_hwc_composer_device_1_t *)dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1006 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1007 | switch (event) { |
| 1008 | case HWC_EVENT_VSYNC: |
| 1009 | __u32 val = !!enabled; |
| 1010 | int err = ioctl(pdev->fd, S3CFB_SET_VSYNC_INT, &val); |
| 1011 | if (err < 0) { |
| 1012 | ALOGE("vsync ioctl failed"); |
| 1013 | return -errno; |
| 1014 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1015 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1016 | return 0; |
| 1017 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1018 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1019 | return -EINVAL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1022 | 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] | 1023 | const char *buff, int len) |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1024 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1025 | const char *s = buff; |
| 1026 | s += strlen(s) + 1; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1027 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1028 | while (*s) { |
| 1029 | if (!strncmp(s, "SWITCH_STATE=", strlen("SWITCH_STATE="))) |
| 1030 | pdev->hdmi_hpd = atoi(s + strlen("SWITCH_STATE=")) == 1; |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1031 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1032 | s += strlen(s) + 1; |
| 1033 | if (s - buff >= len) |
| 1034 | break; |
| 1035 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1036 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1037 | ALOGV("HDMI HPD changed to %s", pdev->hdmi_hpd ? "enabled" : "disabled"); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1038 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1039 | if (pdev->procs && pdev->procs->invalidate) |
| 1040 | pdev->procs->invalidate(pdev->procs); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1043 | 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] | 1044 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1045 | if (!pdev->procs || !pdev->procs->vsync) |
| 1046 | return; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1047 | |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame] | 1048 | int err = lseek(pdev->vsync_fd, 0, SEEK_SET); |
| 1049 | if (err < 0) { |
| 1050 | ALOGE("error seeking to vsync timestamp: %s", strerror(errno)); |
| 1051 | return; |
| 1052 | } |
| 1053 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1054 | char buf[4096]; |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame] | 1055 | err = read(pdev->vsync_fd, buf, sizeof(buf)); |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1056 | if (err < 0) { |
| 1057 | ALOGE("error reading vsync timestamp: %s", strerror(errno)); |
| 1058 | return; |
Greg Hackmann | 3464b1d | 2012-07-24 09:46:23 -0700 | [diff] [blame] | 1059 | } |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1060 | buf[sizeof(buf) - 1] = '\0'; |
Greg Hackmann | 3464b1d | 2012-07-24 09:46:23 -0700 | [diff] [blame] | 1061 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1062 | errno = 0; |
| 1063 | uint64_t timestamp = strtoull(buf, NULL, 0); |
| 1064 | if (!errno) |
| 1065 | pdev->procs->vsync(pdev->procs, 0, timestamp); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static void *hwc_vsync_thread(void *data) |
| 1069 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1070 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 1071 | (struct exynos5_hwc_composer_device_1_t *)data; |
| 1072 | char uevent_desc[4096]; |
| 1073 | memset(uevent_desc, 0, sizeof(uevent_desc)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1074 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1075 | setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1076 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1077 | uevent_init(); |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1078 | |
Greg Hackmann | fbeb853 | 2012-07-26 14:21:16 -0700 | [diff] [blame] | 1079 | char temp[4096]; |
| 1080 | int err = read(pdev->vsync_fd, temp, sizeof(temp)); |
| 1081 | if (err < 0) { |
| 1082 | ALOGE("error reading vsync timestamp: %s", strerror(errno)); |
| 1083 | return NULL; |
| 1084 | } |
| 1085 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1086 | struct pollfd fds[2]; |
| 1087 | fds[0].fd = pdev->vsync_fd; |
| 1088 | fds[0].events = POLLPRI; |
| 1089 | fds[1].fd = uevent_get_fd(); |
| 1090 | fds[1].events = POLLIN; |
| 1091 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1092 | while (true) { |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1093 | int err = poll(fds, 2, -1); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1094 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1095 | if (err > 0) { |
| 1096 | if (fds[0].revents & POLLPRI) { |
| 1097 | handle_vsync_event(pdev); |
| 1098 | } |
| 1099 | else if (fds[1].revents & POLLIN) { |
| 1100 | int len = uevent_next_event(uevent_desc, |
| 1101 | sizeof(uevent_desc) - 2); |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1102 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1103 | bool hdmi = !strcmp(uevent_desc, |
| 1104 | "change@/devices/virtual/switch/hdmi"); |
| 1105 | if (hdmi) |
| 1106 | handle_hdmi_uevent(pdev, uevent_desc, len); |
| 1107 | } |
| 1108 | } |
| 1109 | else if (err == -1) { |
| 1110 | if (errno == EINTR) |
| 1111 | break; |
| 1112 | ALOGE("error in vsync thread: %s", strerror(errno)); |
| 1113 | } |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1114 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1115 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1116 | return NULL; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Jesse Hall | b6e1fa0 | 2012-07-31 12:16:41 -0700 | [diff] [blame] | 1119 | static int exynos5_blank(struct hwc_composer_device_1 *dev, int blank) |
Colin Cross | 00359a8 | 2012-07-12 17:54:17 -0700 | [diff] [blame] | 1120 | { |
| 1121 | struct exynos5_hwc_composer_device_1_t *pdev = |
| 1122 | (struct exynos5_hwc_composer_device_1_t *)dev; |
| 1123 | |
| 1124 | int fb_blank = blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK; |
| 1125 | int err = ioctl(pdev->fd, FBIOBLANK, fb_blank); |
| 1126 | if (err < 0) { |
| 1127 | ALOGE("%sblank ioctl failed", blank ? "" : "un"); |
| 1128 | return -errno; |
| 1129 | } |
| 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Erik Gilling | 87e707e | 2012-06-29 17:35:13 -0700 | [diff] [blame] | 1134 | struct hwc_methods_1 exynos5_methods = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1135 | eventControl: exynos5_eventControl, |
Colin Cross | 00359a8 | 2012-07-12 17:54:17 -0700 | [diff] [blame] | 1136 | blank: exynos5_blank, |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1137 | }; |
| 1138 | |
| 1139 | static int exynos5_close(hw_device_t* device); |
| 1140 | |
| 1141 | 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] | 1142 | struct hw_device_t **device) |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1143 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1144 | int ret; |
| 1145 | int sw_fd; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1146 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1147 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 1148 | return -EINVAL; |
| 1149 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1150 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1151 | struct exynos5_hwc_composer_device_1_t *dev; |
| 1152 | dev = (struct exynos5_hwc_composer_device_1_t *)malloc(sizeof(*dev)); |
| 1153 | memset(dev, 0, sizeof(*dev)); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1154 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1155 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, |
| 1156 | (const struct hw_module_t **)&dev->gralloc_module)) { |
| 1157 | ALOGE("failed to get gralloc hw module"); |
| 1158 | ret = -EINVAL; |
| 1159 | goto err_get_module; |
| 1160 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1161 | |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 1162 | if (gralloc_open((const hw_module_t *)dev->gralloc_module, |
| 1163 | &dev->alloc_device)) { |
| 1164 | ALOGE("failed to open gralloc"); |
| 1165 | ret = -EINVAL; |
| 1166 | goto err_get_module; |
| 1167 | } |
| 1168 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1169 | dev->fd = open("/dev/graphics/fb0", O_RDWR); |
| 1170 | if (dev->fd < 0) { |
| 1171 | ALOGE("failed to open framebuffer"); |
| 1172 | ret = dev->fd; |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 1173 | goto err_open_fb; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1174 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1175 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1176 | dev->vsync_fd = open("/sys/devices/platform/exynos5-fb.1/vsync", O_RDONLY); |
| 1177 | if (dev->vsync_fd < 0) { |
| 1178 | ALOGE("failed to open vsync attribute"); |
| 1179 | ret = dev->vsync_fd; |
| 1180 | goto err_ioctl; |
| 1181 | } |
| 1182 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1183 | sw_fd = open("/sys/class/switch/hdmi/state", O_RDONLY); |
| 1184 | if (sw_fd) { |
| 1185 | char val; |
| 1186 | if (read(sw_fd, &val, 1) == 1 && val == '1') |
| 1187 | dev->hdmi_hpd = true; |
| 1188 | } |
Benoit Goby | cdd61b3 | 2012-07-09 12:09:59 -0700 | [diff] [blame] | 1189 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1190 | dev->base.common.tag = HARDWARE_DEVICE_TAG; |
| 1191 | dev->base.common.version = HWC_DEVICE_API_VERSION_1_0; |
| 1192 | dev->base.common.module = const_cast<hw_module_t *>(module); |
| 1193 | dev->base.common.close = exynos5_close; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1194 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1195 | dev->base.prepare = exynos5_prepare; |
| 1196 | dev->base.set = exynos5_set; |
| 1197 | dev->base.registerProcs = exynos5_registerProcs; |
| 1198 | dev->base.query = exynos5_query; |
| 1199 | dev->base.methods = &exynos5_methods; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1200 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1201 | dev->bufs.pdev = dev; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1202 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1203 | *device = &dev->base.common; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1204 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1205 | ret = pthread_create(&dev->vsync_thread, NULL, hwc_vsync_thread, dev); |
| 1206 | if (ret) { |
| 1207 | ALOGE("failed to start vsync thread: %s", strerror(ret)); |
| 1208 | ret = -ret; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1209 | goto err_vsync; |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1210 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1211 | |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1212 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1213 | |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1214 | err_vsync: |
| 1215 | close(dev->vsync_fd); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1216 | err_ioctl: |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1217 | close(dev->fd); |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 1218 | err_open_fb: |
| 1219 | gralloc_close(dev->alloc_device); |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1220 | err_get_module: |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1221 | free(dev); |
| 1222 | return ret; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | static int exynos5_close(hw_device_t *device) |
| 1226 | { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1227 | struct exynos5_hwc_composer_device_1_t *dev = |
| 1228 | (struct exynos5_hwc_composer_device_1_t *)device; |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1229 | pthread_kill(dev->vsync_thread, SIGTERM); |
| 1230 | pthread_join(dev->vsync_thread, NULL); |
Greg Hackmann | 9130e70 | 2012-07-30 14:53:04 -0700 | [diff] [blame] | 1231 | for (size_t i = 0; i < NUM_GSC_UNITS; i++) { |
| 1232 | if (dev->gsc[i].gsc) |
| 1233 | exynos_gsc_destroy(dev->gsc[i].gsc); |
| 1234 | for (size_t j = 0; i < NUM_GSC_DST_BUFS; j++) |
| 1235 | if (dev->gsc[i].dst_buf[j]) |
| 1236 | dev->alloc_device->free(dev->alloc_device, dev->gsc[i].dst_buf[j]); |
| 1237 | } |
| 1238 | gralloc_close(dev->alloc_device); |
Greg Hackmann | 2972485 | 2012-07-23 15:31:10 -0700 | [diff] [blame] | 1239 | close(dev->vsync_fd); |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1240 | close(dev->fd); |
| 1241 | return 0; |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static struct hw_module_methods_t exynos5_hwc_module_methods = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1245 | open: exynos5_open, |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1246 | }; |
| 1247 | |
| 1248 | hwc_module_t HAL_MODULE_INFO_SYM = { |
Greg Hackmann | f6f2e54 | 2012-07-16 16:10:27 -0700 | [diff] [blame] | 1249 | common: { |
| 1250 | tag: HARDWARE_MODULE_TAG, |
| 1251 | module_api_version: HWC_MODULE_API_VERSION_0_1, |
| 1252 | hal_api_version: HARDWARE_HAL_API_VERSION, |
| 1253 | id: HWC_HARDWARE_MODULE_ID, |
| 1254 | name: "Samsung exynos5 hwcomposer module", |
| 1255 | author: "Google", |
| 1256 | methods: &exynos5_hwc_module_methods, |
| 1257 | } |
Greg Hackmann | 86eb1c6 | 2012-05-30 09:25:51 -0700 | [diff] [blame] | 1258 | }; |