blob: 09fef80cc09d2114aa86baf73baa88062d3f6e8b [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"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070039#include "hwc_ad.h"
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -040040#include "profiler.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070041
42using namespace qhwc;
Saurabh Shah85234ec2013-04-12 17:09:00 -070043using namespace overlay;
44
Naseer Ahmed758bfc52012-11-28 17:02:08 -050045#define VSYNC_DEBUG 0
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -070046#define BLANK_DEBUG 1
Naseer Ahmed29a26812012-06-14 00:56:20 -070047
48static int hwc_device_open(const struct hw_module_t* module,
49 const char* name,
50 struct hw_device_t** device);
51
52static struct hw_module_methods_t hwc_module_methods = {
53 open: hwc_device_open
54};
55
56hwc_module_t HAL_MODULE_INFO_SYM = {
57 common: {
58 tag: HARDWARE_MODULE_TAG,
59 version_major: 2,
60 version_minor: 0,
61 id: HWC_HARDWARE_MODULE_ID,
62 name: "Qualcomm Hardware Composer Module",
63 author: "CodeAurora Forum",
64 methods: &hwc_module_methods,
65 dso: 0,
66 reserved: {0},
67 }
68};
69
70/*
71 * Save callback functions registered to HWC
72 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070073static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 hwc_procs_t const* procs)
75{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070076 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070077 hwc_context_t* ctx = (hwc_context_t*)(dev);
78 if(!ctx) {
79 ALOGE("%s: Invalid context", __FUNCTION__);
80 return;
81 }
Jesse Hall3be78d92012-08-21 15:12:23 -070082 ctx->proc = procs;
83
Naseer Ahmedff4f0252012-10-01 13:03:01 -040084 // Now that we have the functions needed, kick off
85 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070086 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040087 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070088}
89
Saurabh Shah649cda62012-09-16 16:05:58 -070090//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040091static void reset(hwc_context_t *ctx, int numDisplays,
92 hwc_display_contents_1_t** displays) {
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -070093 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040094 hwc_display_contents_1_t *list = displays[i];
95 // XXX:SurfaceFlinger no longer guarantees that this
96 // value is reset on every prepare. However, for the layer
97 // cache we need to reset it.
98 // We can probably rethink that later on
99 if (LIKELY(list && list->numHwLayers > 1)) {
100 for(uint32_t j = 0; j < list->numHwLayers; j++) {
101 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
102 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
103 }
104 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800105
106 if(ctx->mFBUpdate[i])
107 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800108 if(ctx->mCopyBit[i])
109 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700110 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700111
112 ctx->mAD->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700113}
114
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500115//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700116static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500117 if(ctx->layerProp[dpy]) {
118 delete[] ctx->layerProp[dpy];
119 ctx->layerProp[dpy] = NULL;
120 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700121 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500122}
123
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800124static int display_commit(hwc_context_t *ctx, int dpy) {
125 struct mdp_display_commit commit_info;
126 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
127 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
128 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700129 ALOGE("%s: MSMFB_DISPLAY_COMMIT for dpy %d failed", __FUNCTION__,dpy);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800130 return -errno;
131 }
132 return 0;
133}
134
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700135static int hwc_prepare_primary(hwc_composer_device_1 *dev,
136 hwc_display_contents_1_t *list) {
137 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800138 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700139 if (LIKELY(list && list->numHwLayers > 1) &&
140 ctx->dpyAttr[dpy].isActive) {
141 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700142 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700143 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
144 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800145 setListStats(ctx, list, dpy);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700146 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
147 const int fbZ = 0;
148 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
149 }
Terence Hampson0124cc72013-04-18 23:45:56 -0700150 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700151 if(ctx->mCopyBit[dpy])
Terence Hampson0124cc72013-04-18 23:45:56 -0700152 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
153 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700154 }
155 }
156 return 0;
157}
158
159static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800160 hwc_display_contents_1_t *list, int dpy) {
Raj kamale3e68ae2013-05-02 17:28:23 +0530161
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700162 hwc_context_t* ctx = (hwc_context_t*)(dev);
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);
Saurabh Shah2a4eb1b2013-07-22 16:33:23 -0700174 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
175 const int fbZ = 0;
176 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
177 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800178
179 /* Temporarily commenting out C2D until we support partial
180 copybit composition for mixed mode MDP
181
182 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800183 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 */
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700185 if(ctx->listStats[dpy].isDisplayAnimating) {
186 // Mark all app layers as HWC_OVERLAY for external during
187 // animation, so that SF doesnt draw it on FB
188 for(int i = 0 ;i < ctx->listStats[dpy].numAppLayers; i++) {
189 hwc_layer_1_t *layer = &list->hwLayers[i];
190 layer->compositionType = HWC_OVERLAY;
191 }
192 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800193 }
194 } else {
195 // External Display is in Pause state.
196 // ToDo:
197 // Mark all application layers as OVERLAY so that
198 // GPU will not compose. This is done for power
199 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700200 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700201 }
202 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700203}
204
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700205static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
206 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700208 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah567788b2013-07-11 10:19:52 -0700210 Locker::Autolock _bl(ctx->mBlankLock);
Saurabh Shah188e4332013-07-18 10:33:22 -0700211 //Will be unlocked at the end of set
212 ctx->mExtLock.lock();
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400213 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700214
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800216 ctx->mRotMgr->configBegin();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700217 overlay::Writeback::configBegin();
218
Saurabh Shah85234ec2013-04-12 17:09:00 -0700219 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700220
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800221 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500222 hwc_display_contents_1_t *list = displays[i];
223 switch(i) {
224 case HWC_DISPLAY_PRIMARY:
225 ret = hwc_prepare_primary(dev, list);
226 break;
227 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800228 case HWC_DISPLAY_VIRTUAL:
229 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500230 break;
231 default:
232 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233 }
234 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500235
Saurabh Shahcf053c62012-12-13 12:32:55 -0800236 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800237 ctx->mRotMgr->configDone();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700238 overlay::Writeback::configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800239
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700240 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700241}
242
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700243static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500244 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700245{
246 int ret = 0;
247 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248 switch(event) {
249 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500250 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700251 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500252 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400253 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500254 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700255 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500256 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700257 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400258#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700259 case HWC_EVENT_ORIENTATION:
260 if(dpy == HWC_DISPLAY_PRIMARY) {
Naseer Ahmed20585702013-07-09 16:36:28 -0400261 Locker::Autolock _l(ctx->mBlankLock);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700262 // store the primary display orientation
263 // will be used in hwc_video::configure to disable
264 // rotation animation on external display
265 ctx->deviceOrientation = enable;
266 }
267 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400268#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700269 default:
270 ret = -EINVAL;
271 }
272 return ret;
273}
274
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700275static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
276{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500277 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700278 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800279
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500280 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700281 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400282 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500283 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700284 if(blank) {
285 // free up all the overlay pipes in use
286 // when we get a blank for either display
287 // makes sure that all pipes are freed
288 ctx->mOverlay->configBegin();
289 ctx->mOverlay->configDone();
290 ctx->mRotMgr->clear();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700291 overlay::Writeback::clear();
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700292 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700293 switch(dpy) {
294 case HWC_DISPLAY_PRIMARY:
295 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800296 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800297
298 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
299 // Surfaceflinger does not send Blank/unblank event to hwc
300 // for virtual display, handle it explicitly when blank for
301 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800302 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800303 ret = -1;
304 ALOGE("%s:post failed for virtual display !!",
305 __FUNCTION__);
306 } else {
307 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
308 }
309 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700310 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800311 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800312 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
313 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
314 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700315 }
316 break;
317 case HWC_DISPLAY_EXTERNAL:
318 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800319 // call external framebuffer commit on blank,
320 // so that any pipe unsets gets committed
321 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800322 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800323 ALOGE("%s:post failed for external display !! ",
324 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800325 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700326 } else {
327 }
328 break;
329 default:
330 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700331 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800332 // Enable HPD here, as during bootup unblank is called
333 // when SF is completely initialized
334 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500335 if(ret == 0){
336 ctx->dpyAttr[dpy].isActive = !blank;
337 } else {
338 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
339 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700340 return ret;
341 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500342
Naseer Ahmede0205b62013-04-04 13:24:39 -0400343 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500344 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700345 return 0;
346}
347
348static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700349 int param, int* value)
350{
351 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700352 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700353
354 switch (param) {
355 case HWC_BACKGROUND_LAYER_SUPPORTED:
356 // Not supported for now
357 value[0] = 0;
358 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700359 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700360 if(ctx->mMDP.hasOverlay)
361 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700362 value[0] = supported;
363 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700364 default:
365 return -EINVAL;
366 }
367 return 0;
368
369}
370
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800371
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700372static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500373 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700374 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800375 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800376 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700377 uint32_t last = list->numHwLayers - 1;
378 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)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500380 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800381 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500382 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800383 if(list->numHwLayers > 1)
384 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800385
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700386 // Dump the layers for primary
387 if(ctx->mHwcDebug[dpy])
388 ctx->mHwcDebug[dpy]->dumpLayers(list);
389
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800390 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800391 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500392 ret = -1;
393 }
394
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700395 //TODO We dont check for SKIP flag on this layer because we need PAN
396 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700397 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500398 if(copybitDone) {
399 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500400 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700401
402 if(hnd) {
403 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
404 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
405 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500406 }
Saurabh Shah43333302013-02-06 13:30:27 -0800407 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800408
409 if (display_commit(ctx, dpy) < 0) {
410 ALOGE("%s: display commit fail!", __FUNCTION__);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700411 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700412 }
413 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800414
415 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700416 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700417}
418
419static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500420 hwc_display_contents_1_t* list, int dpy)
421{
422 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700423 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700424
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800425 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800426 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700427
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700428 if(!ctx->dpyAttr[dpy].isPause) {
429 uint32_t last = list->numHwLayers - 1;
430 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
431 int fd = -1; //FenceFD from the Copybit(valid in async mode)
432 bool copybitDone = false;
433 if(ctx->mCopyBit[dpy])
434 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700435
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700436 if(list->numHwLayers > 1)
437 hwc_sync(ctx, list, dpy, fd);
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700438
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700439 // Dump the layers for external
440 if(ctx->mHwcDebug[dpy])
441 ctx->mHwcDebug[dpy]->dumpLayers(list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700442
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700443 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
444 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700445 ret = -1;
446 }
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700447
448 int extOnlyLayerIndex =
449 ctx->listStats[dpy].extOnlyLayerIndex;
450
451 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
452 if(extOnlyLayerIndex!= -1) {
453 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
454 hnd = (private_handle_t *)extLayer->handle;
455 } else if(copybitDone) {
456 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
457 }
458
459 if(hnd && !isYuvBuffer(hnd)) {
460 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
461 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
462 ret = -1;
463 }
464 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700465 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800466
467 if (display_commit(ctx, dpy) < 0) {
468 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700469 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700470 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700471 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800472
473 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700474 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700475}
476
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700477static int hwc_set(hwc_composer_device_1 *dev,
478 size_t numDisplays,
479 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700480{
481 int ret = 0;
482 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah567788b2013-07-11 10:19:52 -0700483 Locker::Autolock _bl(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800484 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700485 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700486 switch(i) {
487 case HWC_DISPLAY_PRIMARY:
488 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700489 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700490 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800491 case HWC_DISPLAY_VIRTUAL:
492 /* ToDo: We are using hwc_set_external path for both External and
493 Virtual displays on HWC1.1. Eventually, we will have
494 separate functions when we move to HWC1.2
495 */
496 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700497 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700498 default:
499 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700500 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700501 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400502 // This is only indicative of how many times SurfaceFlinger posts
503 // frames to the display.
504 CALC_FPS();
Saurabh Shah2d998a92013-05-14 17:55:58 -0700505 MDPComp::resetIdleFallBack();
Saurabh Shahd4e65852013-06-17 11:33:53 -0700506 ctx->mVideoTransFlag = false;
Saurabh Shah188e4332013-07-18 10:33:22 -0700507 //Was locked at the beginning of prepare
508 ctx->mExtLock.unlock();
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:
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700527 case HWC_DISPLAY_VIRTUAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700528 ret = -1; //Not connected
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700529 if(ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700530 ret = 0; //NO_ERROR
531 if(*numConfigs > 0) {
532 configs[0] = 0;
533 *numConfigs = 1;
534 }
535 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700536 break;
537 }
538 return ret;
539}
540
541int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
542 uint32_t config, const uint32_t* attributes, int32_t* values) {
543
544 hwc_context_t* ctx = (hwc_context_t*)(dev);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700545 //If hotpluggable displays(i.e, HDMI, WFD) are inactive return error
546 if( (disp >= HWC_DISPLAY_EXTERNAL) && !ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700547 return -1;
548 }
549
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700550 //From HWComposer
551 static const uint32_t DISPLAY_ATTRIBUTES[] = {
552 HWC_DISPLAY_VSYNC_PERIOD,
553 HWC_DISPLAY_WIDTH,
554 HWC_DISPLAY_HEIGHT,
555 HWC_DISPLAY_DPI_X,
556 HWC_DISPLAY_DPI_Y,
557 HWC_DISPLAY_NO_ATTRIBUTE,
558 };
559
560 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
561 sizeof(DISPLAY_ATTRIBUTES)[0]);
562
563 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
564 switch (attributes[i]) {
565 case HWC_DISPLAY_VSYNC_PERIOD:
566 values[i] = ctx->dpyAttr[disp].vsync_period;
567 break;
568 case HWC_DISPLAY_WIDTH:
569 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700570 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
571 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700572 break;
573 case HWC_DISPLAY_HEIGHT:
574 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700575 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
576 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700577 break;
578 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400579 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700580 break;
581 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400582 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700583 break;
584 default:
585 ALOGE("Unknown display attribute %d",
586 attributes[i]);
587 return -EINVAL;
588 }
589 }
590 return 0;
591}
592
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500593void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
594{
595 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800596 android::String8 aBuf("");
597 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
598 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
599 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700600 for(int dpy = 0; dpy < HWC_NUM_DISPLAY_TYPES; dpy++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800601 if(ctx->mMDPComp[dpy])
602 ctx->mMDPComp[dpy]->dump(aBuf);
603 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800604 char ovDump[2048] = {'\0'};
605 ctx->mOverlay->getDump(ovDump, 2048);
606 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800607 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700608 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800609 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800610 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500611}
612
Naseer Ahmed29a26812012-06-14 00:56:20 -0700613static int hwc_device_close(struct hw_device_t *dev)
614{
615 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700616 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700617 return -1;
618 }
619 closeContext((hwc_context_t*)dev);
620 free(dev);
621
622 return 0;
623}
624
625static int hwc_device_open(const struct hw_module_t* module, const char* name,
626 struct hw_device_t** device)
627{
628 int status = -EINVAL;
629
630 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
631 struct hwc_context_t *dev;
632 dev = (hwc_context_t*)malloc(sizeof(*dev));
633 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700634
635 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700636 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700637
638 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700639 dev->device.common.tag = HARDWARE_DEVICE_TAG;
640 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
641 dev->device.common.module = const_cast<hw_module_t*>(module);
642 dev->device.common.close = hwc_device_close;
643 dev->device.prepare = hwc_prepare;
644 dev->device.set = hwc_set;
645 dev->device.eventControl = hwc_eventControl;
646 dev->device.blank = hwc_blank;
647 dev->device.query = hwc_query;
648 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500649 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700650 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
651 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
652 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700653 status = 0;
654 }
655 return status;
656}