blob: a63aed700a330b2a35a70b5402608cc1bd076f7e [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"
Saurabh Shah86623d72012-09-25 19:39:17 -070030#include "hwc_uimirror.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070031#include "external.h"
Naseer Ahmed7c958d42012-07-31 18:57:03 -070032#include "hwc_mdpcomp.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070033
Naseer Ahmedff4f0252012-10-01 13:03:01 -040034#define VSYNC_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070035using namespace qhwc;
36
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++){
84 ctx->overlayInUse[i] = false;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070085 ctx->listStats[i].yuvIndex = -1;
Naseer Ahmedb1c76322012-10-17 00:32:50 -040086 hwc_display_contents_1_t *list = displays[i];
87 // XXX:SurfaceFlinger no longer guarantees that this
88 // value is reset on every prepare. However, for the layer
89 // cache we need to reset it.
90 // We can probably rethink that later on
91 if (LIKELY(list && list->numHwLayers > 1)) {
92 for(uint32_t j = 0; j < list->numHwLayers; j++) {
93 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
94 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
95 }
96 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -070097 }
98}
99
100static int hwc_prepare_primary(hwc_composer_device_1 *dev,
101 hwc_display_contents_1_t *list) {
102 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700103
104 if (LIKELY(list && list->numHwLayers > 1) &&
105 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
106
Saurabh Shah86623d72012-09-25 19:39:17 -0700107 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700108 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
109 if(fbLayer->handle) {
110 setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
111 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) {
112 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
113 } else if(MDPComp::configure(ctx, list)) {
114 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
115 } else {
116 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false;
117 }
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400118 ctx->mLayerCache->updateLayerCache(list);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700119 }
120 }
121 return 0;
122}
123
124static int hwc_prepare_external(hwc_composer_device_1 *dev,
125 hwc_display_contents_1_t *list) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700126 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700127
Saurabh Shahae823e72012-10-05 00:08:11 -0400128 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700129 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
130 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
131
132 setListStats(ctx, list, HWC_DISPLAY_EXTERNAL);
133
134 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700135 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
136 if(fbLayer->handle) {
137 if(UIMirrorOverlay::prepare(ctx, fbLayer)) {
138 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
139 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700140
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700141 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_EXTERNAL)) {
142 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
143 } else {
144 ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(
145 ovutils::OV_UI_MIRROR);
146 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700147 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700148 }
149 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700150}
151
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700152static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
153 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700154{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700155 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400157 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700158
159 //If securing of h/w in progress skip comp using overlay.
160 if(ctx->mSecuring == true) return 0;
161
Saurabh Shah9171ec62012-09-13 09:33:51 -0700162 for (uint32_t i = 0; i < numDisplays; i++) {
163 hwc_display_contents_1_t *list = displays[i];
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700164 switch(i) {
165 case HWC_DISPLAY_PRIMARY:
166 ret = hwc_prepare_primary(dev, list);
167 break;
168 case HWC_DISPLAY_EXTERNAL:
169 ret = hwc_prepare_external(dev, list);
170 break;
171 default:
172 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173 }
174 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700175 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700176}
177
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700178static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700179 int event, int enabled)
180{
181 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400182
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700183 hwc_context_t* ctx = (hwc_context_t*)(dev);
184 private_module_t* m = reinterpret_cast<private_module_t*>(
185 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700186 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700187 switch(event) {
188 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700189 if (ctx->vstate.enable == enabled)
190 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700191 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400192 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700193 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
194 (enabled)?"ENABLED":"DISABLED");
195 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700196 default:
197 ret = -EINVAL;
198 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700199 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700200 return ret;
201}
202
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700203static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
204{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700205 hwc_context_t* ctx = (hwc_context_t*)(dev);
206 private_module_t* m = reinterpret_cast<private_module_t*>(
207 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700208 int ret = 0;
209 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
210 switch(dpy) {
211 case HWC_DISPLAY_PRIMARY:
212 if(blank) {
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400213 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700214 ctx->mOverlay[dpy]->setState(ovutils::OV_CLOSED);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700215 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
216 } else {
217 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
218 }
219 break;
220 case HWC_DISPLAY_EXTERNAL:
221 if(blank) {
222 //TODO actual
223 } else {
224 }
225 break;
226 default:
227 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700228 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700229
230 if(ret < 0) {
231 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
232 __FUNCTION__, dpy, blank, strerror(errno));
233 return ret;
234 }
235 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
236 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700237 return 0;
238}
239
240static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700241 int param, int* value)
242{
243 hwc_context_t* ctx = (hwc_context_t*)(dev);
244 private_module_t* m = reinterpret_cast<private_module_t*>(
245 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700246 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700247
248 switch (param) {
249 case HWC_BACKGROUND_LAYER_SUPPORTED:
250 // Not supported for now
251 value[0] = 0;
252 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700253 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700254 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700255 ALOGI("fps: %d", value[0]);
256 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700257 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700258 if(ctx->mMDP.hasOverlay)
259 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700260 value[0] = supported;
261 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700262 default:
263 return -EINVAL;
264 }
265 return 0;
266
267}
268
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700269static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700270 int ret = 0;
271
Saurabh Shahae823e72012-10-05 00:08:11 -0400272 if (LIKELY(list && list->numHwLayers > 1) &&
273 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700274 uint32_t last = list->numHwLayers - 1;
275 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
276
Saurabh Shah8c8bfd22012-09-26 21:09:40 -0700277 hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY);
278
Saurabh Shaheaf67912012-10-10 17:33:14 -0700279 if (!VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY)) {
280 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
281 ret = -1;
282 }
283 if (MDPComp::draw(ctx, list)) {
284 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
285 ret = -1;
286 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700287 //TODO We dont check for SKIP flag on this layer because we need PAN
288 //always. Last layer is always FB
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700289 if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700290 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
291 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
292 return -1;
293 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700294 }
295 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700296 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700297}
298
299static int hwc_set_external(hwc_context_t *ctx,
300 hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700301 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700302 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700303
Saurabh Shahae823e72012-10-05 00:08:11 -0400304 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700305 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
306 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700307 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700308 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
309
310 hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL);
311
Saurabh Shaheaf67912012-10-10 17:33:14 -0700312 if (!VideoOverlay::draw(ctx, list, HWC_DISPLAY_EXTERNAL)) {
313 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
314 ret = -1;
315 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700316
317 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700318 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
319 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700320 if (!UIMirrorOverlay::draw(ctx, fbLayer)) {
321 ALOGE("%s: UIMirrorOverlay::draw fail!", __FUNCTION__);
322 ret = -1;
323 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700324 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700325 if (!ctx->mExtDisplay->post()) {
326 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
327 return -1;
328 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700329 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700330 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700331}
332
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700333static int hwc_set(hwc_composer_device_1 *dev,
334 size_t numDisplays,
335 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336{
337 int ret = 0;
338 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400339 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700340
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700341 for(uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
342 if(!ctx->overlayInUse[i])
343 ctx->mOverlay[i]->setState(ovutils::OV_CLOSED);
344 }
345
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700346 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700347 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700348 switch(i) {
349 case HWC_DISPLAY_PRIMARY:
350 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700351 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700352 case HWC_DISPLAY_EXTERNAL:
353 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700354 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700355 default:
356 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700357 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700358 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700359 return ret;
360}
361
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700362int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
363 uint32_t* configs, size_t* numConfigs) {
364 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700365 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700366 //in 1.1 there is no way to choose a config, report as config id # 0
367 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700368 switch(disp) {
369 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700370 if(*numConfigs > 0) {
371 configs[0] = 0;
372 *numConfigs = 1;
373 }
374 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700375 break;
376 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700377 ret = -1; //Not connected
378 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
379 ret = 0; //NO_ERROR
380 if(*numConfigs > 0) {
381 configs[0] = 0;
382 *numConfigs = 1;
383 }
384 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700385 break;
386 }
387 return ret;
388}
389
390int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
391 uint32_t config, const uint32_t* attributes, int32_t* values) {
392
393 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700394 //If hotpluggable displays are inactive return error
395 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
396 return -1;
397 }
398
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700399 //From HWComposer
400 static const uint32_t DISPLAY_ATTRIBUTES[] = {
401 HWC_DISPLAY_VSYNC_PERIOD,
402 HWC_DISPLAY_WIDTH,
403 HWC_DISPLAY_HEIGHT,
404 HWC_DISPLAY_DPI_X,
405 HWC_DISPLAY_DPI_Y,
406 HWC_DISPLAY_NO_ATTRIBUTE,
407 };
408
409 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
410 sizeof(DISPLAY_ATTRIBUTES)[0]);
411
412 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
413 switch (attributes[i]) {
414 case HWC_DISPLAY_VSYNC_PERIOD:
415 values[i] = ctx->dpyAttr[disp].vsync_period;
416 break;
417 case HWC_DISPLAY_WIDTH:
418 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700419 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
420 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700421 break;
422 case HWC_DISPLAY_HEIGHT:
423 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700424 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
425 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700426 break;
427 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400428 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700429 break;
430 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400431 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700432 break;
433 default:
434 ALOGE("Unknown display attribute %d",
435 attributes[i]);
436 return -EINVAL;
437 }
438 }
439 return 0;
440}
441
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442static int hwc_device_close(struct hw_device_t *dev)
443{
444 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700445 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700446 return -1;
447 }
448 closeContext((hwc_context_t*)dev);
449 free(dev);
450
451 return 0;
452}
453
454static int hwc_device_open(const struct hw_module_t* module, const char* name,
455 struct hw_device_t** device)
456{
457 int status = -EINVAL;
458
459 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
460 struct hwc_context_t *dev;
461 dev = (hwc_context_t*)malloc(sizeof(*dev));
462 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700463
464 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700465 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700466
467 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700468 dev->device.common.tag = HARDWARE_DEVICE_TAG;
469 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
470 dev->device.common.module = const_cast<hw_module_t*>(module);
471 dev->device.common.close = hwc_device_close;
472 dev->device.prepare = hwc_prepare;
473 dev->device.set = hwc_set;
474 dev->device.eventControl = hwc_eventControl;
475 dev->device.blank = hwc_blank;
476 dev->device.query = hwc_query;
477 dev->device.registerProcs = hwc_registerProcs;
478 dev->device.dump = NULL;
479 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
480 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
481 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700482 status = 0;
483 }
484 return status;
485}