blob: 7826a5f5eb7f24a18b1c10df5bf55388e77c490f [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>
Naseer Ahmed29a26812012-06-14 00:56:20 -070023
24#include "hwc_utils.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070025#include "hwc_video.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070026#include "hwc_uimirror.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070027#include "hwc_copybit.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 Ahmed31da0b12012-07-31 18:55:33 -070086 } else { // Else set this flag to false, otherwise video cases
87 // fail in non-overlay targets.
88 ctx->overlayInUse = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 }
Naseer Ahmed31da0b12012-07-31 18:55:33 -070090 CopyBit::prepare(ctx, list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070092
Naseer Ahmed29a26812012-06-14 00:56:20 -070093 return 0;
94}
95
96static int hwc_set(hwc_composer_device_t *dev,
97 hwc_display_t dpy,
98 hwc_surface_t sur,
99 hwc_layer_list_t* list)
100{
101 int ret = 0;
102 hwc_context_t* ctx = (hwc_context_t*)(dev);
103 if (LIKELY(list)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104 VideoOverlay::draw(ctx, list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700105 CopyBit::draw(ctx, list, (EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 EGLBoolean sucess = eglSwapBuffers((EGLDisplay)dpy, (EGLSurface)sur);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700107 UIMirrorOverlay::draw(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700108 } else {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109 ctx->mOverlay->setState(ovutils::OV_CLOSED);
110 ctx->qbuf->unlockAllPrevious();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112
113 if(!ctx->overlayInUse)
114 ctx->mOverlay->setState(ovutils::OV_CLOSED);
115
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116 return ret;
117}
118
119static int hwc_device_close(struct hw_device_t *dev)
120{
121 if(!dev) {
122 ALOGE("hwc_device_close null device pointer");
123 return -1;
124 }
125 closeContext((hwc_context_t*)dev);
126 free(dev);
127
128 return 0;
129}
130
131static int hwc_device_open(const struct hw_module_t* module, const char* name,
132 struct hw_device_t** device)
133{
134 int status = -EINVAL;
135
136 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
137 struct hwc_context_t *dev;
138 dev = (hwc_context_t*)malloc(sizeof(*dev));
139 memset(dev, 0, sizeof(*dev));
140 initContext(dev);
141 dev->device.common.tag = HARDWARE_DEVICE_TAG;
142 dev->device.common.version = 0;
143 dev->device.common.module = const_cast<hw_module_t*>(module);
144 dev->device.common.close = hwc_device_close;
145 dev->device.prepare = hwc_prepare;
146 dev->device.set = hwc_set;
147 dev->device.registerProcs = hwc_registerProcs;
148 *device = &dev->device.common;
149 status = 0;
150 }
151 return status;
152}