blob: 45fbea2498d08ef73121872a59c3abd78519575d [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));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080087 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040088 hwc_display_contents_1_t *list = displays[i];
89 // XXX:SurfaceFlinger no longer guarantees that this
90 // value is reset on every prepare. However, for the layer
91 // cache we need to reset it.
92 // We can probably rethink that later on
93 if (LIKELY(list && list->numHwLayers > 1)) {
94 for(uint32_t j = 0; j < list->numHwLayers; j++) {
95 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
96 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
97 }
98 }
Saurabh Shahcf053c62012-12-13 12:32:55 -080099
100 if(ctx->mFBUpdate[i])
101 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800102
103 if(ctx->mCopyBit[i])
104 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700105 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500106 VideoOverlay::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700107}
108
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500109//clear prev layer prop flags and realloc for current frame
110static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
111 int layer_count = ctx->listStats[dpy].numAppLayers;
112
113 if(ctx->layerProp[dpy]) {
114 delete[] ctx->layerProp[dpy];
115 ctx->layerProp[dpy] = NULL;
116 }
117
118 if(layer_count) {
119 ctx->layerProp[dpy] = new LayerProp[layer_count];
120 }
121}
122
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700123static int hwc_prepare_primary(hwc_composer_device_1 *dev,
124 hwc_display_contents_1_t *list) {
125 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800126 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700127 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800128 ctx->dpyAttr[dpy].isActive) {
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700129
Saurabh Shah86623d72012-09-25 19:39:17 -0700130 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700131 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
132 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800133 setListStats(ctx, list, dpy);
134 reset_layer_prop(ctx, dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800135 int ret = ctx->mMDPComp->prepare(ctx, list);
136 if(!ret) {
137 // IF MDPcomp fails use this route
Saurabh Shahcf053c62012-12-13 12:32:55 -0800138 VideoOverlay::prepare(ctx, list, dpy);
139 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500140 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800141 ctx->mLayerCache[dpy]->updateLayerCache(list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800142 // Use Copybit, when MDP comp fails
143 if(!ret && ctx->mCopyBit[dpy])
144 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700145 }
146 }
147 return 0;
148}
149
150static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800151 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700152 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700153
Saurabh Shahae823e72012-10-05 00:08:11 -0400154 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800155 ctx->dpyAttr[dpy].isActive &&
156 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700157 uint32_t last = list->numHwLayers - 1;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800158 if(!ctx->dpyAttr[dpy].isPause) {
159 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
160 if(fbLayer->handle) {
161 setListStats(ctx, list, dpy);
162 reset_layer_prop(ctx, dpy);
163 VideoOverlay::prepare(ctx, list, dpy);
164 ctx->mFBUpdate[dpy]->prepare(ctx, fbLayer);
165 ctx->mLayerCache[dpy]->updateLayerCache(list);
166 if(ctx->mCopyBit[dpy])
167 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
168 ctx->mExtDispConfiguring = false;
169 }
170 } else {
171 // External Display is in Pause state.
172 // ToDo:
173 // Mark all application layers as OVERLAY so that
174 // GPU will not compose. This is done for power
175 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700176 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700177 }
178 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700179}
180
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700181static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
182 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700184 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500186 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400187 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700188
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189 ctx->mOverlay->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700190
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800191 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500192 hwc_display_contents_1_t *list = displays[i];
193 switch(i) {
194 case HWC_DISPLAY_PRIMARY:
195 ret = hwc_prepare_primary(dev, list);
196 break;
197 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800198 case HWC_DISPLAY_VIRTUAL:
199 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500200 break;
201 default:
202 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203 }
204 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500205
Saurabh Shahcf053c62012-12-13 12:32:55 -0800206 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700207 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208}
209
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700210static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700211 int event, int enabled)
212{
213 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400214
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700215 hwc_context_t* ctx = (hwc_context_t*)(dev);
216 private_module_t* m = reinterpret_cast<private_module_t*>(
217 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700218 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700219 switch(event) {
220 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700221 if (ctx->vstate.enable == enabled)
222 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700223 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400224 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700225 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
226 (enabled)?"ENABLED":"DISABLED");
227 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700228 default:
229 ret = -EINVAL;
230 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700231 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700232 return ret;
233}
234
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700235static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
236{
Naseer Ahmed934790c2012-08-16 18:11:09 -0700237 hwc_context_t* ctx = (hwc_context_t*)(dev);
238 private_module_t* m = reinterpret_cast<private_module_t*>(
239 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500240 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700241 int ret = 0;
242 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
243 switch(dpy) {
244 case HWC_DISPLAY_PRIMARY:
245 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500246 ctx->mOverlay->configBegin();
247 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700248 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800249
250 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
251 // Surfaceflinger does not send Blank/unblank event to hwc
252 // for virtual display, handle it explicitly when blank for
253 // primary is invoked, so that any pipes unset get committed
254 if (!ctx->mExtDisplay->post()) {
255 ret = -1;
256 ALOGE("%s:post failed for virtual display !!",
257 __FUNCTION__);
258 } else {
259 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
260 }
261 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700262 } else {
263 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800264 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
265 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
266 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700267 }
268 break;
269 case HWC_DISPLAY_EXTERNAL:
270 if(blank) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800271 // External post commits the changes to display
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800272 // Call this on blank, so that any pipe unsets gets committed
273 if (!ctx->mExtDisplay->post()) {
274 ret = -1;
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800275 ALOGE("%s:post failed for external display !! ",
276 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800277 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700278 } else {
279 }
280 break;
281 default:
282 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700283 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800284 // Enable HPD here, as during bootup unblank is called
285 // when SF is completely initialized
286 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700287
288 if(ret < 0) {
289 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
290 __FUNCTION__, dpy, blank, strerror(errno));
291 return ret;
292 }
293 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
294 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700295 return 0;
296}
297
298static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700299 int param, int* value)
300{
301 hwc_context_t* ctx = (hwc_context_t*)(dev);
302 private_module_t* m = reinterpret_cast<private_module_t*>(
303 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700305
306 switch (param) {
307 case HWC_BACKGROUND_LAYER_SUPPORTED:
308 // Not supported for now
309 value[0] = 0;
310 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700311 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700312 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700313 ALOGI("fps: %d", value[0]);
314 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700315 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700316 if(ctx->mMDP.hasOverlay)
317 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700318 value[0] = supported;
319 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700320 default:
321 return -EINVAL;
322 }
323 return 0;
324
325}
326
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700328 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800329 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800330 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700331 uint32_t last = list->numHwLayers - 1;
332 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800333 int fd = -1; //FenceFD from the Copybit(valid in async mode)
334 if(ctx->mCopyBit[dpy])
335 ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800336 if(list->numHwLayers > 1)
337 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800338 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700339 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
340 ret = -1;
341 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800342 if (!ctx->mMDPComp->draw(ctx, list)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500343 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
344 ret = -1;
345 }
346
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700347 //TODO We dont check for SKIP flag on this layer because we need PAN
348 //always. Last layer is always FB
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500349 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
350 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800351 if(!(fbLayer->flags & HWC_SKIP_LAYER) &&
352 (list->numHwLayers > 1)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800353 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500354 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
355 ret = -1;
356 }
357 }
Saurabh Shah43333302013-02-06 13:30:27 -0800358 }
359 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
360 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800361 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700362 }
363 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800364
365 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700366 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700367}
368
369static int hwc_set_external(hwc_context_t *ctx,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800370 hwc_display_contents_1_t* list, int dpy) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700371 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700372 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700373
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800374 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800375 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800376 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700377 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700378 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800379 int fd = -1; //FenceFD from the Copybit(valid in async mode)
380 if(ctx->mCopyBit[dpy])
381 ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700382
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800383 if(list->numHwLayers > 1)
384 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700385
Saurabh Shahcf053c62012-12-13 12:32:55 -0800386 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700387 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
388 ret = -1;
389 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700390
391 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Saurabh Shah150806a2012-10-09 15:38:23 -0700392 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800393 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd &&
394 (list->numHwLayers > 1)) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800395 if (!ctx->mFBUpdate[dpy]->draw(ctx, fbLayer)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500396 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700397 ret = -1;
398 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700399 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700400 if (!ctx->mExtDisplay->post()) {
401 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800402 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700403 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700404 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800405
406 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700407 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700408}
409
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700410static int hwc_set(hwc_composer_device_1 *dev,
411 size_t numDisplays,
412 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700413{
414 int ret = 0;
415 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400416 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800417 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700418 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700419 switch(i) {
420 case HWC_DISPLAY_PRIMARY:
421 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700422 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700423 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800424 case HWC_DISPLAY_VIRTUAL:
425 /* ToDo: We are using hwc_set_external path for both External and
426 Virtual displays on HWC1.1. Eventually, we will have
427 separate functions when we move to HWC1.2
428 */
429 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700430 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700431 default:
432 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700433 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700434 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700435 return ret;
436}
437
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700438int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
439 uint32_t* configs, size_t* numConfigs) {
440 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700441 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700442 //in 1.1 there is no way to choose a config, report as config id # 0
443 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700444 switch(disp) {
445 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700446 if(*numConfigs > 0) {
447 configs[0] = 0;
448 *numConfigs = 1;
449 }
450 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700451 break;
452 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700453 ret = -1; //Not connected
454 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
455 ret = 0; //NO_ERROR
456 if(*numConfigs > 0) {
457 configs[0] = 0;
458 *numConfigs = 1;
459 }
460 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700461 break;
462 }
463 return ret;
464}
465
466int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
467 uint32_t config, const uint32_t* attributes, int32_t* values) {
468
469 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700470 //If hotpluggable displays are inactive return error
471 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
472 return -1;
473 }
474
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700475 //From HWComposer
476 static const uint32_t DISPLAY_ATTRIBUTES[] = {
477 HWC_DISPLAY_VSYNC_PERIOD,
478 HWC_DISPLAY_WIDTH,
479 HWC_DISPLAY_HEIGHT,
480 HWC_DISPLAY_DPI_X,
481 HWC_DISPLAY_DPI_Y,
482 HWC_DISPLAY_NO_ATTRIBUTE,
483 };
484
485 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
486 sizeof(DISPLAY_ATTRIBUTES)[0]);
487
488 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
489 switch (attributes[i]) {
490 case HWC_DISPLAY_VSYNC_PERIOD:
491 values[i] = ctx->dpyAttr[disp].vsync_period;
492 break;
493 case HWC_DISPLAY_WIDTH:
494 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700495 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
496 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700497 break;
498 case HWC_DISPLAY_HEIGHT:
499 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700500 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
501 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700502 break;
503 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400504 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700505 break;
506 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400507 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700508 break;
509 default:
510 ALOGE("Unknown display attribute %d",
511 attributes[i]);
512 return -EINVAL;
513 }
514 }
515 return 0;
516}
517
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500518void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
519{
520 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800521 android::String8 aBuf("");
522 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
523 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
524 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
525 ctx->mMDPComp->dump(aBuf);
526 char ovDump[2048] = {'\0'};
527 ctx->mOverlay->getDump(ovDump, 2048);
528 dumpsys_log(aBuf, ovDump);
529 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500530}
531
Naseer Ahmed29a26812012-06-14 00:56:20 -0700532static int hwc_device_close(struct hw_device_t *dev)
533{
534 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700535 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700536 return -1;
537 }
538 closeContext((hwc_context_t*)dev);
539 free(dev);
540
541 return 0;
542}
543
544static int hwc_device_open(const struct hw_module_t* module, const char* name,
545 struct hw_device_t** device)
546{
547 int status = -EINVAL;
548
549 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
550 struct hwc_context_t *dev;
551 dev = (hwc_context_t*)malloc(sizeof(*dev));
552 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700553
554 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700555 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700556
557 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700558 dev->device.common.tag = HARDWARE_DEVICE_TAG;
559 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
560 dev->device.common.module = const_cast<hw_module_t*>(module);
561 dev->device.common.close = hwc_device_close;
562 dev->device.prepare = hwc_prepare;
563 dev->device.set = hwc_set;
564 dev->device.eventControl = hwc_eventControl;
565 dev->device.blank = hwc_blank;
566 dev->device.query = hwc_query;
567 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500568 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700569 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
570 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
571 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700572 status = 0;
573 }
574 return status;
575}