blob: d7375f81c362d620ccebb262da85abe948be7917 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -08003 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004 *
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08005 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
7 *
Naseer Ahmed29a26812012-06-14 00:56:20 -07008 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Naseer Ahmed64b81212013-02-14 10:29:47 -050020#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Naseer Ahmed29a26812012-06-14 00:56:20 -070021#include <fcntl.h>
22#include <errno.h>
23
24#include <cutils/log.h>
25#include <cutils/atomic.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070026#include <EGL/egl.h>
Naseer Ahmed64b81212013-02-14 10:29:47 -050027#include <utils/Trace.h>
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080028#include <sys/ioctl.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080030#include <overlayRotator.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070031#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070032#include "hwc_utils.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070035#include "hwc_dump_layers.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070036#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080037#include "hwc_copybit.h"
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -040038#include "profiler.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
40using namespace qhwc;
Saurabh Shah85234ec2013-04-12 17:09:00 -070041using namespace overlay;
42
Naseer Ahmed758bfc52012-11-28 17:02:08 -050043#define VSYNC_DEBUG 0
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -070044#define BLANK_DEBUG 1
Naseer Ahmed29a26812012-06-14 00:56:20 -070045
46static int hwc_device_open(const struct hw_module_t* module,
47 const char* name,
48 struct hw_device_t** device);
49
50static struct hw_module_methods_t hwc_module_methods = {
51 open: hwc_device_open
52};
53
54hwc_module_t HAL_MODULE_INFO_SYM = {
55 common: {
56 tag: HARDWARE_MODULE_TAG,
57 version_major: 2,
58 version_minor: 0,
59 id: HWC_HARDWARE_MODULE_ID,
60 name: "Qualcomm Hardware Composer Module",
61 author: "CodeAurora Forum",
62 methods: &hwc_module_methods,
63 dso: 0,
64 reserved: {0},
65 }
66};
67
68/*
69 * Save callback functions registered to HWC
70 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070071static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 hwc_procs_t const* procs)
73{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070074 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070075 hwc_context_t* ctx = (hwc_context_t*)(dev);
76 if(!ctx) {
77 ALOGE("%s: Invalid context", __FUNCTION__);
78 return;
79 }
Jesse Hall3be78d92012-08-21 15:12:23 -070080 ctx->proc = procs;
81
Naseer Ahmedff4f0252012-10-01 13:03:01 -040082 // Now that we have the functions needed, kick off
83 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070084 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040085 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070086}
87
Saurabh Shah649cda62012-09-16 16:05:58 -070088//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040089static void reset(hwc_context_t *ctx, int numDisplays,
90 hwc_display_contents_1_t** displays) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080091 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040092 hwc_display_contents_1_t *list = displays[i];
93 // XXX:SurfaceFlinger no longer guarantees that this
94 // value is reset on every prepare. However, for the layer
95 // cache we need to reset it.
96 // We can probably rethink that later on
97 if (LIKELY(list && list->numHwLayers > 1)) {
98 for(uint32_t j = 0; j < list->numHwLayers; j++) {
99 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
100 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
101 }
102 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800103
104 if(ctx->mFBUpdate[i])
105 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800106 if(ctx->mCopyBit[i])
107 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700108 }
109}
110
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500111//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700112static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500113 if(ctx->layerProp[dpy]) {
114 delete[] ctx->layerProp[dpy];
115 ctx->layerProp[dpy] = NULL;
116 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700117 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500118}
119
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800120static int display_commit(hwc_context_t *ctx, int dpy) {
121 struct mdp_display_commit commit_info;
122 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
123 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
124 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
125 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
126 return -errno;
127 }
128 return 0;
129}
130
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700131static int hwc_prepare_primary(hwc_composer_device_1 *dev,
132 hwc_display_contents_1_t *list) {
133 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800134 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700135 if (LIKELY(list && list->numHwLayers > 1) &&
136 ctx->dpyAttr[dpy].isActive) {
137 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700138 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700139 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
140 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800141 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800142 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
143 if(fbZOrder >= 0)
144 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
145
Terence Hampson0124cc72013-04-18 23:45:56 -0700146 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
147 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
148 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
149 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700150 }
151 }
152 return 0;
153}
154
155static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800156 hwc_display_contents_1_t *list, int dpy) {
Raj kamale3e68ae2013-05-02 17:28:23 +0530157
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700158 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj kamale3e68ae2013-05-02 17:28:23 +0530159 Locker::Autolock _l(ctx->mExtLock);
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);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500210 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400211 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700212
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500213 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800214 ctx->mRotMgr->configBegin();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700215 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700216
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800217 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500218 hwc_display_contents_1_t *list = displays[i];
219 switch(i) {
220 case HWC_DISPLAY_PRIMARY:
221 ret = hwc_prepare_primary(dev, list);
222 break;
223 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800224 case HWC_DISPLAY_VIRTUAL:
225 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500226 break;
227 default:
228 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229 }
230 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500231
Saurabh Shahcf053c62012-12-13 12:32:55 -0800232 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800233 ctx->mRotMgr->configDone();
234
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700235 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236}
237
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700238static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500239 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700240{
241 int ret = 0;
242 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400243 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700244 switch(event) {
245 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500246 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700247 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500248 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400249 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500250 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700251 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500252 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700253 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400254#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700255 case HWC_EVENT_ORIENTATION:
256 if(dpy == HWC_DISPLAY_PRIMARY) {
257 // store the primary display orientation
258 // will be used in hwc_video::configure to disable
259 // rotation animation on external display
260 ctx->deviceOrientation = enable;
261 }
262 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400263#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700264 default:
265 ret = -EINVAL;
266 }
267 return ret;
268}
269
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700270static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
271{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500272 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700273 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800274
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500275 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700276 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400277 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500278 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700279 if(blank) {
280 // free up all the overlay pipes in use
281 // when we get a blank for either display
282 // makes sure that all pipes are freed
283 ctx->mOverlay->configBegin();
284 ctx->mOverlay->configDone();
285 ctx->mRotMgr->clear();
286 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700287 switch(dpy) {
288 case HWC_DISPLAY_PRIMARY:
289 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800290 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800291
292 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
293 // Surfaceflinger does not send Blank/unblank event to hwc
294 // for virtual display, handle it explicitly when blank for
295 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800296 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800297 ret = -1;
298 ALOGE("%s:post failed for virtual display !!",
299 __FUNCTION__);
300 } else {
301 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
302 }
303 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800305 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800306 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
307 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
308 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700309 }
310 break;
311 case HWC_DISPLAY_EXTERNAL:
312 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800313 // call external framebuffer commit on blank,
314 // so that any pipe unsets gets committed
315 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800316 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800317 ALOGE("%s:post failed for external display !! ",
318 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800319 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700320 } else {
321 }
322 break;
323 default:
324 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700325 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800326 // Enable HPD here, as during bootup unblank is called
327 // when SF is completely initialized
328 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500329 if(ret == 0){
330 ctx->dpyAttr[dpy].isActive = !blank;
331 } else {
332 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
333 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700334 return ret;
335 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500336
Naseer Ahmede0205b62013-04-04 13:24:39 -0400337 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500338 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700339 return 0;
340}
341
342static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700343 int param, int* value)
344{
345 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700346 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700347
348 switch (param) {
349 case HWC_BACKGROUND_LAYER_SUPPORTED:
350 // Not supported for now
351 value[0] = 0;
352 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700353 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700354 if(ctx->mMDP.hasOverlay)
355 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700356 value[0] = supported;
357 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700358 default:
359 return -EINVAL;
360 }
361 return 0;
362
363}
364
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800365
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700366static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500367 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700368 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800369 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800370 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700371 uint32_t last = list->numHwLayers - 1;
372 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800373 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500374 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800375 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500376 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800377 if(list->numHwLayers > 1)
378 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800379
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700380 // Dump the layers for primary
381 if(ctx->mHwcDebug[dpy])
382 ctx->mHwcDebug[dpy]->dumpLayers(list);
383
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800384 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800385 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500386 ret = -1;
387 }
388
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700389 //TODO We dont check for SKIP flag on this layer because we need PAN
390 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700391 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500392 if(copybitDone) {
393 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500394 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700395
396 if(hnd) {
397 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
398 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
399 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500400 }
Saurabh Shah43333302013-02-06 13:30:27 -0800401 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800402
403 if (display_commit(ctx, dpy) < 0) {
404 ALOGE("%s: display commit fail!", __FUNCTION__);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700405 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700406 }
407 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800408
409 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700410 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700411}
412
413static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500414 hwc_display_contents_1_t* list, int dpy)
415{
416 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700417 int ret = 0;
Raj kamale3e68ae2013-05-02 17:28:23 +0530418 Locker::Autolock _l(ctx->mExtLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700419
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800420 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800421 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800422 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700423 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700424 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800425 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500426 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800427 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500428 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700429
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800430 if(list->numHwLayers > 1)
431 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700432
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700433 // Dump the layers for external
434 if(ctx->mHwcDebug[dpy])
435 ctx->mHwcDebug[dpy]->dumpLayers(list);
436
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800437 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
438 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700439 ret = -1;
440 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700441
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800442 int extOnlyLayerIndex =
443 ctx->listStats[dpy].extOnlyLayerIndex;
444
Saurabh Shah2b033392013-03-22 11:29:44 -0700445 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800446 if(extOnlyLayerIndex!= -1) {
447 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
448 hnd = (private_handle_t *)extLayer->handle;
449 } else if(copybitDone) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500450 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500451 }
452
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800453 if(hnd && !isYuvBuffer(hnd)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500454 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500455 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700456 ret = -1;
457 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700458 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800459
460 if (display_commit(ctx, dpy) < 0) {
461 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700462 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700463 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700464 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800465
466 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700467 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700468}
469
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700470static int hwc_set(hwc_composer_device_1 *dev,
471 size_t numDisplays,
472 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700473{
474 int ret = 0;
475 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400476 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800477 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700478 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700479 switch(i) {
480 case HWC_DISPLAY_PRIMARY:
481 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700482 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700483 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800484 case HWC_DISPLAY_VIRTUAL:
485 /* ToDo: We are using hwc_set_external path for both External and
486 Virtual displays on HWC1.1. Eventually, we will have
487 separate functions when we move to HWC1.2
488 */
489 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700490 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700491 default:
492 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700493 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700494 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400495 // This is only indicative of how many times SurfaceFlinger posts
496 // frames to the display.
497 CALC_FPS();
Saurabh Shah2d998a92013-05-14 17:55:58 -0700498 MDPComp::resetIdleFallBack();
Saurabh Shahd4e65852013-06-17 11:33:53 -0700499 ctx->mVideoTransFlag = false;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700500 return ret;
501}
502
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700503int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
504 uint32_t* configs, size_t* numConfigs) {
505 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700506 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700507 //in 1.1 there is no way to choose a config, report as config id # 0
508 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700509 switch(disp) {
510 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700511 if(*numConfigs > 0) {
512 configs[0] = 0;
513 *numConfigs = 1;
514 }
515 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700516 break;
517 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700518 ret = -1; //Not connected
519 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
520 ret = 0; //NO_ERROR
521 if(*numConfigs > 0) {
522 configs[0] = 0;
523 *numConfigs = 1;
524 }
525 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700526 break;
527 }
528 return ret;
529}
530
531int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
532 uint32_t config, const uint32_t* attributes, int32_t* values) {
533
534 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700535 //If hotpluggable displays are inactive return error
536 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
537 return -1;
538 }
539
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700540 //From HWComposer
541 static const uint32_t DISPLAY_ATTRIBUTES[] = {
542 HWC_DISPLAY_VSYNC_PERIOD,
543 HWC_DISPLAY_WIDTH,
544 HWC_DISPLAY_HEIGHT,
545 HWC_DISPLAY_DPI_X,
546 HWC_DISPLAY_DPI_Y,
547 HWC_DISPLAY_NO_ATTRIBUTE,
548 };
549
550 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
551 sizeof(DISPLAY_ATTRIBUTES)[0]);
552
553 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
554 switch (attributes[i]) {
555 case HWC_DISPLAY_VSYNC_PERIOD:
556 values[i] = ctx->dpyAttr[disp].vsync_period;
557 break;
558 case HWC_DISPLAY_WIDTH:
559 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700560 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
561 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700562 break;
563 case HWC_DISPLAY_HEIGHT:
564 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700565 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
566 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700567 break;
568 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400569 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700570 break;
571 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400572 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700573 break;
574 default:
575 ALOGE("Unknown display attribute %d",
576 attributes[i]);
577 return -EINVAL;
578 }
579 }
580 return 0;
581}
582
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500583void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
584{
585 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800586 android::String8 aBuf("");
587 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
588 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
589 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800590 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
591 if(ctx->mMDPComp[dpy])
592 ctx->mMDPComp[dpy]->dump(aBuf);
593 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800594 char ovDump[2048] = {'\0'};
595 ctx->mOverlay->getDump(ovDump, 2048);
596 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800597 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700598 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800599 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800600 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500601}
602
Naseer Ahmed29a26812012-06-14 00:56:20 -0700603static int hwc_device_close(struct hw_device_t *dev)
604{
605 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700606 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700607 return -1;
608 }
609 closeContext((hwc_context_t*)dev);
610 free(dev);
611
612 return 0;
613}
614
615static int hwc_device_open(const struct hw_module_t* module, const char* name,
616 struct hw_device_t** device)
617{
618 int status = -EINVAL;
619
620 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
621 struct hwc_context_t *dev;
622 dev = (hwc_context_t*)malloc(sizeof(*dev));
623 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700624
625 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700626 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700627
628 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700629 dev->device.common.tag = HARDWARE_DEVICE_TAG;
630 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
631 dev->device.common.module = const_cast<hw_module_t*>(module);
632 dev->device.common.close = hwc_device_close;
633 dev->device.prepare = hwc_prepare;
634 dev->device.set = hwc_set;
635 dev->device.eventControl = hwc_eventControl;
636 dev->device.blank = hwc_blank;
637 dev->device.query = hwc_query;
638 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500639 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700640 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
641 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
642 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700643 status = 0;
644 }
645 return status;
646}