blob: 36e30e8108a61a79c158392898f5301be08ddd0c [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004 *
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 Ahmed72cf9762012-07-21 12:17:13 -070023#include <EGL/egl.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070024
Naseer Ahmed72cf9762012-07-21 12:17:13 -070025#include <overlay.h>
26#include <fb_priv.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070027#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070028#include "hwc_utils.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070029#include "hwc_video.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050031#include "hwc_mdpcomp.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070032#include "external.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070033
34using namespace qhwc;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050035#define VSYNC_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070036
37static int hwc_device_open(const struct hw_module_t* module,
38 const char* name,
39 struct hw_device_t** device);
40
41static struct hw_module_methods_t hwc_module_methods = {
42 open: hwc_device_open
43};
44
45hwc_module_t HAL_MODULE_INFO_SYM = {
46 common: {
47 tag: HARDWARE_MODULE_TAG,
48 version_major: 2,
49 version_minor: 0,
50 id: HWC_HARDWARE_MODULE_ID,
51 name: "Qualcomm Hardware Composer Module",
52 author: "CodeAurora Forum",
53 methods: &hwc_module_methods,
54 dso: 0,
55 reserved: {0},
56 }
57};
58
59/*
60 * Save callback functions registered to HWC
61 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070062static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070063 hwc_procs_t const* procs)
64{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070065 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070066 hwc_context_t* ctx = (hwc_context_t*)(dev);
67 if(!ctx) {
68 ALOGE("%s: Invalid context", __FUNCTION__);
69 return;
70 }
Jesse Hall3be78d92012-08-21 15:12:23 -070071 ctx->proc = procs;
72
Naseer Ahmedff4f0252012-10-01 13:03:01 -040073 // Now that we have the functions needed, kick off
74 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070075 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040076 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070077}
78
Saurabh Shah649cda62012-09-16 16:05:58 -070079//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040080static void reset(hwc_context_t *ctx, int numDisplays,
81 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070082 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070083 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++){
Saurabh Shah3e858eb2012-09-17 16:53:21 -070084 ctx->listStats[i].yuvIndex = -1;
Naseer Ahmedb1c76322012-10-17 00:32:50 -040085 hwc_display_contents_1_t *list = displays[i];
86 // XXX:SurfaceFlinger no longer guarantees that this
87 // value is reset on every prepare. However, for the layer
88 // cache we need to reset it.
89 // We can probably rethink that later on
90 if (LIKELY(list && list->numHwLayers > 1)) {
91 for(uint32_t j = 0; j < list->numHwLayers; j++) {
92 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
93 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
94 }
95 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -070096 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050097 VideoOverlay::reset();
98 FBUpdate::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -070099}
100
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500101//clear prev layer prop flags and realloc for current frame
102static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
103 int layer_count = ctx->listStats[dpy].numAppLayers;
104
105 if(ctx->layerProp[dpy]) {
106 delete[] ctx->layerProp[dpy];
107 ctx->layerProp[dpy] = NULL;
108 }
109
110 if(layer_count) {
111 ctx->layerProp[dpy] = new LayerProp[layer_count];
112 }
113}
114
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700115static int hwc_prepare_primary(hwc_composer_device_1 *dev,
116 hwc_display_contents_1_t *list) {
117 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700118
119 if (LIKELY(list && list->numHwLayers > 1) &&
120 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
121
Saurabh Shah86623d72012-09-25 19:39:17 -0700122 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700123 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
124 if(fbLayer->handle) {
125 setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500126 reset_layer_prop(ctx, HWC_DISPLAY_PRIMARY);
127 if(!MDPComp::configure(ctx, list)) {
128 VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY);
129 FBUpdate::prepare(ctx, fbLayer, HWC_DISPLAY_PRIMARY);
Naseer Ahmed76e313c2012-12-01 18:12:59 -0500130 ctx->mLayerCache->updateLayerCache(list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500131 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700132 }
133 }
134 return 0;
135}
136
137static int hwc_prepare_external(hwc_composer_device_1 *dev,
138 hwc_display_contents_1_t *list) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700139 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700140
Saurabh Shahae823e72012-10-05 00:08:11 -0400141 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700142 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
143 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
144
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700145 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700146 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
147 if(fbLayer->handle) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500148 setListStats(ctx, list, HWC_DISPLAY_EXTERNAL);
149 reset_layer_prop(ctx, HWC_DISPLAY_EXTERNAL);
150
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 VideoOverlay::prepare(ctx, list, HWC_DISPLAY_EXTERNAL);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500152 FBUpdate::prepare(ctx, fbLayer, HWC_DISPLAY_EXTERNAL);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700153 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700154 }
155 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700156}
157
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700158static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
159 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700161 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400164 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700165
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166 ctx->mOverlay->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700167
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500168 for (int32_t i = numDisplays - 1; i >= 0; i--) {
169 hwc_display_contents_1_t *list = displays[i];
170 switch(i) {
171 case HWC_DISPLAY_PRIMARY:
172 ret = hwc_prepare_primary(dev, list);
173 break;
174 case HWC_DISPLAY_EXTERNAL:
175
176 ret = hwc_prepare_external(dev, list);
177 break;
178 default:
179 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 }
181 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500182 ctx->mOverlay->configDone();
183
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700184 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185}
186
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700187static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700188 int event, int enabled)
189{
190 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400191
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700192 hwc_context_t* ctx = (hwc_context_t*)(dev);
193 private_module_t* m = reinterpret_cast<private_module_t*>(
194 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700195 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700196 switch(event) {
197 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700198 if (ctx->vstate.enable == enabled)
199 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700200 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400201 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700202 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
203 (enabled)?"ENABLED":"DISABLED");
204 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205 default:
206 ret = -EINVAL;
207 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700208 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700209 return ret;
210}
211
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700212static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
213{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700214 hwc_context_t* ctx = (hwc_context_t*)(dev);
215 private_module_t* m = reinterpret_cast<private_module_t*>(
216 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500217 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700218 int ret = 0;
219 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
220 switch(dpy) {
221 case HWC_DISPLAY_PRIMARY:
222 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223 ctx->mOverlay->configBegin();
224 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700225 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
226 } else {
227 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
228 }
229 break;
230 case HWC_DISPLAY_EXTERNAL:
231 if(blank) {
232 //TODO actual
233 } else {
234 }
235 break;
236 default:
237 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700238 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800239 // Enable HPD here, as during bootup unblank is called
240 // when SF is completely initialized
241 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700242
243 if(ret < 0) {
244 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
245 __FUNCTION__, dpy, blank, strerror(errno));
246 return ret;
247 }
248 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
249 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700250 return 0;
251}
252
253static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700254 int param, int* value)
255{
256 hwc_context_t* ctx = (hwc_context_t*)(dev);
257 private_module_t* m = reinterpret_cast<private_module_t*>(
258 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700259 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700260
261 switch (param) {
262 case HWC_BACKGROUND_LAYER_SUPPORTED:
263 // Not supported for now
264 value[0] = 0;
265 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700266 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700267 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700268 ALOGI("fps: %d", value[0]);
269 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700270 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700271 if(ctx->mMDP.hasOverlay)
272 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700273 value[0] = supported;
274 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700275 default:
276 return -EINVAL;
277 }
278 return 0;
279
280}
281
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700282static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700283 int ret = 0;
284
Saurabh Shahae823e72012-10-05 00:08:11 -0400285 if (LIKELY(list && list->numHwLayers > 1) &&
286 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700287 uint32_t last = list->numHwLayers - 1;
288 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
289
Saurabh Shah8c8bfd22012-09-26 21:09:40 -0700290 hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700291 if (!VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY)) {
292 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
293 ret = -1;
294 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500295 if (!MDPComp::draw(ctx, list)) {
296 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
297 ret = -1;
298 }
299
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700300 //TODO We dont check for SKIP flag on this layer because we need PAN
301 //always. Last layer is always FB
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500302 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
303 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
304 if(!(fbLayer->flags & HWC_SKIP_LAYER)) {
305 if (!FBUpdate::draw(ctx, fbLayer, HWC_DISPLAY_PRIMARY)) {
306 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
307 ret = -1;
308 }
309 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700310 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
311 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
312 return -1;
313 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700314 }
315 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700316 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700317}
318
319static int hwc_set_external(hwc_context_t *ctx,
320 hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700321 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700322 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700323
Saurabh Shahae823e72012-10-05 00:08:11 -0400324 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700325 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
326 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700328 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
329
330 hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL);
331
Saurabh Shaheaf67912012-10-10 17:33:14 -0700332 if (!VideoOverlay::draw(ctx, list, HWC_DISPLAY_EXTERNAL)) {
333 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
334 ret = -1;
335 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700336
337 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700338 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
339 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500340 if (!FBUpdate::draw(ctx, fbLayer, HWC_DISPLAY_EXTERNAL)) {
341 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700342 ret = -1;
343 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700344 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700345 if (!ctx->mExtDisplay->post()) {
346 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
347 return -1;
348 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700349 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700350 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700351}
352
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700353static int hwc_set(hwc_composer_device_1 *dev,
354 size_t numDisplays,
355 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700356{
357 int ret = 0;
358 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400359 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700360
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700361 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700362 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700363 switch(i) {
364 case HWC_DISPLAY_PRIMARY:
365 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700366 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700367 case HWC_DISPLAY_EXTERNAL:
368 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700369 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700370 default:
371 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700372 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 return ret;
375}
376
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700377int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
378 uint32_t* configs, size_t* numConfigs) {
379 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700380 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700381 //in 1.1 there is no way to choose a config, report as config id # 0
382 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700383 switch(disp) {
384 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700385 if(*numConfigs > 0) {
386 configs[0] = 0;
387 *numConfigs = 1;
388 }
389 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700390 break;
391 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700392 ret = -1; //Not connected
393 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
394 ret = 0; //NO_ERROR
395 if(*numConfigs > 0) {
396 configs[0] = 0;
397 *numConfigs = 1;
398 }
399 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700400 break;
401 }
402 return ret;
403}
404
405int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
406 uint32_t config, const uint32_t* attributes, int32_t* values) {
407
408 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700409 //If hotpluggable displays are inactive return error
410 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
411 return -1;
412 }
413
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700414 //From HWComposer
415 static const uint32_t DISPLAY_ATTRIBUTES[] = {
416 HWC_DISPLAY_VSYNC_PERIOD,
417 HWC_DISPLAY_WIDTH,
418 HWC_DISPLAY_HEIGHT,
419 HWC_DISPLAY_DPI_X,
420 HWC_DISPLAY_DPI_Y,
421 HWC_DISPLAY_NO_ATTRIBUTE,
422 };
423
424 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
425 sizeof(DISPLAY_ATTRIBUTES)[0]);
426
427 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
428 switch (attributes[i]) {
429 case HWC_DISPLAY_VSYNC_PERIOD:
430 values[i] = ctx->dpyAttr[disp].vsync_period;
431 break;
432 case HWC_DISPLAY_WIDTH:
433 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700434 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
435 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700436 break;
437 case HWC_DISPLAY_HEIGHT:
438 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700439 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
440 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700441 break;
442 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400443 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700444 break;
445 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400446 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700447 break;
448 default:
449 ALOGE("Unknown display attribute %d",
450 attributes[i]);
451 return -EINVAL;
452 }
453 }
454 return 0;
455}
456
Naseer Ahmed29a26812012-06-14 00:56:20 -0700457static int hwc_device_close(struct hw_device_t *dev)
458{
459 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700460 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 return -1;
462 }
463 closeContext((hwc_context_t*)dev);
464 free(dev);
465
466 return 0;
467}
468
469static int hwc_device_open(const struct hw_module_t* module, const char* name,
470 struct hw_device_t** device)
471{
472 int status = -EINVAL;
473
474 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
475 struct hwc_context_t *dev;
476 dev = (hwc_context_t*)malloc(sizeof(*dev));
477 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700478
479 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700480 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700481
482 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700483 dev->device.common.tag = HARDWARE_DEVICE_TAG;
484 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
485 dev->device.common.module = const_cast<hw_module_t*>(module);
486 dev->device.common.close = hwc_device_close;
487 dev->device.prepare = hwc_prepare;
488 dev->device.set = hwc_set;
489 dev->device.eventControl = hwc_eventControl;
490 dev->device.blank = hwc_blank;
491 dev->device.query = hwc_query;
492 dev->device.registerProcs = hwc_registerProcs;
493 dev->device.dump = NULL;
494 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
495 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
496 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700497 status = 0;
498 }
499 return status;
500}