2009-08-05 07:26:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2011-12-16 23:46:50 +00:00
|
|
|
* Copyright (c) 2010-2012 Code Aurora Forum. All rights reserved.
|
2009-08-05 07:26:21 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2009-08-13 05:55:02 +00:00
|
|
|
#include <sys/mman.h>
|
2009-08-19 01:39:57 +00:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
#include <cutils/ashmem.h>
|
|
|
|
#include <cutils/log.h>
|
2009-12-05 03:22:39 +00:00
|
|
|
#include <cutils/properties.h>
|
2011-08-23 12:17:08 +00:00
|
|
|
#include <utils/Timers.h>
|
2009-08-19 01:39:57 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
#include <hardware/hardware.h>
|
|
|
|
#include <hardware/gralloc.h>
|
|
|
|
|
2009-08-19 01:39:57 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2011-03-08 01:31:51 +00:00
|
|
|
#include <pthread.h>
|
2011-01-21 14:35:52 +00:00
|
|
|
#include <utils/Timers.h>
|
2009-08-19 01:39:57 +00:00
|
|
|
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#include <cutils/atomic.h>
|
|
|
|
|
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/msm_mdp.h>
|
|
|
|
|
2009-10-03 02:18:55 +00:00
|
|
|
#include <GLES/gl.h>
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
#include "gralloc_priv.h"
|
2009-08-19 01:39:57 +00:00
|
|
|
#include "gr.h"
|
2011-03-08 01:31:51 +00:00
|
|
|
#ifdef NO_SURFACEFLINGER_SWAPINTERVAL
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-22 01:05:54 +00:00
|
|
|
#include <utils/profiler.h>
|
2012-04-11 23:03:21 +00:00
|
|
|
#include <qcom_ui.h>
|
2012-01-20 06:53:50 +00:00
|
|
|
|
2011-01-21 14:35:52 +00:00
|
|
|
#define FB_DEBUG 0
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
|
|
|
#define EVEN_OUT(x) if (x & 0x0001) {x--;}
|
|
|
|
using overlay::Overlay;
|
|
|
|
/** min of int a, b */
|
|
|
|
static inline int min(int a, int b) {
|
|
|
|
return (a<b) ? a : b;
|
|
|
|
}
|
|
|
|
/** max of int a, b */
|
|
|
|
static inline int max(int a, int b) {
|
|
|
|
return (a>b) ? a : b;
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-13 05:55:02 +00:00
|
|
|
|
2011-01-21 14:35:52 +00:00
|
|
|
char framebufferStateName[] = {'S', 'R', 'A'};
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
enum {
|
|
|
|
MDDI_PANEL = '1',
|
|
|
|
EBI2_PANEL = '2',
|
|
|
|
LCDC_PANEL = '3',
|
|
|
|
EXT_MDDI_PANEL = '4',
|
|
|
|
TV_PANEL = '5'
|
|
|
|
};
|
2009-08-19 01:39:57 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
enum {
|
|
|
|
PAGE_FLIP = 0x00000001,
|
|
|
|
LOCKED = 0x00000002
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fb_context_t {
|
|
|
|
framebuffer_device_t device;
|
|
|
|
};
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
static int neworientation;
|
2011-08-23 12:17:08 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2009-08-13 05:55:02 +00:00
|
|
|
static void
|
2009-11-04 02:42:05 +00:00
|
|
|
msm_copy_buffer(buffer_handle_t handle, int fd,
|
|
|
|
int width, int height, int format,
|
2009-08-05 07:26:21 +00:00
|
|
|
int x, int y, int w, int h);
|
|
|
|
|
|
|
|
static int fb_setSwapInterval(struct framebuffer_device_t* dev,
|
|
|
|
int interval)
|
|
|
|
{
|
2012-01-11 17:42:50 +00:00
|
|
|
char pval[PROPERTY_VALUE_MAX];
|
2012-03-27 19:57:58 +00:00
|
|
|
property_get("debug.egl.swapinterval", pval, "-1");
|
2012-01-11 17:42:50 +00:00
|
|
|
int property_interval = atoi(pval);
|
|
|
|
if (property_interval >= 0)
|
|
|
|
interval = property_interval;
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
fb_context_t* ctx = (fb_context_t*)dev;
|
2011-03-08 01:31:51 +00:00
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
2009-08-05 07:26:21 +00:00
|
|
|
if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
|
|
|
|
return -EINVAL;
|
2011-03-08 01:31:51 +00:00
|
|
|
|
|
|
|
m->swapInterval = interval;
|
2009-08-05 07:26:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fb_setUpdateRect(struct framebuffer_device_t* dev,
|
|
|
|
int l, int t, int w, int h)
|
|
|
|
{
|
|
|
|
if (((w|h) <= 0) || ((l|t)<0))
|
|
|
|
return -EINVAL;
|
|
|
|
fb_context_t* ctx = (fb_context_t*)dev;
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
m->info.reserved[0] = 0x54445055; // "UPDT";
|
|
|
|
m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16);
|
|
|
|
m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
static void *disp_loop(void *ptr)
|
|
|
|
{
|
|
|
|
struct qbuf_t nxtBuf;
|
|
|
|
static int cur_buf=-1;
|
|
|
|
private_module_t *m = reinterpret_cast<private_module_t*>(ptr);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
pthread_mutex_lock(&(m->qlock));
|
|
|
|
|
|
|
|
// wait (sleep) while display queue is empty;
|
2012-01-20 20:48:01 +00:00
|
|
|
if (m->disp.isEmpty()) {
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_cond_wait(&(m->qpost),&(m->qlock));
|
|
|
|
}
|
|
|
|
|
|
|
|
// dequeue next buff to display and lock it
|
|
|
|
nxtBuf = m->disp.getHeadValue();
|
|
|
|
m->disp.pop();
|
|
|
|
pthread_mutex_unlock(&(m->qlock));
|
|
|
|
|
|
|
|
// post buf out to display synchronously
|
|
|
|
private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>
|
|
|
|
(nxtBuf.buf);
|
|
|
|
const size_t offset = hnd->base - m->framebuffer->base;
|
|
|
|
m->info.activate = FB_ACTIVATE_VBL;
|
|
|
|
m->info.yoffset = offset / m->finfo.line_length;
|
|
|
|
|
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
m->orientation = neworientation;
|
|
|
|
m->currentOffset = offset;
|
2011-04-01 03:27:26 +00:00
|
|
|
m->hdmiStateChanged = true;
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_cond_signal(&(m->overlayPost));
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
#endif
|
|
|
|
if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
|
|
|
|
LOGE("ERROR FBIOPUT_VSCREENINFO failed; frame not displayed");
|
|
|
|
}
|
|
|
|
|
2012-05-03 13:10:09 +00:00
|
|
|
//Signal so that we can close channels if we need to
|
|
|
|
pthread_mutex_lock(&m->bufferPostLock);
|
|
|
|
m->bufferPostDone = true;
|
|
|
|
pthread_cond_signal(&m->bufferPostCond);
|
|
|
|
pthread_mutex_unlock(&m->bufferPostLock);
|
|
|
|
|
2012-01-20 06:53:50 +00:00
|
|
|
CALC_FPS();
|
2011-08-23 12:17:08 +00:00
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
if (cur_buf == -1) {
|
2011-01-21 14:35:52 +00:00
|
|
|
int nxtAvail = ((nxtBuf.idx + 1) % m->numBuffers);
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_lock(&(m->avail[nxtBuf.idx].lock));
|
|
|
|
m->avail[nxtBuf.idx].is_avail = true;
|
2011-01-21 14:35:52 +00:00
|
|
|
m->avail[nxtBuf.idx].state = REF;
|
|
|
|
pthread_cond_broadcast(&(m->avail[nxtBuf.idx].cond));
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_unlock(&(m->avail[nxtBuf.idx].lock));
|
|
|
|
} else {
|
2011-01-21 14:35:52 +00:00
|
|
|
pthread_mutex_lock(&(m->avail[nxtBuf.idx].lock));
|
|
|
|
if (m->avail[nxtBuf.idx].state != SUB) {
|
2011-04-15 08:44:33 +00:00
|
|
|
LOGE_IF(m->swapInterval != 0, "[%d] state %c, expected %c", nxtBuf.idx,
|
2011-01-21 14:35:52 +00:00
|
|
|
framebufferStateName[m->avail[nxtBuf.idx].state],
|
|
|
|
framebufferStateName[SUB]);
|
|
|
|
}
|
|
|
|
m->avail[nxtBuf.idx].state = REF;
|
|
|
|
pthread_mutex_unlock(&(m->avail[nxtBuf.idx].lock));
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_lock(&(m->avail[cur_buf].lock));
|
|
|
|
m->avail[cur_buf].is_avail = true;
|
2011-01-21 14:35:52 +00:00
|
|
|
if (m->avail[cur_buf].state != REF) {
|
2011-04-15 08:44:33 +00:00
|
|
|
LOGE_IF(m->swapInterval != 0, "[%d] state %c, expected %c", cur_buf,
|
2011-01-21 14:35:52 +00:00
|
|
|
framebufferStateName[m->avail[cur_buf].state],
|
|
|
|
framebufferStateName[REF]);
|
|
|
|
}
|
|
|
|
m->avail[cur_buf].state = AVL;
|
|
|
|
pthread_cond_broadcast(&(m->avail[cur_buf].cond));
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_unlock(&(m->avail[cur_buf].lock));
|
|
|
|
}
|
|
|
|
cur_buf = nxtBuf.idx;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
2012-01-18 05:23:58 +00:00
|
|
|
static void getSecondaryDisplayDestinationInfo(private_module_t* m, overlay_rect&
|
|
|
|
rect, int& orientation)
|
|
|
|
{
|
|
|
|
Overlay* pTemp = m->pobjOverlay;
|
|
|
|
int width = pTemp->getFBWidth();
|
|
|
|
int height = pTemp->getFBHeight();
|
|
|
|
int fbwidth = m->info.xres, fbheight = m->info.yres;
|
|
|
|
rect.x = 0; rect.y = 0;
|
|
|
|
rect.w = width; rect.h = height;
|
|
|
|
int rot = m->orientation;
|
|
|
|
switch(rot) {
|
|
|
|
// ROT_0
|
|
|
|
case 0:
|
|
|
|
// ROT_180
|
|
|
|
case HAL_TRANSFORM_ROT_180:
|
|
|
|
pTemp->getAspectRatioPosition(fbwidth, fbheight,
|
|
|
|
&rect);
|
|
|
|
if(rot == HAL_TRANSFORM_ROT_180)
|
|
|
|
orientation = HAL_TRANSFORM_ROT_180;
|
|
|
|
else
|
|
|
|
orientation = 0;
|
|
|
|
break;
|
|
|
|
// ROT_90
|
|
|
|
case HAL_TRANSFORM_ROT_90:
|
|
|
|
// ROT_270
|
|
|
|
case HAL_TRANSFORM_ROT_270:
|
|
|
|
//Calculate the Aspectratio for the UI
|
|
|
|
//in the landscape mode
|
|
|
|
//Width and height will be swapped as there
|
|
|
|
//is rotation
|
|
|
|
pTemp->getAspectRatioPosition(fbheight, fbwidth,
|
|
|
|
&rect);
|
|
|
|
|
|
|
|
if(rot == HAL_TRANSFORM_ROT_90)
|
|
|
|
orientation = HAL_TRANSFORM_ROT_270;
|
|
|
|
else if(rot == HAL_TRANSFORM_ROT_270)
|
|
|
|
orientation = HAL_TRANSFORM_ROT_90;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-08 21:58:29 +00:00
|
|
|
static int closeExternalChannel(private_module_t *m)
|
|
|
|
{
|
|
|
|
Overlay* pTemp = m->pobjOverlay;
|
|
|
|
if(pTemp != NULL)
|
|
|
|
pTemp->closeChannel();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int startExternalChannel(private_module_t *m)
|
|
|
|
{
|
|
|
|
Overlay *pTemp = m->pobjOverlay;
|
|
|
|
bool success = true;
|
|
|
|
int flags = WAIT_FOR_VSYNC;
|
|
|
|
if (!pTemp->isChannelUP()) {
|
|
|
|
int alignedW = ALIGN(m->info.xres, 32);
|
|
|
|
|
|
|
|
private_handle_t const* hnd =
|
|
|
|
reinterpret_cast<private_handle_t const*>(m->framebuffer);
|
|
|
|
overlay_buffer_info info;
|
|
|
|
info.width = alignedW;
|
|
|
|
info.height = hnd->height;
|
|
|
|
info.format = hnd->format;
|
|
|
|
info.size = hnd->size;
|
|
|
|
|
|
|
|
if (m->trueMirrorSupport)
|
|
|
|
flags &= ~WAIT_FOR_VSYNC;
|
|
|
|
// External display connected during secure video playback
|
|
|
|
// Open secure UI session
|
|
|
|
// NOTE: when external display is already connected and then secure
|
|
|
|
// playback is started, we dont have to do anything
|
|
|
|
if(m->secureVideoOverlay)
|
|
|
|
flags |= SECURE_OVERLAY_SESSION;
|
|
|
|
// start the overlay Channel for mirroring
|
|
|
|
// m->enableHDMIOutput corresponds to the fbnum
|
|
|
|
|
|
|
|
success = pTemp->startChannel(info, m->enableHDMIOutput,
|
|
|
|
false, true, 0, VG0_PIPE, flags) &&
|
|
|
|
pTemp->setFd(m->framebuffer->fd) &&
|
|
|
|
pTemp->setCrop(0, 0, m->info.xres, m->info.yres);
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay_rect destRect;
|
|
|
|
int rot = 0;
|
|
|
|
int currOrientation = 0;
|
|
|
|
int currentX = 0, currentY = 0;
|
|
|
|
uint32_t currentW = 0, currentH = 0;
|
|
|
|
|
|
|
|
getSecondaryDisplayDestinationInfo(m, destRect, rot);
|
|
|
|
pTemp->getOrientation(currOrientation);
|
|
|
|
|
|
|
|
if(rot != currOrientation) {
|
|
|
|
success &= pTemp->setTransform(rot);
|
|
|
|
}
|
|
|
|
|
|
|
|
pTemp->getPosition(currentX, currentY, currentW, currentH);
|
|
|
|
|
|
|
|
if ((currentX != destRect.x) || (currentY != destRect.y) ||
|
|
|
|
(currentW != destRect.w) || (currentH != destRect.h)) {
|
|
|
|
success &= pTemp->setPosition(destRect.x, destRect.y, destRect.w,
|
|
|
|
destRect.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m->trueMirrorSupport) {
|
|
|
|
// if video is started the UI channel should be NO_WAIT.
|
|
|
|
flags = !m->videoOverlay ? WAIT_FOR_VSYNC : 0;
|
|
|
|
pTemp->updateOverlayFlags(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
static void *hdmi_ui_loop(void *ptr)
|
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
ptr);
|
|
|
|
while (1) {
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
2011-04-01 03:27:26 +00:00
|
|
|
while(!(m->hdmiStateChanged))
|
|
|
|
pthread_cond_wait(&(m->overlayPost), &(m->overlayLock));
|
|
|
|
m->hdmiStateChanged = false;
|
2011-03-08 01:31:51 +00:00
|
|
|
if (m->exitHDMIUILoop) {
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-26 02:16:07 +00:00
|
|
|
int flags = WAIT_FOR_VSYNC;
|
2012-05-08 21:58:29 +00:00
|
|
|
const int NO_ERROR = 0;
|
|
|
|
Overlay* pTemp = m->pobjOverlay;
|
|
|
|
if(m->hdmiMirroringState == HDMI_UI_MIRRORING) {
|
|
|
|
if (startExternalChannel(m) == NO_ERROR) {
|
|
|
|
pTemp->queueBuffer(m->currentOffset);
|
2011-03-08 01:31:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fb_videoOverlayStarted(struct framebuffer_device_t* dev, int started)
|
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
Overlay* pTemp = m->pobjOverlay;
|
2011-03-16 20:23:20 +00:00
|
|
|
if(started != m->videoOverlay) {
|
2011-12-07 06:18:21 +00:00
|
|
|
m->videoOverlay = started;
|
|
|
|
if (!m->trueMirrorSupport) {
|
|
|
|
m->hdmiStateChanged = true;
|
|
|
|
if (started && pTemp) {
|
|
|
|
m->hdmiMirroringState = HDMI_NO_MIRRORING;
|
2012-05-08 21:58:29 +00:00
|
|
|
closeExternalChannel(m);
|
2011-12-07 06:18:21 +00:00
|
|
|
} else if (m->enableHDMIOutput)
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
2011-03-16 20:23:20 +00:00
|
|
|
pthread_cond_signal(&(m->overlayPost));
|
|
|
|
}
|
2011-03-08 01:31:51 +00:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-16 23:46:50 +00:00
|
|
|
static int fb_enableHDMIOutput(struct framebuffer_device_t* dev, int externaltype)
|
2011-03-08 01:31:51 +00:00
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
Overlay* pTemp = m->pobjOverlay;
|
2012-02-28 00:10:04 +00:00
|
|
|
//Check if true mirroring can be supported
|
|
|
|
m->trueMirrorSupport = FrameBufferInfo::getInstance()->canSupportTrueMirroring();
|
2011-12-16 23:46:50 +00:00
|
|
|
m->enableHDMIOutput = externaltype;
|
|
|
|
LOGE("In fb_enableHDMIOutput: externaltype = %d", m->enableHDMIOutput);
|
|
|
|
if(externaltype) {
|
2011-12-07 06:18:21 +00:00
|
|
|
if (m->trueMirrorSupport) {
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
} else {
|
|
|
|
if(!m->videoOverlay)
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
}
|
2011-12-16 23:46:50 +00:00
|
|
|
} else if (!externaltype && pTemp) {
|
2011-12-07 06:18:21 +00:00
|
|
|
m->hdmiMirroringState = HDMI_NO_MIRRORING;
|
2012-05-08 21:58:29 +00:00
|
|
|
closeExternalChannel(m);
|
|
|
|
}
|
|
|
|
if(m->hdmiMirroringState == HDMI_UI_MIRRORING) {
|
|
|
|
startExternalChannel(m);
|
2011-12-07 06:18:21 +00:00
|
|
|
}
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-11 23:03:21 +00:00
|
|
|
static int fb_orientationChanged(struct framebuffer_device_t* dev, int orientation)
|
2011-03-08 01:31:51 +00:00
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
2012-04-11 23:03:21 +00:00
|
|
|
neworientation = orientation;
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-17 22:36:11 +00:00
|
|
|
|
|
|
|
static int handle_open_secure_start(private_module_t* m) {
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
m->hdmiMirroringState = HDMI_NO_MIRRORING;
|
|
|
|
m->secureVideoOverlay = true;
|
2012-05-08 21:58:29 +00:00
|
|
|
closeExternalChannel(m);
|
2012-04-17 22:36:11 +00:00
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_open_secure_end(private_module_t* m) {
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
if (m->enableHDMIOutput) {
|
|
|
|
if (m->trueMirrorSupport) {
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
} else if(!m->videoOverlay) {
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
}
|
|
|
|
m->hdmiStateChanged = true;
|
|
|
|
pthread_cond_signal(&(m->overlayPost));
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_close_secure_start(private_module_t* m) {
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
m->hdmiMirroringState = HDMI_NO_MIRRORING;
|
|
|
|
m->secureVideoOverlay = false;
|
2012-05-08 21:58:29 +00:00
|
|
|
closeExternalChannel(m);
|
2012-04-17 22:36:11 +00:00
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_close_secure_end(private_module_t* m) {
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
if (m->enableHDMIOutput) {
|
|
|
|
if (m->trueMirrorSupport) {
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
} else if(!m->videoOverlay) {
|
|
|
|
m->hdmiMirroringState = HDMI_UI_MIRRORING;
|
|
|
|
}
|
|
|
|
m->hdmiStateChanged = true;
|
|
|
|
pthread_cond_signal(&(m->overlayPost));
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-11 23:03:21 +00:00
|
|
|
#endif
|
2011-12-07 06:18:21 +00:00
|
|
|
|
2012-05-03 13:10:09 +00:00
|
|
|
//Wait until framebuffer content is displayed.
|
|
|
|
////This is called in the context of threadLoop.
|
|
|
|
////Display loop wakes this up after display.
|
|
|
|
static int fb_waitForBufferPost(struct framebuffer_device_t* dev)
|
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
pthread_mutex_lock(&m->bufferPostLock);
|
|
|
|
while(m->bufferPostDone == false) {
|
|
|
|
pthread_cond_wait(&(m->bufferPostCond), &(m->bufferPostLock));
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&m->bufferPostLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fb_resetBufferPostStatus(struct framebuffer_device_t* dev)
|
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
pthread_mutex_lock(&m->bufferPostLock);
|
|
|
|
m->bufferPostDone = false;
|
|
|
|
pthread_mutex_unlock(&m->bufferPostLock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-11 23:03:21 +00:00
|
|
|
/* fb_perform - used to add custom event and handle them in fb HAL
|
|
|
|
* Used for external display related functions as of now
|
|
|
|
*/
|
|
|
|
static int fb_perform(struct framebuffer_device_t* dev, int event, int value)
|
2011-03-08 01:31:51 +00:00
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
2012-04-11 23:03:21 +00:00
|
|
|
switch(event) {
|
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
|
|
|
case EVENT_EXTERNAL_DISPLAY:
|
|
|
|
fb_enableHDMIOutput(dev, value);
|
|
|
|
break;
|
|
|
|
case EVENT_VIDEO_OVERLAY:
|
|
|
|
fb_videoOverlayStarted(dev, value);
|
|
|
|
break;
|
|
|
|
case EVENT_ORIENTATION_CHANGE:
|
|
|
|
fb_orientationChanged(dev, value);
|
|
|
|
break;
|
2012-04-17 22:36:11 +00:00
|
|
|
case EVENT_OPEN_SECURE_START:
|
|
|
|
handle_open_secure_start(m);
|
|
|
|
break;
|
|
|
|
case EVENT_OPEN_SECURE_END:
|
|
|
|
handle_open_secure_end(m);
|
|
|
|
break;
|
|
|
|
case EVENT_CLOSE_SECURE_START:
|
|
|
|
handle_close_secure_start(m);
|
|
|
|
break;
|
|
|
|
case EVENT_CLOSE_SECURE_END:
|
|
|
|
handle_close_secure_end(m);
|
|
|
|
break;
|
2011-03-08 01:31:51 +00:00
|
|
|
#endif
|
2012-05-03 13:10:09 +00:00
|
|
|
case EVENT_RESET_POSTBUFFER:
|
|
|
|
fb_resetBufferPostStatus(dev);
|
|
|
|
break;
|
|
|
|
case EVENT_WAIT_POSTBUFFER:
|
|
|
|
fb_waitForBufferPost(dev);
|
|
|
|
break;
|
2012-04-11 23:03:21 +00:00
|
|
|
default:
|
|
|
|
LOGE("In %s: UNKNOWN Event = %d!!!", __FUNCTION__, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
|
|
|
|
{
|
|
|
|
if (private_handle_t::validate(buffer) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-21 14:35:52 +00:00
|
|
|
int nxtIdx, futureIdx = -1;
|
2011-03-08 01:31:51 +00:00
|
|
|
bool reuse;
|
|
|
|
struct qbuf_t qb;
|
2009-08-05 07:26:21 +00:00
|
|
|
fb_context_t* ctx = (fb_context_t*)dev;
|
|
|
|
|
|
|
|
private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
|
|
|
|
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
|
2009-08-19 01:39:57 +00:00
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
reuse = false;
|
2011-01-21 14:35:52 +00:00
|
|
|
nxtIdx = (m->currentIdx + 1) % m->numBuffers;
|
|
|
|
futureIdx = (nxtIdx + 1) % m->numBuffers;
|
2011-03-08 01:31:51 +00:00
|
|
|
|
|
|
|
if (m->swapInterval == 0) {
|
|
|
|
// if SwapInterval = 0 and no buffers available then reuse
|
|
|
|
// current buf for next rendering so don't post new buffer
|
|
|
|
if (pthread_mutex_trylock(&(m->avail[nxtIdx].lock))) {
|
|
|
|
reuse = true;
|
|
|
|
} else {
|
|
|
|
if (! m->avail[nxtIdx].is_avail)
|
|
|
|
reuse = true;
|
|
|
|
pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
|
|
|
|
}
|
|
|
|
}
|
2009-08-05 07:26:21 +00:00
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
if(!reuse){
|
|
|
|
// unlock previous ("current") Buffer and lock the new buffer
|
|
|
|
m->base.lock(&m->base, buffer,
|
|
|
|
private_module_t::PRIV_USAGE_LOCKED_FOR_POST,
|
|
|
|
0,0, m->info.xres, m->info.yres, NULL);
|
|
|
|
|
|
|
|
// post/queue the new buffer
|
|
|
|
pthread_mutex_lock(&(m->avail[nxtIdx].lock));
|
2011-01-21 14:35:52 +00:00
|
|
|
if (m->avail[nxtIdx].is_avail != true) {
|
2011-11-21 01:05:55 +00:00
|
|
|
LOGE_IF(m->swapInterval != 0, "Found %d buf to be not avail", nxtIdx);
|
2011-01-21 14:35:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
m->avail[nxtIdx].is_avail = false;
|
2011-01-21 14:35:52 +00:00
|
|
|
|
|
|
|
if (m->avail[nxtIdx].state != AVL) {
|
2011-11-21 01:05:55 +00:00
|
|
|
LOGD("[%d] state %c, expected %c", nxtIdx,
|
|
|
|
framebufferStateName[m->avail[nxtIdx].state],
|
|
|
|
framebufferStateName[AVL]);
|
2011-01-21 14:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m->avail[nxtIdx].state = SUB;
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_unlock(&(m->avail[nxtIdx].lock));
|
|
|
|
|
|
|
|
qb.idx = nxtIdx;
|
|
|
|
qb.buf = buffer;
|
|
|
|
pthread_mutex_lock(&(m->qlock));
|
|
|
|
m->disp.push(qb);
|
|
|
|
pthread_cond_signal(&(m->qpost));
|
|
|
|
pthread_mutex_unlock(&(m->qlock));
|
|
|
|
|
2011-09-19 00:35:45 +00:00
|
|
|
if (m->currentBuffer)
|
2011-03-08 01:31:51 +00:00
|
|
|
m->base.unlock(&m->base, m->currentBuffer);
|
2011-09-19 00:35:45 +00:00
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
m->currentBuffer = buffer;
|
|
|
|
m->currentIdx = nxtIdx;
|
|
|
|
} else {
|
|
|
|
if (m->currentBuffer)
|
|
|
|
m->base.unlock(&m->base, m->currentBuffer);
|
|
|
|
m->base.lock(&m->base, buffer,
|
|
|
|
private_module_t::PRIV_USAGE_LOCKED_FOR_POST,
|
|
|
|
0,0, m->info.xres, m->info.yres, NULL);
|
|
|
|
m->currentBuffer = buffer;
|
2009-08-05 07:26:21 +00:00
|
|
|
}
|
2011-03-08 01:31:51 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
} else {
|
|
|
|
void* fb_vaddr;
|
|
|
|
void* buffer_vaddr;
|
2011-11-16 21:41:37 +00:00
|
|
|
m->base.lock(&m->base, m->framebuffer,
|
|
|
|
GRALLOC_USAGE_SW_WRITE_RARELY,
|
2009-08-05 07:26:21 +00:00
|
|
|
0, 0, m->info.xres, m->info.yres,
|
|
|
|
&fb_vaddr);
|
|
|
|
|
2011-11-16 21:41:37 +00:00
|
|
|
m->base.lock(&m->base, buffer,
|
|
|
|
GRALLOC_USAGE_SW_READ_RARELY,
|
2009-08-05 07:26:21 +00:00
|
|
|
0, 0, m->info.xres, m->info.yres,
|
|
|
|
&buffer_vaddr);
|
|
|
|
|
|
|
|
//memcpy(fb_vaddr, buffer_vaddr, m->finfo.line_length * m->info.yres);
|
2009-08-13 05:55:02 +00:00
|
|
|
|
2009-11-04 02:42:05 +00:00
|
|
|
msm_copy_buffer(
|
|
|
|
m->framebuffer, m->framebuffer->fd,
|
|
|
|
m->info.xres, m->info.yres, m->fbFormat,
|
2009-08-05 07:26:21 +00:00
|
|
|
m->info.xoffset, m->info.yoffset,
|
|
|
|
m->info.width, m->info.height);
|
|
|
|
|
2011-11-16 21:41:37 +00:00
|
|
|
m->base.unlock(&m->base, buffer);
|
|
|
|
m->base.unlock(&m->base, m->framebuffer);
|
2009-08-05 07:26:21 +00:00
|
|
|
}
|
2009-08-13 05:55:02 +00:00
|
|
|
|
2011-01-21 14:35:52 +00:00
|
|
|
LOGD_IF(FB_DEBUG, "Framebuffer state: [0] = %c [1] = %c [2] = %c",
|
|
|
|
framebufferStateName[m->avail[0].state],
|
|
|
|
framebufferStateName[m->avail[1].state],
|
|
|
|
framebufferStateName[m->avail[2].state]);
|
2009-08-05 07:26:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-03 02:18:55 +00:00
|
|
|
static int fb_compositionComplete(struct framebuffer_device_t* dev)
|
|
|
|
{
|
2009-12-04 23:41:06 +00:00
|
|
|
// TODO: Properly implement composition complete callback
|
2009-10-03 02:18:55 +00:00
|
|
|
glFinish();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-19 00:35:45 +00:00
|
|
|
static int fb_lockBuffer(struct framebuffer_device_t* dev, int index)
|
2011-01-21 14:35:52 +00:00
|
|
|
{
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
dev->common.module);
|
|
|
|
|
|
|
|
// Return immediately if the buffer is available
|
2011-04-15 08:44:33 +00:00
|
|
|
if ((m->avail[index].state == AVL) || (m->swapInterval == 0))
|
2011-01-21 14:35:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&(m->avail[index].lock));
|
|
|
|
while (m->avail[index].state != AVL) {
|
|
|
|
pthread_cond_wait(&(m->avail[index].cond),
|
|
|
|
&(m->avail[index].lock));
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&(m->avail[index].lock));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
int mapFrameBufferLocked(struct private_module_t* module)
|
|
|
|
{
|
|
|
|
// already initialized...
|
|
|
|
if (module->framebuffer) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
char const * const device_template[] = {
|
|
|
|
"/dev/graphics/fb%u",
|
|
|
|
"/dev/fb%u",
|
|
|
|
0 };
|
|
|
|
|
|
|
|
int fd = -1;
|
|
|
|
int i=0;
|
|
|
|
char name[64];
|
2011-01-21 14:35:52 +00:00
|
|
|
char property[PROPERTY_VALUE_MAX];
|
2009-08-05 07:26:21 +00:00
|
|
|
|
|
|
|
while ((fd==-1) && device_template[i]) {
|
|
|
|
snprintf(name, 64, device_template[i], 0);
|
|
|
|
fd = open(name, O_RDWR, 0);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (fd < 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
struct fb_fix_screeninfo finfo;
|
|
|
|
if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
struct fb_var_screeninfo info;
|
|
|
|
if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
info.reserved[0] = 0;
|
|
|
|
info.reserved[1] = 0;
|
|
|
|
info.reserved[2] = 0;
|
|
|
|
info.xoffset = 0;
|
|
|
|
info.yoffset = 0;
|
|
|
|
info.activate = FB_ACTIVATE_NOW;
|
|
|
|
|
2009-11-04 02:42:05 +00:00
|
|
|
/* Interpretation of offset for color fields: All offsets are from the right,
|
|
|
|
* inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
|
|
|
|
* can use the offset as right argument to <<). A pixel afterwards is a bit
|
|
|
|
* stream and is written to video memory as that unmodified. This implies
|
|
|
|
* big-endian byte order if bits_per_pixel is greater than 8.
|
|
|
|
*/
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
if(info.bits_per_pixel == 32) {
|
2011-11-16 21:41:37 +00:00
|
|
|
/*
|
|
|
|
* Explicitly request RGBA_8888
|
|
|
|
*/
|
|
|
|
info.bits_per_pixel = 32;
|
|
|
|
info.red.offset = 24;
|
|
|
|
info.red.length = 8;
|
|
|
|
info.green.offset = 16;
|
|
|
|
info.green.length = 8;
|
|
|
|
info.blue.offset = 8;
|
|
|
|
info.blue.length = 8;
|
|
|
|
info.transp.offset = 0;
|
|
|
|
info.transp.length = 8;
|
|
|
|
|
|
|
|
/* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we do
|
|
|
|
* not use the MDP for composition (i.e. hw composition == 0), ask for
|
|
|
|
* RGBA instead of RGBX. */
|
|
|
|
if (property_get("debug.sf.hw", property, NULL) > 0 && atoi(property) == 0)
|
|
|
|
module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
|
|
|
|
else if(property_get("debug.composition.type", property, NULL) > 0 && (strncmp(property, "mdp", 3) == 0))
|
|
|
|
module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
|
|
|
|
else
|
|
|
|
module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888;
|
2011-03-08 01:31:51 +00:00
|
|
|
} else {
|
2011-11-16 21:41:37 +00:00
|
|
|
/*
|
|
|
|
* Explicitly request 5/6/5
|
|
|
|
*/
|
|
|
|
info.bits_per_pixel = 16;
|
|
|
|
info.red.offset = 11;
|
|
|
|
info.red.length = 5;
|
|
|
|
info.green.offset = 5;
|
|
|
|
info.green.length = 6;
|
|
|
|
info.blue.offset = 0;
|
|
|
|
info.blue.length = 5;
|
|
|
|
info.transp.offset = 0;
|
|
|
|
info.transp.length = 0;
|
|
|
|
module->fbFormat = HAL_PIXEL_FORMAT_RGB_565;
|
2011-03-08 01:31:51 +00:00
|
|
|
}
|
2012-01-23 10:43:38 +00:00
|
|
|
|
|
|
|
//adreno needs 4k aligned offsets. Max hole size is 4096-1
|
|
|
|
int size = roundUpToPageSize(info.yres * info.xres * (info.bits_per_pixel/8));
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
/*
|
|
|
|
* Request NUM_BUFFERS screens (at lest 2 for page flipping)
|
|
|
|
*/
|
2012-01-23 10:43:38 +00:00
|
|
|
int numberOfBuffers = (int)(finfo.smem_len/size);
|
2011-01-21 14:35:52 +00:00
|
|
|
LOGV("num supported framebuffers in kernel = %d", numberOfBuffers);
|
|
|
|
|
|
|
|
if (property_get("debug.gr.numframebuffers", property, NULL) > 0) {
|
|
|
|
int num = atoi(property);
|
|
|
|
if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) {
|
|
|
|
numberOfBuffers = num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX)
|
|
|
|
numberOfBuffers = NUM_FRAMEBUFFERS_MAX;
|
|
|
|
|
2012-03-16 19:27:49 +00:00
|
|
|
LOGV("We support %d buffers", numberOfBuffers);
|
2011-01-21 14:35:52 +00:00
|
|
|
|
2012-03-16 19:27:49 +00:00
|
|
|
//consider the included hole by 4k alignment
|
|
|
|
uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
|
|
|
|
info.yres_virtual = (size * numberOfBuffers) / line_length;
|
2009-08-05 07:26:21 +00:00
|
|
|
|
|
|
|
uint32_t flags = PAGE_FLIP;
|
|
|
|
if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
|
2012-03-16 19:27:49 +00:00
|
|
|
info.yres_virtual = size / line_length;
|
2009-08-05 07:26:21 +00:00
|
|
|
flags &= ~PAGE_FLIP;
|
|
|
|
LOGW("FBIOPUT_VSCREENINFO failed, page flipping not supported");
|
|
|
|
}
|
|
|
|
|
2012-03-16 19:27:49 +00:00
|
|
|
if (info.yres_virtual < ((size * 2) / line_length) ) {
|
2009-08-05 07:26:21 +00:00
|
|
|
// we need at least 2 for page-flipping
|
2012-03-16 19:27:49 +00:00
|
|
|
info.yres_virtual = size / line_length;
|
2009-08-05 07:26:21 +00:00
|
|
|
flags &= ~PAGE_FLIP;
|
|
|
|
LOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
|
|
|
|
info.yres_virtual, info.yres*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
if (int(info.width) <= 0 || int(info.height) <= 0) {
|
|
|
|
// the driver doesn't return that information
|
|
|
|
// default to 160 dpi
|
|
|
|
info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
|
|
|
|
info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
|
|
|
|
}
|
|
|
|
|
|
|
|
float xdpi = (info.xres * 25.4f) / info.width;
|
|
|
|
float ydpi = (info.yres * 25.4f) / info.height;
|
2011-05-07 02:13:59 +00:00
|
|
|
//The reserved[4] field is used to store FPS by the driver.
|
|
|
|
float fps = info.reserved[4];
|
2009-08-05 07:26:21 +00:00
|
|
|
|
|
|
|
LOGI( "using (fd=%d)\n"
|
|
|
|
"id = %s\n"
|
|
|
|
"xres = %d px\n"
|
|
|
|
"yres = %d px\n"
|
|
|
|
"xres_virtual = %d px\n"
|
|
|
|
"yres_virtual = %d px\n"
|
|
|
|
"bpp = %d\n"
|
|
|
|
"r = %2u:%u\n"
|
|
|
|
"g = %2u:%u\n"
|
|
|
|
"b = %2u:%u\n",
|
|
|
|
fd,
|
|
|
|
finfo.id,
|
|
|
|
info.xres,
|
|
|
|
info.yres,
|
|
|
|
info.xres_virtual,
|
|
|
|
info.yres_virtual,
|
|
|
|
info.bits_per_pixel,
|
|
|
|
info.red.offset, info.red.length,
|
|
|
|
info.green.offset, info.green.length,
|
|
|
|
info.blue.offset, info.blue.length
|
|
|
|
);
|
|
|
|
|
|
|
|
LOGI( "width = %d mm (%f dpi)\n"
|
|
|
|
"height = %d mm (%f dpi)\n"
|
|
|
|
"refresh rate = %.2f Hz\n",
|
|
|
|
info.width, xdpi,
|
|
|
|
info.height, ydpi,
|
|
|
|
fps
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
if (finfo.smem_len <= 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
module->flags = flags;
|
|
|
|
module->info = info;
|
|
|
|
module->finfo = finfo;
|
|
|
|
module->xdpi = xdpi;
|
|
|
|
module->ydpi = ydpi;
|
|
|
|
module->fps = fps;
|
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
#ifdef NO_SURFACEFLINGER_SWAPINTERVAL
|
|
|
|
char pval[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.gr.swapinterval", pval, "1");
|
|
|
|
module->swapInterval = atoi(pval);
|
|
|
|
if (module->swapInterval < private_module_t::PRIV_MIN_SWAP_INTERVAL ||
|
|
|
|
module->swapInterval > private_module_t::PRIV_MAX_SWAP_INTERVAL) {
|
|
|
|
module->swapInterval = 1;
|
|
|
|
LOGW("Out of range (%d to %d) value for debug.gr.swapinterval, using 1",
|
|
|
|
private_module_t::PRIV_MIN_SWAP_INTERVAL,
|
|
|
|
private_module_t::PRIV_MAX_SWAP_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* when surfaceflinger supports swapInterval then can just do this */
|
|
|
|
module->swapInterval = 1;
|
|
|
|
#endif
|
|
|
|
|
2012-01-20 06:53:50 +00:00
|
|
|
CALC_INIT();
|
2011-08-23 12:17:08 +00:00
|
|
|
|
2011-03-08 01:31:51 +00:00
|
|
|
module->currentIdx = -1;
|
|
|
|
pthread_cond_init(&(module->qpost), NULL);
|
|
|
|
pthread_mutex_init(&(module->qlock), NULL);
|
2011-01-21 14:35:52 +00:00
|
|
|
for (i = 0; i < NUM_FRAMEBUFFERS_MAX; i++) {
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_mutex_init(&(module->avail[i].lock), NULL);
|
|
|
|
pthread_cond_init(&(module->avail[i].cond), NULL);
|
|
|
|
module->avail[i].is_avail = true;
|
2011-01-21 14:35:52 +00:00
|
|
|
module->avail[i].state = AVL;
|
2011-11-16 21:41:37 +00:00
|
|
|
}
|
2011-03-08 01:31:51 +00:00
|
|
|
|
|
|
|
/* create display update thread */
|
|
|
|
pthread_t thread1;
|
|
|
|
if (pthread_create(&thread1, NULL, &disp_loop, (void *) module)) {
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
/*
|
|
|
|
* map the framebuffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
int err;
|
|
|
|
module->numBuffers = info.yres_virtual / info.yres;
|
|
|
|
module->bufferMask = 0;
|
2012-01-23 10:43:38 +00:00
|
|
|
//adreno needs page aligned offsets. Align the fbsize to pagesize.
|
|
|
|
size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres) * module->numBuffers;
|
|
|
|
module->framebuffer = new private_handle_t(fd, fbSize,
|
|
|
|
private_handle_t::PRIV_FLAGS_USES_PMEM, BUFFER_TYPE_UI,
|
|
|
|
module->fbFormat, info.xres, info.yres);
|
2009-08-05 07:26:21 +00:00
|
|
|
void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
if (vaddr == MAP_FAILED) {
|
|
|
|
LOGE("Error mapping the framebuffer (%s)", strerror(errno));
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
module->framebuffer->base = intptr_t(vaddr);
|
|
|
|
memset(vaddr, 0, fbSize);
|
2011-03-08 01:31:51 +00:00
|
|
|
|
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
|
|
|
/* Overlay for HDMI*/
|
|
|
|
pthread_mutex_init(&(module->overlayLock), NULL);
|
|
|
|
pthread_cond_init(&(module->overlayPost), NULL);
|
|
|
|
module->pobjOverlay = new Overlay();
|
|
|
|
module->currentOffset = 0;
|
|
|
|
module->exitHDMIUILoop = false;
|
2011-04-01 03:27:26 +00:00
|
|
|
module->hdmiStateChanged = false;
|
2011-03-08 01:31:51 +00:00
|
|
|
pthread_t hdmiUIThread;
|
|
|
|
pthread_create(&hdmiUIThread, NULL, &hdmi_ui_loop, (void *) module);
|
2011-12-07 06:18:21 +00:00
|
|
|
module->hdmiMirroringState = HDMI_NO_MIRRORING;
|
2012-02-28 00:10:04 +00:00
|
|
|
module->trueMirrorSupport = false;
|
2011-03-08 01:31:51 +00:00
|
|
|
#endif
|
2012-05-03 13:10:09 +00:00
|
|
|
pthread_mutex_init(&(module->bufferPostLock), NULL);
|
|
|
|
pthread_cond_init(&(module->bufferPostCond), NULL);
|
|
|
|
module->bufferPostDone = false;
|
2011-03-08 01:31:51 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mapFrameBuffer(struct private_module_t* module)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&module->lock);
|
|
|
|
int err = mapFrameBufferLocked(module);
|
|
|
|
pthread_mutex_unlock(&module->lock);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_close(struct hw_device_t *dev)
|
|
|
|
{
|
|
|
|
fb_context_t* ctx = (fb_context_t*)dev;
|
2011-03-08 01:31:51 +00:00
|
|
|
#if defined(HDMI_DUAL_DISPLAY)
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
ctx->device.common.module);
|
|
|
|
pthread_mutex_lock(&m->overlayLock);
|
|
|
|
m->exitHDMIUILoop = true;
|
|
|
|
pthread_cond_signal(&(m->overlayPost));
|
|
|
|
pthread_mutex_unlock(&m->overlayLock);
|
|
|
|
#endif
|
2009-08-05 07:26:21 +00:00
|
|
|
if (ctx) {
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fb_device_open(hw_module_t const* module, const char* name,
|
|
|
|
hw_device_t** device)
|
|
|
|
{
|
|
|
|
int status = -EINVAL;
|
|
|
|
if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
|
|
|
|
alloc_device_t* gralloc_device;
|
|
|
|
status = gralloc_open(module, &gralloc_device);
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* initialize our state here */
|
|
|
|
fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
|
|
|
|
/* initialize the procs */
|
|
|
|
dev->device.common.tag = HARDWARE_DEVICE_TAG;
|
|
|
|
dev->device.common.version = 0;
|
|
|
|
dev->device.common.module = const_cast<hw_module_t*>(module);
|
|
|
|
dev->device.common.close = fb_close;
|
|
|
|
dev->device.setSwapInterval = fb_setSwapInterval;
|
|
|
|
dev->device.post = fb_post;
|
2009-08-13 05:55:02 +00:00
|
|
|
dev->device.setUpdateRect = 0;
|
2009-10-03 02:18:55 +00:00
|
|
|
dev->device.compositionComplete = fb_compositionComplete;
|
2011-09-19 00:35:45 +00:00
|
|
|
dev->device.lockBuffer = fb_lockBuffer;
|
2012-04-11 23:03:21 +00:00
|
|
|
dev->device.perform = fb_perform;
|
2009-08-05 07:26:21 +00:00
|
|
|
|
|
|
|
private_module_t* m = (private_module_t*)module;
|
|
|
|
status = mapFrameBuffer(m);
|
|
|
|
if (status >= 0) {
|
|
|
|
int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
|
|
|
|
const_cast<uint32_t&>(dev->device.flags) = 0;
|
|
|
|
const_cast<uint32_t&>(dev->device.width) = m->info.xres;
|
|
|
|
const_cast<uint32_t&>(dev->device.height) = m->info.yres;
|
|
|
|
const_cast<int&>(dev->device.stride) = stride;
|
2009-11-04 02:42:05 +00:00
|
|
|
const_cast<int&>(dev->device.format) = m->fbFormat;
|
2009-08-05 07:26:21 +00:00
|
|
|
const_cast<float&>(dev->device.xdpi) = m->xdpi;
|
|
|
|
const_cast<float&>(dev->device.ydpi) = m->ydpi;
|
|
|
|
const_cast<float&>(dev->device.fps) = m->fps;
|
2011-03-08 01:31:51 +00:00
|
|
|
const_cast<int&>(dev->device.minSwapInterval) = private_module_t::PRIV_MIN_SWAP_INTERVAL;
|
|
|
|
const_cast<int&>(dev->device.maxSwapInterval) = private_module_t::PRIV_MAX_SWAP_INTERVAL;
|
2011-01-21 14:35:52 +00:00
|
|
|
const_cast<int&>(dev->device.numFramebuffers) = m->numBuffers;
|
2009-08-13 05:55:02 +00:00
|
|
|
if (m->finfo.reserved[0] == 0x5444 &&
|
|
|
|
m->finfo.reserved[1] == 0x5055) {
|
|
|
|
dev->device.setUpdateRect = fb_setUpdateRect;
|
|
|
|
LOGD("UPDATE_ON_DEMAND supported");
|
|
|
|
}
|
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
*device = &dev->device.common;
|
|
|
|
}
|
2011-01-03 20:53:06 +00:00
|
|
|
|
|
|
|
// Close the gralloc module
|
|
|
|
gralloc_close(gralloc_device);
|
2009-08-05 07:26:21 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy a pmem buffer to the framebuffer */
|
|
|
|
|
2009-08-13 05:55:02 +00:00
|
|
|
static void
|
2009-11-04 02:42:05 +00:00
|
|
|
msm_copy_buffer(buffer_handle_t handle, int fd,
|
|
|
|
int width, int height, int format,
|
2009-08-05 07:26:21 +00:00
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
unsigned int count;
|
|
|
|
mdp_blit_req req;
|
|
|
|
} blit;
|
|
|
|
private_handle_t *priv = (private_handle_t*) handle;
|
|
|
|
|
|
|
|
memset(&blit, 0, sizeof(blit));
|
|
|
|
blit.count = 1;
|
|
|
|
|
|
|
|
blit.req.flags = 0;
|
|
|
|
blit.req.alpha = 0xff;
|
|
|
|
blit.req.transp_mask = 0xffffffff;
|
|
|
|
|
|
|
|
blit.req.src.width = width;
|
|
|
|
blit.req.src.height = height;
|
|
|
|
blit.req.src.offset = 0;
|
|
|
|
blit.req.src.memory_id = priv->fd;
|
2009-08-13 05:55:02 +00:00
|
|
|
|
2009-08-05 07:26:21 +00:00
|
|
|
blit.req.dst.width = width;
|
|
|
|
blit.req.dst.height = height;
|
|
|
|
blit.req.dst.offset = 0;
|
2011-11-16 21:41:37 +00:00
|
|
|
blit.req.dst.memory_id = fd;
|
2009-11-04 02:42:05 +00:00
|
|
|
blit.req.dst.format = format;
|
2009-08-05 07:26:21 +00:00
|
|
|
|
|
|
|
blit.req.src_rect.x = blit.req.dst_rect.x = x;
|
|
|
|
blit.req.src_rect.y = blit.req.dst_rect.y = y;
|
|
|
|
blit.req.src_rect.w = blit.req.dst_rect.w = w;
|
|
|
|
blit.req.src_rect.h = blit.req.dst_rect.h = h;
|
|
|
|
|
|
|
|
if (ioctl(fd, MSMFB_BLIT, &blit))
|
|
|
|
LOGE("MSMFB_BLIT failed = %d", -errno);
|
|
|
|
}
|