blob: ac1be1981aee721a9e329ac21c81756cebd59954 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -08003 * Copyright (C) 2012-2013, 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 Shahcf053c62012-12-13 12:32:55 -080096
97 if(ctx->mFBUpdate[i])
98 ctx->mFBUpdate[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -070099 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 VideoOverlay::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700101}
102
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500103//clear prev layer prop flags and realloc for current frame
104static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
105 int layer_count = ctx->listStats[dpy].numAppLayers;
106
107 if(ctx->layerProp[dpy]) {
108 delete[] ctx->layerProp[dpy];
109 ctx->layerProp[dpy] = NULL;
110 }
111
112 if(layer_count) {
113 ctx->layerProp[dpy] = new LayerProp[layer_count];
114 }
115}
116
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700117static int hwc_prepare_primary(hwc_composer_device_1 *dev,
118 hwc_display_contents_1_t *list) {
119 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800120 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700121
122 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800123 ctx->dpyAttr[dpy].isActive) {
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700124
Saurabh Shah86623d72012-09-25 19:39:17 -0700125 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700126 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
127 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800128 setListStats(ctx, list, dpy);
129 reset_layer_prop(ctx, dpy);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800130 if(!ctx->mMDPComp->prepare(ctx, list)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800131 VideoOverlay::prepare(ctx, list, dpy);
132 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500133 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800134 ctx->mLayerCache[dpy]->updateLayerCache(list);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700135 }
136 }
137 return 0;
138}
139
140static int hwc_prepare_external(hwc_composer_device_1 *dev,
141 hwc_display_contents_1_t *list) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700142 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800143 const int dpy = HWC_DISPLAY_EXTERNAL;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700144
Saurabh Shahae823e72012-10-05 00:08:11 -0400145 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800146 ctx->dpyAttr[dpy].isActive &&
147 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700148
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700149 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700150 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
151 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800152 setListStats(ctx, list, dpy);
153 reset_layer_prop(ctx, dpy);
154 VideoOverlay::prepare(ctx, list, dpy);
155 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
156 ctx->mLayerCache[dpy]->updateLayerCache(list);
Amara Venkata Mastan Manoj Kumar75526f52012-12-27 18:27:01 -0800157 ctx->mExtDispConfiguring = false;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700158 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700159 }
160 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700161}
162
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700163static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
164 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700166 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700167 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500168 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400169 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700170
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500171 ctx->mOverlay->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700172
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500173 for (int32_t i = numDisplays - 1; i >= 0; i--) {
174 hwc_display_contents_1_t *list = displays[i];
175 switch(i) {
176 case HWC_DISPLAY_PRIMARY:
177 ret = hwc_prepare_primary(dev, list);
178 break;
179 case HWC_DISPLAY_EXTERNAL:
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500180 ret = hwc_prepare_external(dev, list);
181 break;
182 default:
183 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184 }
185 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186
Saurabh Shahcf053c62012-12-13 12:32:55 -0800187 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700188 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189}
190
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700191static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700192 int event, int enabled)
193{
194 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400195
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700196 hwc_context_t* ctx = (hwc_context_t*)(dev);
197 private_module_t* m = reinterpret_cast<private_module_t*>(
198 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700199 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700200 switch(event) {
201 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700202 if (ctx->vstate.enable == enabled)
203 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700204 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400205 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700206 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
207 (enabled)?"ENABLED":"DISABLED");
208 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700209 default:
210 ret = -EINVAL;
211 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700212 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700213 return ret;
214}
215
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700216static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
217{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700218 hwc_context_t* ctx = (hwc_context_t*)(dev);
219 private_module_t* m = reinterpret_cast<private_module_t*>(
220 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500221 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700222 int ret = 0;
223 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
224 switch(dpy) {
225 case HWC_DISPLAY_PRIMARY:
226 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227 ctx->mOverlay->configBegin();
228 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700229 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
230 } else {
231 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
232 }
233 break;
234 case HWC_DISPLAY_EXTERNAL:
235 if(blank) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800236 // External Display post commits the changes to display
237 // Call this on blank, so that any pipe unsets gets committed
238 if (!ctx->mExtDisplay->post()) {
239 ret = -1;
240 ALOGE("%s:ctx->mExtDisplay->post fail!! ", __FUNCTION__);
241 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700242 } else {
243 }
244 break;
245 default:
246 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700247 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800248 // Enable HPD here, as during bootup unblank is called
249 // when SF is completely initialized
250 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700251
252 if(ret < 0) {
253 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
254 __FUNCTION__, dpy, blank, strerror(errno));
255 return ret;
256 }
257 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
258 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700259 return 0;
260}
261
262static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700263 int param, int* value)
264{
265 hwc_context_t* ctx = (hwc_context_t*)(dev);
266 private_module_t* m = reinterpret_cast<private_module_t*>(
267 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700268 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700269
270 switch (param) {
271 case HWC_BACKGROUND_LAYER_SUPPORTED:
272 // Not supported for now
273 value[0] = 0;
274 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700275 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700276 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700277 ALOGI("fps: %d", value[0]);
278 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700279 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700280 if(ctx->mMDP.hasOverlay)
281 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700282 value[0] = supported;
283 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700284 default:
285 return -EINVAL;
286 }
287 return 0;
288
289}
290
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700291static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700292 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800293 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700294
Saurabh Shahae823e72012-10-05 00:08:11 -0400295 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800296 ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700297 uint32_t last = list->numHwLayers - 1;
298 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
299
Saurabh Shahcf053c62012-12-13 12:32:55 -0800300 hwc_sync(ctx, list, dpy);
301 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700302 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
303 ret = -1;
304 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800305 if (!ctx->mMDPComp->draw(ctx, list)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500306 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
307 ret = -1;
308 }
309
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700310 //TODO We dont check for SKIP flag on this layer because we need PAN
311 //always. Last layer is always FB
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500312 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
313 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
314 if(!(fbLayer->flags & HWC_SKIP_LAYER)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800315 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500316 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
317 ret = -1;
318 }
319 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700320 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
321 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
322 return -1;
323 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700324 }
325 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700326 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327}
328
329static int hwc_set_external(hwc_context_t *ctx,
330 hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700331 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800332 const int dpy = HWC_DISPLAY_EXTERNAL;
333
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700334 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700335
Saurabh Shahae823e72012-10-05 00:08:11 -0400336 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800337 ctx->dpyAttr[dpy].isActive &&
338 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700339 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700340 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
341
Saurabh Shahcf053c62012-12-13 12:32:55 -0800342 hwc_sync(ctx, list, dpy);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700343
Saurabh Shahcf053c62012-12-13 12:32:55 -0800344 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700345 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
346 ret = -1;
347 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700348
349 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700350 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
351 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800352 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500353 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700354 ret = -1;
355 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700356 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700357 if (!ctx->mExtDisplay->post()) {
358 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
359 return -1;
360 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700361 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700362 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700363}
364
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700365static int hwc_set(hwc_composer_device_1 *dev,
366 size_t numDisplays,
367 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368{
369 int ret = 0;
370 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400371 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700372
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700373 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700374 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700375 switch(i) {
376 case HWC_DISPLAY_PRIMARY:
377 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700378 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700379 case HWC_DISPLAY_EXTERNAL:
380 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700381 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700382 default:
383 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700384 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386 return ret;
387}
388
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700389int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
390 uint32_t* configs, size_t* numConfigs) {
391 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700392 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700393 //in 1.1 there is no way to choose a config, report as config id # 0
394 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700395 switch(disp) {
396 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700397 if(*numConfigs > 0) {
398 configs[0] = 0;
399 *numConfigs = 1;
400 }
401 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700402 break;
403 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700404 ret = -1; //Not connected
405 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
406 ret = 0; //NO_ERROR
407 if(*numConfigs > 0) {
408 configs[0] = 0;
409 *numConfigs = 1;
410 }
411 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700412 break;
413 }
414 return ret;
415}
416
417int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
418 uint32_t config, const uint32_t* attributes, int32_t* values) {
419
420 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700421 //If hotpluggable displays are inactive return error
422 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
423 return -1;
424 }
425
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700426 //From HWComposer
427 static const uint32_t DISPLAY_ATTRIBUTES[] = {
428 HWC_DISPLAY_VSYNC_PERIOD,
429 HWC_DISPLAY_WIDTH,
430 HWC_DISPLAY_HEIGHT,
431 HWC_DISPLAY_DPI_X,
432 HWC_DISPLAY_DPI_Y,
433 HWC_DISPLAY_NO_ATTRIBUTE,
434 };
435
436 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
437 sizeof(DISPLAY_ATTRIBUTES)[0]);
438
439 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
440 switch (attributes[i]) {
441 case HWC_DISPLAY_VSYNC_PERIOD:
442 values[i] = ctx->dpyAttr[disp].vsync_period;
443 break;
444 case HWC_DISPLAY_WIDTH:
445 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700446 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
447 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700448 break;
449 case HWC_DISPLAY_HEIGHT:
450 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700451 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
452 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700453 break;
454 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400455 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700456 break;
457 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400458 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700459 break;
460 default:
461 ALOGE("Unknown display attribute %d",
462 attributes[i]);
463 return -EINVAL;
464 }
465 }
466 return 0;
467}
468
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500469void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
470{
471 hwc_context_t* ctx = (hwc_context_t*)(dev);
472 android::String8 buf("");
473 dumpsys_log(buf, "Qualcomm HWC state:\n");
474 dumpsys_log(buf, " MDPVersion=%d\n", ctx->mMDP.version);
475 dumpsys_log(buf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800476 ctx->mMDPComp->dump(buf);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500477 //XXX: Call Other dump functions
478 strlcpy(buff, buf.string(), buff_len);
479}
480
Naseer Ahmed29a26812012-06-14 00:56:20 -0700481static int hwc_device_close(struct hw_device_t *dev)
482{
483 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700484 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700485 return -1;
486 }
487 closeContext((hwc_context_t*)dev);
488 free(dev);
489
490 return 0;
491}
492
493static int hwc_device_open(const struct hw_module_t* module, const char* name,
494 struct hw_device_t** device)
495{
496 int status = -EINVAL;
497
498 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
499 struct hwc_context_t *dev;
500 dev = (hwc_context_t*)malloc(sizeof(*dev));
501 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700502
503 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700504 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700505
506 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700507 dev->device.common.tag = HARDWARE_DEVICE_TAG;
508 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
509 dev->device.common.module = const_cast<hw_module_t*>(module);
510 dev->device.common.close = hwc_device_close;
511 dev->device.prepare = hwc_prepare;
512 dev->device.set = hwc_set;
513 dev->device.eventControl = hwc_eventControl;
514 dev->device.blank = hwc_blank;
515 dev->device.query = hwc_query;
516 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500517 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700518 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
519 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
520 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700521 status = 0;
522 }
523 return status;
524}