blob: 84b11000aee158bbcd770f25f136b62bce5d24b9 [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 *
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08005 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
Naseer Ahmed29a26812012-06-14 00:56:20 -07008 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#include <fcntl.h>
22#include <errno.h>
23
24#include <cutils/log.h>
25#include <cutils/atomic.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include <EGL/egl.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070027
Naseer Ahmed72cf9762012-07-21 12:17:13 -070028#include <overlay.h>
29#include <fb_priv.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070030#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070031#include "hwc_utils.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070032#include "hwc_video.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070035#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080036#include "hwc_copybit.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070037
38using namespace qhwc;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050039#define VSYNC_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070040
41static int hwc_device_open(const struct hw_module_t* module,
42 const char* name,
43 struct hw_device_t** device);
44
45static struct hw_module_methods_t hwc_module_methods = {
46 open: hwc_device_open
47};
48
49hwc_module_t HAL_MODULE_INFO_SYM = {
50 common: {
51 tag: HARDWARE_MODULE_TAG,
52 version_major: 2,
53 version_minor: 0,
54 id: HWC_HARDWARE_MODULE_ID,
55 name: "Qualcomm Hardware Composer Module",
56 author: "CodeAurora Forum",
57 methods: &hwc_module_methods,
58 dso: 0,
59 reserved: {0},
60 }
61};
62
63/*
64 * Save callback functions registered to HWC
65 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070066static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070067 hwc_procs_t const* procs)
68{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070069 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 hwc_context_t* ctx = (hwc_context_t*)(dev);
71 if(!ctx) {
72 ALOGE("%s: Invalid context", __FUNCTION__);
73 return;
74 }
Jesse Hall3be78d92012-08-21 15:12:23 -070075 ctx->proc = procs;
76
Naseer Ahmedff4f0252012-10-01 13:03:01 -040077 // Now that we have the functions needed, kick off
78 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070079 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040080 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070081}
82
Saurabh Shah649cda62012-09-16 16:05:58 -070083//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040084static void reset(hwc_context_t *ctx, int numDisplays,
85 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070086 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Saurabh Shah1a8cda02012-10-12 17:00:39 -070087 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++){
Saurabh Shah3e858eb2012-09-17 16:53:21 -070088 ctx->listStats[i].yuvIndex = -1;
Naseer Ahmedb1c76322012-10-17 00:32:50 -040089 hwc_display_contents_1_t *list = displays[i];
90 // XXX:SurfaceFlinger no longer guarantees that this
91 // value is reset on every prepare. However, for the layer
92 // cache we need to reset it.
93 // We can probably rethink that later on
94 if (LIKELY(list && list->numHwLayers > 1)) {
95 for(uint32_t j = 0; j < list->numHwLayers; j++) {
96 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
97 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
98 }
99 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800100
101 if(ctx->mFBUpdate[i])
102 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800103
104 if(ctx->mCopyBit[i])
105 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700106 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 VideoOverlay::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700108}
109
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500110//clear prev layer prop flags and realloc for current frame
111static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
112 int layer_count = ctx->listStats[dpy].numAppLayers;
113
114 if(ctx->layerProp[dpy]) {
115 delete[] ctx->layerProp[dpy];
116 ctx->layerProp[dpy] = NULL;
117 }
118
119 if(layer_count) {
120 ctx->layerProp[dpy] = new LayerProp[layer_count];
121 }
122}
123
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700124static int hwc_prepare_primary(hwc_composer_device_1 *dev,
125 hwc_display_contents_1_t *list) {
126 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800127 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700128 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800129 ctx->dpyAttr[dpy].isActive) {
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700130
Saurabh Shah86623d72012-09-25 19:39:17 -0700131 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700132 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
133 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800134 setListStats(ctx, list, dpy);
135 reset_layer_prop(ctx, dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800136 int ret = ctx->mMDPComp->prepare(ctx, list);
137 if(!ret) {
138 // IF MDPcomp fails use this route
Saurabh Shahcf053c62012-12-13 12:32:55 -0800139 VideoOverlay::prepare(ctx, list, dpy);
140 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500141 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800142 ctx->mLayerCache[dpy]->updateLayerCache(list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800143 // Use Copybit, when MDP comp fails
144 if(!ret && ctx->mCopyBit[dpy])
145 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700146 }
147 }
148 return 0;
149}
150
151static int hwc_prepare_external(hwc_composer_device_1 *dev,
152 hwc_display_contents_1_t *list) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700153 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800154 const int dpy = HWC_DISPLAY_EXTERNAL;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700155
Saurabh Shahae823e72012-10-05 00:08:11 -0400156 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800157 ctx->dpyAttr[dpy].isActive &&
158 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700159
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700160 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700161 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
162 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800163 setListStats(ctx, list, dpy);
164 reset_layer_prop(ctx, dpy);
165 VideoOverlay::prepare(ctx, list, dpy);
166 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
167 ctx->mLayerCache[dpy]->updateLayerCache(list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800168 if(ctx->mCopyBit[dpy])
169 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Amara Venkata Mastan Manoj Kumar75526f52012-12-27 18:27:01 -0800170 ctx->mExtDispConfiguring = false;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700171 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700172 }
173 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700174}
175
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700176static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
177 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700178{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700179 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500181 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400182 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700183
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500184 ctx->mOverlay->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700185
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500186 for (int32_t i = numDisplays - 1; i >= 0; i--) {
187 hwc_display_contents_1_t *list = displays[i];
188 switch(i) {
189 case HWC_DISPLAY_PRIMARY:
190 ret = hwc_prepare_primary(dev, list);
191 break;
192 case HWC_DISPLAY_EXTERNAL:
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500193 ret = hwc_prepare_external(dev, list);
194 break;
195 default:
196 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197 }
198 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500199
Saurabh Shahcf053c62012-12-13 12:32:55 -0800200 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700201 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}
203
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700204static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205 int event, int enabled)
206{
207 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400208
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700209 hwc_context_t* ctx = (hwc_context_t*)(dev);
210 private_module_t* m = reinterpret_cast<private_module_t*>(
211 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700212 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700213 switch(event) {
214 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700215 if (ctx->vstate.enable == enabled)
216 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700217 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400218 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700219 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
220 (enabled)?"ENABLED":"DISABLED");
221 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700222 default:
223 ret = -EINVAL;
224 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700225 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700226 return ret;
227}
228
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700229static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
230{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700231 hwc_context_t* ctx = (hwc_context_t*)(dev);
232 private_module_t* m = reinterpret_cast<private_module_t*>(
233 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500234 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700235 int ret = 0;
236 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
237 switch(dpy) {
238 case HWC_DISPLAY_PRIMARY:
239 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500240 ctx->mOverlay->configBegin();
241 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700242 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
243 } else {
244 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
245 }
246 break;
247 case HWC_DISPLAY_EXTERNAL:
248 if(blank) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800249 // External Display post commits the changes to display
250 // Call this on blank, so that any pipe unsets gets committed
251 if (!ctx->mExtDisplay->post()) {
252 ret = -1;
253 ALOGE("%s:ctx->mExtDisplay->post fail!! ", __FUNCTION__);
254 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700255 } else {
256 }
257 break;
258 default:
259 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700260 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800261 // Enable HPD here, as during bootup unblank is called
262 // when SF is completely initialized
263 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700264
265 if(ret < 0) {
266 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
267 __FUNCTION__, dpy, blank, strerror(errno));
268 return ret;
269 }
270 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
271 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700272 return 0;
273}
274
275static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700276 int param, int* value)
277{
278 hwc_context_t* ctx = (hwc_context_t*)(dev);
279 private_module_t* m = reinterpret_cast<private_module_t*>(
280 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700281 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700282
283 switch (param) {
284 case HWC_BACKGROUND_LAYER_SUPPORTED:
285 // Not supported for now
286 value[0] = 0;
287 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700288 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700289 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700290 ALOGI("fps: %d", value[0]);
291 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700292 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700293 if(ctx->mMDP.hasOverlay)
294 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700295 value[0] = supported;
296 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700297 default:
298 return -EINVAL;
299 }
300 return 0;
301
302}
303
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700305 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800306 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700307
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800308 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700309 uint32_t last = list->numHwLayers - 1;
310 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800311 int fd = -1; //FenceFD from the Copybit(valid in async mode)
312 if(ctx->mCopyBit[dpy])
313 ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800314 if(list->numHwLayers > 1)
315 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800316 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700317 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
318 ret = -1;
319 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800320 if (!ctx->mMDPComp->draw(ctx, list)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500321 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
322 ret = -1;
323 }
324
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700325 //TODO We dont check for SKIP flag on this layer because we need PAN
326 //always. Last layer is always FB
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500327 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
328 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800329 if(!(fbLayer->flags & HWC_SKIP_LAYER) &&
330 (list->numHwLayers > 1)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800331 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500332 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
333 ret = -1;
334 }
335 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700336 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
337 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
338 return -1;
339 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700340 }
341 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700342 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700343}
344
345static int hwc_set_external(hwc_context_t *ctx,
346 hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700347 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800348 const int dpy = HWC_DISPLAY_EXTERNAL;
349
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700350 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700351
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800352 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800353 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700354 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700355 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800356 int fd = -1; //FenceFD from the Copybit(valid in async mode)
357 if(ctx->mCopyBit[dpy])
358 ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700359
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800360 if(list->numHwLayers > 1)
361 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700362
Saurabh Shahcf053c62012-12-13 12:32:55 -0800363 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700364 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
365 ret = -1;
366 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700367
368 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700369 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800370 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd &&
371 (list->numHwLayers > 1)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800372 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500373 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700374 ret = -1;
375 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700376 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700377 if (!ctx->mExtDisplay->post()) {
378 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
379 return -1;
380 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700381 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700382 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700383}
384
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700385static int hwc_set(hwc_composer_device_1 *dev,
386 size_t numDisplays,
387 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388{
389 int ret = 0;
390 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400391 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700392 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700393 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700394 switch(i) {
395 case HWC_DISPLAY_PRIMARY:
396 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700397 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700398 case HWC_DISPLAY_EXTERNAL:
399 ret = hwc_set_external(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700400 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700401 default:
402 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700403 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700405 return ret;
406}
407
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700408int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
409 uint32_t* configs, size_t* numConfigs) {
410 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700411 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700412 //in 1.1 there is no way to choose a config, report as config id # 0
413 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700414 switch(disp) {
415 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700416 if(*numConfigs > 0) {
417 configs[0] = 0;
418 *numConfigs = 1;
419 }
420 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700421 break;
422 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700423 ret = -1; //Not connected
424 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
425 ret = 0; //NO_ERROR
426 if(*numConfigs > 0) {
427 configs[0] = 0;
428 *numConfigs = 1;
429 }
430 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700431 break;
432 }
433 return ret;
434}
435
436int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
437 uint32_t config, const uint32_t* attributes, int32_t* values) {
438
439 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700440 //If hotpluggable displays are inactive return error
441 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
442 return -1;
443 }
444
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700445 //From HWComposer
446 static const uint32_t DISPLAY_ATTRIBUTES[] = {
447 HWC_DISPLAY_VSYNC_PERIOD,
448 HWC_DISPLAY_WIDTH,
449 HWC_DISPLAY_HEIGHT,
450 HWC_DISPLAY_DPI_X,
451 HWC_DISPLAY_DPI_Y,
452 HWC_DISPLAY_NO_ATTRIBUTE,
453 };
454
455 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
456 sizeof(DISPLAY_ATTRIBUTES)[0]);
457
458 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
459 switch (attributes[i]) {
460 case HWC_DISPLAY_VSYNC_PERIOD:
461 values[i] = ctx->dpyAttr[disp].vsync_period;
462 break;
463 case HWC_DISPLAY_WIDTH:
464 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700465 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
466 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700467 break;
468 case HWC_DISPLAY_HEIGHT:
469 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700470 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
471 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700472 break;
473 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400474 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700475 break;
476 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400477 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700478 break;
479 default:
480 ALOGE("Unknown display attribute %d",
481 attributes[i]);
482 return -EINVAL;
483 }
484 }
485 return 0;
486}
487
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500488void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
489{
490 hwc_context_t* ctx = (hwc_context_t*)(dev);
491 android::String8 buf("");
492 dumpsys_log(buf, "Qualcomm HWC state:\n");
493 dumpsys_log(buf, " MDPVersion=%d\n", ctx->mMDP.version);
494 dumpsys_log(buf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800495 ctx->mMDPComp->dump(buf);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500496 //XXX: Call Other dump functions
497 strlcpy(buff, buf.string(), buff_len);
498}
499
Naseer Ahmed29a26812012-06-14 00:56:20 -0700500static int hwc_device_close(struct hw_device_t *dev)
501{
502 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700503 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700504 return -1;
505 }
506 closeContext((hwc_context_t*)dev);
507 free(dev);
508
509 return 0;
510}
511
512static int hwc_device_open(const struct hw_module_t* module, const char* name,
513 struct hw_device_t** device)
514{
515 int status = -EINVAL;
516
517 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
518 struct hwc_context_t *dev;
519 dev = (hwc_context_t*)malloc(sizeof(*dev));
520 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700521
522 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700524
525 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700526 dev->device.common.tag = HARDWARE_DEVICE_TAG;
527 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
528 dev->device.common.module = const_cast<hw_module_t*>(module);
529 dev->device.common.close = hwc_device_close;
530 dev->device.prepare = hwc_prepare;
531 dev->device.set = hwc_set;
532 dev->device.eventControl = hwc_eventControl;
533 dev->device.blank = hwc_blank;
534 dev->device.query = hwc_query;
535 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500536 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700537 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
538 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
539 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700540 status = 0;
541 }
542 return status;
543}