blob: 931024bc938f668b0fd04ae010772a40fd4682b2 [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
585 private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
586 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700587 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700588
589 if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
590
591 reuse = false;
592 nxtIdx = (m->currentIdx + 1) % m->numBuffers;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700593 //futureIdx = (nxtIdx + 1) % m->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700594 if (m->swapInterval == 0) {
595 // if SwapInterval = 0 and no buffers available then reuse
596 // current buf for next rendering so don't post new buffer
597 if (pthread_mutex_trylock(&(m->avail[nxtIdx].lock))) {
598 reuse = true;
599 } else {
600 if (! m->avail[nxtIdx].is_avail)
601 reuse = true;
602 pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
603 }
604 }
605
606 if(!reuse){
607 // unlock previous ("current") Buffer and lock the new buffer
608 m->base.lock(&m->base, buffer,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700609 PRIV_USAGE_LOCKED_FOR_POST,
610 0,0, m->info.xres, m->info.yres, NULL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700611
612 // post/queue the new buffer
613 pthread_mutex_lock(&(m->avail[nxtIdx].lock));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700614 m->avail[nxtIdx].is_avail = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700615#if 0 //XXX: Triple FB
616 if (m->avail[nxtIdx].is_avail != true) {
617 ALOGE_IF(m->swapInterval != 0, "Found %d buf to be not avail", nxtIdx);
618 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700619
620 if (m->avail[nxtIdx].state != AVL) {
621 ALOGD("[%d] state %c, expected %c", nxtIdx,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700622 framebufferStateName[m->avail[nxtIdx].state],
623 framebufferStateName[AVL]);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700624 }
625
626 m->avail[nxtIdx].state = SUB;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700627#endif
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700628 pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
629
630 qb.idx = nxtIdx;
631 qb.buf = buffer;
632 pthread_mutex_lock(&(m->qlock));
633 m->disp.push(qb);
634 pthread_cond_signal(&(m->qpost));
635 pthread_mutex_unlock(&(m->qlock));
636
637 if (m->currentBuffer)
638 m->base.unlock(&m->base, m->currentBuffer);
639
640 m->currentBuffer = buffer;
641 m->currentIdx = nxtIdx;
642 } else {
643 if (m->currentBuffer)
644 m->base.unlock(&m->base, m->currentBuffer);
645 m->base.lock(&m->base, buffer,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700646 PRIV_USAGE_LOCKED_FOR_POST,
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700647 0,0, m->info.xres, m->info.yres, NULL);
648 m->currentBuffer = buffer;
649 }
650
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700651 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700652 return 0;
653}
654
655static int fb_compositionComplete(struct framebuffer_device_t* dev)
656{
657 // TODO: Properly implement composition complete callback
658 glFinish();
659
660 return 0;
661}
662
663static int fb_lockBuffer(struct framebuffer_device_t* dev, int index)
664{
665 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700666 dev->common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700667
668 // Return immediately if the buffer is available
669 if ((m->avail[index].state == AVL) || (m->swapInterval == 0))
670 return 0;
671
672 pthread_mutex_lock(&(m->avail[index].lock));
673 while (m->avail[index].state != AVL) {
674 pthread_cond_wait(&(m->avail[index].cond),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700675 &(m->avail[index].lock));
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700676 }
677 pthread_mutex_unlock(&(m->avail[index].lock));
678
679 return 0;
680}
681
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700682int mapFrameBufferLocked(struct private_module_t* module)
683{
684 // already initialized...
685 if (module->framebuffer) {
686 return 0;
687 }
688 char const * const device_template[] = {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700689 "/dev/graphics/fb%u",
690 "/dev/fb%u",
691 0 };
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700692
693 int fd = -1;
694 int i=0;
695 char name[64];
696 char property[PROPERTY_VALUE_MAX];
697
698 while ((fd==-1) && device_template[i]) {
699 snprintf(name, 64, device_template[i], 0);
700 fd = open(name, O_RDWR, 0);
701 i++;
702 }
703 if (fd < 0)
704 return -errno;
705
706 struct fb_fix_screeninfo finfo;
707 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
708 return -errno;
709
710 struct fb_var_screeninfo info;
711 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
712 return -errno;
713
714 info.reserved[0] = 0;
715 info.reserved[1] = 0;
716 info.reserved[2] = 0;
717 info.xoffset = 0;
718 info.yoffset = 0;
719 info.activate = FB_ACTIVATE_NOW;
720
721 /* Interpretation of offset for color fields: All offsets are from the right,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700722 * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
723 * can use the offset as right argument to <<). A pixel afterwards is a bit
724 * stream and is written to video memory as that unmodified. This implies
725 * big-endian byte order if bits_per_pixel is greater than 8.
726 */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700727
728 if(info.bits_per_pixel == 32) {
729 /*
730 * Explicitly request RGBA_8888
731 */
732 info.bits_per_pixel = 32;
733 info.red.offset = 24;
734 info.red.length = 8;
735 info.green.offset = 16;
736 info.green.length = 8;
737 info.blue.offset = 8;
738 info.blue.length = 8;
739 info.transp.offset = 0;
740 info.transp.length = 8;
741
742 /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we do
743 * not use the MDP for composition (i.e. hw composition == 0), ask for
744 * RGBA instead of RGBX. */
745 if (property_get("debug.sf.hw", property, NULL) > 0 && atoi(property) == 0)
746 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700747 else if(property_get("debug.composition.type", property, NULL) > 0 &&
748 (strncmp(property, "mdp", 3) == 0))
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700749 module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
750 else
751 module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888;
752 } else {
753 /*
754 * Explicitly request 5/6/5
755 */
756 info.bits_per_pixel = 16;
757 info.red.offset = 11;
758 info.red.length = 5;
759 info.green.offset = 5;
760 info.green.length = 6;
761 info.blue.offset = 0;
762 info.blue.length = 5;
763 info.transp.offset = 0;
764 info.transp.length = 0;
765 module->fbFormat = HAL_PIXEL_FORMAT_RGB_565;
766 }
767
768 //adreno needs 4k aligned offsets. Max hole size is 4096-1
769 int size = roundUpToPageSize(info.yres * info.xres * (info.bits_per_pixel/8));
770
771 /*
Naseer Ahmed29a26812012-06-14 00:56:20 -0700772 * Request NUM_BUFFERS screens (at least 2 for page flipping)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700773 */
774 int numberOfBuffers = (int)(finfo.smem_len/size);
775 ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers);
776
777 if (property_get("debug.gr.numframebuffers", property, NULL) > 0) {
778 int num = atoi(property);
779 if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) {
780 numberOfBuffers = num;
781 }
782 }
783 if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX)
784 numberOfBuffers = NUM_FRAMEBUFFERS_MAX;
785
786 ALOGV("We support %d buffers", numberOfBuffers);
787
788 //consider the included hole by 4k alignment
789 uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
790 info.yres_virtual = (size * numberOfBuffers) / line_length;
791
792 uint32_t flags = PAGE_FLIP;
793 if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
794 info.yres_virtual = size / line_length;
795 flags &= ~PAGE_FLIP;
796 ALOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");
797 }
798
799 if (info.yres_virtual < ((size * 2) / line_length) ) {
800 // we need at least 2 for page-flipping
801 info.yres_virtual = size / line_length;
802 flags &= ~PAGE_FLIP;
803 ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700804 info.yres_virtual, info.yres*2);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700805 }
806
807 if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
808 return -errno;
809
810 if (int(info.width) <= 0 || int(info.height) <= 0) {
811 // the driver doesn't return that information
812 // default to 160 dpi
813 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
814 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
815 }
816
817 float xdpi = (info.xres * 25.4f) / info.width;
818 float ydpi = (info.yres * 25.4f) / info.height;
choongryeol.lee26145b82012-06-26 23:41:00 -0700819 //The reserved[3] field is used to store FPS by the driver.
820 float fps = info.reserved[3];
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700821
Naseer Ahmed29a26812012-06-14 00:56:20 -0700822 ALOGI("using (fd=%d)\n"
823 "id = %s\n"
824 "xres = %d px\n"
825 "yres = %d px\n"
826 "xres_virtual = %d px\n"
827 "yres_virtual = %d px\n"
828 "bpp = %d\n"
829 "r = %2u:%u\n"
830 "g = %2u:%u\n"
831 "b = %2u:%u\n",
832 fd,
833 finfo.id,
834 info.xres,
835 info.yres,
836 info.xres_virtual,
837 info.yres_virtual,
838 info.bits_per_pixel,
839 info.red.offset, info.red.length,
840 info.green.offset, info.green.length,
841 info.blue.offset, info.blue.length
842 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700843
Naseer Ahmed29a26812012-06-14 00:56:20 -0700844 ALOGI("width = %d mm (%f dpi)\n"
845 "height = %d mm (%f dpi)\n"
846 "refresh rate = %.2f Hz\n",
847 info.width, xdpi,
848 info.height, ydpi,
849 fps
850 );
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700851
852
853 if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
854 return -errno;
855
856 if (finfo.smem_len <= 0)
857 return -errno;
858
859 module->flags = flags;
860 module->info = info;
861 module->finfo = finfo;
862 module->xdpi = xdpi;
863 module->ydpi = ydpi;
864 module->fps = fps;
865
866#ifdef NO_SURFACEFLINGER_SWAPINTERVAL
867 char pval[PROPERTY_VALUE_MAX];
868 property_get("debug.gr.swapinterval", pval, "1");
869 module->swapInterval = atoi(pval);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700870 if (module->swapInterval < PRIV_MIN_SWAP_INTERVAL ||
871 module->swapInterval > PRIV_MAX_SWAP_INTERVAL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700872 module->swapInterval = 1;
873 ALOGW("Out of range (%d to %d) value for debug.gr.swapinterval, using 1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700874 PRIV_MIN_SWAP_INTERVAL,
875 PRIV_MAX_SWAP_INTERVAL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700876 }
877
878#else
879 /* when surfaceflinger supports swapInterval then can just do this */
880 module->swapInterval = 1;
881#endif
882
883 CALC_INIT();
884
885 module->currentIdx = -1;
886 pthread_cond_init(&(module->qpost), NULL);
887 pthread_mutex_init(&(module->qlock), NULL);
888 for (i = 0; i < NUM_FRAMEBUFFERS_MAX; i++) {
889 pthread_mutex_init(&(module->avail[i].lock), NULL);
890 pthread_cond_init(&(module->avail[i].cond), NULL);
891 module->avail[i].is_avail = true;
892 module->avail[i].state = AVL;
893 }
894
895 /* create display update thread */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700896 pthread_t disp_thread;
897 if (pthread_create(&disp_thread, NULL, &disp_loop, (void *) module)) {
898 return -errno;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700899 }
900
901 /*
902 * map the framebuffer
903 */
904
905 int err;
906 module->numBuffers = info.yres_virtual / info.yres;
907 module->bufferMask = 0;
908 //adreno needs page aligned offsets. Align the fbsize to pagesize.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700909 size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
910 module->numBuffers;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700911 module->framebuffer = new private_handle_t(fd, fbSize,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700912 private_handle_t::PRIV_FLAGS_USES_PMEM,
913 BUFFER_TYPE_UI,
914 module->fbFormat, info.xres, info.yres);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700915 void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
916 if (vaddr == MAP_FAILED) {
917 ALOGE("Error mapping the framebuffer (%s)", strerror(errno));
918 return -errno;
919 }
920 module->framebuffer->base = intptr_t(vaddr);
921 memset(vaddr, 0, fbSize);
922
923#if defined(HDMI_DUAL_DISPLAY)
924 /* Overlay for HDMI*/
925 pthread_mutex_init(&(module->overlayLock), NULL);
926 pthread_cond_init(&(module->overlayPost), NULL);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700927 module->currentOffset = 0;
928 module->exitHDMIUILoop = false;
929 module->hdmiStateChanged = false;
930 pthread_t hdmiUIThread;
931 pthread_create(&hdmiUIThread, NULL, &hdmi_ui_loop, (void *) module);
932 module->hdmiMirroringState = HDMI_NO_MIRRORING;
933 module->trueMirrorSupport = false;
934#endif
935
936 return 0;
937}
938
939static int mapFrameBuffer(struct private_module_t* module)
940{
941 pthread_mutex_lock(&module->lock);
942 int err = mapFrameBufferLocked(module);
943 pthread_mutex_unlock(&module->lock);
944 return err;
945}
946
947/*****************************************************************************/
948
949static int fb_close(struct hw_device_t *dev)
950{
951 fb_context_t* ctx = (fb_context_t*)dev;
952#if defined(HDMI_DUAL_DISPLAY)
953 private_module_t* m = reinterpret_cast<private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700954 ctx->device.common.module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700955 pthread_mutex_lock(&m->overlayLock);
956 m->exitHDMIUILoop = true;
957 pthread_cond_signal(&(m->overlayPost));
958 pthread_mutex_unlock(&m->overlayLock);
959#endif
960 if (ctx) {
961 free(ctx);
962 }
963 return 0;
964}
965
966int fb_device_open(hw_module_t const* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700967 hw_device_t** device)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700968{
969 int status = -EINVAL;
970 if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
971 alloc_device_t* gralloc_device;
972 status = gralloc_open(module, &gralloc_device);
973 if (status < 0)
974 return status;
975
976 /* initialize our state here */
977 fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
978 memset(dev, 0, sizeof(*dev));
979
980 /* initialize the procs */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700981 dev->device.common.tag = HARDWARE_DEVICE_TAG;
982 dev->device.common.version = 0;
983 dev->device.common.module = const_cast<hw_module_t*>(module);
984 dev->device.common.close = fb_close;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700985 dev->device.setSwapInterval = fb_setSwapInterval;
986 dev->device.post = fb_post;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700987 dev->device.setUpdateRect = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700988 dev->device.compositionComplete = fb_compositionComplete;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700989
990 private_module_t* m = (private_module_t*)module;
991 status = mapFrameBuffer(m);
992 if (status >= 0) {
993 int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
994 const_cast<uint32_t&>(dev->device.flags) = 0;
995 const_cast<uint32_t&>(dev->device.width) = m->info.xres;
996 const_cast<uint32_t&>(dev->device.height) = m->info.yres;
997 const_cast<int&>(dev->device.stride) = stride;
998 const_cast<int&>(dev->device.format) = m->fbFormat;
999 const_cast<float&>(dev->device.xdpi) = m->xdpi;
1000 const_cast<float&>(dev->device.ydpi) = m->ydpi;
1001 const_cast<float&>(dev->device.fps) = m->fps;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001002 const_cast<int&>(dev->device.minSwapInterval) = PRIV_MIN_SWAP_INTERVAL;
1003 const_cast<int&>(dev->device.maxSwapInterval) = PRIV_MAX_SWAP_INTERVAL;
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001004 if (m->finfo.reserved[0] == 0x5444 &&
Naseer Ahmed29a26812012-06-14 00:56:20 -07001005 m->finfo.reserved[1] == 0x5055) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001006 dev->device.setUpdateRect = fb_setUpdateRect;
1007 ALOGD("UPDATE_ON_DEMAND supported");
1008 }
1009
1010 *device = &dev->device.common;
1011 }
1012
1013 // Close the gralloc module
1014 gralloc_close(gralloc_device);
1015 }
1016 return status;
1017}