blob: bd9ca9cda8e8e141e857ff9039680b49bfa92947 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Naseer Ahmed29a26812012-06-14 00:56:20 -07003 * Copyright (c) 2010-2012 Code Aurora Forum. 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 Ahmed29a26812012-06-14 00:56:20 -070043#include <qcomutils/profiler.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070044
Naseer Ahmed29a26812012-06-14 00:56:20 -070045#include "overlay.h"
46namespace ovutils = overlay::utils;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070047
Iliyan Malchev202a77d2012-06-11 14:41:12 -070048#define EVEN_OUT(x) if (x & 0x0001) {x--;}
Iliyan Malchev202a77d2012-06-11 14:41:12 -070049/** min of int a, b */
50static inline int min(int a, int b) {
51 return (a<b) ? a : b;
52}
53/** max of int a, b */
54static inline int max(int a, int b) {
55 return (a>b) ? a : b;
56}
Iliyan Malchev202a77d2012-06-11 14:41:12 -070057
58char framebufferStateName[] = {'S', 'R', 'A'};
59
Iliyan Malchev202a77d2012-06-11 14:41:12 -070060enum {
61 PAGE_FLIP = 0x00000001,
Naseer Ahmed29a26812012-06-14 00:56:20 -070062 LOCKED = 0x00000002
Iliyan Malchev202a77d2012-06-11 14:41:12 -070063};
64
65struct fb_context_t {
66 framebuffer_device_t device;
67};
68
Iliyan Malchev202a77d2012-06-11 14:41:12 -070069
70static int fb_setSwapInterval(struct framebuffer_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070071 int interval)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070072{
73 char pval[PROPERTY_VALUE_MAX];
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 property_get("debug.egl.swapinterval", pval, "-1");
Iliyan Malchev202a77d2012-06-11 14:41:12 -070075 int property_interval = atoi(pval);
76 if (property_interval >= 0)
77 interval = property_interval;
78
79 fb_context_t* ctx = (fb_context_t*)dev;
80 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070082 if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
83 return -EINVAL;
84
85 m->swapInterval = interval;
86 return 0;
87}
88
89static int fb_setUpdateRect(struct framebuffer_device_t* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070090 int l, int t, int w, int h)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070091{
92 if (((w|h) <= 0) || ((l|t)<0))
93 return -EINVAL;
94 fb_context_t* ctx = (fb_context_t*)dev;
95 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -070096 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070097 m->info.reserved[0] = 0x54445055; // "UPDT";
98 m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16);
99 m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16);
100 return 0;
101}
102
103static void *disp_loop(void *ptr)
104{
105 struct qbuf_t nxtBuf;
106 static int cur_buf=-1;
107 private_module_t *m = reinterpret_cast<private_module_t*>(ptr);
108
109 while (1) {
110 pthread_mutex_lock(&(m->qlock));
111
112 // wait (sleep) while display queue is empty;
113 if (m->disp.isEmpty()) {
114 pthread_cond_wait(&(m->qpost),&(m->qlock));
115 }
116
117 // dequeue next buff to display and lock it
118 nxtBuf = m->disp.getHeadValue();
119 m->disp.pop();
120 pthread_mutex_unlock(&(m->qlock));
121
122 // post buf out to display synchronously
123 private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>
Naseer Ahmed29a26812012-06-14 00:56:20 -0700124 (nxtBuf.buf);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700125 const size_t offset = hnd->base - m->framebuffer->base;
126 m->info.activate = FB_ACTIVATE_VBL;
127 m->info.yoffset = offset / m->finfo.line_length;
128
129#if defined(HDMI_DUAL_DISPLAY)
130 pthread_mutex_lock(&m->overlayLock);
131 m->orientation = neworientation;
132 m->currentOffset = offset;
133 m->hdmiStateChanged = true;
134 pthread_cond_signal(&(m->overlayPost));
135 pthread_mutex_unlock(&m->overlayLock);
136#endif
137 if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
138 ALOGE("ERROR FBIOPUT_VSCREENINFO failed; frame not displayed");
139 }
140
141 CALC_FPS();
142
143 if (cur_buf == -1) {
144 int nxtAvail = ((nxtBuf.idx + 1) % m->numBuffers);
145 pthread_mutex_lock(&(m->avail[nxtBuf.idx].lock));
146 m->avail[nxtBuf.idx].is_avail = true;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147 m->avail[nxtBuf.idx].state = SUB;
148 pthread_cond_signal(&(m->avail[nxtBuf.idx].cond));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700149 pthread_mutex_unlock(&(m->avail[nxtBuf.idx].lock));
150 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151#if 0 //XXX: Triple FB
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700152 pthread_mutex_lock(&(m->avail[nxtBuf.idx].lock));
153 if (m->avail[nxtBuf.idx].state != SUB) {
154 ALOGE_IF(m->swapInterval != 0, "[%d] state %c, expected %c", nxtBuf.idx,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 framebufferStateName[m->avail[nxtBuf.idx].state],
156 framebufferStateName[SUB]);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700157 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700158
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700159 m->avail[nxtBuf.idx].state = REF;
160 pthread_mutex_unlock(&(m->avail[nxtBuf.idx].lock));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700161 if (m->avail[cur_buf].state != REF) {
162 ALOGE_IF(m->swapInterval != 0, "[%d] state %c, expected %c", cur_buf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 framebufferStateName[m->avail[cur_buf].state],
164 framebufferStateName[SUB]);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700165 }
166 m->avail[cur_buf].state = AVL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167#endif
168 pthread_mutex_lock(&(m->avail[cur_buf].lock));
169 m->avail[cur_buf].is_avail = true;
170 pthread_cond_signal(&(m->avail[cur_buf].cond));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700171 pthread_mutex_unlock(&(m->avail[cur_buf].lock));
172 }
173 cur_buf = nxtBuf.idx;
174 }
175 return NULL;
176}
177
178#if defined(HDMI_DUAL_DISPLAY)
179static int closeHDMIChannel(private_module_t* m)
180{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181 // XXX - when enabling HDMI
182#if 0
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700183 Overlay* pTemp = m->pobjOverlay;
184 if(pTemp != NULL)
185 pTemp->closeChannel();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186#endif
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700187 return 0;
188}
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190// XXX - Complete when enabling HDMI
191#if 0
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700192static void getSecondaryDisplayDestinationInfo(private_module_t* m, overlay_rect&
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 rect, int& orientation)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700194{
195 Overlay* pTemp = m->pobjOverlay;
196 int width = pTemp->getFBWidth();
197 int height = pTemp->getFBHeight();
198 int fbwidth = m->info.xres, fbheight = m->info.yres;
199 rect.x = 0; rect.y = 0;
200 rect.w = width; rect.h = height;
201 int rot = m->orientation;
202 switch(rot) {
203 // ROT_0
204 case 0:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205 // ROT_180
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700206 case HAL_TRANSFORM_ROT_180:
207 pTemp->getAspectRatioPosition(fbwidth, fbheight,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208 &rect);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700209 if(rot == HAL_TRANSFORM_ROT_180)
210 orientation = HAL_TRANSFORM_ROT_180;
211 else
212 orientation = 0;
213 break;
214 // ROT_90
215 case HAL_TRANSFORM_ROT_90:
216 // ROT_270
217 case HAL_TRANSFORM_ROT_270:
218 //Calculate the Aspectratio for the UI
219 //in the landscape mode
220 //Width and height will be swapped as there
221 //is rotation
222 pTemp->getAspectRatioPosition(fbheight, fbwidth,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223 &rect);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700224
225 if(rot == HAL_TRANSFORM_ROT_90)
226 orientation = HAL_TRANSFORM_ROT_270;
227 else if(rot == HAL_TRANSFORM_ROT_270)
228 orientation = HAL_TRANSFORM_ROT_90;
229 break;
230 }
231 return;
232}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233#endif
234
235/* Determine overlay state based on whether hardware supports true UI
236 mirroring and whether video is playing or not */
237static ovutils::eOverlayState getOverlayState(struct private_module_t* module)
238{
239 overlay2::Overlay& ov = *(Overlay::getInstance());
240
241 // Default to existing state
242 ovutils::eOverlayState state = ov.getState();
243
244 // Sanity check
245 if (!module) {
246 ALOGE("%s: NULL module", __FUNCTION__);
247 return state;
248 }
249
250 // Check if video is playing or not
251 if (module->videoOverlay) {
252 // Video is playing, check if hardware supports true UI mirroring
253 if (module->trueMirrorSupport) {
254 // True UI mirroring is supported by hardware
255 if (ov.getState() == ovutils::OV_2D_VIDEO_ON_PANEL) {
256 // Currently playing 2D video
257 state = ovutils::OV_2D_TRUE_UI_MIRROR;
258 } else if (ov.getState() == ovutils::OV_3D_VIDEO_ON_2D_PANEL) {
259 // Currently playing M3D video
260 // FIXME: Support M3D true UI mirroring
261 state = ovutils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV;
262 }
263 } else {
264 // True UI mirroring is not supported by hardware
265 if (ov.getState() == ovutils::OV_2D_VIDEO_ON_PANEL) {
266 // Currently playing 2D video
267 state = ovutils::OV_2D_VIDEO_ON_PANEL_TV;
268 } else if (ov.getState() == ovutils::OV_3D_VIDEO_ON_2D_PANEL) {
269 // Currently playing M3D video
270 state = ovutils::OV_3D_VIDEO_ON_2D_PANEL_2D_TV;
271 }
272 }
273 } else {
274 // Video is not playing, true UI mirroring support is irrelevant
275 state = ovutils::OV_UI_MIRROR;
276 }
277
278 return state;
279}
280
281/* Set overlay state */
282static void setOverlayState(ovutils::eOverlayState state)
283{
284 overlay2::Overlay& ov = *(Overlay::getInstance());
285 ov.setState(state);
286}
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700287
288static void *hdmi_ui_loop(void *ptr)
289{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700290 private_module_t* m = reinterpret_cast<private_module_t*>(ptr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700291 while (1) {
292 pthread_mutex_lock(&m->overlayLock);
293 while(!(m->hdmiStateChanged))
294 pthread_cond_wait(&(m->overlayPost), &(m->overlayLock));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700296 m->hdmiStateChanged = false;
297 if (m->exitHDMIUILoop) {
298 pthread_mutex_unlock(&m->overlayLock);
299 return NULL;
300 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700301
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302 // No need to mirror UI if HDMI is not on
303 if (!m->enableHDMIOutput) {
304 ALOGE_IF(FB_DEBUG, "%s: hdmi not ON", __FUNCTION__);
305 pthread_mutex_unlock(&m->overlayLock);
306 continue;
307 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700308
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309 overlay2::OverlayMgr* ovMgr =
310 overlay2::OverlayMgrSingleton::getOverlayMgr();
311 overlay2::Overlay& ov = ovMgr->ov();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700312
Naseer Ahmed29a26812012-06-14 00:56:20 -0700313 // Set overlay state
314 ovutils::eOverlayState state = getOverlayState(m);
315 setOverlayState(state);
316
317 // Determine the RGB pipe for UI depending on the state
318 ovutils::eDest dest = ovutils::OV_PIPE_ALL;
319 if (state == ovutils::OV_2D_TRUE_UI_MIRROR) {
320 // True UI mirroring state: external RGB pipe is OV_PIPE2
321 dest = ovutils::OV_PIPE2;
322 } else if (state == ovutils::OV_UI_MIRROR) {
323 // UI-only mirroring state: external RGB pipe is OV_PIPE0
324 dest = ovutils::OV_PIPE0;
325 } else {
326 // No UI in this case
327 pthread_mutex_unlock(&m->overlayLock);
328 continue;
329 }
330
331 if (m->hdmiMirroringState == HDMI_UI_MIRRORING) {
332 int alignedW = ALIGN(m->info.xres, 32);
333
334 private_handle_t const* hnd =
335 reinterpret_cast<private_handle_t const*>(m->framebuffer);
336 unsigned int width = alignedW;
337 unsigned int height = hnd->height;
338 unsigned int format = hnd->format;
339 unsigned int size = hnd->size/m->numBuffers;
340
341 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
342 // External display connected during secure video playback
343 // Open secure UI session
344 // NOTE: when external display is already connected and then secure
345 // playback is started, we dont have to do anything
346 if (m->secureVideoOverlay) {
347 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700348 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700349
350 ovutils::Whf whf(width, height, format, size);
351 ovutils::PipeArgs parg(mdpFlags,
352 ovutils::OVERLAY_TRANSFORM_0,
353 whf,
354 ovutils::WAIT,
355 ovutils::ZORDER_0,
356 ovutils::IS_FG_OFF,
357 ovutils::ROT_FLAG_ENABLED);
358 ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
359 bool ret = ov.setSource(pargs, dest);
360 if (!ret) {
361 ALOGE("%s setSource failed", __FUNCTION__);
362 }
363
364 // we need to communicate m->orientation that will get some
365 // modifications within setParameter func.
366 // FIXME that is ugly.
367 const ovutils::Params prms (ovutils::OVERLAY_TRANSFORM_UI,
368 m->orientation);
369 ov.setParameter(prms, dest);
370 if (!ret) {
371 ALOGE("%s setParameter failed transform", __FUNCTION__);
372 }
373
374 // x,y,w,h
375 ovutils::Dim dcrop(0, 0, m->info.xres, m->info.yres);
376 ov.setMemoryId(m->framebuffer->fd, dest);
377 ret = ov.setCrop(dcrop, dest);
378 if (!ret) {
379 ALOGE("%s setCrop failed", __FUNCTION__);
380 }
381
382 ovutils::Dim pdim (m->info.xres,
383 m->info.yres,
384 0,
385 0,
386 m->orientation);
387 ret = ov.setPosition(pdim, dest);
388 if (!ret) {
389 ALOGE("%s setPosition failed", __FUNCTION__);
390 }
391
392 if (!ov.commit(dest)) {
393 ALOGE("%s commit fails", __FUNCTION__);
394 }
395
396 ret = ov.queueBuffer(m->currentOffset, dest);
397 if (!ret) {
398 ALOGE("%s queueBuffer failed", __FUNCTION__);
399 }
400 } else {
401 setOverlayState(ovutils::OV_CLOSED);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700402 }
403 pthread_mutex_unlock(&m->overlayLock);
404 }
405 return NULL;
406}
407
408static int fb_videoOverlayStarted(struct framebuffer_device_t* dev, int started)
409{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700410 ALOGE_IF(FB_DEBUG, "%s started=%d", __FUNCTION__, started);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700411 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700412 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700413 pthread_mutex_lock(&m->overlayLock);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700414 if(started != m->videoOverlay) {
415 m->videoOverlay = started;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700416 m->hdmiStateChanged = true;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700417 if (!m->trueMirrorSupport) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700418 if (started) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700419 m->hdmiMirroringState = HDMI_NO_MIRRORING;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420 ovutils::eOverlayState state = getOverlayState(m);
421 setOverlayState(state);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700422 } else if (m->enableHDMIOutput)
423 m->hdmiMirroringState = HDMI_UI_MIRRORING;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424 } else {
425 if (m->videoOverlay == VIDEO_3D_OVERLAY_STARTED) {
426 ALOGE_IF(FB_DEBUG, "3D Video Started, stop mirroring!");
427 m->hdmiMirroringState = HDMI_NO_MIRRORING;
428 ovutils::eOverlayState state = getOverlayState(m);
429 setOverlayState(state);
430 }
431 else if (m->enableHDMIOutput) {
432 m->hdmiMirroringState = HDMI_UI_MIRRORING;
433 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700434 }
435 }
436 pthread_mutex_unlock(&m->overlayLock);
437 return 0;
438}
439
440static int fb_enableHDMIOutput(struct framebuffer_device_t* dev, int externaltype)
441{
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442 ALOGE_IF(FB_DEBUG, "%s externaltype=%d", __FUNCTION__, externaltype);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700443 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700444 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700445 pthread_mutex_lock(&m->overlayLock);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700446 //Check if true mirroring can be supported
Naseer Ahmed29a26812012-06-14 00:56:20 -0700447 m->trueMirrorSupport = ovutils::FrameBufferInfo::getInstance()->supportTrueMirroring();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700448 m->enableHDMIOutput = externaltype;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700449 if(externaltype) {
450 if (m->trueMirrorSupport) {
451 m->hdmiMirroringState = HDMI_UI_MIRRORING;
452 } else {
453 if(!m->videoOverlay)
454 m->hdmiMirroringState = HDMI_UI_MIRRORING;
455 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700456 } else if (!externaltype) {
457 // Either HDMI is disconnected or suspend occurred
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700458 m->hdmiMirroringState = HDMI_NO_MIRRORING;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700459 ovutils::eOverlayState state = getOverlayState(m);
460 setOverlayState(state);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700461 }
462 m->hdmiStateChanged = true;
463 pthread_cond_signal(&(m->overlayPost));
464 pthread_mutex_unlock(&m->overlayLock);
465 return 0;
466}
467
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700468static int fb_orientationChanged(struct framebuffer_device_t* dev, int orientation)
469{
470 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700471 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700472 pthread_mutex_lock(&m->overlayLock);
473 neworientation = orientation;
474 pthread_mutex_unlock(&m->overlayLock);
475 return 0;
476}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700477
478static int handle_open_secure_start(private_module_t* m) {
479 pthread_mutex_lock(&m->overlayLock);
480 m->hdmiMirroringState = HDMI_NO_MIRRORING;
481 m->secureVideoOverlay = true;
482 pthread_mutex_unlock(&m->overlayLock);
483 return 0;
484}
485
486static int handle_open_secure_end(private_module_t* m) {
487 pthread_mutex_lock(&m->overlayLock);
488 if (m->enableHDMIOutput) {
489 if (m->trueMirrorSupport) {
490 m->hdmiMirroringState = HDMI_UI_MIRRORING;
491 } else if(!m->videoOverlay) {
492 m->hdmiMirroringState = HDMI_UI_MIRRORING;
493 }
494 m->hdmiStateChanged = true;
495 pthread_cond_signal(&(m->overlayPost));
496 }
497 pthread_mutex_unlock(&m->overlayLock);
498 return 0;
499}
500
501static int handle_close_secure_start(private_module_t* m) {
502 pthread_mutex_lock(&m->overlayLock);
503 m->hdmiMirroringState = HDMI_NO_MIRRORING;
504 m->secureVideoOverlay = false;
505 pthread_mutex_unlock(&m->overlayLock);
506 return 0;
507}
508
509static int handle_close_secure_end(private_module_t* m) {
510 pthread_mutex_lock(&m->overlayLock);
511 if (m->enableHDMIOutput) {
512 if (m->trueMirrorSupport) {
513 m->hdmiMirroringState = HDMI_UI_MIRRORING;
514 } else if(!m->videoOverlay) {
515 m->hdmiMirroringState = HDMI_UI_MIRRORING;
516 }
517 m->hdmiStateChanged = true;
518 pthread_cond_signal(&(m->overlayPost));
519 }
520 pthread_mutex_unlock(&m->overlayLock);
521 return 0;
522}
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700523#endif
524
Naseer Ahmed29a26812012-06-14 00:56:20 -0700525
526
527/* fb_perform - used to add custom event and handle them in fb HAL
528 * Used for external display related functions as of now
529 */
530static int fb_perform(struct framebuffer_device_t* dev, int event, int value)
531{
532 private_module_t* m = reinterpret_cast<private_module_t*>(
533 dev->common.module);
534 switch(event) {
535#if defined(HDMI_DUAL_DISPLAY)
536 case EVENT_EXTERNAL_DISPLAY:
537 fb_enableHDMIOutput(dev, value);
538 break;
539 case EVENT_VIDEO_OVERLAY:
540 fb_videoOverlayStarted(dev, value);
541 break;
542 case EVENT_ORIENTATION_CHANGE:
543 fb_orientationChanged(dev, value);
544 break;
545 case EVENT_OVERLAY_STATE_CHANGE:
546 if (value == OVERLAY_STATE_CHANGE_START) {
547 // When state change starts, get a lock on overlay
548 pthread_mutex_lock(&m->overlayLock);
549 } else if (value == OVERLAY_STATE_CHANGE_END) {
550 // When state change is complete, unlock overlay
551 pthread_mutex_unlock(&m->overlayLock);
552 }
553 break;
554 case EVENT_OPEN_SECURE_START:
555 handle_open_secure_start(m);
556 break;
557 case EVENT_OPEN_SECURE_END:
558 handle_open_secure_end(m);
559 break;
560 case EVENT_CLOSE_SECURE_START:
561 handle_close_secure_start(m);
562 break;
563 case EVENT_CLOSE_SECURE_END:
564 handle_close_secure_end(m);
565 break;
566#endif
567 default:
568 ALOGE("In %s: UNKNOWN Event = %d!!!", __FUNCTION__, event);
569 break;
570 }
571 return 0;
572}
573
574
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700575static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
576{
577 if (private_handle_t::validate(buffer) < 0)
578 return -EINVAL;
579
Naseer Ahmed29a26812012-06-14 00:56:20 -0700580 int nxtIdx;//, futureIdx = -1;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700581 bool reuse;
582 struct qbuf_t qb;
583 fb_context_t* ctx = (fb_context_t*)dev;
584
Naseer Ahmed00fd6a52012-07-03 21:23:12 -0700585 private_handle_t const* hnd =
586 reinterpret_cast<private_handle_t const*>(buffer);
587 private_module_t* m =
588 reinterpret_cast<private_module_t*>(dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700589
590 if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
591
592 reuse = false;
593 nxtIdx = (m->currentIdx + 1) % m->numBuffers;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700594 //futureIdx = (nxtIdx + 1) % m->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700595 if (m->swapInterval == 0) {
596 // if SwapInterval = 0 and no buffers available then reuse
597 // current buf for next rendering so don't post new buffer
598 if (pthread_mutex_trylock(&(m->avail[nxtIdx].lock))) {
599 reuse = true;
600 } else {
601 if (! m->avail[nxtIdx].is_avail)
602 reuse = true;
603 pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
604 }
605 }
606
607 if(!reuse){
608 // unlock previous ("current") Buffer and lock the new buffer
609 m->base.lock(&m->base, buffer,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700610 PRIV_USAGE_LOCKED_FOR_POST,
611 0,0, m->info.xres, m->info.yres, NULL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700612
613 // post/queue the new buffer
614 pthread_mutex_lock(&(m->avail[nxtIdx].lock));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700615 m->avail[nxtIdx].is_avail = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700616#if 0 //XXX: Triple FB
617 if (m->avail[nxtIdx].is_avail != true) {
618 ALOGE_IF(m->swapInterval != 0, "Found %d buf to be not avail", nxtIdx);
619 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700620
621 if (m->avail[nxtIdx].state != AVL) {
622 ALOGD("[%d] state %c, expected %c", nxtIdx,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700623 framebufferStateName[m->avail[nxtIdx].state],
624 framebufferStateName[AVL]);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700625 }
626
627 m->avail[nxtIdx].state = SUB;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700628#endif
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700629 pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
630
631 qb.idx = nxtIdx;
632 qb.buf = buffer;
633 pthread_mutex_lock(&(m->qlock));
634 m->disp.push(qb);
635 pthread_cond_signal(&(m->qpost));
636 pthread_mutex_unlock(&(m->qlock));
637
638 if (m->currentBuffer)
639 m->base.unlock(&m->base, m->currentBuffer);
640
641 m->currentBuffer = buffer;
642 m->currentIdx = nxtIdx;
643 } else {
644 if (m->currentBuffer)
645 m->base.unlock(&m->base, m->currentBuffer);
646 m->base.lock(&m->base, buffer,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700647 PRIV_USAGE_LOCKED_FOR_POST,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700648 0,0, m->info.xres, m->info.yres, NULL);
649 m->currentBuffer = buffer;
650 }
651
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700652 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700653 return 0;
654}
655
656static int fb_compositionComplete(struct framebuffer_device_t* dev)
657{
658 // TODO: Properly implement composition complete callback
659 glFinish();
660
661 return 0;
662}
663
664static int fb_lockBuffer(struct framebuffer_device_t* dev, int index)
665{
666 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700667 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700668
669 // Return immediately if the buffer is available
670 if ((m->avail[index].state == AVL) || (m->swapInterval == 0))
671 return 0;
672
673 pthread_mutex_lock(&(m->avail[index].lock));
674 while (m->avail[index].state != AVL) {
675 pthread_cond_wait(&(m->avail[index].cond),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700676 &(m->avail[index].lock));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700677 }
678 pthread_mutex_unlock(&(m->avail[index].lock));
679
680 return 0;
681}
682
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700683int mapFrameBufferLocked(struct private_module_t* module)
684{
685 // already initialized...
686 if (module->framebuffer) {
687 return 0;
688 }
689 char const * const device_template[] = {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700690 "/dev/graphics/fb%u",
691 "/dev/fb%u",
692 0 };
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700693
694 int fd = -1;
695 int i=0;
696 char name[64];
697 char property[PROPERTY_VALUE_MAX];
698
699 while ((fd==-1) && device_template[i]) {
700 snprintf(name, 64, device_template[i], 0);
701 fd = open(name, O_RDWR, 0);
702 i++;
703 }
704 if (fd < 0)
705 return -errno;
706
707 struct fb_fix_screeninfo finfo;
708 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
709 return -errno;
710
711 struct fb_var_screeninfo info;
712 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
713 return -errno;
714
715 info.reserved[0] = 0;
716 info.reserved[1] = 0;
717 info.reserved[2] = 0;
718 info.xoffset = 0;
719 info.yoffset = 0;
720 info.activate = FB_ACTIVATE_NOW;
721
722 /* Interpretation of offset for color fields: All offsets are from the right,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700723 * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
724 * can use the offset as right argument to <<). A pixel afterwards is a bit
725 * stream and is written to video memory as that unmodified. This implies
726 * big-endian byte order if bits_per_pixel is greater than 8.
727 */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700728
729 if(info.bits_per_pixel == 32) {
730 /*
731 * Explicitly request RGBA_8888
732 */
733 info.bits_per_pixel = 32;
734 info.red.offset = 24;
735 info.red.length = 8;
736 info.green.offset = 16;
737 info.green.length = 8;
738 info.blue.offset = 8;
739 info.blue.length = 8;
740 info.transp.offset = 0;
741 info.transp.length = 8;
742
743 /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we do
744 * not use the MDP for composition (i.e. hw composition == 0), ask for
745 * RGBA instead of RGBX. */
746 if (property_get("debug.sf.hw", property, NULL) > 0 && atoi(property) == 0)
747 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700748 else if(property_get("debug.composition.type", property, NULL) > 0 &&
749 (strncmp(property, "mdp", 3) == 0))
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700750 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
751 else
752 module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888;
753 } else {
754 /*
755 * Explicitly request 5/6/5
756 */
757 info.bits_per_pixel = 16;
758 info.red.offset = 11;
759 info.red.length = 5;
760 info.green.offset = 5;
761 info.green.length = 6;
762 info.blue.offset = 0;
763 info.blue.length = 5;
764 info.transp.offset = 0;
765 info.transp.length = 0;
766 module->fbFormat = HAL_PIXEL_FORMAT_RGB_565;
767 }
768
769 //adreno needs 4k aligned offsets. Max hole size is 4096-1
770 int size = roundUpToPageSize(info.yres * info.xres * (info.bits_per_pixel/8));
771
772 /*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700773 * Request NUM_BUFFERS screens (at least 2 for page flipping)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700774 */
775 int numberOfBuffers = (int)(finfo.smem_len/size);
776 ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers);
777
778 if (property_get("debug.gr.numframebuffers", property, NULL) > 0) {
779 int num = atoi(property);
780 if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) {
781 numberOfBuffers = num;
782 }
783 }
784 if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX)
785 numberOfBuffers = NUM_FRAMEBUFFERS_MAX;
786
787 ALOGV("We support %d buffers", numberOfBuffers);
788
789 //consider the included hole by 4k alignment
790 uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
791 info.yres_virtual = (size * numberOfBuffers) / line_length;
792
793 uint32_t flags = PAGE_FLIP;
794 if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
795 info.yres_virtual = size / line_length;
796 flags &= ~PAGE_FLIP;
797 ALOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");
798 }
799
800 if (info.yres_virtual < ((size * 2) / line_length) ) {
801 // we need at least 2 for page-flipping
802 info.yres_virtual = size / line_length;
803 flags &= ~PAGE_FLIP;
804 ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700805 info.yres_virtual, info.yres*2);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700806 }
807
808 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
809 return -errno;
810
811 if (int(info.width) <= 0 || int(info.height) <= 0) {
812 // the driver doesn't return that information
813 // default to 160 dpi
814 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
815 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
816 }
817
818 float xdpi = (info.xres * 25.4f) / info.width;
819 float ydpi = (info.yres * 25.4f) / info.height;
choongryeol.lee26145b82012-06-26 23:41:00 -0700820 //The reserved[3] field is used to store FPS by the driver.
821 float fps = info.reserved[3];
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700822
Naseer Ahmed29a26812012-06-14 00:56:20 -0700823 ALOGI("using (fd=%d)\n"
824 "id = %s\n"
825 "xres = %d px\n"
826 "yres = %d px\n"
827 "xres_virtual = %d px\n"
828 "yres_virtual = %d px\n"
829 "bpp = %d\n"
830 "r = %2u:%u\n"
831 "g = %2u:%u\n"
832 "b = %2u:%u\n",
833 fd,
834 finfo.id,
835 info.xres,
836 info.yres,
837 info.xres_virtual,
838 info.yres_virtual,
839 info.bits_per_pixel,
840 info.red.offset, info.red.length,
841 info.green.offset, info.green.length,
842 info.blue.offset, info.blue.length
843 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700844
Naseer Ahmed29a26812012-06-14 00:56:20 -0700845 ALOGI("width = %d mm (%f dpi)\n"
846 "height = %d mm (%f dpi)\n"
847 "refresh rate = %.2f Hz\n",
848 info.width, xdpi,
849 info.height, ydpi,
850 fps
851 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700852
853
854 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
855 return -errno;
856
857 if (finfo.smem_len <= 0)
858 return -errno;
859
860 module->flags = flags;
861 module->info = info;
862 module->finfo = finfo;
863 module->xdpi = xdpi;
864 module->ydpi = ydpi;
865 module->fps = fps;
866
867#ifdef NO_SURFACEFLINGER_SWAPINTERVAL
868 char pval[PROPERTY_VALUE_MAX];
869 property_get("debug.gr.swapinterval", pval, "1");
870 module->swapInterval = atoi(pval);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700871 if (module->swapInterval < PRIV_MIN_SWAP_INTERVAL ||
872 module->swapInterval > PRIV_MAX_SWAP_INTERVAL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700873 module->swapInterval = 1;
874 ALOGW("Out of range (%d to %d) value for debug.gr.swapinterval, using 1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700875 PRIV_MIN_SWAP_INTERVAL,
876 PRIV_MAX_SWAP_INTERVAL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700877 }
878
879#else
880 /* when surfaceflinger supports swapInterval then can just do this */
881 module->swapInterval = 1;
882#endif
883
884 CALC_INIT();
885
886 module->currentIdx = -1;
887 pthread_cond_init(&(module->qpost), NULL);
888 pthread_mutex_init(&(module->qlock), NULL);
889 for (i = 0; i < NUM_FRAMEBUFFERS_MAX; i++) {
890 pthread_mutex_init(&(module->avail[i].lock), NULL);
891 pthread_cond_init(&(module->avail[i].cond), NULL);
892 module->avail[i].is_avail = true;
893 module->avail[i].state = AVL;
894 }
895
896 /* create display update thread */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700897 pthread_t disp_thread;
898 if (pthread_create(&disp_thread, NULL, &disp_loop, (void *) module)) {
899 return -errno;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700900 }
901
902 /*
903 * map the framebuffer
904 */
905
906 int err;
907 module->numBuffers = info.yres_virtual / info.yres;
908 module->bufferMask = 0;
909 //adreno needs page aligned offsets. Align the fbsize to pagesize.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700910 size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
911 module->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700912 module->framebuffer = new private_handle_t(fd, fbSize,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700913 private_handle_t::PRIV_FLAGS_USES_PMEM,
914 BUFFER_TYPE_UI,
915 module->fbFormat, info.xres, info.yres);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700916 void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
917 if (vaddr == MAP_FAILED) {
918 ALOGE("Error mapping the framebuffer (%s)", strerror(errno));
919 return -errno;
920 }
921 module->framebuffer->base = intptr_t(vaddr);
922 memset(vaddr, 0, fbSize);
923
924#if defined(HDMI_DUAL_DISPLAY)
925 /* Overlay for HDMI*/
926 pthread_mutex_init(&(module->overlayLock), NULL);
927 pthread_cond_init(&(module->overlayPost), NULL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700928 module->currentOffset = 0;
929 module->exitHDMIUILoop = false;
930 module->hdmiStateChanged = false;
931 pthread_t hdmiUIThread;
932 pthread_create(&hdmiUIThread, NULL, &hdmi_ui_loop, (void *) module);
933 module->hdmiMirroringState = HDMI_NO_MIRRORING;
934 module->trueMirrorSupport = false;
935#endif
936
937 return 0;
938}
939
940static int mapFrameBuffer(struct private_module_t* module)
941{
942 pthread_mutex_lock(&module->lock);
943 int err = mapFrameBufferLocked(module);
944 pthread_mutex_unlock(&module->lock);
945 return err;
946}
947
948/*****************************************************************************/
949
950static int fb_close(struct hw_device_t *dev)
951{
952 fb_context_t* ctx = (fb_context_t*)dev;
953#if defined(HDMI_DUAL_DISPLAY)
954 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700955 ctx->device.common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700956 pthread_mutex_lock(&m->overlayLock);
957 m->exitHDMIUILoop = true;
958 pthread_cond_signal(&(m->overlayPost));
959 pthread_mutex_unlock(&m->overlayLock);
960#endif
961 if (ctx) {
962 free(ctx);
963 }
964 return 0;
965}
966
967int fb_device_open(hw_module_t const* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700968 hw_device_t** device)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700969{
970 int status = -EINVAL;
971 if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
972 alloc_device_t* gralloc_device;
973 status = gralloc_open(module, &gralloc_device);
974 if (status < 0)
975 return status;
976
977 /* initialize our state here */
978 fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
979 memset(dev, 0, sizeof(*dev));
980
981 /* initialize the procs */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700982 dev->device.common.tag = HARDWARE_DEVICE_TAG;
983 dev->device.common.version = 0;
984 dev->device.common.module = const_cast<hw_module_t*>(module);
985 dev->device.common.close = fb_close;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700986 dev->device.setSwapInterval = fb_setSwapInterval;
987 dev->device.post = fb_post;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700988 dev->device.setUpdateRect = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700989 dev->device.compositionComplete = fb_compositionComplete;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700990
991 private_module_t* m = (private_module_t*)module;
992 status = mapFrameBuffer(m);
993 if (status >= 0) {
994 int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
995 const_cast<uint32_t&>(dev->device.flags) = 0;
996 const_cast<uint32_t&>(dev->device.width) = m->info.xres;
997 const_cast<uint32_t&>(dev->device.height) = m->info.yres;
998 const_cast<int&>(dev->device.stride) = stride;
999 const_cast<int&>(dev->device.format) = m->fbFormat;
1000 const_cast<float&>(dev->device.xdpi) = m->xdpi;
1001 const_cast<float&>(dev->device.ydpi) = m->ydpi;
1002 const_cast<float&>(dev->device.fps) = m->fps;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001003 const_cast<int&>(dev->device.minSwapInterval) = PRIV_MIN_SWAP_INTERVAL;
1004 const_cast<int&>(dev->device.maxSwapInterval) = PRIV_MAX_SWAP_INTERVAL;
Naseer Ahmed00fd6a52012-07-03 21:23:12 -07001005 const_cast<int&>(dev->device.numFramebuffers) = m->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001006 if (m->finfo.reserved[0] == 0x5444 &&
Naseer Ahmed29a26812012-06-14 00:56:20 -07001007 m->finfo.reserved[1] == 0x5055) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001008 dev->device.setUpdateRect = fb_setUpdateRect;
1009 ALOGD("UPDATE_ON_DEMAND supported");
1010 }
1011
1012 *device = &dev->device.common;
1013 }
1014
1015 // Close the gralloc module
1016 gralloc_close(gralloc_device);
1017 }
1018 return status;
1019}