blob: 30555fa60746819bb57a7fc314058e911a70bdce [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 */
Naseer Ahmed64b81212013-02-14 10:29:47 -050020#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Naseer Ahmed29a26812012-06-14 00:56:20 -070021#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 Ahmed64b81212013-02-14 10:29:47 -050027#include <utils/Trace.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070028
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080030#include <overlayRotator.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070031#include <fb_priv.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070032#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070034#include "hwc_video.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050035#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050036#include "hwc_mdpcomp.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070037#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
40using namespace qhwc;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050041#define VSYNC_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43static int hwc_device_open(const struct hw_module_t* module,
44 const char* name,
45 struct hw_device_t** device);
46
47static struct hw_module_methods_t hwc_module_methods = {
48 open: hwc_device_open
49};
50
51hwc_module_t HAL_MODULE_INFO_SYM = {
52 common: {
53 tag: HARDWARE_MODULE_TAG,
54 version_major: 2,
55 version_minor: 0,
56 id: HWC_HARDWARE_MODULE_ID,
57 name: "Qualcomm Hardware Composer Module",
58 author: "CodeAurora Forum",
59 methods: &hwc_module_methods,
60 dso: 0,
61 reserved: {0},
62 }
63};
64
65/*
66 * Save callback functions registered to HWC
67 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070068static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 hwc_procs_t const* procs)
70{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070071 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 hwc_context_t* ctx = (hwc_context_t*)(dev);
73 if(!ctx) {
74 ALOGE("%s: Invalid context", __FUNCTION__);
75 return;
76 }
Jesse Hall3be78d92012-08-21 15:12:23 -070077 ctx->proc = procs;
78
Naseer Ahmedff4f0252012-10-01 13:03:01 -040079 // Now that we have the functions needed, kick off
80 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070081 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040082 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070083}
84
Saurabh Shah649cda62012-09-16 16:05:58 -070085//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040086static void reset(hwc_context_t *ctx, int numDisplays,
87 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070088 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080089 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040090 hwc_display_contents_1_t *list = displays[i];
91 // XXX:SurfaceFlinger no longer guarantees that this
92 // value is reset on every prepare. However, for the layer
93 // cache we need to reset it.
94 // We can probably rethink that later on
95 if (LIKELY(list && list->numHwLayers > 1)) {
96 for(uint32_t j = 0; j < list->numHwLayers; j++) {
97 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
98 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
99 }
100 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800101
102 if(ctx->mFBUpdate[i])
103 ctx->mFBUpdate[i]->reset();
Saurabh Shahacf10202013-02-26 10:15:15 -0800104 if(ctx->mVidOv[i])
105 ctx->mVidOv[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800106 if(ctx->mCopyBit[i])
107 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700108 }
109}
110
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500111//clear prev layer prop flags and realloc for current frame
112static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
113 int layer_count = ctx->listStats[dpy].numAppLayers;
114
115 if(ctx->layerProp[dpy]) {
116 delete[] ctx->layerProp[dpy];
117 ctx->layerProp[dpy] = NULL;
118 }
119
120 if(layer_count) {
121 ctx->layerProp[dpy] = new LayerProp[layer_count];
122 }
123}
124
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700125static int hwc_prepare_primary(hwc_composer_device_1 *dev,
126 hwc_display_contents_1_t *list) {
127 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800128 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shahbf1e02a2013-02-26 13:38:05 -0800129 if (LIKELY(list && list->numHwLayers > 1 &&
130 list->numHwLayers <= MAX_NUM_LAYERS) && ctx->dpyAttr[dpy].isActive) {
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 Shahacf10202013-02-26 10:15:15 -0800139 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500140 ctx->mFBUpdate[dpy]->prepare(ctx, list);
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,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800152 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700153 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700154
Saurabh Shahbf1e02a2013-02-26 13:38:05 -0800155 if (LIKELY(list && list->numHwLayers > 1 &&
156 list->numHwLayers <= MAX_NUM_LAYERS) &&
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 uint32_t last = list->numHwLayers - 1;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800160 if(!ctx->dpyAttr[dpy].isPause) {
161 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
162 if(fbLayer->handle) {
163 setListStats(ctx, list, dpy);
164 reset_layer_prop(ctx, dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800165 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500166 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800167 ctx->mLayerCache[dpy]->updateLayerCache(list);
168 if(ctx->mCopyBit[dpy])
169 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
170 ctx->mExtDispConfiguring = false;
171 }
172 } else {
173 // External Display is in Pause state.
174 // ToDo:
175 // Mark all application layers as OVERLAY so that
176 // GPU will not compose. This is done for power
177 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700178 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700179 }
180 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700181}
182
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700183static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
184 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700186 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500188 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400189 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700190
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500191 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800192 ctx->mRotMgr->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700193
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800194 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500195 hwc_display_contents_1_t *list = displays[i];
196 switch(i) {
197 case HWC_DISPLAY_PRIMARY:
198 ret = hwc_prepare_primary(dev, list);
199 break;
200 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800201 case HWC_DISPLAY_VIRTUAL:
202 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500203 break;
204 default:
205 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 }
207 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500208
Saurabh Shahcf053c62012-12-13 12:32:55 -0800209 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800210 ctx->mRotMgr->configDone();
211
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700212 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213}
214
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700215static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500216 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700217{
218 int ret = 0;
219 hwc_context_t* ctx = (hwc_context_t*)(dev);
220 private_module_t* m = reinterpret_cast<private_module_t*>(
221 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700222 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700223 switch(event) {
224 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500225 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700226 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500227 ret = hwc_vsync_control(ctx, dpy, enable);
228 if(ret == 0) {
229 ctx->vstate.enable = !!enable;
230 pthread_cond_signal(&ctx->vstate.cond);
231 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700232 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500233 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700234 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700235 default:
236 ret = -EINVAL;
237 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700238 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700239 return ret;
240}
241
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700242static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
243{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500244 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700245 hwc_context_t* ctx = (hwc_context_t*)(dev);
246 private_module_t* m = reinterpret_cast<private_module_t*>(
247 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500248 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700249 int ret = 0;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500250 ALOGD("%s: %s display: %d", __FUNCTION__,
251 blank==1 ? "Blanking":"Unblanking", dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700252 switch(dpy) {
253 case HWC_DISPLAY_PRIMARY:
254 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255 ctx->mOverlay->configBegin();
256 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800257 ctx->mRotMgr->clear();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700258 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800259
260 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
261 // Surfaceflinger does not send Blank/unblank event to hwc
262 // for virtual display, handle it explicitly when blank for
263 // primary is invoked, so that any pipes unset get committed
264 if (!ctx->mExtDisplay->post()) {
265 ret = -1;
266 ALOGE("%s:post failed for virtual display !!",
267 __FUNCTION__);
268 } else {
269 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
270 }
271 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700272 } else {
273 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800274 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
275 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
276 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700277 }
278 break;
279 case HWC_DISPLAY_EXTERNAL:
280 if(blank) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800281 // External post commits the changes to display
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800282 // Call this on blank, so that any pipe unsets gets committed
283 if (!ctx->mExtDisplay->post()) {
284 ret = -1;
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800285 ALOGE("%s:post failed for external display !! ",
286 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800287 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700288 } else {
289 }
290 break;
291 default:
292 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700293 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800294 // Enable HPD here, as during bootup unblank is called
295 // when SF is completely initialized
296 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500297 if(ret == 0){
298 ctx->dpyAttr[dpy].isActive = !blank;
299 } else {
300 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
301 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700302 return ret;
303 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500304
305 ALOGD("%s: Done %s display: %d", __FUNCTION__,
306 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700307 return 0;
308}
309
310static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700311 int param, int* value)
312{
313 hwc_context_t* ctx = (hwc_context_t*)(dev);
314 private_module_t* m = reinterpret_cast<private_module_t*>(
315 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700316 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700317
318 switch (param) {
319 case HWC_BACKGROUND_LAYER_SUPPORTED:
320 // Not supported for now
321 value[0] = 0;
322 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700323 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700324 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700325 ALOGI("fps: %d", value[0]);
326 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700328 if(ctx->mMDP.hasOverlay)
329 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700330 value[0] = supported;
331 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700332 default:
333 return -EINVAL;
334 }
335 return 0;
336
337}
338
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700339static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500340 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700341 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800342 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800343 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700344 uint32_t last = list->numHwLayers - 1;
345 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800346 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500347 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800348 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500349 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800350 if(list->numHwLayers > 1)
351 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahacf10202013-02-26 10:15:15 -0800352 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
353 ALOGE("%s: VideoOverlay draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700354 ret = -1;
355 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800356 if (!ctx->mMDPComp->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800357 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500358 ret = -1;
359 }
360
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700361 //TODO We dont check for SKIP flag on this layer because we need PAN
362 //always. Last layer is always FB
Naseer Ahmed64b81212013-02-14 10:29:47 -0500363 private_handle_t *hnd = NULL;
364 if(copybitDone) {
365 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
366 } else {
367 hnd = (private_handle_t *)fbLayer->handle;
368 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500369 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800370 if(!(fbLayer->flags & HWC_SKIP_LAYER) &&
371 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500372 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800373 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500374 ret = -1;
375 }
376 }
Saurabh Shah43333302013-02-06 13:30:27 -0800377 }
378 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
379 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800380 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700381 }
382 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800383
384 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700385 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700386}
387
388static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500389 hwc_display_contents_1_t* list, int dpy)
390{
391 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700392 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700393 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700394
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800395 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800396 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800397 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700398 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700399 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800400 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500401 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800402 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500403 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700404
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800405 if(list->numHwLayers > 1)
406 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700407
Saurabh Shahacf10202013-02-26 10:15:15 -0800408 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700409 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
410 ret = -1;
411 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700412
Naseer Ahmed64b81212013-02-14 10:29:47 -0500413 private_handle_t *hnd = NULL;
414 if(copybitDone) {
415 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
416 } else {
417 hnd = (private_handle_t *)fbLayer->handle;
418 }
419
Saurabh Shah150806a2012-10-09 15:38:23 -0700420 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800421 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd &&
422 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500423 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500424 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700425 ret = -1;
426 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700427 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700428 if (!ctx->mExtDisplay->post()) {
429 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800430 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700431 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700432 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800433
434 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700435 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700436}
437
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700438static int hwc_set(hwc_composer_device_1 *dev,
439 size_t numDisplays,
440 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700441{
442 int ret = 0;
443 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400444 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800445 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700446 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700447 switch(i) {
448 case HWC_DISPLAY_PRIMARY:
449 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700450 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700451 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800452 case HWC_DISPLAY_VIRTUAL:
453 /* ToDo: We are using hwc_set_external path for both External and
454 Virtual displays on HWC1.1. Eventually, we will have
455 separate functions when we move to HWC1.2
456 */
457 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700458 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700459 default:
460 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700461 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700462 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700463 return ret;
464}
465
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700466int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
467 uint32_t* configs, size_t* numConfigs) {
468 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700469 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470 //in 1.1 there is no way to choose a config, report as config id # 0
471 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700472 switch(disp) {
473 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700474 if(*numConfigs > 0) {
475 configs[0] = 0;
476 *numConfigs = 1;
477 }
478 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700479 break;
480 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700481 ret = -1; //Not connected
482 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
483 ret = 0; //NO_ERROR
484 if(*numConfigs > 0) {
485 configs[0] = 0;
486 *numConfigs = 1;
487 }
488 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700489 break;
490 }
491 return ret;
492}
493
494int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
495 uint32_t config, const uint32_t* attributes, int32_t* values) {
496
497 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700498 //If hotpluggable displays are inactive return error
499 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
500 return -1;
501 }
502
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700503 //From HWComposer
504 static const uint32_t DISPLAY_ATTRIBUTES[] = {
505 HWC_DISPLAY_VSYNC_PERIOD,
506 HWC_DISPLAY_WIDTH,
507 HWC_DISPLAY_HEIGHT,
508 HWC_DISPLAY_DPI_X,
509 HWC_DISPLAY_DPI_Y,
510 HWC_DISPLAY_NO_ATTRIBUTE,
511 };
512
513 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
514 sizeof(DISPLAY_ATTRIBUTES)[0]);
515
516 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
517 switch (attributes[i]) {
518 case HWC_DISPLAY_VSYNC_PERIOD:
519 values[i] = ctx->dpyAttr[disp].vsync_period;
520 break;
521 case HWC_DISPLAY_WIDTH:
522 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700523 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
524 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700525 break;
526 case HWC_DISPLAY_HEIGHT:
527 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700528 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
529 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700530 break;
531 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400532 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700533 break;
534 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400535 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700536 break;
537 default:
538 ALOGE("Unknown display attribute %d",
539 attributes[i]);
540 return -EINVAL;
541 }
542 }
543 return 0;
544}
545
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500546void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
547{
548 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800549 android::String8 aBuf("");
550 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
551 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
552 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
553 ctx->mMDPComp->dump(aBuf);
554 char ovDump[2048] = {'\0'};
555 ctx->mOverlay->getDump(ovDump, 2048);
556 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800557 ovDump[0] = '\0';
558 ctx->mRotMgr->getDump(ovDump, 2048);
559 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800560 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500561}
562
Naseer Ahmed29a26812012-06-14 00:56:20 -0700563static int hwc_device_close(struct hw_device_t *dev)
564{
565 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700566 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700567 return -1;
568 }
569 closeContext((hwc_context_t*)dev);
570 free(dev);
571
572 return 0;
573}
574
575static int hwc_device_open(const struct hw_module_t* module, const char* name,
576 struct hw_device_t** device)
577{
578 int status = -EINVAL;
579
580 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
581 struct hwc_context_t *dev;
582 dev = (hwc_context_t*)malloc(sizeof(*dev));
583 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700584
585 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700586 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700587
588 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700589 dev->device.common.tag = HARDWARE_DEVICE_TAG;
590 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
591 dev->device.common.module = const_cast<hw_module_t*>(module);
592 dev->device.common.close = hwc_device_close;
593 dev->device.prepare = hwc_prepare;
594 dev->device.set = hwc_set;
595 dev->device.eventControl = hwc_eventControl;
596 dev->device.blank = hwc_blank;
597 dev->device.query = hwc_query;
598 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500599 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700600 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
601 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
602 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700603 status = 0;
604 }
605 return status;
606}