blob: 2c63e46397edd796b2ff9f5a6babda7bbb3f9a63 [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 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);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500130 if(!MDPComp::configure(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) {
236 //TODO actual
237 } else {
238 }
239 break;
240 default:
241 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700242 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800243 // Enable HPD here, as during bootup unblank is called
244 // when SF is completely initialized
245 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700246
247 if(ret < 0) {
248 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
249 __FUNCTION__, dpy, blank, strerror(errno));
250 return ret;
251 }
252 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
253 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700254 return 0;
255}
256
257static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700258 int param, int* value)
259{
260 hwc_context_t* ctx = (hwc_context_t*)(dev);
261 private_module_t* m = reinterpret_cast<private_module_t*>(
262 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700263 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700264
265 switch (param) {
266 case HWC_BACKGROUND_LAYER_SUPPORTED:
267 // Not supported for now
268 value[0] = 0;
269 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700270 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700271 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700272 ALOGI("fps: %d", value[0]);
273 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700274 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700275 if(ctx->mMDP.hasOverlay)
276 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700277 value[0] = supported;
278 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700279 default:
280 return -EINVAL;
281 }
282 return 0;
283
284}
285
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700286static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700287 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800288 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700289
Saurabh Shahae823e72012-10-05 00:08:11 -0400290 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800291 ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700292 uint32_t last = list->numHwLayers - 1;
293 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
294
Saurabh Shahcf053c62012-12-13 12:32:55 -0800295 hwc_sync(ctx, list, dpy);
296 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700297 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
298 ret = -1;
299 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500300 if (!MDPComp::draw(ctx, list)) {
301 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
302 ret = -1;
303 }
304
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700305 //TODO We dont check for SKIP flag on this layer because we need PAN
306 //always. Last layer is always FB
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500307 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
308 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
309 if(!(fbLayer->flags & HWC_SKIP_LAYER)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800310 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500311 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
312 ret = -1;
313 }
314 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700315 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
316 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
317 return -1;
318 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700319 }
320 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700321 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700322}
323
324static int hwc_set_external(hwc_context_t *ctx,
325 hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700326 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800327 const int dpy = HWC_DISPLAY_EXTERNAL;
328
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700329 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700330
Saurabh Shahae823e72012-10-05 00:08:11 -0400331 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800332 ctx->dpyAttr[dpy].isActive &&
333 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700334 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700335 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
336
Saurabh Shahcf053c62012-12-13 12:32:55 -0800337 hwc_sync(ctx, list, dpy);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700338
Saurabh Shahcf053c62012-12-13 12:32:55 -0800339 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700340 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
341 ret = -1;
342 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700343
344 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700345 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
346 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800347 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500348 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700349 ret = -1;
350 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700351 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700352 if (!ctx->mExtDisplay->post()) {
353 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
354 return -1;
355 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700356 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700357 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700358}
359
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700360static int hwc_set(hwc_composer_device_1 *dev,
361 size_t numDisplays,
362 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363{
364 int ret = 0;
365 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400366 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700367
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700368 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700369 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700370 switch(i) {
371 case HWC_DISPLAY_PRIMARY:
372 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700373 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700374 case HWC_DISPLAY_EXTERNAL:
375 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700376 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700377 default:
378 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700379 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 return ret;
382}
383
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700384int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
385 uint32_t* configs, size_t* numConfigs) {
386 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700387 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700388 //in 1.1 there is no way to choose a config, report as config id # 0
389 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700390 switch(disp) {
391 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700392 if(*numConfigs > 0) {
393 configs[0] = 0;
394 *numConfigs = 1;
395 }
396 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700397 break;
398 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700399 ret = -1; //Not connected
400 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
401 ret = 0; //NO_ERROR
402 if(*numConfigs > 0) {
403 configs[0] = 0;
404 *numConfigs = 1;
405 }
406 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700407 break;
408 }
409 return ret;
410}
411
412int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
413 uint32_t config, const uint32_t* attributes, int32_t* values) {
414
415 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700416 //If hotpluggable displays are inactive return error
417 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
418 return -1;
419 }
420
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700421 //From HWComposer
422 static const uint32_t DISPLAY_ATTRIBUTES[] = {
423 HWC_DISPLAY_VSYNC_PERIOD,
424 HWC_DISPLAY_WIDTH,
425 HWC_DISPLAY_HEIGHT,
426 HWC_DISPLAY_DPI_X,
427 HWC_DISPLAY_DPI_Y,
428 HWC_DISPLAY_NO_ATTRIBUTE,
429 };
430
431 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
432 sizeof(DISPLAY_ATTRIBUTES)[0]);
433
434 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
435 switch (attributes[i]) {
436 case HWC_DISPLAY_VSYNC_PERIOD:
437 values[i] = ctx->dpyAttr[disp].vsync_period;
438 break;
439 case HWC_DISPLAY_WIDTH:
440 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700441 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
442 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700443 break;
444 case HWC_DISPLAY_HEIGHT:
445 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700446 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
447 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700448 break;
449 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400450 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700451 break;
452 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400453 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700454 break;
455 default:
456 ALOGE("Unknown display attribute %d",
457 attributes[i]);
458 return -EINVAL;
459 }
460 }
461 return 0;
462}
463
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500464void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
465{
466 hwc_context_t* ctx = (hwc_context_t*)(dev);
467 android::String8 buf("");
468 dumpsys_log(buf, "Qualcomm HWC state:\n");
469 dumpsys_log(buf, " MDPVersion=%d\n", ctx->mMDP.version);
470 dumpsys_log(buf, " DisplayPanel=%c\n", ctx->mMDP.panel);
471 MDPComp::dump(buf);
472 //XXX: Call Other dump functions
473 strlcpy(buff, buf.string(), buff_len);
474}
475
Naseer Ahmed29a26812012-06-14 00:56:20 -0700476static int hwc_device_close(struct hw_device_t *dev)
477{
478 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700479 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700480 return -1;
481 }
482 closeContext((hwc_context_t*)dev);
483 free(dev);
484
485 return 0;
486}
487
488static int hwc_device_open(const struct hw_module_t* module, const char* name,
489 struct hw_device_t** device)
490{
491 int status = -EINVAL;
492
493 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
494 struct hwc_context_t *dev;
495 dev = (hwc_context_t*)malloc(sizeof(*dev));
496 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700497
498 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700499 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700500
501 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700502 dev->device.common.tag = HARDWARE_DEVICE_TAG;
503 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
504 dev->device.common.module = const_cast<hw_module_t*>(module);
505 dev->device.common.close = hwc_device_close;
506 dev->device.prepare = hwc_prepare;
507 dev->device.set = hwc_set;
508 dev->device.eventControl = hwc_eventControl;
509 dev->device.blank = hwc_blank;
510 dev->device.query = hwc_query;
511 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500512 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700513 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
514 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
515 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700516 status = 0;
517 }
518 return status;
519}