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