blob: 5c297c1f88e0ddc5540e527a2af18f6179ba03a0 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Arun Kumar K.R6c85f052014-01-21 21:47:41 -08003 * Copyright (c) 2010-2014 The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
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 Malchev202a77d2012-06-11 14:41:12 -070020#include <cutils/log.h>
21#include <cutils/properties.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070022#include <dlfcn.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070023
24#include <hardware/hardware.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070025
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 Malchev202a77d2012-06-11 14:41:12 -070032#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 Ahmed29a26812012-06-14 00:56:20 -070040#include "fb_priv.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070041#include "gr.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070042#include <cutils/properties.h>
Naseer Ahmeda87da602012-07-01 23:54:19 -070043#include <profiler.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070044
Iliyan Malchev202a77d2012-06-11 14:41:12 -070045#define EVEN_OUT(x) if (x & 0x0001) {x--;}
Iliyan Malchev202a77d2012-06-11 14:41:12 -070046
Iliyan Malchev202a77d2012-06-11 14:41:12 -070047enum {
48 PAGE_FLIP = 0x00000001,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070049};
50
51struct fb_context_t {
52 framebuffer_device_t device;
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -070053 //fd - which is returned on open
54 int fbFd;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055};
56
Iliyan Malchev202a77d2012-06-11 14:41:12 -070057static int fb_setSwapInterval(struct framebuffer_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 int interval)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070059{
Naseer Ahmed30621ab2012-06-25 15:37:21 -070060 //XXX: Get the value here and implement along with
61 //single vsync in HWC
Iliyan Malchev202a77d2012-06-11 14:41:12 -070062 char pval[PROPERTY_VALUE_MAX];
Naseer Ahmed29a26812012-06-14 00:56:20 -070063 property_get("debug.egl.swapinterval", pval, "-1");
Iliyan Malchev202a77d2012-06-11 14:41:12 -070064 int property_interval = atoi(pval);
65 if (property_interval >= 0)
66 interval = property_interval;
67
Iliyan Malchev202a77d2012-06-11 14:41:12 -070068 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070070 if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
71 return -EINVAL;
72
73 m->swapInterval = interval;
74 return 0;
75}
76
Iliyan Malchev202a77d2012-06-11 14:41:12 -070077static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
78{
Naseer Ahmed00fd6a52012-07-03 21:23:12 -070079 private_module_t* m =
80 reinterpret_cast<private_module_t*>(dev->common.module);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -040081 private_handle_t *hnd = static_cast<private_handle_t*>
82 (const_cast<native_handle_t*>(buffer));
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -070083 fb_context_t *ctx = reinterpret_cast<fb_context_t*>(dev);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070084 const unsigned int offset = (unsigned int) (hnd->base -
85 m->framebuffer->base);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -040086 m->info.activate = FB_ACTIVATE_VBL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080087 m->info.yoffset = (int)(offset / m->finfo.line_length);
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -070088 if (ioctl(ctx->fbFd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
Naseer Ahmed47aa15e2013-04-10 21:27:09 -040089 ALOGE("%s: FBIOPUT_VSCREENINFO for primary failed, str: %s",
Saurabh Shah43333302013-02-06 13:30:27 -080090 __FUNCTION__, strerror(errno));
91 return -errno;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070092 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070093 return 0;
94}
95
96static int fb_compositionComplete(struct framebuffer_device_t* dev)
97{
98 // TODO: Properly implement composition complete callback
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080099 if(!dev) {
100 return -1;
101 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700102 glFinish();
103
104 return 0;
105}
106
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700107int mapFrameBufferLocked(framebuffer_device_t *dev)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700108{
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700109 private_module_t* module =
110 reinterpret_cast<private_module_t*>(dev->common.module);
111 fb_context_t *ctx = reinterpret_cast<fb_context_t*>(dev);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700112 // already initialized...
113 if (module->framebuffer) {
114 return 0;
115 }
116 char const * const device_template[] = {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117 "/dev/graphics/fb%u",
118 "/dev/fb%u",
119 0 };
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700120
121 int fd = -1;
122 int i=0;
123 char name[64];
124 char property[PROPERTY_VALUE_MAX];
125
126 while ((fd==-1) && device_template[i]) {
127 snprintf(name, 64, device_template[i], 0);
128 fd = open(name, O_RDWR, 0);
129 i++;
130 }
131 if (fd < 0)
132 return -errno;
133
134 struct fb_fix_screeninfo finfo;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800135 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
136 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700137 return -errno;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800138 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700139
140 struct fb_var_screeninfo info;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800141 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
142 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700143 return -errno;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800144 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700145
146 info.reserved[0] = 0;
147 info.reserved[1] = 0;
148 info.reserved[2] = 0;
149 info.xoffset = 0;
150 info.yoffset = 0;
151 info.activate = FB_ACTIVATE_NOW;
152
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700153 /* Interpretation of offset for color fields: All offsets are from the
154 * right, inside a "pixel" value, which is exactly 'bits_per_pixel' wide
155 * (means: you can use the offset as right argument to <<). A pixel
156 * afterwards is a bit stream and is written to video memory as that
157 * unmodified. This implies big-endian byte order if bits_per_pixel is
158 * greater than 8.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159 */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700160
161 if(info.bits_per_pixel == 32) {
162 /*
163 * Explicitly request RGBA_8888
164 */
165 info.bits_per_pixel = 32;
166 info.red.offset = 24;
167 info.red.length = 8;
168 info.green.offset = 16;
169 info.green.length = 8;
170 info.blue.offset = 8;
171 info.blue.length = 8;
172 info.transp.offset = 0;
173 info.transp.length = 8;
174
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700175 /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we
176 * do not use the MDP for composition (i.e. hw composition == 0), ask
177 * for RGBA instead of RGBX. */
178 if (property_get("debug.sf.hw", property, NULL) > 0 &&
179 atoi(property) == 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700180 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 else if(property_get("debug.composition.type", property, NULL) > 0 &&
182 (strncmp(property, "mdp", 3) == 0))
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700183 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
184 else
185 module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888;
186 } else {
187 /*
188 * Explicitly request 5/6/5
189 */
190 info.bits_per_pixel = 16;
191 info.red.offset = 11;
192 info.red.length = 5;
193 info.green.offset = 5;
194 info.green.length = 6;
195 info.blue.offset = 0;
196 info.blue.length = 5;
197 info.transp.offset = 0;
198 info.transp.length = 0;
199 module->fbFormat = HAL_PIXEL_FORMAT_RGB_565;
200 }
201
202 //adreno needs 4k aligned offsets. Max hole size is 4096-1
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700203 unsigned int size = roundUpToPageSize(info.yres * info.xres *
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800204 (info.bits_per_pixel/8));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700205
206 /*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207 * Request NUM_BUFFERS screens (at least 2 for page flipping)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700208 */
209 int numberOfBuffers = (int)(finfo.smem_len/size);
210 ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers);
211
212 if (property_get("debug.gr.numframebuffers", property, NULL) > 0) {
213 int num = atoi(property);
214 if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) {
215 numberOfBuffers = num;
216 }
217 }
218 if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX)
219 numberOfBuffers = NUM_FRAMEBUFFERS_MAX;
220
221 ALOGV("We support %d buffers", numberOfBuffers);
222
223 //consider the included hole by 4k alignment
224 uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800225 info.yres_virtual = (uint32_t) ((size * numberOfBuffers) / line_length);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700226
227 uint32_t flags = PAGE_FLIP;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700228
229 if (info.yres_virtual < ((size * 2) / line_length) ) {
230 // we need at least 2 for page-flipping
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800231 info.yres_virtual = (int)(size / line_length);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700232 flags &= ~PAGE_FLIP;
233 ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 info.yres_virtual, info.yres*2);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700235 }
236
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800237 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
238 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700239 return -errno;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800240 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700241
242 if (int(info.width) <= 0 || int(info.height) <= 0) {
243 // the driver doesn't return that information
244 // default to 160 dpi
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800245 info.width = (uint32_t)(((float)(info.xres) * 25.4f)/160.0f + 0.5f);
246 info.height = (uint32_t)(((float)(info.yres) * 25.4f)/160.0f + 0.5f);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700247 }
248
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800249 float xdpi = ((float)(info.xres) * 25.4f) / (float)info.width;
250 float ydpi = ((float)(info.yres) * 25.4f) / (float)info.height;
251
Ken Zhang6e6f9a92013-01-08 15:09:27 -0500252#ifdef MSMFB_METADATA_GET
253 struct msmfb_metadata metadata;
254 memset(&metadata, 0 , sizeof(metadata));
255 metadata.op = metadata_op_frame_rate;
256 if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) {
257 ALOGE("Error retrieving panel frame rate");
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800258 close(fd);
Ken Zhang6e6f9a92013-01-08 15:09:27 -0500259 return -errno;
260 }
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800261 float fps = (float)metadata.data.panel_frame_rate;
Ken Zhang6e6f9a92013-01-08 15:09:27 -0500262#else
263 //XXX: Remove reserved field usage on all baselines
choongryeol.lee26145b82012-06-26 23:41:00 -0700264 //The reserved[3] field is used to store FPS by the driver.
Naseer Ahmed9edd17c2012-08-15 18:16:50 -0700265 float fps = info.reserved[3] & 0xFF;
Ken Zhang6e6f9a92013-01-08 15:09:27 -0500266#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267 ALOGI("using (fd=%d)\n"
268 "id = %s\n"
269 "xres = %d px\n"
270 "yres = %d px\n"
271 "xres_virtual = %d px\n"
272 "yres_virtual = %d px\n"
273 "bpp = %d\n"
274 "r = %2u:%u\n"
275 "g = %2u:%u\n"
276 "b = %2u:%u\n",
277 fd,
278 finfo.id,
279 info.xres,
280 info.yres,
281 info.xres_virtual,
282 info.yres_virtual,
283 info.bits_per_pixel,
284 info.red.offset, info.red.length,
285 info.green.offset, info.green.length,
286 info.blue.offset, info.blue.length
287 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700288
Naseer Ahmed29a26812012-06-14 00:56:20 -0700289 ALOGI("width = %d mm (%f dpi)\n"
290 "height = %d mm (%f dpi)\n"
291 "refresh rate = %.2f Hz\n",
292 info.width, xdpi,
293 info.height, ydpi,
294 fps
295 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700296
297
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800298 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
299 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700300 return -errno;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800301 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700302
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800303 if (finfo.smem_len <= 0) {
304 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700305 return -errno;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800306 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700307
308 module->flags = flags;
309 module->info = info;
310 module->finfo = finfo;
311 module->xdpi = xdpi;
312 module->ydpi = ydpi;
313 module->fps = fps;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700314 module->swapInterval = 1;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700315
316 CALC_INIT();
317
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700318 /*
319 * map the framebuffer
320 */
321
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400322 module->numBuffers = info.yres_virtual / info.yres;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700323 module->bufferMask = 0;
324 //adreno needs page aligned offsets. Align the fbsize to pagesize.
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700325 unsigned int fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326 module->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700327 void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
328 if (vaddr == MAP_FAILED) {
329 ALOGE("Error mapping the framebuffer (%s)", strerror(errno));
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800330 close(fd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700331 return -errno;
332 }
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700333 //store the framebuffer fd in the ctx
334 ctx->fbFd = fd;
335#ifdef MSMFB_METADATA_GET
336 memset(&metadata, 0 , sizeof(metadata));
337 metadata.op = metadata_op_get_ion_fd;
338 // get the ION fd for the framebuffer, as GPU needs ION fd
339 if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) {
340 ALOGE("Error getting ION fd (%s)", strerror(errno));
341 close(fd);
342 return -errno;
343 }
344 if(metadata.data.fbmem_ionfd < 0) {
345 ALOGE("Error: Ioctl returned invalid ION fd = %d",
346 metadata.data.fbmem_ionfd);
347 close(fd);
348 return -errno;
349 }
350 fd = metadata.data.fbmem_ionfd;
351#endif
352 // Create framebuffer handle using the ION fd
353 module->framebuffer = new private_handle_t(fd, fbSize,
354 private_handle_t::PRIV_FLAGS_USES_ION,
355 BUFFER_TYPE_UI,
356 module->fbFormat, info.xres, info.yres);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700357 module->framebuffer->base = uint64_t(vaddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700358 memset(vaddr, 0, fbSize);
Naseer Ahmed47aa15e2013-04-10 21:27:09 -0400359 //Enable vsync
360 int enable = 1;
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700361 ioctl(ctx->fbFd, MSMFB_OVERLAY_VSYNC_CTRL, &enable);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700362 return 0;
363}
364
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700365static int mapFrameBuffer(framebuffer_device_t *dev)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700366{
Naseer Ahmed473986c2013-07-16 12:47:21 -0400367 int err = -1;
Naseer Ahmed499ab3d2013-07-04 15:24:31 -0400368 char property[PROPERTY_VALUE_MAX];
369 if((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
370 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
371 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700372 private_module_t* module =
373 reinterpret_cast<private_module_t*>(dev->common.module);
Naseer Ahmed499ab3d2013-07-04 15:24:31 -0400374 pthread_mutex_lock(&module->lock);
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700375 err = mapFrameBufferLocked(dev);
Naseer Ahmed499ab3d2013-07-04 15:24:31 -0400376 pthread_mutex_unlock(&module->lock);
377 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700378 return err;
379}
380
381/*****************************************************************************/
382
383static int fb_close(struct hw_device_t *dev)
384{
385 fb_context_t* ctx = (fb_context_t*)dev;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700386 if (ctx) {
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700387#ifdef MSMFB_METADATA_GET
388 if(ctx->fbFd >=0) {
389 close(ctx->fbFd);
390 }
391#endif
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700392 //Hack until fbdev is removed. Framework could close this causing hwc a
393 //pain.
394 //free(ctx);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700395 }
396 return 0;
397}
398
399int fb_device_open(hw_module_t const* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400 hw_device_t** device)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700401{
402 int status = -EINVAL;
403 if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
404 alloc_device_t* gralloc_device;
405 status = gralloc_open(module, &gralloc_device);
406 if (status < 0)
407 return status;
408
409 /* initialize our state here */
410 fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800411 if(dev == NULL) {
412 gralloc_close(gralloc_device);
413 return status;
414 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700415 memset(dev, 0, sizeof(*dev));
416
417 /* initialize the procs */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700418 dev->device.common.tag = HARDWARE_DEVICE_TAG;
419 dev->device.common.version = 0;
420 dev->device.common.module = const_cast<hw_module_t*>(module);
421 dev->device.common.close = fb_close;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700422 dev->device.setSwapInterval = fb_setSwapInterval;
423 dev->device.post = fb_post;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424 dev->device.setUpdateRect = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700425 dev->device.compositionComplete = fb_compositionComplete;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700426
Arun Kumar K.Rf0f853f2014-03-17 16:03:21 -0700427 status = mapFrameBuffer((framebuffer_device_t*)dev);
428 private_module_t* m = (private_module_t*)dev->device.common.module;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700429 if (status >= 0) {
430 int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
431 const_cast<uint32_t&>(dev->device.flags) = 0;
432 const_cast<uint32_t&>(dev->device.width) = m->info.xres;
433 const_cast<uint32_t&>(dev->device.height) = m->info.yres;
434 const_cast<int&>(dev->device.stride) = stride;
435 const_cast<int&>(dev->device.format) = m->fbFormat;
436 const_cast<float&>(dev->device.xdpi) = m->xdpi;
437 const_cast<float&>(dev->device.ydpi) = m->ydpi;
438 const_cast<float&>(dev->device.fps) = m->fps;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700439 const_cast<int&>(dev->device.minSwapInterval) =
440 PRIV_MIN_SWAP_INTERVAL;
441 const_cast<int&>(dev->device.maxSwapInterval) =
442 PRIV_MAX_SWAP_INTERVAL;
Naseer Ahmed00fd6a52012-07-03 21:23:12 -0700443 const_cast<int&>(dev->device.numFramebuffers) = m->numBuffers;
Naseer Ahmed6f8ca312013-01-15 16:55:06 -0500444 dev->device.setUpdateRect = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700445
446 *device = &dev->device.common;
447 }
448
449 // Close the gralloc module
450 gralloc_close(gralloc_device);
451 }
452 return status;
453}