blob: 920902e31de0acbc3ee4309f2686a492a191eba3 [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{
65 hwc_context_t* ctx = (hwc_context_t*)(dev);
66 if(!ctx) {
67 ALOGE("%s: Invalid context", __FUNCTION__);
68 return;
69 }
Jesse Hall3be78d92012-08-21 15:12:23 -070070 ctx->proc = procs;
71
Naseer Ahmedff4f0252012-10-01 13:03:01 -040072 // Now that we have the functions needed, kick off
73 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070074 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040075 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070076}
77
Saurabh Shah649cda62012-09-16 16:05:58 -070078//Helper
Saurabh Shah3e858eb2012-09-17 16:53:21 -070079static void reset(hwc_context_t *ctx, int numDisplays) {
80 memset(ctx->listStats, 0, sizeof(ctx->listStats));
81 for(int i = 0; i < numDisplays; i++){
82 ctx->listStats[i].yuvIndex = -1;
83 }
84}
85
86static int hwc_prepare_primary(hwc_composer_device_1 *dev,
87 hwc_display_contents_1_t *list) {
88 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -070089 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070090 if (LIKELY(list && list->numHwLayers)) {
Saurabh Shah86623d72012-09-25 19:39:17 -070091 uint32_t last = list->numHwLayers - 1;
92 hwc_layer_1_t *fblayer = &list->hwLayers[last];
Saurabh Shah3e858eb2012-09-17 16:53:21 -070093 setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
94 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_PRIMARY)) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -070095 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070096 } else if(MDPComp::configure(ctx, list)) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -070097 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = true;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070098 } else {
Saurabh Shahc4d034f2012-09-27 15:55:15 -070099 ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700100 }
101 }
102 return 0;
103}
104
105static int hwc_prepare_external(hwc_composer_device_1 *dev,
106 hwc_display_contents_1_t *list) {
107
108 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700109 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = false;
110
111 if (LIKELY(list && list->numHwLayers) &&
112 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
113 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
114
115 setListStats(ctx, list, HWC_DISPLAY_EXTERNAL);
116
117 uint32_t last = list->numHwLayers - 1;
118 hwc_layer_1_t *fblayer = &list->hwLayers[last];
119 if(UIMirrorOverlay::prepare(ctx, fblayer)) {
120 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
121 }
122
123 if(VideoOverlay::prepare(ctx, list, HWC_DISPLAY_EXTERNAL)) {
124 ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = true;
125 } else {
126 ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(ovutils::OV_UI_MIRROR);
127 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700128 }
129 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700130}
131
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700132static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
133 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700135 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700137
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700138 reset(ctx, numDisplays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700139
140 //If securing of h/w in progress skip comp using overlay.
141 if(ctx->mSecuring == true) return 0;
142
Saurabh Shah9171ec62012-09-13 09:33:51 -0700143 for (uint32_t i = 0; i < numDisplays; i++) {
144 hwc_display_contents_1_t *list = displays[i];
Naseer Ahmed6282c952012-09-26 18:33:58 -0400145 if(list && list->numHwLayers) {
146 uint32_t last = list->numHwLayers - 1;
147 if(list->hwLayers[last].handle != NULL) {
148 switch(i) {
149 case HWC_DISPLAY_PRIMARY:
150 ret = hwc_prepare_primary(dev, list);
151 break;
152 case HWC_DISPLAY_EXTERNAL:
153 ret = hwc_prepare_external(dev, list);
154 break;
155 default:
156 ret = -EINVAL;
157 }
158 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159 }
160 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700161 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162}
163
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700164static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700165 int event, int enabled)
166{
167 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400168
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700169 hwc_context_t* ctx = (hwc_context_t*)(dev);
170 private_module_t* m = reinterpret_cast<private_module_t*>(
171 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700172 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700173 switch(event) {
174 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700175 if (ctx->vstate.enable == enabled)
176 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700177 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_OVERLAY_VSYNC_CTRL,
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400178 &enabled) < 0) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700179 ALOGE("%s: vsync control failed. Dpy=%d, enabled=%d : %s",
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400180 __FUNCTION__, dpy, enabled, strerror(errno));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700181 ret = -errno;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700182 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700183 ctx->vstate.enable = !!enabled;
184 if (enabled)
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400185 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700186 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
187 (enabled)?"ENABLED":"DISABLED");
188 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700189 default:
190 ret = -EINVAL;
191 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700192 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700193 return ret;
194}
195
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700196static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
197{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700198 hwc_context_t* ctx = (hwc_context_t*)(dev);
199 private_module_t* m = reinterpret_cast<private_module_t*>(
200 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700201 int ret = 0;
202 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
203 switch(dpy) {
204 case HWC_DISPLAY_PRIMARY:
205 if(blank) {
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400206 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700207 ctx->mOverlay[dpy]->setState(ovutils::OV_CLOSED);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700208 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
209 } else {
210 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
211 }
212 break;
213 case HWC_DISPLAY_EXTERNAL:
214 if(blank) {
215 //TODO actual
216 } else {
217 }
218 break;
219 default:
220 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700221 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700222
223 if(ret < 0) {
224 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
225 __FUNCTION__, dpy, blank, strerror(errno));
226 return ret;
227 }
228 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
229 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700230 return 0;
231}
232
233static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234 int param, int* value)
235{
236 hwc_context_t* ctx = (hwc_context_t*)(dev);
237 private_module_t* m = reinterpret_cast<private_module_t*>(
238 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700239 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700240
241 switch (param) {
242 case HWC_BACKGROUND_LAYER_SUPPORTED:
243 // Not supported for now
244 value[0] = 0;
245 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700246 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700247 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248 ALOGI("fps: %d", value[0]);
249 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700250 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700251 if(ctx->mMDP.hasOverlay)
252 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700253 value[0] = supported;
254 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700255 default:
256 return -EINVAL;
257 }
258 return 0;
259
260}
261
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700262static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700263 if(!ctx->overlayInUse[HWC_DISPLAY_PRIMARY])
264 ctx->mOverlay[HWC_DISPLAY_PRIMARY]->setState(ovutils::OV_CLOSED);
265
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700266 if (LIKELY(list && list->numHwLayers)) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700267 uint32_t last = list->numHwLayers - 1;
268 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
269
Saurabh Shah8c8bfd22012-09-26 21:09:40 -0700270 hwc_sync(ctx, list, HWC_DISPLAY_PRIMARY);
271
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700272 VideoOverlay::draw(ctx, list, HWC_DISPLAY_PRIMARY);
273 MDPComp::draw(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700274
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700275 //TODO We dont check for SKIP flag on this layer because we need PAN
276 //always. Last layer is always FB
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700277 if(list->hwLayers[last].compositionType == HWC_FRAMEBUFFER_TARGET) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700278 ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700279 }
280 }
281 return 0;
282}
283
284static int hwc_set_external(hwc_context_t *ctx,
285 hwc_display_contents_1_t* list) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700286
287 if(!ctx->overlayInUse[HWC_DISPLAY_EXTERNAL])
288 ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(ovutils::OV_CLOSED);
289
290 if (LIKELY(list && list->numHwLayers) &&
291 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
292 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700293 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700294 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
295
296 hwc_sync(ctx, list, HWC_DISPLAY_EXTERNAL);
297
298 VideoOverlay::draw(ctx, list, HWC_DISPLAY_EXTERNAL);
299
300 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
301 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
302 UIMirrorOverlay::draw(ctx, fbLayer);
303 ctx->mExtDisplay->post();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304 }
305 }
306 return 0;
307}
308
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700309static bool isGpuUsed(hwc_context_t *ctx,
310 size_t numDisplays,
311 hwc_display_contents_1_t** displays)
312{
313 bool isUsed = false;
314 for (uint32_t i = 0; i < numDisplays; i++) {
315 hwc_display_contents_1_t* list = displays[i];
316 if (list && list->numHwLayers) {
317 uint32_t last = list->numHwLayers - 1;
318 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
319 if(!(fbLayer->flags & HWC_SKIP_LAYER)) {
320 isUsed = true;
321 break;
322 }
323
324 }
325 }
326 return isUsed;
327}
328
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700329static int hwc_set(hwc_composer_device_1 *dev,
330 size_t numDisplays,
331 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700332{
333 int ret = 0;
334 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400335 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700336
337 if(isGpuUsed(ctx, numDisplays, displays)) {
338 //Call glFinish, only if gpu is used
339 ctx->mFbDev->compositionComplete(ctx->mFbDev);
340 }
Naseer Ahmedaee5e6e2012-09-27 13:17:59 -0400341
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700342 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700343 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700344 switch(i) {
345 case HWC_DISPLAY_PRIMARY:
346 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700347 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700348 case HWC_DISPLAY_EXTERNAL:
349 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700350 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700351 default:
352 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700353 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355 return ret;
356}
357
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700358int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
359 uint32_t* configs, size_t* numConfigs) {
360 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700361 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700362 //in 1.1 there is no way to choose a config, report as config id # 0
363 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700364 switch(disp) {
365 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700366 if(*numConfigs > 0) {
367 configs[0] = 0;
368 *numConfigs = 1;
369 }
370 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700371 break;
372 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700373 ret = -1; //Not connected
374 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
375 ret = 0; //NO_ERROR
376 if(*numConfigs > 0) {
377 configs[0] = 0;
378 *numConfigs = 1;
379 }
380 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700381 break;
382 }
383 return ret;
384}
385
386int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
387 uint32_t config, const uint32_t* attributes, int32_t* values) {
388
389 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700390 //If hotpluggable displays are inactive return error
391 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
392 return -1;
393 }
394
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700395 //From HWComposer
396 static const uint32_t DISPLAY_ATTRIBUTES[] = {
397 HWC_DISPLAY_VSYNC_PERIOD,
398 HWC_DISPLAY_WIDTH,
399 HWC_DISPLAY_HEIGHT,
400 HWC_DISPLAY_DPI_X,
401 HWC_DISPLAY_DPI_Y,
402 HWC_DISPLAY_NO_ATTRIBUTE,
403 };
404
405 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
406 sizeof(DISPLAY_ATTRIBUTES)[0]);
407
408 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
409 switch (attributes[i]) {
410 case HWC_DISPLAY_VSYNC_PERIOD:
411 values[i] = ctx->dpyAttr[disp].vsync_period;
412 break;
413 case HWC_DISPLAY_WIDTH:
414 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700415 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
416 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700417 break;
418 case HWC_DISPLAY_HEIGHT:
419 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700420 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
421 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700422 break;
423 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400424 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700425 break;
426 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400427 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700428 break;
429 default:
430 ALOGE("Unknown display attribute %d",
431 attributes[i]);
432 return -EINVAL;
433 }
434 }
435 return 0;
436}
437
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438static int hwc_device_close(struct hw_device_t *dev)
439{
440 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700441 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442 return -1;
443 }
444 closeContext((hwc_context_t*)dev);
445 free(dev);
446
447 return 0;
448}
449
450static int hwc_device_open(const struct hw_module_t* module, const char* name,
451 struct hw_device_t** device)
452{
453 int status = -EINVAL;
454
455 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
456 struct hwc_context_t *dev;
457 dev = (hwc_context_t*)malloc(sizeof(*dev));
458 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700459
460 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700462
463 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700464 dev->device.common.tag = HARDWARE_DEVICE_TAG;
465 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
466 dev->device.common.module = const_cast<hw_module_t*>(module);
467 dev->device.common.close = hwc_device_close;
468 dev->device.prepare = hwc_prepare;
469 dev->device.set = hwc_set;
470 dev->device.eventControl = hwc_eventControl;
471 dev->device.blank = hwc_blank;
472 dev->device.query = hwc_query;
473 dev->device.registerProcs = hwc_registerProcs;
474 dev->device.dump = NULL;
475 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
476 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
477 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700478 status = 0;
479 }
480 return status;
481}