blob: 8e7afa2c73740fe03adb7283bc9456ea253b80b9 [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>
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080028#include <sys/ioctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080030#include <overlayRotator.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070031#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070032#include "hwc_utils.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"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070035#include "hwc_dump_layers.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070036#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080037#include "hwc_copybit.h"
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -040038#include "profiler.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 Ahmede0205b62013-04-04 13:24:39 -040042#define BLANK_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070043
44static int hwc_device_open(const struct hw_module_t* module,
45 const char* name,
46 struct hw_device_t** device);
47
48static struct hw_module_methods_t hwc_module_methods = {
49 open: hwc_device_open
50};
51
52hwc_module_t HAL_MODULE_INFO_SYM = {
53 common: {
54 tag: HARDWARE_MODULE_TAG,
55 version_major: 2,
56 version_minor: 0,
57 id: HWC_HARDWARE_MODULE_ID,
58 name: "Qualcomm Hardware Composer Module",
59 author: "CodeAurora Forum",
60 methods: &hwc_module_methods,
61 dso: 0,
62 reserved: {0},
63 }
64};
65
66/*
67 * Save callback functions registered to HWC
68 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070069static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 hwc_procs_t const* procs)
71{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070072 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 hwc_context_t* ctx = (hwc_context_t*)(dev);
74 if(!ctx) {
75 ALOGE("%s: Invalid context", __FUNCTION__);
76 return;
77 }
Jesse Hall3be78d92012-08-21 15:12:23 -070078 ctx->proc = procs;
79
Naseer Ahmedff4f0252012-10-01 13:03:01 -040080 // Now that we have the functions needed, kick off
81 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070082 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040083 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084}
85
Saurabh Shah649cda62012-09-16 16:05:58 -070086//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040087static void reset(hwc_context_t *ctx, int numDisplays,
88 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070089 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080090 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040091 hwc_display_contents_1_t *list = displays[i];
92 // XXX:SurfaceFlinger no longer guarantees that this
93 // value is reset on every prepare. However, for the layer
94 // cache we need to reset it.
95 // We can probably rethink that later on
96 if (LIKELY(list && list->numHwLayers > 1)) {
97 for(uint32_t j = 0; j < list->numHwLayers; j++) {
98 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
99 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
100 }
101 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800102
103 if(ctx->mFBUpdate[i])
104 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800105 if(ctx->mCopyBit[i])
106 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700107 }
108}
109
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500110//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700111static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500112 if(ctx->layerProp[dpy]) {
113 delete[] ctx->layerProp[dpy];
114 ctx->layerProp[dpy] = NULL;
115 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700116 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500117}
118
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800119static int display_commit(hwc_context_t *ctx, int dpy) {
120 struct mdp_display_commit commit_info;
121 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
122 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
123 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
124 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
125 return -errno;
126 }
127 return 0;
128}
129
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700130static int hwc_prepare_primary(hwc_composer_device_1 *dev,
131 hwc_display_contents_1_t *list) {
132 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800133 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700134 if (LIKELY(list && list->numHwLayers > 1) &&
135 ctx->dpyAttr[dpy].isActive) {
136 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700137 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700138 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
139 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800140 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800141 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
142 if(fbZOrder >= 0)
143 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
144
145 /* Temporarily commenting out C2D until we support partial
146 copybit composition for mixed mode MDP
147
148 // Use Copybit, when MDP comp fails
149 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
150 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
151 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700152 }
153 }
154 return 0;
155}
156
157static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800158 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700159 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700160
Saurabh Shah2b033392013-03-22 11:29:44 -0700161 if (LIKELY(list && list->numHwLayers > 1) &&
162 ctx->dpyAttr[dpy].isActive &&
163 ctx->dpyAttr[dpy].connected) {
164 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700165 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700166 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800167 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800168 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700169 ctx->mExtDispConfiguring = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800170 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
172 if(fbZOrder >= 0)
173 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
174
175 /* Temporarily commenting out C2D until we support partial
176 copybit composition for mixed mode MDP
177
178 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800179 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800180 */
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800181 }
182 } else {
183 // External Display is in Pause state.
184 // ToDo:
185 // Mark all application layers as OVERLAY so that
186 // GPU will not compose. This is done for power
187 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700188 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700189 }
190 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700191}
192
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700193static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
194 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700196 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400199 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700200
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800202 ctx->mRotMgr->configBegin();
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800203 ctx->mNeedsRotator = false;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700204
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800205 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500206 hwc_display_contents_1_t *list = displays[i];
207 switch(i) {
208 case HWC_DISPLAY_PRIMARY:
209 ret = hwc_prepare_primary(dev, list);
210 break;
211 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800212 case HWC_DISPLAY_VIRTUAL:
213 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500214 break;
215 default:
216 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 }
218 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219
Saurabh Shahcf053c62012-12-13 12:32:55 -0800220 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800221 ctx->mRotMgr->configDone();
222
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700223 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224}
225
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700226static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500227 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700228{
229 int ret = 0;
230 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700231 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700232 switch(event) {
233 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500234 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700235 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500236 ret = hwc_vsync_control(ctx, dpy, enable);
237 if(ret == 0) {
238 ctx->vstate.enable = !!enable;
239 pthread_cond_signal(&ctx->vstate.cond);
240 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700241 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500242 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700243 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700244 default:
245 ret = -EINVAL;
246 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700247 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248 return ret;
249}
250
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700251static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
252{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500253 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700254 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800255
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700257 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400258 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500259 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700260 if(blank) {
261 // free up all the overlay pipes in use
262 // when we get a blank for either display
263 // makes sure that all pipes are freed
264 ctx->mOverlay->configBegin();
265 ctx->mOverlay->configDone();
266 ctx->mRotMgr->clear();
267 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700268 switch(dpy) {
269 case HWC_DISPLAY_PRIMARY:
270 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800271 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800272
273 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
274 // Surfaceflinger does not send Blank/unblank event to hwc
275 // for virtual display, handle it explicitly when blank for
276 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800277 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800278 ret = -1;
279 ALOGE("%s:post failed for virtual display !!",
280 __FUNCTION__);
281 } else {
282 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
283 }
284 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700285 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800286 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800287 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
288 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
289 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700290 }
291 break;
292 case HWC_DISPLAY_EXTERNAL:
293 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800294 // call external framebuffer commit on blank,
295 // so that any pipe unsets gets committed
296 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800297 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800298 ALOGE("%s:post failed for external display !! ",
299 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800300 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700301 } else {
302 }
303 break;
304 default:
305 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700306 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800307 // Enable HPD here, as during bootup unblank is called
308 // when SF is completely initialized
309 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500310 if(ret == 0){
311 ctx->dpyAttr[dpy].isActive = !blank;
312 } else {
313 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
314 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700315 return ret;
316 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500317
Naseer Ahmede0205b62013-04-04 13:24:39 -0400318 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500319 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700320 return 0;
321}
322
323static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700324 int param, int* value)
325{
326 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700328
329 switch (param) {
330 case HWC_BACKGROUND_LAYER_SUPPORTED:
331 // Not supported for now
332 value[0] = 0;
333 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700334 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700335 if(ctx->mMDP.hasOverlay)
336 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700337 value[0] = supported;
338 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700339 default:
340 return -EINVAL;
341 }
342 return 0;
343
344}
345
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800346
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700347static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500348 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700349 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800350 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800351 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700352 uint32_t last = list->numHwLayers - 1;
353 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800354 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500355 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800356 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500357 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800358 if(list->numHwLayers > 1)
359 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800360
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700361 // Dump the layers for primary
362 if(ctx->mHwcDebug[dpy])
363 ctx->mHwcDebug[dpy]->dumpLayers(list);
364
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800366 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500367 ret = -1;
368 }
369
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700370 //TODO We dont check for SKIP flag on this layer because we need PAN
371 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700372 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500373 if(copybitDone) {
374 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500375 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700376
377 if(hnd) {
378 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
379 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
380 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500381 }
Saurabh Shah43333302013-02-06 13:30:27 -0800382 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800383
384 if (display_commit(ctx, dpy) < 0) {
385 ALOGE("%s: display commit fail!", __FUNCTION__);
386 return -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700387 }
388 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800389
390 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700391 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700392}
393
394static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500395 hwc_display_contents_1_t* list, int dpy)
396{
397 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700398 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700399 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700400
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800401 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800402 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800403 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700404 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700405 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800406 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500407 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800408 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500409 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700410
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800411 if(list->numHwLayers > 1)
412 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700413
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700414 // Dump the layers for external
415 if(ctx->mHwcDebug[dpy])
416 ctx->mHwcDebug[dpy]->dumpLayers(list);
417
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800418 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
419 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700420 ret = -1;
421 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700422
Saurabh Shah2b033392013-03-22 11:29:44 -0700423 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500424 if(copybitDone) {
425 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500426 }
427
Saurabh Shah2b033392013-03-22 11:29:44 -0700428 if(hnd) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500429 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500430 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700431 ret = -1;
432 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700433 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800434
435 if (display_commit(ctx, dpy) < 0) {
436 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700437 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700438 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700439 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800440
441 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700442 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700443}
444
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700445static int hwc_set(hwc_composer_device_1 *dev,
446 size_t numDisplays,
447 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700448{
449 int ret = 0;
450 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400451 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800452 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700453 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700454 switch(i) {
455 case HWC_DISPLAY_PRIMARY:
456 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700457 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700458 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800459 case HWC_DISPLAY_VIRTUAL:
460 /* ToDo: We are using hwc_set_external path for both External and
461 Virtual displays on HWC1.1. Eventually, we will have
462 separate functions when we move to HWC1.2
463 */
464 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700465 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700466 default:
467 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700468 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700469 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400470 // This is only indicative of how many times SurfaceFlinger posts
471 // frames to the display.
472 CALC_FPS();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700473 return ret;
474}
475
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700476int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
477 uint32_t* configs, size_t* numConfigs) {
478 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700479 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700480 //in 1.1 there is no way to choose a config, report as config id # 0
481 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700482 switch(disp) {
483 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700484 if(*numConfigs > 0) {
485 configs[0] = 0;
486 *numConfigs = 1;
487 }
488 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700489 break;
490 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700491 ret = -1; //Not connected
492 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
493 ret = 0; //NO_ERROR
494 if(*numConfigs > 0) {
495 configs[0] = 0;
496 *numConfigs = 1;
497 }
498 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700499 break;
500 }
501 return ret;
502}
503
504int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
505 uint32_t config, const uint32_t* attributes, int32_t* values) {
506
507 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700508 //If hotpluggable displays are inactive return error
509 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
510 return -1;
511 }
512
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700513 //From HWComposer
514 static const uint32_t DISPLAY_ATTRIBUTES[] = {
515 HWC_DISPLAY_VSYNC_PERIOD,
516 HWC_DISPLAY_WIDTH,
517 HWC_DISPLAY_HEIGHT,
518 HWC_DISPLAY_DPI_X,
519 HWC_DISPLAY_DPI_Y,
520 HWC_DISPLAY_NO_ATTRIBUTE,
521 };
522
523 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
524 sizeof(DISPLAY_ATTRIBUTES)[0]);
525
526 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
527 switch (attributes[i]) {
528 case HWC_DISPLAY_VSYNC_PERIOD:
529 values[i] = ctx->dpyAttr[disp].vsync_period;
530 break;
531 case HWC_DISPLAY_WIDTH:
532 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700533 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
534 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700535 break;
536 case HWC_DISPLAY_HEIGHT:
537 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700538 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
539 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700540 break;
541 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400542 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700543 break;
544 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400545 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700546 break;
547 default:
548 ALOGE("Unknown display attribute %d",
549 attributes[i]);
550 return -EINVAL;
551 }
552 }
553 return 0;
554}
555
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500556void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
557{
558 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800559 android::String8 aBuf("");
560 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
561 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
562 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800563 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
564 if(ctx->mMDPComp[dpy])
565 ctx->mMDPComp[dpy]->dump(aBuf);
566 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800567 char ovDump[2048] = {'\0'};
568 ctx->mOverlay->getDump(ovDump, 2048);
569 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800570 ovDump[0] = '\0';
571 ctx->mRotMgr->getDump(ovDump, 2048);
572 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800573 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500574}
575
Naseer Ahmed29a26812012-06-14 00:56:20 -0700576static int hwc_device_close(struct hw_device_t *dev)
577{
578 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700579 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700580 return -1;
581 }
582 closeContext((hwc_context_t*)dev);
583 free(dev);
584
585 return 0;
586}
587
588static int hwc_device_open(const struct hw_module_t* module, const char* name,
589 struct hw_device_t** device)
590{
591 int status = -EINVAL;
592
593 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
594 struct hwc_context_t *dev;
595 dev = (hwc_context_t*)malloc(sizeof(*dev));
596 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700597
598 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700599 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700600
601 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700602 dev->device.common.tag = HARDWARE_DEVICE_TAG;
603 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
604 dev->device.common.module = const_cast<hw_module_t*>(module);
605 dev->device.common.close = hwc_device_close;
606 dev->device.prepare = hwc_prepare;
607 dev->device.set = hwc_set;
608 dev->device.eventControl = hwc_eventControl;
609 dev->device.blank = hwc_blank;
610 dev->device.query = hwc_query;
611 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500612 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700613 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
614 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
615 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700616 status = 0;
617 }
618 return status;
619}