blob: 6c238460b4f70a739feba0d207962be5878d285d [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
Saurabh Shah3e858eb2012-09-17 16:53:21 -070080static void reset(hwc_context_t *ctx, int numDisplays) {
81 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070082 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++){
83 ctx->overlayInUse[i] = false;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070084 ctx->listStats[i].yuvIndex = -1;
85 }
86}
87
88static int hwc_prepare_primary(hwc_composer_device_1 *dev,
89 hwc_display_contents_1_t *list) {
90 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah1a8cda02012-10-12 17:00:39 -070091
92 if (LIKELY(list && list->numHwLayers > 1) &&
93 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
94
Saurabh Shah86623d72012-09-25 19:39:17 -070095 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -070096 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
97 if(fbLayer->handle) {
98 setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
99 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) {
100 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
101 } else if(MDPComp::configure(ctx, list)) {
102 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
103 } else {
104 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false;
105 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700106 }
107 }
108 return 0;
109}
110
111static int hwc_prepare_external(hwc_composer_device_1 *dev,
112 hwc_display_contents_1_t *list) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700113 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700114
Saurabh Shahae823e72012-10-05 00:08:11 -0400115 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700116 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
117 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
118
119 setListStats(ctx, list, HWC_DISPLAY_EXTERNAL);
120
121 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700122 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
123 if(fbLayer->handle) {
124 if(UIMirrorOverlay::prepare(ctx, fbLayer)) {
125 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
126 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700127
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700128 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_EXTERNAL)) {
129 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
130 } else {
131 ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(
132 ovutils::OV_UI_MIRROR);
133 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700134 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700135 }
136 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700137}
138
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700139static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
140 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700141{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700142 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700143 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700144 reset(ctx, numDisplays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700145
146 //If securing of h/w in progress skip comp using overlay.
147 if(ctx->mSecuring == true) return 0;
148
Saurabh Shah9171ec62012-09-13 09:33:51 -0700149 for (uint32_t i = 0; i < numDisplays; i++) {
150 hwc_display_contents_1_t *list = displays[i];
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700151 switch(i) {
152 case HWC_DISPLAY_PRIMARY:
153 ret = hwc_prepare_primary(dev, list);
154 break;
155 case HWC_DISPLAY_EXTERNAL:
156 ret = hwc_prepare_external(dev, list);
157 break;
158 default:
159 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160 }
161 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700162 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163}
164
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700165static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700166 int event, int enabled)
167{
168 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400169
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700170 hwc_context_t* ctx = (hwc_context_t*)(dev);
171 private_module_t* m = reinterpret_cast<private_module_t*>(
172 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700173 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700174 switch(event) {
175 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700176 if (ctx->vstate.enable == enabled)
177 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700178 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400179 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700180 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
181 (enabled)?"ENABLED":"DISABLED");
182 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700183 default:
184 ret = -EINVAL;
185 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700186 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700187 return ret;
188}
189
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700190static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
191{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700192 hwc_context_t* ctx = (hwc_context_t*)(dev);
193 private_module_t* m = reinterpret_cast<private_module_t*>(
194 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700195 int ret = 0;
196 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
197 switch(dpy) {
198 case HWC_DISPLAY_PRIMARY:
199 if(blank) {
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400200 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700201 ctx->mOverlay[dpy]->setState(ovutils::OV_CLOSED);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700202 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
203 } else {
204 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
205 }
206 break;
207 case HWC_DISPLAY_EXTERNAL:
208 if(blank) {
209 //TODO actual
210 } else {
211 }
212 break;
213 default:
214 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700215 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700216
217 if(ret < 0) {
218 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
219 __FUNCTION__, dpy, blank, strerror(errno));
220 return ret;
221 }
222 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
223 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700224 return 0;
225}
226
227static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700228 int param, int* value)
229{
230 hwc_context_t* ctx = (hwc_context_t*)(dev);
231 private_module_t* m = reinterpret_cast<private_module_t*>(
232 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700233 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234
235 switch (param) {
236 case HWC_BACKGROUND_LAYER_SUPPORTED:
237 // Not supported for now
238 value[0] = 0;
239 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700240 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700241 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700242 ALOGI("fps: %d", value[0]);
243 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700244 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700245 if(ctx->mMDP.hasOverlay)
246 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700247 value[0] = supported;
248 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700249 default:
250 return -EINVAL;
251 }
252 return 0;
253
254}
255
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700256static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahae823e72012-10-05 00:08:11 -0400257 if (LIKELY(list && list->numHwLayers > 1) &&
258 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700259 uint32_t last = list->numHwLayers - 1;
260 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
261
Saurabh Shah8c8bfd22012-09-26 21:09:40 -0700262 hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY);
263
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700264 VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY);
265 MDPComp::draw(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700266
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700267 //TODO We dont check for SKIP flag on this layer because we need PAN
268 //always. Last layer is always FB
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700269 if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700270 ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700271 }
272 }
273 return 0;
274}
275
276static int hwc_set_external(hwc_context_t *ctx,
277 hwc_display_contents_1_t* list) {
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700278 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700279
Saurabh Shahae823e72012-10-05 00:08:11 -0400280 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700281 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
282 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700283 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700284 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
285
286 hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL);
287
288 VideoOverlay::draw(ctx, list, HWC_DISPLAY_EXTERNAL);
289
290 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700291 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
292 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700293 UIMirrorOverlay::draw(ctx, fbLayer);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700294 }
Saurabh Shah150806a2012-10-09 15:38:23 -0700295 ctx->mExtDisplay->post();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700296 }
297 return 0;
298}
299
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700300static int hwc_set(hwc_composer_device_1 *dev,
301 size_t numDisplays,
302 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303{
304 int ret = 0;
305 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400306 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700307
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700308 for(uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
309 if(!ctx->overlayInUse[i])
310 ctx->mOverlay[i]->setState(ovutils::OV_CLOSED);
311 }
312
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700313 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700314 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700315 switch(i) {
316 case HWC_DISPLAY_PRIMARY:
317 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700318 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700319 case HWC_DISPLAY_EXTERNAL:
320 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700321 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700322 default:
323 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700324 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326 return ret;
327}
328
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700329int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
330 uint32_t* configs, size_t* numConfigs) {
331 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700332 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700333 //in 1.1 there is no way to choose a config, report as config id # 0
334 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700335 switch(disp) {
336 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700337 if(*numConfigs > 0) {
338 configs[0] = 0;
339 *numConfigs = 1;
340 }
341 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700342 break;
343 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700344 ret = -1; //Not connected
345 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
346 ret = 0; //NO_ERROR
347 if(*numConfigs > 0) {
348 configs[0] = 0;
349 *numConfigs = 1;
350 }
351 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700352 break;
353 }
354 return ret;
355}
356
357int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
358 uint32_t config, const uint32_t* attributes, int32_t* values) {
359
360 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700361 //If hotpluggable displays are inactive return error
362 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
363 return -1;
364 }
365
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700366 //From HWComposer
367 static const uint32_t DISPLAY_ATTRIBUTES[] = {
368 HWC_DISPLAY_VSYNC_PERIOD,
369 HWC_DISPLAY_WIDTH,
370 HWC_DISPLAY_HEIGHT,
371 HWC_DISPLAY_DPI_X,
372 HWC_DISPLAY_DPI_Y,
373 HWC_DISPLAY_NO_ATTRIBUTE,
374 };
375
376 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
377 sizeof(DISPLAY_ATTRIBUTES)[0]);
378
379 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
380 switch (attributes[i]) {
381 case HWC_DISPLAY_VSYNC_PERIOD:
382 values[i] = ctx->dpyAttr[disp].vsync_period;
383 break;
384 case HWC_DISPLAY_WIDTH:
385 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700386 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
387 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700388 break;
389 case HWC_DISPLAY_HEIGHT:
390 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700391 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
392 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700393 break;
394 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400395 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700396 break;
397 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400398 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700399 break;
400 default:
401 ALOGE("Unknown display attribute %d",
402 attributes[i]);
403 return -EINVAL;
404 }
405 }
406 return 0;
407}
408
Naseer Ahmed29a26812012-06-14 00:56:20 -0700409static int hwc_device_close(struct hw_device_t *dev)
410{
411 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700412 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413 return -1;
414 }
415 closeContext((hwc_context_t*)dev);
416 free(dev);
417
418 return 0;
419}
420
421static int hwc_device_open(const struct hw_module_t* module, const char* name,
422 struct hw_device_t** device)
423{
424 int status = -EINVAL;
425
426 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
427 struct hwc_context_t *dev;
428 dev = (hwc_context_t*)malloc(sizeof(*dev));
429 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700430
431 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700432 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700433
434 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700435 dev->device.common.tag = HARDWARE_DEVICE_TAG;
436 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
437 dev->device.common.module = const_cast<hw_module_t*>(module);
438 dev->device.common.close = hwc_device_close;
439 dev->device.prepare = hwc_prepare;
440 dev->device.set = hwc_set;
441 dev->device.eventControl = hwc_eventControl;
442 dev->device.blank = hwc_blank;
443 dev->device.query = hwc_query;
444 dev->device.registerProcs = hwc_registerProcs;
445 dev->device.dump = NULL;
446 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
447 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
448 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700449 status = 0;
450 }
451 return status;
452}