blob: 143957872af54a09f9751dc578f78e16069a424f [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>
Saurabh Shahc8118ac2013-06-27 10:03:19 -070031#include <overlayWriteback.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 Ahmed758bfc52012-11-28 17:02:08 -050034#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050035#include "hwc_mdpcomp.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070036#include "hwc_dump_layers.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 Ahmed0d05d4f2013-03-28 14:49:07 -040039#include "profiler.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070040
41using namespace qhwc;
Saurabh Shah85234ec2013-04-12 17:09:00 -070042using namespace overlay;
43
Naseer Ahmed758bfc52012-11-28 17:02:08 -050044#define VSYNC_DEBUG 0
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -070045#define BLANK_DEBUG 1
Naseer Ahmed29a26812012-06-14 00:56:20 -070046
47static int hwc_device_open(const struct hw_module_t* module,
48 const char* name,
49 struct hw_device_t** device);
50
51static struct hw_module_methods_t hwc_module_methods = {
52 open: hwc_device_open
53};
54
55hwc_module_t HAL_MODULE_INFO_SYM = {
56 common: {
57 tag: HARDWARE_MODULE_TAG,
58 version_major: 2,
59 version_minor: 0,
60 id: HWC_HARDWARE_MODULE_ID,
61 name: "Qualcomm Hardware Composer Module",
62 author: "CodeAurora Forum",
63 methods: &hwc_module_methods,
64 dso: 0,
65 reserved: {0},
66 }
67};
68
69/*
70 * Save callback functions registered to HWC
71 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070072static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070073 hwc_procs_t const* procs)
74{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070075 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070076 hwc_context_t* ctx = (hwc_context_t*)(dev);
77 if(!ctx) {
78 ALOGE("%s: Invalid context", __FUNCTION__);
79 return;
80 }
Jesse Hall3be78d92012-08-21 15:12:23 -070081 ctx->proc = procs;
82
Naseer Ahmedff4f0252012-10-01 13:03:01 -040083 // Now that we have the functions needed, kick off
84 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070085 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040086 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070087}
88
Saurabh Shah649cda62012-09-16 16:05:58 -070089//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040090static void reset(hwc_context_t *ctx, int numDisplays,
91 hwc_display_contents_1_t** displays) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080092 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040093 hwc_display_contents_1_t *list = displays[i];
94 // XXX:SurfaceFlinger no longer guarantees that this
95 // value is reset on every prepare. However, for the layer
96 // cache we need to reset it.
97 // We can probably rethink that later on
98 if (LIKELY(list && list->numHwLayers > 1)) {
99 for(uint32_t j = 0; j < list->numHwLayers; j++) {
100 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
101 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
102 }
103 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800104
105 if(ctx->mFBUpdate[i])
106 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800107 if(ctx->mCopyBit[i])
108 ctx->mCopyBit[i]->reset();
Saurabh Shah23a813c2013-03-20 16:58:12 -0700109 if(ctx->mLayerRotMap[i])
110 ctx->mLayerRotMap[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700111 }
112}
113
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500114//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700115static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500116 if(ctx->layerProp[dpy]) {
117 delete[] ctx->layerProp[dpy];
118 ctx->layerProp[dpy] = NULL;
119 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700120 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500121}
122
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800123static int display_commit(hwc_context_t *ctx, int dpy) {
124 struct mdp_display_commit commit_info;
125 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
126 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
127 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700128 ALOGE("%s: MSMFB_DISPLAY_COMMIT for dpy %d failed", __FUNCTION__,dpy);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800129 return -errno;
130 }
131 return 0;
132}
133
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700134static int hwc_prepare_primary(hwc_composer_device_1 *dev,
135 hwc_display_contents_1_t *list) {
136 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800137 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700138 if (LIKELY(list && list->numHwLayers > 1) &&
139 ctx->dpyAttr[dpy].isActive) {
140 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700141 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700142 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
143 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800144 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800145 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
146 if(fbZOrder >= 0)
147 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
148
Terence Hampson0124cc72013-04-18 23:45:56 -0700149 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
150 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
151 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
152 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700153 }
154 }
155 return 0;
156}
157
158static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800159 hwc_display_contents_1_t *list, int dpy) {
Raj kamale3e68ae2013-05-02 17:28:23 +0530160
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700161 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj kamale3e68ae2013-05-02 17:28:23 +0530162 Locker::Autolock _l(ctx->mExtLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700163
Saurabh Shah2b033392013-03-22 11:29:44 -0700164 if (LIKELY(list && list->numHwLayers > 1) &&
165 ctx->dpyAttr[dpy].isActive &&
166 ctx->dpyAttr[dpy].connected) {
167 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700168 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700169 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800170 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800171 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700172 ctx->mExtDispConfiguring = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800173 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700175 if(ctx->deviceOrientation &&
176 ctx->listStats[dpy].isDisplayAnimating) {
177 fbZOrder = 0;
178 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800179 if(fbZOrder >= 0)
180 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
181
182 /* Temporarily commenting out C2D until we support partial
183 copybit composition for mixed mode MDP
184
185 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800186 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 */
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700188 if(ctx->listStats[dpy].isDisplayAnimating) {
189 // Mark all app layers as HWC_OVERLAY for external during
190 // animation, so that SF doesnt draw it on FB
191 for(int i = 0 ;i < ctx->listStats[dpy].numAppLayers; i++) {
192 hwc_layer_1_t *layer = &list->hwLayers[i];
193 layer->compositionType = HWC_OVERLAY;
194 }
195 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800196 }
197 } else {
198 // External Display is in Pause state.
199 // ToDo:
200 // Mark all application layers as OVERLAY so that
201 // GPU will not compose. This is done for power
202 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700203 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700204 }
205 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700206}
207
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700208static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
209 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700211 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500213 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400214 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700215
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500216 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800217 ctx->mRotMgr->configBegin();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700218 overlay::Writeback::configBegin();
219
Saurabh Shah85234ec2013-04-12 17:09:00 -0700220 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700221
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800222 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500223 hwc_display_contents_1_t *list = displays[i];
224 switch(i) {
225 case HWC_DISPLAY_PRIMARY:
226 ret = hwc_prepare_primary(dev, list);
227 break;
228 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800229 case HWC_DISPLAY_VIRTUAL:
230 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500231 break;
232 default:
233 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700234 }
235 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500236
Saurabh Shahcf053c62012-12-13 12:32:55 -0800237 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800238 ctx->mRotMgr->configDone();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700239 overlay::Writeback::configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800240
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700241 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700242}
243
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700244static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500245 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700246{
247 int ret = 0;
248 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400249 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700250 switch(event) {
251 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500252 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700253 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500254 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400255 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500256 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700257 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500258 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700259 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400260#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700261 case HWC_EVENT_ORIENTATION:
262 if(dpy == HWC_DISPLAY_PRIMARY) {
263 // store the primary display orientation
264 // will be used in hwc_video::configure to disable
265 // rotation animation on external display
266 ctx->deviceOrientation = enable;
267 }
268 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400269#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700270 default:
271 ret = -EINVAL;
272 }
273 return ret;
274}
275
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700276static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
277{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500278 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700279 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800280
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500281 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700282 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400283 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500284 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700285 if(blank) {
286 // free up all the overlay pipes in use
287 // when we get a blank for either display
288 // makes sure that all pipes are freed
289 ctx->mOverlay->configBegin();
290 ctx->mOverlay->configDone();
291 ctx->mRotMgr->clear();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700292 overlay::Writeback::clear();
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700293 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700294 switch(dpy) {
295 case HWC_DISPLAY_PRIMARY:
296 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800297 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800298
299 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
300 // Surfaceflinger does not send Blank/unblank event to hwc
301 // for virtual display, handle it explicitly when blank for
302 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800303 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800304 ret = -1;
305 ALOGE("%s:post failed for virtual display !!",
306 __FUNCTION__);
307 } else {
308 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
309 }
310 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700311 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800312 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800313 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
314 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
315 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700316 }
317 break;
318 case HWC_DISPLAY_EXTERNAL:
319 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800320 // call external framebuffer commit on blank,
321 // so that any pipe unsets gets committed
322 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800323 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800324 ALOGE("%s:post failed for external display !! ",
325 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800326 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700327 } else {
328 }
329 break;
330 default:
331 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700332 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800333 // Enable HPD here, as during bootup unblank is called
334 // when SF is completely initialized
335 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500336 if(ret == 0){
337 ctx->dpyAttr[dpy].isActive = !blank;
338 } else {
339 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
340 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700341 return ret;
342 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500343
Naseer Ahmede0205b62013-04-04 13:24:39 -0400344 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500345 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700346 return 0;
347}
348
349static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700350 int param, int* value)
351{
352 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700353 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700354
355 switch (param) {
356 case HWC_BACKGROUND_LAYER_SUPPORTED:
357 // Not supported for now
358 value[0] = 0;
359 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700360 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700361 if(ctx->mMDP.hasOverlay)
362 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700363 value[0] = supported;
364 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700365 default:
366 return -EINVAL;
367 }
368 return 0;
369
370}
371
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800372
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700373static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500374 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700375 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800376 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800377 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700378 uint32_t last = list->numHwLayers - 1;
379 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800380 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500381 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800382 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500383 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800384 if(list->numHwLayers > 1)
385 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800386
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700387 // Dump the layers for primary
388 if(ctx->mHwcDebug[dpy])
389 ctx->mHwcDebug[dpy]->dumpLayers(list);
390
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800391 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800392 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500393 ret = -1;
394 }
395
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700396 //TODO We dont check for SKIP flag on this layer because we need PAN
397 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700398 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500399 if(copybitDone) {
400 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500401 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700402
403 if(hnd) {
404 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
405 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
406 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500407 }
Saurabh Shah43333302013-02-06 13:30:27 -0800408 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800409
410 if (display_commit(ctx, dpy) < 0) {
411 ALOGE("%s: display commit fail!", __FUNCTION__);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700412 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700413 }
414 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800415
416 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700417 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700418}
419
420static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500421 hwc_display_contents_1_t* list, int dpy)
422{
423 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700424 int ret = 0;
Raj kamale3e68ae2013-05-02 17:28:23 +0530425 Locker::Autolock _l(ctx->mExtLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700426
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800427 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800428 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700429
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700430 if(!ctx->dpyAttr[dpy].isPause) {
431 uint32_t last = list->numHwLayers - 1;
432 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
433 int fd = -1; //FenceFD from the Copybit(valid in async mode)
434 bool copybitDone = false;
435 if(ctx->mCopyBit[dpy])
436 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700437
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700438 if(list->numHwLayers > 1)
439 hwc_sync(ctx, list, dpy, fd);
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700440
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700441 // Dump the layers for external
442 if(ctx->mHwcDebug[dpy])
443 ctx->mHwcDebug[dpy]->dumpLayers(list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700444
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700445 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
446 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700447 ret = -1;
448 }
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700449
450 int extOnlyLayerIndex =
451 ctx->listStats[dpy].extOnlyLayerIndex;
452
453 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
454 if(extOnlyLayerIndex!= -1) {
455 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
456 hnd = (private_handle_t *)extLayer->handle;
457 } else if(copybitDone) {
458 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
459 }
460
461 if(hnd && !isYuvBuffer(hnd)) {
462 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
463 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
464 ret = -1;
465 }
466 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700467 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800468
469 if (display_commit(ctx, dpy) < 0) {
470 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700471 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700472 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700473 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800474
475 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700476 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700477}
478
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700479static int hwc_set(hwc_composer_device_1 *dev,
480 size_t numDisplays,
481 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700482{
483 int ret = 0;
484 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400485 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800486 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700487 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700488 switch(i) {
489 case HWC_DISPLAY_PRIMARY:
490 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700491 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700492 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800493 case HWC_DISPLAY_VIRTUAL:
494 /* ToDo: We are using hwc_set_external path for both External and
495 Virtual displays on HWC1.1. Eventually, we will have
496 separate functions when we move to HWC1.2
497 */
498 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700499 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700500 default:
501 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700502 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700503 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400504 // This is only indicative of how many times SurfaceFlinger posts
505 // frames to the display.
506 CALC_FPS();
Saurabh Shah2d998a92013-05-14 17:55:58 -0700507 MDPComp::resetIdleFallBack();
Saurabh Shahd4e65852013-06-17 11:33:53 -0700508 ctx->mVideoTransFlag = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700509 return ret;
510}
511
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700512int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
513 uint32_t* configs, size_t* numConfigs) {
514 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700515 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700516 //in 1.1 there is no way to choose a config, report as config id # 0
517 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700518 switch(disp) {
519 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700520 if(*numConfigs > 0) {
521 configs[0] = 0;
522 *numConfigs = 1;
523 }
524 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700525 break;
526 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700527 ret = -1; //Not connected
528 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
529 ret = 0; //NO_ERROR
530 if(*numConfigs > 0) {
531 configs[0] = 0;
532 *numConfigs = 1;
533 }
534 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700535 break;
536 }
537 return ret;
538}
539
540int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
541 uint32_t config, const uint32_t* attributes, int32_t* values) {
542
543 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700544 //If hotpluggable displays are inactive return error
545 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
546 return -1;
547 }
548
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700549 //From HWComposer
550 static const uint32_t DISPLAY_ATTRIBUTES[] = {
551 HWC_DISPLAY_VSYNC_PERIOD,
552 HWC_DISPLAY_WIDTH,
553 HWC_DISPLAY_HEIGHT,
554 HWC_DISPLAY_DPI_X,
555 HWC_DISPLAY_DPI_Y,
556 HWC_DISPLAY_NO_ATTRIBUTE,
557 };
558
559 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
560 sizeof(DISPLAY_ATTRIBUTES)[0]);
561
562 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
563 switch (attributes[i]) {
564 case HWC_DISPLAY_VSYNC_PERIOD:
565 values[i] = ctx->dpyAttr[disp].vsync_period;
566 break;
567 case HWC_DISPLAY_WIDTH:
568 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700569 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
570 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700571 break;
572 case HWC_DISPLAY_HEIGHT:
573 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700574 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
575 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700576 break;
577 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400578 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700579 break;
580 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400581 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700582 break;
583 default:
584 ALOGE("Unknown display attribute %d",
585 attributes[i]);
586 return -EINVAL;
587 }
588 }
589 return 0;
590}
591
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500592void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
593{
594 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800595 android::String8 aBuf("");
596 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
597 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
598 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
600 if(ctx->mMDPComp[dpy])
601 ctx->mMDPComp[dpy]->dump(aBuf);
602 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800603 char ovDump[2048] = {'\0'};
604 ctx->mOverlay->getDump(ovDump, 2048);
605 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800606 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700607 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800608 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800609 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500610}
611
Naseer Ahmed29a26812012-06-14 00:56:20 -0700612static int hwc_device_close(struct hw_device_t *dev)
613{
614 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700615 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700616 return -1;
617 }
618 closeContext((hwc_context_t*)dev);
619 free(dev);
620
621 return 0;
622}
623
624static int hwc_device_open(const struct hw_module_t* module, const char* name,
625 struct hw_device_t** device)
626{
627 int status = -EINVAL;
628
629 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
630 struct hwc_context_t *dev;
631 dev = (hwc_context_t*)malloc(sizeof(*dev));
632 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700633
634 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700635 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700636
637 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700638 dev->device.common.tag = HARDWARE_DEVICE_TAG;
639 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
640 dev->device.common.module = const_cast<hw_module_t*>(module);
641 dev->device.common.close = hwc_device_close;
642 dev->device.prepare = hwc_prepare;
643 dev->device.set = hwc_set;
644 dev->device.eventControl = hwc_eventControl;
645 dev->device.blank = hwc_blank;
646 dev->device.query = hwc_query;
647 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500648 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700649 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
650 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
651 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700652 status = 0;
653 }
654 return status;
655}