blob: 1b1aa8691ee9f9ed4ada46b8d3b4eba70185a0f8 [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();
Ajay Dudanie217fbf2012-07-25 17:46:07 -070074 return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070075
Naseer Ahmed29a26812012-06-14 00:56:20 -070076 if (LIKELY(list)) {
77 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070078 if(VideoOverlay::prepare(ctx, list)) {
79 ctx->overlayInUse = true;
80 //Nothing here
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070081 } else if(UIMirrorOverlay::prepare(ctx, list)) {
82 ctx->overlayInUse = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070083 } else if (0) {
84 //Other features
85 ctx->overlayInUse = true;
Naseer Ahmed29a26812012-06-14 00:56:20 -070086 }
87 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070088
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 return 0;
90}
91
92static int hwc_set(hwc_composer_device_t *dev,
93 hwc_display_t dpy,
94 hwc_surface_t sur,
95 hwc_layer_list_t* list)
96{
97 int ret = 0;
98 hwc_context_t* ctx = (hwc_context_t*)(dev);
99 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100 VideoOverlay::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700102 UIMirrorOverlay::draw(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 ctx->mOverlay->setState(ovutils::OV_CLOSED);
105 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700107
108 if(!ctx->overlayInUse)
109 ctx->mOverlay->setState(ovutils::OV_CLOSED);
110
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 return ret;
112}
113
114static int hwc_device_close(struct hw_device_t *dev)
115{
116 if(!dev) {
117 ALOGE("hwc_device_close null device pointer");
118 return -1;
119 }
120 closeContext((hwc_context_t*)dev);
121 free(dev);
122
123 return 0;
124}
125
126static int hwc_device_open(const struct hw_module_t* module, const char* name,
127 struct hw_device_t** device)
128{
129 int status = -EINVAL;
130
131 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
132 struct hwc_context_t *dev;
133 dev = (hwc_context_t*)malloc(sizeof(*dev));
134 memset(dev, 0, sizeof(*dev));
135 initContext(dev);
136 dev->device.common.tag = HARDWARE_DEVICE_TAG;
137 dev->device.common.version = 0;
138 dev->device.common.module = const_cast<hw_module_t*>(module);
139 dev->device.common.close = hwc_device_close;
140 dev->device.prepare = hwc_prepare;
141 dev->device.set = hwc_set;
142 dev->device.registerProcs = hwc_registerProcs;
143 *device = &dev->device.common;
144 status = 0;
145 }
146 return status;
147}