2012-06-14 07:56:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
* Copyright (C) 2012, Code Aurora Forum. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#include <cutils/atomic.h>
|
2012-07-21 19:17:13 +00:00
|
|
|
#include <EGL/egl.h>
|
2012-06-14 07:56:20 +00:00
|
|
|
|
2012-07-21 19:17:13 +00:00
|
|
|
#include <overlay.h>
|
|
|
|
#include <fb_priv.h>
|
2012-07-26 01:27:14 +00:00
|
|
|
#include <mdp_version.h>
|
2012-06-14 07:56:20 +00:00
|
|
|
#include "hwc_utils.h"
|
2012-07-21 19:17:13 +00:00
|
|
|
#include "hwc_qbuf.h"
|
2012-07-11 01:33:17 +00:00
|
|
|
#include "hwc_video.h"
|
2012-08-13 06:19:01 +00:00
|
|
|
#include "hwc_pip.h"
|
2012-06-26 00:34:58 +00:00
|
|
|
#include "hwc_uimirror.h"
|
2012-07-19 09:33:29 +00:00
|
|
|
#include "hwc_copybit.h"
|
2012-07-23 20:44:38 +00:00
|
|
|
#include "hwc_external.h"
|
2012-07-23 19:22:21 +00:00
|
|
|
#include "hwc_mdpcomp.h"
|
2012-07-22 02:06:55 +00:00
|
|
|
#include "hwc_extonly.h"
|
2012-08-29 00:56:00 +00:00
|
|
|
#include "qcom_ui.h"
|
2012-06-14 07:56:20 +00:00
|
|
|
|
2012-09-15 20:05:41 +00:00
|
|
|
#define VSYNC_DEBUG 0
|
2012-06-14 07:56:20 +00:00
|
|
|
using namespace qhwc;
|
|
|
|
|
|
|
|
static int hwc_device_open(const struct hw_module_t* module,
|
|
|
|
const char* name,
|
|
|
|
struct hw_device_t** device);
|
|
|
|
|
|
|
|
static struct hw_module_methods_t hwc_module_methods = {
|
|
|
|
open: hwc_device_open
|
|
|
|
};
|
|
|
|
|
|
|
|
hwc_module_t HAL_MODULE_INFO_SYM = {
|
|
|
|
common: {
|
|
|
|
tag: HARDWARE_MODULE_TAG,
|
|
|
|
version_major: 2,
|
|
|
|
version_minor: 0,
|
|
|
|
id: HWC_HARDWARE_MODULE_ID,
|
|
|
|
name: "Qualcomm Hardware Composer Module",
|
|
|
|
author: "CodeAurora Forum",
|
|
|
|
methods: &hwc_module_methods,
|
|
|
|
dso: 0,
|
|
|
|
reserved: {0},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save callback functions registered to HWC
|
|
|
|
*/
|
|
|
|
static void hwc_registerProcs(struct hwc_composer_device* dev,
|
|
|
|
hwc_procs_t const* procs)
|
|
|
|
{
|
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
|
|
|
if(!ctx) {
|
|
|
|
ALOGE("%s: Invalid context", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->device.reserved_proc[0] = (void*)procs;
|
2012-08-22 23:09:48 +00:00
|
|
|
|
2012-09-12 12:44:25 +00:00
|
|
|
// Now that we have the functions needed, kick off
|
|
|
|
// the uevent & vsync threads
|
2012-08-22 23:09:48 +00:00
|
|
|
init_uevent_thread(ctx);
|
2012-09-12 12:44:25 +00:00
|
|
|
init_vsync_thread(ctx);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
|
|
|
|
{
|
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
2012-07-11 01:33:17 +00:00
|
|
|
ctx->overlayInUse = false;
|
|
|
|
|
2012-09-06 01:18:51 +00:00
|
|
|
if(ctx->mSecureConfig == true) {
|
|
|
|
// This will tear down External Display Device.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-02 15:26:21 +00:00
|
|
|
if(ctx->mExtDisplay->getExternalDisplay())
|
|
|
|
ovutils::setExtType(ctx->mExtDisplay->getExternalDisplay());
|
2012-09-22 09:00:29 +00:00
|
|
|
if (ctx->hdmi_pending == true) {
|
|
|
|
if ((qdutils::MDPVersion::getInstance().getMDPVersion() >=
|
|
|
|
qdutils::MDP_V4_2) || (ctx->mOverlay->getState() !=
|
|
|
|
ovutils::OV_BYPASS_3_LAYER)) {
|
|
|
|
ctx->mExtDisplay->processUEventOnline((const char*)ctx->mHDMIEvent);
|
|
|
|
ctx->hdmi_pending = false;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 07:56:20 +00:00
|
|
|
if (LIKELY(list)) {
|
2012-07-22 02:06:55 +00:00
|
|
|
//reset for this draw round
|
|
|
|
VideoOverlay::reset();
|
2012-08-13 06:19:01 +00:00
|
|
|
VideoPIP::reset();
|
2012-07-22 02:06:55 +00:00
|
|
|
ExtOnly::reset();
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
getLayerStats(ctx, list);
|
2012-07-21 15:32:05 +00:00
|
|
|
// Mark all layers to COPYBIT initially
|
|
|
|
CopyBit::prepare(ctx, list);
|
2012-07-11 01:33:17 +00:00
|
|
|
if(VideoOverlay::prepare(ctx, list)) {
|
|
|
|
ctx->overlayInUse = true;
|
|
|
|
//Nothing here
|
2012-08-13 06:19:01 +00:00
|
|
|
} else if(VideoPIP::prepare(ctx, list)) {
|
|
|
|
ctx->overlayInUse = true;
|
2012-07-22 02:06:55 +00:00
|
|
|
} else if(ExtOnly::prepare(ctx, list)) {
|
|
|
|
ctx->overlayInUse = true;
|
2012-06-26 00:34:58 +00:00
|
|
|
} else if(UIMirrorOverlay::prepare(ctx, list)) {
|
|
|
|
ctx->overlayInUse = true;
|
2012-07-23 19:22:21 +00:00
|
|
|
} else if(MDPComp::configure(dev, list)) {
|
|
|
|
ctx->overlayInUse = true;
|
2012-07-11 01:33:17 +00:00
|
|
|
} else if (0) {
|
|
|
|
//Other features
|
|
|
|
ctx->overlayInUse = true;
|
2012-07-19 09:33:29 +00:00
|
|
|
} else { // Else set this flag to false, otherwise video cases
|
|
|
|
// fail in non-overlay targets.
|
|
|
|
ctx->overlayInUse = false;
|
2012-08-23 18:07:40 +00:00
|
|
|
ctx->mOverlay->setState(ovutils::OV_CLOSED);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
2012-09-14 17:34:58 +00:00
|
|
|
} else {
|
|
|
|
ctx->overlayInUse = false;
|
|
|
|
ctx->mOverlay->setState(ovutils::OV_CLOSED);
|
|
|
|
ctx->qbuf->unlockAll();
|
2012-08-29 00:56:00 +00:00
|
|
|
|
|
|
|
qdutils::CBUtils::checkforGPULayer(list);
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-21 19:17:13 +00:00
|
|
|
static int hwc_eventControl(struct hwc_composer_device* dev,
|
2012-07-28 02:49:03 +00:00
|
|
|
int event, int value)
|
2012-07-21 19:17:13 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2012-09-15 20:05:41 +00:00
|
|
|
static int prev_value, temp;
|
|
|
|
|
2012-07-21 19:17:13 +00:00
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
ctx->mFbDev->common.module);
|
|
|
|
switch(event) {
|
2012-08-08 02:56:31 +00:00
|
|
|
#ifndef NO_HW_VSYNC
|
2012-07-21 19:17:13 +00:00
|
|
|
case HWC_EVENT_VSYNC:
|
2012-09-15 20:05:41 +00:00
|
|
|
if (value == prev_value){
|
|
|
|
//TODO see why HWC gets repeated events
|
|
|
|
ALOGD_IF(VSYNC_DEBUG, "%s - VSYNC is already %s",
|
|
|
|
__FUNCTION__, (value)?"ENABLED":"DISABLED");
|
|
|
|
}
|
|
|
|
temp = ctx->vstate.enable;
|
2012-07-28 02:49:03 +00:00
|
|
|
if(ioctl(m->framebuffer->fd, MSMFB_OVERLAY_VSYNC_CTRL, &value) < 0)
|
2012-07-21 19:17:13 +00:00
|
|
|
ret = -errno;
|
2012-07-23 20:44:38 +00:00
|
|
|
|
2012-09-15 20:05:41 +00:00
|
|
|
/* vsync state change logic */
|
|
|
|
if (value == 1) {
|
|
|
|
//unblock vsync thread
|
|
|
|
pthread_mutex_lock(&ctx->vstate.lock);
|
|
|
|
ctx->vstate.enable = true;
|
|
|
|
pthread_cond_signal(&ctx->vstate.cond);
|
|
|
|
pthread_mutex_unlock(&ctx->vstate.lock);
|
2012-07-23 20:44:38 +00:00
|
|
|
}
|
2012-09-15 20:05:41 +00:00
|
|
|
if (value == 0 && temp) {
|
|
|
|
//vsync thread will block
|
|
|
|
pthread_mutex_lock(&ctx->vstate.lock);
|
|
|
|
ctx->vstate.enable = false;
|
|
|
|
pthread_mutex_unlock(&ctx->vstate.lock);
|
|
|
|
}
|
|
|
|
ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed from %s to %s",
|
|
|
|
(prev_value)?"ENABLED":"DISABLED", (value)?"ENABLED":"DISABLED");
|
|
|
|
prev_value = value;
|
|
|
|
/* vsync state change logic - end*/
|
|
|
|
|
|
|
|
if(ctx->mExtDisplay->isHDMIConfigured() &&
|
|
|
|
(ctx->mExtDisplay->getExternalDisplay()==EXTERN_DISPLAY_FB1)) {
|
2012-09-20 18:01:09 +00:00
|
|
|
// enableHDMIVsync will return -errno on error
|
2012-09-15 20:05:41 +00:00
|
|
|
ret = ctx->mExtDisplay->enableHDMIVsync(value);
|
|
|
|
}
|
2012-07-21 19:17:13 +00:00
|
|
|
break;
|
2012-08-08 02:56:31 +00:00
|
|
|
#endif
|
2012-07-28 02:49:03 +00:00
|
|
|
case HWC_EVENT_ORIENTATION:
|
|
|
|
ctx->deviceOrientation = value;
|
|
|
|
break;
|
2012-07-21 19:17:13 +00:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_query(struct hwc_composer_device* dev,
|
|
|
|
int param, int* value)
|
|
|
|
{
|
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
|
|
|
private_module_t* m = reinterpret_cast<private_module_t*>(
|
|
|
|
ctx->mFbDev->common.module);
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case HWC_BACKGROUND_LAYER_SUPPORTED:
|
|
|
|
// Not supported for now
|
|
|
|
value[0] = 0;
|
|
|
|
break;
|
|
|
|
case HWC_VSYNC_PERIOD:
|
|
|
|
value[0] = 1000000000.0 / m->fps;
|
|
|
|
ALOGI("fps: %d", value[0]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
static int hwc_set(hwc_composer_device_t *dev,
|
|
|
|
hwc_display_t dpy,
|
|
|
|
hwc_surface_t sur,
|
|
|
|
hwc_layer_list_t* list)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
hwc_context_t* ctx = (hwc_context_t*)(dev);
|
2012-08-27 17:49:18 +00:00
|
|
|
if (dpy && sur) {
|
|
|
|
if (LIKELY(list)) {
|
|
|
|
VideoOverlay::draw(ctx, list);
|
|
|
|
VideoPIP::draw(ctx,list);
|
|
|
|
ExtOnly::draw(ctx, list);
|
|
|
|
CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
|
|
|
|
MDPComp::draw(ctx, list);
|
|
|
|
}
|
|
|
|
eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
|
2012-09-10 18:39:45 +00:00
|
|
|
if (ctx->mMDP.hasOverlay) {
|
|
|
|
wait4fbPost(ctx);
|
|
|
|
//Can draw to HDMI only when fb_post is reached
|
|
|
|
UIMirrorOverlay::draw(ctx);
|
|
|
|
//HDMI commit and primary commit (PAN) happening in parallel
|
|
|
|
if(ctx->mExtDisplay->getExternalDisplay())
|
|
|
|
ctx->mExtDisplay->commit();
|
|
|
|
//Virtual barrier for threads to finish
|
|
|
|
wait4Pan(ctx);
|
|
|
|
}
|
2012-06-14 07:56:20 +00:00
|
|
|
} else {
|
2012-07-11 01:33:17 +00:00
|
|
|
ctx->mOverlay->setState(ovutils::OV_CLOSED);
|
2012-08-16 17:19:07 +00:00
|
|
|
ctx->qbuf->unlockAll();
|
2012-06-14 07:56:20 +00:00
|
|
|
}
|
2012-07-11 01:33:17 +00:00
|
|
|
|
|
|
|
|
2012-08-23 15:41:05 +00:00
|
|
|
ctx->qbuf->unlockAllPrevious();
|
2012-06-14 07:56:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_device_close(struct hw_device_t *dev)
|
|
|
|
{
|
|
|
|
if(!dev) {
|
2012-07-21 19:17:13 +00:00
|
|
|
ALOGE("%s: NULL device pointer", __FUNCTION__);
|
2012-06-14 07:56:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
closeContext((hwc_context_t*)dev);
|
|
|
|
free(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwc_device_open(const struct hw_module_t* module, const char* name,
|
|
|
|
struct hw_device_t** device)
|
|
|
|
{
|
|
|
|
int status = -EINVAL;
|
|
|
|
|
|
|
|
if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
|
|
|
|
struct hwc_context_t *dev;
|
|
|
|
dev = (hwc_context_t*)malloc(sizeof(*dev));
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
2012-07-21 19:17:13 +00:00
|
|
|
|
|
|
|
//Initialize hwc context
|
2012-06-14 07:56:20 +00:00
|
|
|
initContext(dev);
|
2012-07-21 19:17:13 +00:00
|
|
|
|
|
|
|
//Setup HWC methods
|
|
|
|
hwc_methods_t *methods;
|
|
|
|
methods = (hwc_methods_t *)malloc(sizeof(*methods));
|
|
|
|
memset(methods, 0, sizeof(*methods));
|
|
|
|
methods->eventControl = hwc_eventControl;
|
|
|
|
|
2012-06-14 07:56:20 +00:00
|
|
|
dev->device.common.tag = HARDWARE_DEVICE_TAG;
|
2012-09-12 12:44:25 +00:00
|
|
|
#ifndef NO_HW_VSYNC
|
|
|
|
//XXX: This disables hardware vsync on 8x55
|
|
|
|
// Fix when HW vsync is available on 8x55
|
|
|
|
if(dev->mMDP.version == 400 || (dev->mMDP.version >= 500)) {
|
|
|
|
#endif
|
|
|
|
dev->device.common.version = 0;
|
|
|
|
ALOGI("%s: Hardware VSYNC not supported", __FUNCTION__);
|
|
|
|
#ifndef NO_HW_VSYNC
|
|
|
|
} else {
|
|
|
|
dev->device.common.version = HWC_DEVICE_API_VERSION_0_3;
|
|
|
|
ALOGI("%s: Hardware VSYNC supported", __FUNCTION__);
|
|
|
|
}
|
2012-08-08 02:56:31 +00:00
|
|
|
#endif
|
2012-06-14 07:56:20 +00:00
|
|
|
dev->device.common.module = const_cast<hw_module_t*>(module);
|
|
|
|
dev->device.common.close = hwc_device_close;
|
|
|
|
dev->device.prepare = hwc_prepare;
|
|
|
|
dev->device.set = hwc_set;
|
|
|
|
dev->device.registerProcs = hwc_registerProcs;
|
2012-07-21 19:17:13 +00:00
|
|
|
dev->device.query = hwc_query;
|
|
|
|
dev->device.methods = methods;
|
2012-06-14 07:56:20 +00:00
|
|
|
*device = &dev->device.common;
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|