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