blob: 7b0fa11414138d2b59d35377faad38b9112b1afc [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 Kumar7fb13272013-07-01 13:59:34 -070092 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; 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 Shah3e858eb2012-09-17 16:53:21 -0700109 }
110}
111
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500112//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700113static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500114 if(ctx->layerProp[dpy]) {
115 delete[] ctx->layerProp[dpy];
116 ctx->layerProp[dpy] = NULL;
117 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700118 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500119}
120
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800121static int display_commit(hwc_context_t *ctx, int dpy) {
122 struct mdp_display_commit commit_info;
123 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
124 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
125 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700126 ALOGE("%s: MSMFB_DISPLAY_COMMIT for dpy %d failed", __FUNCTION__,dpy);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800127 return -errno;
128 }
129 return 0;
130}
131
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700132static int hwc_prepare_primary(hwc_composer_device_1 *dev,
133 hwc_display_contents_1_t *list) {
134 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800135 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700136 if (LIKELY(list && list->numHwLayers > 1) &&
137 ctx->dpyAttr[dpy].isActive) {
138 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700139 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700140 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
141 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800142 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800143 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
144 if(fbZOrder >= 0)
145 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
146
Terence Hampson0124cc72013-04-18 23:45:56 -0700147 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
148 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
149 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
150 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700151 }
152 }
153 return 0;
154}
155
156static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800157 hwc_display_contents_1_t *list, int dpy) {
Raj kamale3e68ae2013-05-02 17:28:23 +0530158
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);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700172 if(ctx->deviceOrientation &&
173 ctx->listStats[dpy].isDisplayAnimating) {
174 fbZOrder = 0;
175 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800176 if(fbZOrder >= 0)
177 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
178
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);
211 Locker::Autolock _el(ctx->mExtLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400212 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700213
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500214 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800215 ctx->mRotMgr->configBegin();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700216 overlay::Writeback::configBegin();
217
Saurabh Shah85234ec2013-04-12 17:09:00 -0700218 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700219
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800220 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500221 hwc_display_contents_1_t *list = displays[i];
222 switch(i) {
223 case HWC_DISPLAY_PRIMARY:
224 ret = hwc_prepare_primary(dev, list);
225 break;
226 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800227 case HWC_DISPLAY_VIRTUAL:
228 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500229 break;
230 default:
231 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700232 }
233 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500234
Saurabh Shahcf053c62012-12-13 12:32:55 -0800235 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800236 ctx->mRotMgr->configDone();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700237 overlay::Writeback::configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800238
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700239 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240}
241
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700242static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500243 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700244{
245 int ret = 0;
246 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700247 switch(event) {
248 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500249 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700250 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500251 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400252 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500253 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700254 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500255 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700256 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400257#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700258 case HWC_EVENT_ORIENTATION:
259 if(dpy == HWC_DISPLAY_PRIMARY) {
Naseer Ahmed20585702013-07-09 16:36:28 -0400260 Locker::Autolock _l(ctx->mBlankLock);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700261 // store the primary display orientation
262 // will be used in hwc_video::configure to disable
263 // rotation animation on external display
264 ctx->deviceOrientation = enable;
265 }
266 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400267#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700268 default:
269 ret = -EINVAL;
270 }
271 return ret;
272}
273
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700274static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
275{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500276 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700277 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800278
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500279 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700280 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400281 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500282 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700283 if(blank) {
284 // free up all the overlay pipes in use
285 // when we get a blank for either display
286 // makes sure that all pipes are freed
287 ctx->mOverlay->configBegin();
288 ctx->mOverlay->configDone();
289 ctx->mRotMgr->clear();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700290 overlay::Writeback::clear();
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700291 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700292 switch(dpy) {
293 case HWC_DISPLAY_PRIMARY:
294 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800295 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800296
297 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
298 // Surfaceflinger does not send Blank/unblank event to hwc
299 // for virtual display, handle it explicitly when blank for
300 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800301 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800302 ret = -1;
303 ALOGE("%s:post failed for virtual display !!",
304 __FUNCTION__);
305 } else {
306 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
307 }
308 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700309 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800310 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800311 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
312 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
313 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700314 }
315 break;
316 case HWC_DISPLAY_EXTERNAL:
317 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800318 // call external framebuffer commit on blank,
319 // so that any pipe unsets gets committed
320 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800321 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800322 ALOGE("%s:post failed for external display !! ",
323 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800324 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700325 } else {
326 }
327 break;
328 default:
329 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700330 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800331 // Enable HPD here, as during bootup unblank is called
332 // when SF is completely initialized
333 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500334 if(ret == 0){
335 ctx->dpyAttr[dpy].isActive = !blank;
336 } else {
337 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
338 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700339 return ret;
340 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500341
Naseer Ahmede0205b62013-04-04 13:24:39 -0400342 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500343 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700344 return 0;
345}
346
347static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700348 int param, int* value)
349{
350 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700351 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700352
353 switch (param) {
354 case HWC_BACKGROUND_LAYER_SUPPORTED:
355 // Not supported for now
356 value[0] = 0;
357 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700358 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700359 if(ctx->mMDP.hasOverlay)
360 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700361 value[0] = supported;
362 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700363 default:
364 return -EINVAL;
365 }
366 return 0;
367
368}
369
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800370
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700371static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500372 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700373 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800374 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800375 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700376 uint32_t last = list->numHwLayers - 1;
377 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800378 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500379 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800380 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500381 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800382 if(list->numHwLayers > 1)
383 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700385 // Dump the layers for primary
386 if(ctx->mHwcDebug[dpy])
387 ctx->mHwcDebug[dpy]->dumpLayers(list);
388
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800389 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800390 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500391 ret = -1;
392 }
393
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700394 //TODO We dont check for SKIP flag on this layer because we need PAN
395 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700396 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500397 if(copybitDone) {
398 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500399 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700400
401 if(hnd) {
402 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
403 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
404 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500405 }
Saurabh Shah43333302013-02-06 13:30:27 -0800406 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800407
408 if (display_commit(ctx, dpy) < 0) {
409 ALOGE("%s: display commit fail!", __FUNCTION__);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700410 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700411 }
412 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800413
414 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700415 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700416}
417
418static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500419 hwc_display_contents_1_t* list, int dpy)
420{
421 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700422 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700423
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800424 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800425 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700426
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700427 if(!ctx->dpyAttr[dpy].isPause) {
428 uint32_t last = list->numHwLayers - 1;
429 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
430 int fd = -1; //FenceFD from the Copybit(valid in async mode)
431 bool copybitDone = false;
432 if(ctx->mCopyBit[dpy])
433 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700434
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700435 if(list->numHwLayers > 1)
436 hwc_sync(ctx, list, dpy, fd);
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700437
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700438 // Dump the layers for external
439 if(ctx->mHwcDebug[dpy])
440 ctx->mHwcDebug[dpy]->dumpLayers(list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700441
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700442 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
443 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700444 ret = -1;
445 }
Saurabh Shahad0f0d02013-06-24 15:48:50 -0700446
447 int extOnlyLayerIndex =
448 ctx->listStats[dpy].extOnlyLayerIndex;
449
450 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
451 if(extOnlyLayerIndex!= -1) {
452 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
453 hnd = (private_handle_t *)extLayer->handle;
454 } else if(copybitDone) {
455 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
456 }
457
458 if(hnd && !isYuvBuffer(hnd)) {
459 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
460 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
461 ret = -1;
462 }
463 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700464 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800465
466 if (display_commit(ctx, dpy) < 0) {
467 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700468 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700469 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800471
472 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700473 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700474}
475
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700476static int hwc_set(hwc_composer_device_1 *dev,
477 size_t numDisplays,
478 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700479{
480 int ret = 0;
481 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah567788b2013-07-11 10:19:52 -0700482 Locker::Autolock _bl(ctx->mBlankLock);
483 Locker::Autolock _el(ctx->mExtLock);
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;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700507 return ret;
508}
509
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700510int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
511 uint32_t* configs, size_t* numConfigs) {
512 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700513 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700514 //in 1.1 there is no way to choose a config, report as config id # 0
515 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700516 switch(disp) {
517 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700518 if(*numConfigs > 0) {
519 configs[0] = 0;
520 *numConfigs = 1;
521 }
522 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700523 break;
524 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700525 case HWC_DISPLAY_VIRTUAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700526 ret = -1; //Not connected
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700527 if(ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700528 ret = 0; //NO_ERROR
529 if(*numConfigs > 0) {
530 configs[0] = 0;
531 *numConfigs = 1;
532 }
533 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700534 break;
535 }
536 return ret;
537}
538
539int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
540 uint32_t config, const uint32_t* attributes, int32_t* values) {
541
542 hwc_context_t* ctx = (hwc_context_t*)(dev);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700543 //If hotpluggable displays(i.e, HDMI, WFD) are inactive return error
544 if( (disp >= HWC_DISPLAY_EXTERNAL) && !ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700545 return -1;
546 }
547
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700548 //From HWComposer
549 static const uint32_t DISPLAY_ATTRIBUTES[] = {
550 HWC_DISPLAY_VSYNC_PERIOD,
551 HWC_DISPLAY_WIDTH,
552 HWC_DISPLAY_HEIGHT,
553 HWC_DISPLAY_DPI_X,
554 HWC_DISPLAY_DPI_Y,
555 HWC_DISPLAY_NO_ATTRIBUTE,
556 };
557
558 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
559 sizeof(DISPLAY_ATTRIBUTES)[0]);
560
561 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
562 switch (attributes[i]) {
563 case HWC_DISPLAY_VSYNC_PERIOD:
564 values[i] = ctx->dpyAttr[disp].vsync_period;
565 break;
566 case HWC_DISPLAY_WIDTH:
567 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700568 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
569 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700570 break;
571 case HWC_DISPLAY_HEIGHT:
572 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700573 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
574 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700575 break;
576 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400577 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700578 break;
579 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400580 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700581 break;
582 default:
583 ALOGE("Unknown display attribute %d",
584 attributes[i]);
585 return -EINVAL;
586 }
587 }
588 return 0;
589}
590
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500591void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
592{
593 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800594 android::String8 aBuf("");
595 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
596 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
597 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700598 for(int dpy = 0; dpy < HWC_NUM_DISPLAY_TYPES; dpy++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800599 if(ctx->mMDPComp[dpy])
600 ctx->mMDPComp[dpy]->dump(aBuf);
601 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800602 char ovDump[2048] = {'\0'};
603 ctx->mOverlay->getDump(ovDump, 2048);
604 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800605 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700606 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800607 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800608 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500609}
610
Naseer Ahmed29a26812012-06-14 00:56:20 -0700611static int hwc_device_close(struct hw_device_t *dev)
612{
613 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700614 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700615 return -1;
616 }
617 closeContext((hwc_context_t*)dev);
618 free(dev);
619
620 return 0;
621}
622
623static int hwc_device_open(const struct hw_module_t* module, const char* name,
624 struct hw_device_t** device)
625{
626 int status = -EINVAL;
627
628 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
629 struct hwc_context_t *dev;
630 dev = (hwc_context_t*)malloc(sizeof(*dev));
631 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700632
633 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700634 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700635
636 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700637 dev->device.common.tag = HARDWARE_DEVICE_TAG;
638 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
639 dev->device.common.module = const_cast<hw_module_t*>(module);
640 dev->device.common.close = hwc_device_close;
641 dev->device.prepare = hwc_prepare;
642 dev->device.set = hwc_set;
643 dev->device.eventControl = hwc_eventControl;
644 dev->device.blank = hwc_blank;
645 dev->device.query = hwc_query;
646 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500647 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700648 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
649 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
650 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700651 status = 0;
652 }
653 return status;
654}