blob: 9dd95ff35af3237a8f21b8f0c3ddb0087dcf14c2 [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) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070091 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080092 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040093 hwc_display_contents_1_t *list = displays[i];
94 // XXX:SurfaceFlinger no longer guarantees that this
95 // value is reset on every prepare. However, for the layer
96 // cache we need to reset it.
97 // We can probably rethink that later on
98 if (LIKELY(list && list->numHwLayers > 1)) {
99 for(uint32_t j = 0; j < list->numHwLayers; j++) {
100 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
101 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
102 }
103 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800104
105 if(ctx->mFBUpdate[i])
106 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800107 if(ctx->mCopyBit[i])
108 ctx->mCopyBit[i]->reset();
Saurabh 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) {
126 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
127 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
147 /* Temporarily commenting out C2D until we support partial
148 copybit composition for mixed mode MDP
149
150 // Use Copybit, when MDP comp fails
151 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
152 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);
Raj kamale3e68ae2013-05-02 17:28:23 +0530163 Locker::Autolock _l(ctx->mExtLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700164
Saurabh Shah2b033392013-03-22 11:29:44 -0700165 if (LIKELY(list && list->numHwLayers > 1) &&
166 ctx->dpyAttr[dpy].isActive &&
167 ctx->dpyAttr[dpy].connected) {
168 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700169 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700170 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800171 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800172 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700173 ctx->mExtDispConfiguring = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800174 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800175 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
176 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 */
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800185 }
186 } else {
187 // External Display is in Pause state.
188 // ToDo:
189 // Mark all application layers as OVERLAY so that
190 // GPU will not compose. This is done for power
191 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700192 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700193 }
194 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700195}
196
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700197static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
198 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700200 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500202 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400203 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700204
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500205 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800206 ctx->mRotMgr->configBegin();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700207 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700208
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800209 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500210 hwc_display_contents_1_t *list = displays[i];
211 switch(i) {
212 case HWC_DISPLAY_PRIMARY:
213 ret = hwc_prepare_primary(dev, list);
214 break;
215 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800216 case HWC_DISPLAY_VIRTUAL:
217 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500218 break;
219 default:
220 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221 }
222 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223
Saurabh Shahcf053c62012-12-13 12:32:55 -0800224 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800225 ctx->mRotMgr->configDone();
Saurabh Shah98acd092013-05-03 10:48:24 -0700226 MDPComp::resetIdleFallBack();
Saurabh Shahacf10202013-02-26 10:15:15 -0800227
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700228 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700229}
230
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700231static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500232 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700233{
234 int ret = 0;
235 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700236 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700237 switch(event) {
238 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500239 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700240 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500241 ret = hwc_vsync_control(ctx, dpy, enable);
242 if(ret == 0) {
243 ctx->vstate.enable = !!enable;
244 pthread_cond_signal(&ctx->vstate.cond);
245 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700246 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500247 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700248 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700249 default:
250 ret = -EINVAL;
251 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700252 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700253 return ret;
254}
255
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700256static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
257{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500258 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700259 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800260
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500261 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700262 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400263 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500264 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700265 if(blank) {
266 // free up all the overlay pipes in use
267 // when we get a blank for either display
268 // makes sure that all pipes are freed
269 ctx->mOverlay->configBegin();
270 ctx->mOverlay->configDone();
271 ctx->mRotMgr->clear();
272 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700273 switch(dpy) {
274 case HWC_DISPLAY_PRIMARY:
275 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800276 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800277
278 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
279 // Surfaceflinger does not send Blank/unblank event to hwc
280 // for virtual display, handle it explicitly when blank for
281 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800282 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800283 ret = -1;
284 ALOGE("%s:post failed for virtual display !!",
285 __FUNCTION__);
286 } else {
287 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
288 }
289 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700290 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800291 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800292 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
293 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
294 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700295 }
296 break;
297 case HWC_DISPLAY_EXTERNAL:
298 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800299 // call external framebuffer commit on blank,
300 // so that any pipe unsets gets committed
301 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800302 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800303 ALOGE("%s:post failed for external display !! ",
304 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800305 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700306 } else {
307 }
308 break;
309 default:
310 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700311 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800312 // Enable HPD here, as during bootup unblank is called
313 // when SF is completely initialized
314 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500315 if(ret == 0){
316 ctx->dpyAttr[dpy].isActive = !blank;
317 } else {
318 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
319 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700320 return ret;
321 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500322
Naseer Ahmede0205b62013-04-04 13:24:39 -0400323 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500324 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700325 return 0;
326}
327
328static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700329 int param, int* value)
330{
331 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700332 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700333
334 switch (param) {
335 case HWC_BACKGROUND_LAYER_SUPPORTED:
336 // Not supported for now
337 value[0] = 0;
338 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700339 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700340 if(ctx->mMDP.hasOverlay)
341 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700342 value[0] = supported;
343 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700344 default:
345 return -EINVAL;
346 }
347 return 0;
348
349}
350
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800351
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700352static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500353 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700354 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800355 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800356 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700357 uint32_t last = list->numHwLayers - 1;
358 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800359 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500360 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800361 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500362 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800363 if(list->numHwLayers > 1)
364 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800365
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700366 // Dump the layers for primary
367 if(ctx->mHwcDebug[dpy])
368 ctx->mHwcDebug[dpy]->dumpLayers(list);
369
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800371 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500372 ret = -1;
373 }
374
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700375 //TODO We dont check for SKIP flag on this layer because we need PAN
376 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700377 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500378 if(copybitDone) {
379 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500380 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700381
382 if(hnd) {
383 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
384 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
385 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500386 }
Saurabh Shah43333302013-02-06 13:30:27 -0800387 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800388
389 if (display_commit(ctx, dpy) < 0) {
390 ALOGE("%s: display commit fail!", __FUNCTION__);
391 return -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700392 }
393 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800394
395 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700396 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700397}
398
399static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500400 hwc_display_contents_1_t* list, int dpy)
401{
402 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700403 int ret = 0;
Raj kamale3e68ae2013-05-02 17:28:23 +0530404 Locker::Autolock _l(ctx->mExtLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700405
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800406 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800407 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800408 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700409 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700410 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800411 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500412 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800413 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500414 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700415
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800416 if(list->numHwLayers > 1)
417 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700418
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700419 // Dump the layers for external
420 if(ctx->mHwcDebug[dpy])
421 ctx->mHwcDebug[dpy]->dumpLayers(list);
422
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800423 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
424 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700425 ret = -1;
426 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700427
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800428 int extOnlyLayerIndex =
429 ctx->listStats[dpy].extOnlyLayerIndex;
430
Saurabh Shah2b033392013-03-22 11:29:44 -0700431 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800432 if(extOnlyLayerIndex!= -1) {
433 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
434 hnd = (private_handle_t *)extLayer->handle;
435 } else if(copybitDone) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500436 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500437 }
438
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800439 if(hnd && !isYuvBuffer(hnd)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500440 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500441 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700442 ret = -1;
443 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700444 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800445
446 if (display_commit(ctx, dpy) < 0) {
447 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700448 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700449 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700450 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800451
452 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700453 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700454}
455
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700456static int hwc_set(hwc_composer_device_1 *dev,
457 size_t numDisplays,
458 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700459{
460 int ret = 0;
461 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400462 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800463 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700464 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700465 switch(i) {
466 case HWC_DISPLAY_PRIMARY:
467 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700468 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700469 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800470 case HWC_DISPLAY_VIRTUAL:
471 /* ToDo: We are using hwc_set_external path for both External and
472 Virtual displays on HWC1.1. Eventually, we will have
473 separate functions when we move to HWC1.2
474 */
475 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700476 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700477 default:
478 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700479 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700480 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400481 // This is only indicative of how many times SurfaceFlinger posts
482 // frames to the display.
483 CALC_FPS();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700484 return ret;
485}
486
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700487int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
488 uint32_t* configs, size_t* numConfigs) {
489 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700490 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700491 //in 1.1 there is no way to choose a config, report as config id # 0
492 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700493 switch(disp) {
494 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700495 if(*numConfigs > 0) {
496 configs[0] = 0;
497 *numConfigs = 1;
498 }
499 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700500 break;
501 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700502 ret = -1; //Not connected
503 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
504 ret = 0; //NO_ERROR
505 if(*numConfigs > 0) {
506 configs[0] = 0;
507 *numConfigs = 1;
508 }
509 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700510 break;
511 }
512 return ret;
513}
514
515int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
516 uint32_t config, const uint32_t* attributes, int32_t* values) {
517
518 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700519 //If hotpluggable displays are inactive return error
520 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
521 return -1;
522 }
523
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700524 //From HWComposer
525 static const uint32_t DISPLAY_ATTRIBUTES[] = {
526 HWC_DISPLAY_VSYNC_PERIOD,
527 HWC_DISPLAY_WIDTH,
528 HWC_DISPLAY_HEIGHT,
529 HWC_DISPLAY_DPI_X,
530 HWC_DISPLAY_DPI_Y,
531 HWC_DISPLAY_NO_ATTRIBUTE,
532 };
533
534 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
535 sizeof(DISPLAY_ATTRIBUTES)[0]);
536
537 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
538 switch (attributes[i]) {
539 case HWC_DISPLAY_VSYNC_PERIOD:
540 values[i] = ctx->dpyAttr[disp].vsync_period;
541 break;
542 case HWC_DISPLAY_WIDTH:
543 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700544 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
545 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700546 break;
547 case HWC_DISPLAY_HEIGHT:
548 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700549 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
550 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700551 break;
552 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400553 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700554 break;
555 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400556 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700557 break;
558 default:
559 ALOGE("Unknown display attribute %d",
560 attributes[i]);
561 return -EINVAL;
562 }
563 }
564 return 0;
565}
566
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500567void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
568{
569 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800570 android::String8 aBuf("");
571 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
572 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
573 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800574 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
575 if(ctx->mMDPComp[dpy])
576 ctx->mMDPComp[dpy]->dump(aBuf);
577 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800578 char ovDump[2048] = {'\0'};
579 ctx->mOverlay->getDump(ovDump, 2048);
580 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800581 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700582 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800583 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800584 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500585}
586
Naseer Ahmed29a26812012-06-14 00:56:20 -0700587static int hwc_device_close(struct hw_device_t *dev)
588{
589 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700590 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700591 return -1;
592 }
593 closeContext((hwc_context_t*)dev);
594 free(dev);
595
596 return 0;
597}
598
599static int hwc_device_open(const struct hw_module_t* module, const char* name,
600 struct hw_device_t** device)
601{
602 int status = -EINVAL;
603
604 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
605 struct hwc_context_t *dev;
606 dev = (hwc_context_t*)malloc(sizeof(*dev));
607 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700608
609 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700610 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700611
612 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700613 dev->device.common.tag = HARDWARE_DEVICE_TAG;
614 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
615 dev->device.common.module = const_cast<hw_module_t*>(module);
616 dev->device.common.close = hwc_device_close;
617 dev->device.prepare = hwc_prepare;
618 dev->device.set = hwc_set;
619 dev->device.eventControl = hwc_eventControl;
620 dev->device.blank = hwc_blank;
621 dev->device.query = hwc_query;
622 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500623 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700624 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
625 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
626 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700627 status = 0;
628 }
629 return status;
630}