blob: 699e2ac722a4f946f6ec5048928f0da1591ad588 [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 Ahmed29a26812012-06-14 00:56:20 -070027
28using namespace qhwc;
29
30static int hwc_device_open(const struct hw_module_t* module,
31 const char* name,
32 struct hw_device_t** device);
33
34static struct hw_module_methods_t hwc_module_methods = {
35 open: hwc_device_open
36};
37
38hwc_module_t HAL_MODULE_INFO_SYM = {
39 common: {
40 tag: HARDWARE_MODULE_TAG,
41 version_major: 2,
42 version_minor: 0,
43 id: HWC_HARDWARE_MODULE_ID,
44 name: "Qualcomm Hardware Composer Module",
45 author: "CodeAurora Forum",
46 methods: &hwc_module_methods,
47 dso: 0,
48 reserved: {0},
49 }
50};
51
52/*
53 * Save callback functions registered to HWC
54 */
55static void hwc_registerProcs(struct hwc_composer_device* dev,
56 hwc_procs_t const* procs)
57{
58 hwc_context_t* ctx = (hwc_context_t*)(dev);
59 if(!ctx) {
60 ALOGE("%s: Invalid context", __FUNCTION__);
61 return;
62 }
63 ctx->device.reserved_proc[0] = (void*)procs;
64}
65
66static int hwc_prepare(hwc_composer_device_t *dev, hwc_layer_list_t* list)
67{
68 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070069 ctx->overlayInUse = false;
70
71 //Prepare is called after a vsync, so unlock previous buffers here.
72 ctx->qbuf->unlockAllPrevious();
73
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 if (LIKELY(list)) {
75 getLayerStats(ctx, list);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070076 if(VideoOverlay::prepare(ctx, list)) {
77 ctx->overlayInUse = true;
78 //Nothing here
79 } else if (0) {
80 //Other features
81 ctx->overlayInUse = true;
Naseer Ahmed29a26812012-06-14 00:56:20 -070082 }
83 }
84 return 0;
85}
86
87static int hwc_set(hwc_composer_device_t *dev,
88 hwc_display_t dpy,
89 hwc_surface_t sur,
90 hwc_layer_list_t* list)
91{
92 int ret = 0;
93 hwc_context_t* ctx = (hwc_context_t*)(dev);
94 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070095 VideoOverlay::draw(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070096 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
97 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070098 ctx->mOverlay->setState(ovutils::OV_CLOSED);
99 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700100 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101
102 if(!ctx->overlayInUse)
103 ctx->mOverlay->setState(ovutils::OV_CLOSED);
104
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105 return ret;
106}
107
108static int hwc_device_close(struct hw_device_t *dev)
109{
110 if(!dev) {
111 ALOGE("hwc_device_close null device pointer");
112 return -1;
113 }
114 closeContext((hwc_context_t*)dev);
115 free(dev);
116
117 return 0;
118}
119
120static int hwc_device_open(const struct hw_module_t* module, const char* name,
121 struct hw_device_t** device)
122{
123 int status = -EINVAL;
124
125 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
126 struct hwc_context_t *dev;
127 dev = (hwc_context_t*)malloc(sizeof(*dev));
128 memset(dev, 0, sizeof(*dev));
129 initContext(dev);
130 dev->device.common.tag = HARDWARE_DEVICE_TAG;
131 dev->device.common.version = 0;
132 dev->device.common.module = const_cast<hw_module_t*>(module);
133 dev->device.common.close = hwc_device_close;
134 dev->device.prepare = hwc_prepare;
135 dev->device.set = hwc_set;
136 dev->device.registerProcs = hwc_registerProcs;
137 *device = &dev->device.common;
138 status = 0;
139 }
140 return status;
141}