blob: 8aa6e837d49a79443a44176d5e8990cb79e0e5fd [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
4 *
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 <fcntl.h>
19#include <errno.h>
20
21#include <cutils/log.h>
22#include <cutils/atomic.h>
23#include <EGL/egl.h>
24
25#include "hwc_utils.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070026#include "hwc_video.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070027#include "hwc_uimirror.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070028
29using namespace qhwc;
30
31static int hwc_device_open(const struct hw_module_t* module,
32 const char* name,
33 struct hw_device_t** device);
34
35static struct hw_module_methods_t hwc_module_methods = {
36 open: hwc_device_open
37};
38
39hwc_module_t HAL_MODULE_INFO_SYM = {
40 common: {
41 tag: HARDWARE_MODULE_TAG,
42 version_major: 2,
43 version_minor: 0,
44 id: HWC_HARDWARE_MODULE_ID,
45 name: "Qualcomm Hardware Composer Module",
46 author: "CodeAurora Forum",
47 methods: &hwc_module_methods,
48 dso: 0,
49 reserved: {0},
50 }
51};
52
53/*
54 * Save callback functions registered to HWC
55 */
56static void hwc_registerProcs(struct hwc_composer_device* dev,
57 hwc_procs_t const* procs)
58{
59 hwc_context_t* ctx = (hwc_context_t*)(dev);
60 if(!ctx) {
61 ALOGE("%s: Invalid context", __FUNCTION__);
62 return;
63 }
64 ctx->device.reserved_proc[0] = (void*)procs;
65}
66
67static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
68{
69 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070070 ctx->overlayInUse = false;
71
72 //Prepare is called after a vsync, so unlock previous buffers here.
73 ctx->qbuf->unlockAllPrevious();
74
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 if (LIKELY(list)) {
76 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077 if(VideoOverlay::prepare(ctx, list)) {
78 ctx->overlayInUse = true;
79 //Nothing here
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070080 } else if(UIMirrorOverlay::prepare(ctx, list)) {
81 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070082 } else if (0) {
83 //Other features
84 ctx->overlayInUse = true;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085 }
86 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070087
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 return 0;
89}
90
91static int hwc_set(hwc_composer_device_t *dev,
92 hwc_display_t dpy,
93 hwc_surface_t sur,
94 hwc_layer_list_t* list)
95{
96 int ret = 0;
97 hwc_context_t* ctx = (hwc_context_t*)(dev);
98 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070099 VideoOverlay::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700101 UIMirrorOverlay::draw(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103 ctx->mOverlay->setState(ovutils::OV_CLOSED);
104 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106
107 if(!ctx->overlayInUse)
108 ctx->mOverlay->setState(ovutils::OV_CLOSED);
109
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110 return ret;
111}
112
113static int hwc_device_close(struct hw_device_t *dev)
114{
115 if(!dev) {
116 ALOGE("hwc_device_close null device pointer");
117 return -1;
118 }
119 closeContext((hwc_context_t*)dev);
120 free(dev);
121
122 return 0;
123}
124
125static int hwc_device_open(const struct hw_module_t* module, const char* name,
126 struct hw_device_t** device)
127{
128 int status = -EINVAL;
129
130 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
131 struct hwc_context_t *dev;
132 dev = (hwc_context_t*)malloc(sizeof(*dev));
133 memset(dev, 0, sizeof(*dev));
134 initContext(dev);
135 dev->device.common.tag = HARDWARE_DEVICE_TAG;
136 dev->device.common.version = 0;
137 dev->device.common.module = const_cast<hw_module_t*>(module);
138 dev->device.common.close = hwc_device_close;
139 dev->device.prepare = hwc_prepare;
140 dev->device.set = hwc_set;
141 dev->device.registerProcs = hwc_registerProcs;
142 *device = &dev->device.common;
143 status = 0;
144 }
145 return status;
146}