Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 3 | * Copyright (c) 2010-2012 Code Aurora Forum. All rights reserved. |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <sys/mman.h> |
| 19 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 20 | #include <cutils/log.h> |
| 21 | #include <cutils/properties.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 22 | #include <dlfcn.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 23 | |
| 24 | #include <hardware/hardware.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 25 | |
| 26 | #include <fcntl.h> |
| 27 | #include <errno.h> |
| 28 | #include <sys/ioctl.h> |
| 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <pthread.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 32 | #include <cutils/atomic.h> |
| 33 | |
| 34 | #include <linux/fb.h> |
| 35 | #include <linux/msm_mdp.h> |
| 36 | |
| 37 | #include <GLES/gl.h> |
| 38 | |
| 39 | #include "gralloc_priv.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | #include "fb_priv.h" |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 41 | #include "gr.h" |
Naseer Ahmed | 8831816 | 2012-07-13 07:16:20 -0700 | [diff] [blame] | 42 | #include <genlock.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 43 | #include <cutils/properties.h> |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 44 | #include <profiler.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 45 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 46 | #define EVEN_OUT(x) if (x & 0x0001) {x--;} |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 47 | /** min of int a, b */ |
| 48 | static inline int min(int a, int b) { |
| 49 | return (a<b) ? a : b; |
| 50 | } |
| 51 | /** max of int a, b */ |
| 52 | static inline int max(int a, int b) { |
| 53 | return (a>b) ? a : b; |
| 54 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 55 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 56 | enum { |
| 57 | PAGE_FLIP = 0x00000001, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | LOCKED = 0x00000002 |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct fb_context_t { |
| 62 | framebuffer_device_t device; |
| 63 | }; |
| 64 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 65 | |
| 66 | static int fb_setSwapInterval(struct framebuffer_device_t* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 67 | int interval) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 68 | { |
Naseer Ahmed | 30621ab | 2012-06-25 15:37:21 -0700 | [diff] [blame] | 69 | //XXX: Get the value here and implement along with |
| 70 | //single vsync in HWC |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 71 | char pval[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 72 | property_get("debug.egl.swapinterval", pval, "-1"); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 73 | int property_interval = atoi(pval); |
| 74 | if (property_interval >= 0) |
| 75 | interval = property_interval; |
| 76 | |
| 77 | fb_context_t* ctx = (fb_context_t*)dev; |
| 78 | private_module_t* m = reinterpret_cast<private_module_t*>( |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 79 | dev->common.module); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 80 | if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval) |
| 81 | return -EINVAL; |
| 82 | |
| 83 | m->swapInterval = interval; |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int fb_setUpdateRect(struct framebuffer_device_t* dev, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 88 | int l, int t, int w, int h) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 89 | { |
| 90 | if (((w|h) <= 0) || ((l|t)<0)) |
| 91 | return -EINVAL; |
| 92 | fb_context_t* ctx = (fb_context_t*)dev; |
| 93 | private_module_t* m = reinterpret_cast<private_module_t*>( |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 94 | dev->common.module); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 95 | m->info.reserved[0] = 0x54445055; // "UPDT"; |
| 96 | m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16); |
| 97 | m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16); |
| 98 | return 0; |
| 99 | } |
| 100 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 101 | static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer) |
| 102 | { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 103 | |
Naseer Ahmed | 8831816 | 2012-07-13 07:16:20 -0700 | [diff] [blame] | 104 | fb_context_t* ctx = (fb_context_t*) dev; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 105 | |
Naseer Ahmed | 8831816 | 2012-07-13 07:16:20 -0700 | [diff] [blame] | 106 | private_handle_t *hnd = static_cast<private_handle_t*> |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame^] | 107 | (const_cast<native_handle_t*>(buffer)); |
Naseer Ahmed | 00fd6a5 | 2012-07-03 21:23:12 -0700 | [diff] [blame] | 108 | private_module_t* m = |
| 109 | reinterpret_cast<private_module_t*>(dev->common.module); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 110 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame^] | 111 | if (hnd && hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) { |
| 112 | m->info.activate = FB_ACTIVATE_VBL | FB_ACTIVATE_FORCE; |
| 113 | m->info.yoffset = hnd->offset / m->finfo.line_length; |
Naseer Ahmed | 30621ab | 2012-06-25 15:37:21 -0700 | [diff] [blame] | 114 | if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame^] | 115 | ALOGE("%s: FBIOPUT_VSCREENINFO failed for external, err: %s", __FUNCTION__, |
| 116 | strerror(errno)); |
Naseer Ahmed | 30621ab | 2012-06-25 15:37:21 -0700 | [diff] [blame] | 117 | return -errno; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 118 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 119 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int fb_compositionComplete(struct framebuffer_device_t* dev) |
| 124 | { |
| 125 | // TODO: Properly implement composition complete callback |
| 126 | glFinish(); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 131 | int mapFrameBufferLocked(struct private_module_t* module) |
| 132 | { |
| 133 | // already initialized... |
| 134 | if (module->framebuffer) { |
| 135 | return 0; |
| 136 | } |
| 137 | char const * const device_template[] = { |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 138 | "/dev/graphics/fb%u", |
| 139 | "/dev/fb%u", |
| 140 | 0 }; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 141 | |
| 142 | int fd = -1; |
| 143 | int i=0; |
| 144 | char name[64]; |
| 145 | char property[PROPERTY_VALUE_MAX]; |
| 146 | |
| 147 | while ((fd==-1) && device_template[i]) { |
| 148 | snprintf(name, 64, device_template[i], 0); |
| 149 | fd = open(name, O_RDWR, 0); |
| 150 | i++; |
| 151 | } |
| 152 | if (fd < 0) |
| 153 | return -errno; |
| 154 | |
| 155 | struct fb_fix_screeninfo finfo; |
| 156 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) |
| 157 | return -errno; |
| 158 | |
| 159 | struct fb_var_screeninfo info; |
| 160 | if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) |
| 161 | return -errno; |
| 162 | |
| 163 | info.reserved[0] = 0; |
| 164 | info.reserved[1] = 0; |
| 165 | info.reserved[2] = 0; |
| 166 | info.xoffset = 0; |
| 167 | info.yoffset = 0; |
| 168 | info.activate = FB_ACTIVATE_NOW; |
| 169 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 170 | /* Interpretation of offset for color fields: All offsets are from the |
| 171 | * right, inside a "pixel" value, which is exactly 'bits_per_pixel' wide |
| 172 | * (means: you can use the offset as right argument to <<). A pixel |
| 173 | * afterwards is a bit stream and is written to video memory as that |
| 174 | * unmodified. This implies big-endian byte order if bits_per_pixel is |
| 175 | * greater than 8. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 176 | */ |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 177 | |
| 178 | if(info.bits_per_pixel == 32) { |
| 179 | /* |
| 180 | * Explicitly request RGBA_8888 |
| 181 | */ |
| 182 | info.bits_per_pixel = 32; |
| 183 | info.red.offset = 24; |
| 184 | info.red.length = 8; |
| 185 | info.green.offset = 16; |
| 186 | info.green.length = 8; |
| 187 | info.blue.offset = 8; |
| 188 | info.blue.length = 8; |
| 189 | info.transp.offset = 0; |
| 190 | info.transp.length = 8; |
| 191 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 192 | /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we |
| 193 | * do not use the MDP for composition (i.e. hw composition == 0), ask |
| 194 | * for RGBA instead of RGBX. */ |
| 195 | if (property_get("debug.sf.hw", property, NULL) > 0 && |
| 196 | atoi(property) == 0) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 197 | module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 198 | else if(property_get("debug.composition.type", property, NULL) > 0 && |
| 199 | (strncmp(property, "mdp", 3) == 0)) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 200 | module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888; |
| 201 | else |
| 202 | module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888; |
| 203 | } else { |
| 204 | /* |
| 205 | * Explicitly request 5/6/5 |
| 206 | */ |
| 207 | info.bits_per_pixel = 16; |
| 208 | info.red.offset = 11; |
| 209 | info.red.length = 5; |
| 210 | info.green.offset = 5; |
| 211 | info.green.length = 6; |
| 212 | info.blue.offset = 0; |
| 213 | info.blue.length = 5; |
| 214 | info.transp.offset = 0; |
| 215 | info.transp.length = 0; |
| 216 | module->fbFormat = HAL_PIXEL_FORMAT_RGB_565; |
| 217 | } |
| 218 | |
| 219 | //adreno needs 4k aligned offsets. Max hole size is 4096-1 |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 220 | int size = roundUpToPageSize(info.yres * info.xres * |
| 221 | (info.bits_per_pixel/8)); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 222 | |
| 223 | /* |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 224 | * Request NUM_BUFFERS screens (at least 2 for page flipping) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 225 | */ |
| 226 | int numberOfBuffers = (int)(finfo.smem_len/size); |
| 227 | ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers); |
| 228 | |
| 229 | if (property_get("debug.gr.numframebuffers", property, NULL) > 0) { |
| 230 | int num = atoi(property); |
| 231 | if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) { |
| 232 | numberOfBuffers = num; |
| 233 | } |
| 234 | } |
| 235 | if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX) |
| 236 | numberOfBuffers = NUM_FRAMEBUFFERS_MAX; |
| 237 | |
| 238 | ALOGV("We support %d buffers", numberOfBuffers); |
| 239 | |
| 240 | //consider the included hole by 4k alignment |
| 241 | uint32_t line_length = (info.xres * info.bits_per_pixel / 8); |
| 242 | info.yres_virtual = (size * numberOfBuffers) / line_length; |
| 243 | |
| 244 | uint32_t flags = PAGE_FLIP; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 245 | |
| 246 | if (info.yres_virtual < ((size * 2) / line_length) ) { |
| 247 | // we need at least 2 for page-flipping |
| 248 | info.yres_virtual = size / line_length; |
| 249 | flags &= ~PAGE_FLIP; |
| 250 | ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)", |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 251 | info.yres_virtual, info.yres*2); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) |
| 255 | return -errno; |
| 256 | |
| 257 | if (int(info.width) <= 0 || int(info.height) <= 0) { |
| 258 | // the driver doesn't return that information |
| 259 | // default to 160 dpi |
| 260 | info.width = ((info.xres * 25.4f)/160.0f + 0.5f); |
| 261 | info.height = ((info.yres * 25.4f)/160.0f + 0.5f); |
| 262 | } |
| 263 | |
| 264 | float xdpi = (info.xres * 25.4f) / info.width; |
| 265 | float ydpi = (info.yres * 25.4f) / info.height; |
choongryeol.lee | 26145b8 | 2012-06-26 23:41:00 -0700 | [diff] [blame] | 266 | //The reserved[3] field is used to store FPS by the driver. |
Naseer Ahmed | 9edd17c | 2012-08-15 18:16:50 -0700 | [diff] [blame] | 267 | float fps = info.reserved[3] & 0xFF; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 268 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 269 | ALOGI("using (fd=%d)\n" |
| 270 | "id = %s\n" |
| 271 | "xres = %d px\n" |
| 272 | "yres = %d px\n" |
| 273 | "xres_virtual = %d px\n" |
| 274 | "yres_virtual = %d px\n" |
| 275 | "bpp = %d\n" |
| 276 | "r = %2u:%u\n" |
| 277 | "g = %2u:%u\n" |
| 278 | "b = %2u:%u\n", |
| 279 | fd, |
| 280 | finfo.id, |
| 281 | info.xres, |
| 282 | info.yres, |
| 283 | info.xres_virtual, |
| 284 | info.yres_virtual, |
| 285 | info.bits_per_pixel, |
| 286 | info.red.offset, info.red.length, |
| 287 | info.green.offset, info.green.length, |
| 288 | info.blue.offset, info.blue.length |
| 289 | ); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 290 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 291 | ALOGI("width = %d mm (%f dpi)\n" |
| 292 | "height = %d mm (%f dpi)\n" |
| 293 | "refresh rate = %.2f Hz\n", |
| 294 | info.width, xdpi, |
| 295 | info.height, ydpi, |
| 296 | fps |
| 297 | ); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 298 | |
| 299 | |
| 300 | if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) |
| 301 | return -errno; |
| 302 | |
| 303 | if (finfo.smem_len <= 0) |
| 304 | return -errno; |
| 305 | |
| 306 | module->flags = flags; |
| 307 | module->info = info; |
| 308 | module->finfo = finfo; |
| 309 | module->xdpi = xdpi; |
| 310 | module->ydpi = ydpi; |
| 311 | module->fps = fps; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 312 | module->swapInterval = 1; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 313 | |
| 314 | CALC_INIT(); |
| 315 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 316 | /* |
| 317 | * map the framebuffer |
| 318 | */ |
| 319 | |
| 320 | int err; |
| 321 | module->numBuffers = info.yres_virtual / info.yres; |
| 322 | module->bufferMask = 0; |
| 323 | //adreno needs page aligned offsets. Align the fbsize to pagesize. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 324 | size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres)* |
| 325 | module->numBuffers; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 326 | module->framebuffer = new private_handle_t(fd, fbSize, |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 327 | private_handle_t::PRIV_FLAGS_USES_PMEM, |
| 328 | BUFFER_TYPE_UI, |
| 329 | module->fbFormat, info.xres, info.yres); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 330 | void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); |
| 331 | if (vaddr == MAP_FAILED) { |
| 332 | ALOGE("Error mapping the framebuffer (%s)", strerror(errno)); |
| 333 | return -errno; |
| 334 | } |
| 335 | module->framebuffer->base = intptr_t(vaddr); |
| 336 | memset(vaddr, 0, fbSize); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 337 | module->currentOffset = 0; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 338 | module->fbPostDone = false; |
| 339 | pthread_mutex_init(&(module->fbPostLock), NULL); |
| 340 | pthread_cond_init(&(module->fbPostCond), NULL); |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 341 | module->fbPanDone = false; |
| 342 | pthread_mutex_init(&(module->fbPanLock), NULL); |
| 343 | pthread_cond_init(&(module->fbPanCond), NULL); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int mapFrameBuffer(struct private_module_t* module) |
| 348 | { |
| 349 | pthread_mutex_lock(&module->lock); |
| 350 | int err = mapFrameBufferLocked(module); |
| 351 | pthread_mutex_unlock(&module->lock); |
| 352 | return err; |
| 353 | } |
| 354 | |
| 355 | /*****************************************************************************/ |
| 356 | |
| 357 | static int fb_close(struct hw_device_t *dev) |
| 358 | { |
| 359 | fb_context_t* ctx = (fb_context_t*)dev; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 360 | if (ctx) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame^] | 361 | //Hack until fbdev is removed. Framework could close this causing hwc a |
| 362 | //pain. |
| 363 | //free(ctx); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | int fb_device_open(hw_module_t const* module, const char* name, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 369 | hw_device_t** device) |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 370 | { |
| 371 | int status = -EINVAL; |
| 372 | if (!strcmp(name, GRALLOC_HARDWARE_FB0)) { |
| 373 | alloc_device_t* gralloc_device; |
| 374 | status = gralloc_open(module, &gralloc_device); |
| 375 | if (status < 0) |
| 376 | return status; |
| 377 | |
| 378 | /* initialize our state here */ |
| 379 | fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev)); |
| 380 | memset(dev, 0, sizeof(*dev)); |
| 381 | |
| 382 | /* initialize the procs */ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 383 | dev->device.common.tag = HARDWARE_DEVICE_TAG; |
| 384 | dev->device.common.version = 0; |
| 385 | dev->device.common.module = const_cast<hw_module_t*>(module); |
| 386 | dev->device.common.close = fb_close; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 387 | dev->device.setSwapInterval = fb_setSwapInterval; |
| 388 | dev->device.post = fb_post; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 389 | dev->device.setUpdateRect = 0; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 390 | dev->device.compositionComplete = fb_compositionComplete; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 391 | |
| 392 | private_module_t* m = (private_module_t*)module; |
| 393 | status = mapFrameBuffer(m); |
| 394 | if (status >= 0) { |
| 395 | int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3); |
| 396 | const_cast<uint32_t&>(dev->device.flags) = 0; |
| 397 | const_cast<uint32_t&>(dev->device.width) = m->info.xres; |
| 398 | const_cast<uint32_t&>(dev->device.height) = m->info.yres; |
| 399 | const_cast<int&>(dev->device.stride) = stride; |
| 400 | const_cast<int&>(dev->device.format) = m->fbFormat; |
| 401 | const_cast<float&>(dev->device.xdpi) = m->xdpi; |
| 402 | const_cast<float&>(dev->device.ydpi) = m->ydpi; |
| 403 | const_cast<float&>(dev->device.fps) = m->fps; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 404 | const_cast<int&>(dev->device.minSwapInterval) = |
| 405 | PRIV_MIN_SWAP_INTERVAL; |
| 406 | const_cast<int&>(dev->device.maxSwapInterval) = |
| 407 | PRIV_MAX_SWAP_INTERVAL; |
Naseer Ahmed | 00fd6a5 | 2012-07-03 21:23:12 -0700 | [diff] [blame] | 408 | const_cast<int&>(dev->device.numFramebuffers) = m->numBuffers; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 409 | if (m->finfo.reserved[0] == 0x5444 && |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 410 | m->finfo.reserved[1] == 0x5055) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 411 | dev->device.setUpdateRect = fb_setUpdateRect; |
| 412 | ALOGD("UPDATE_ON_DEMAND supported"); |
| 413 | } |
| 414 | |
| 415 | *device = &dev->device.common; |
| 416 | } |
| 417 | |
| 418 | // Close the gralloc module |
| 419 | gralloc_close(gralloc_device); |
| 420 | } |
| 421 | return status; |
| 422 | } |