blob: f7bb192e26607c029f8722b1e0b3a76b175f7fea [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) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700161 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700162
Saurabh Shah2b033392013-03-22 11:29:44 -0700163 if (LIKELY(list && list->numHwLayers > 1) &&
164 ctx->dpyAttr[dpy].isActive &&
165 ctx->dpyAttr[dpy].connected) {
166 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700167 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700168 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800169 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800170 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700171 ctx->mExtDispConfiguring = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800172 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800173 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
174 if(fbZOrder >= 0)
175 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
176
177 /* Temporarily commenting out C2D until we support partial
178 copybit composition for mixed mode MDP
179
180 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800181 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800182 */
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800183 }
184 } else {
185 // External Display is in Pause state.
186 // ToDo:
187 // Mark all application layers as OVERLAY so that
188 // GPU will not compose. This is done for power
189 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700190 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700191 }
192 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700193}
194
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700195static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
196 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700198 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700199 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400201 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700202
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500203 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800204 ctx->mRotMgr->configBegin();
Saurabh Shah85234ec2013-04-12 17:09:00 -0700205 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700206
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800207 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500208 hwc_display_contents_1_t *list = displays[i];
209 switch(i) {
210 case HWC_DISPLAY_PRIMARY:
211 ret = hwc_prepare_primary(dev, list);
212 break;
213 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800214 case HWC_DISPLAY_VIRTUAL:
215 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500216 break;
217 default:
218 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 }
220 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500221
Saurabh Shahcf053c62012-12-13 12:32:55 -0800222 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800223 ctx->mRotMgr->configDone();
Saurabh Shah98acd092013-05-03 10:48:24 -0700224 MDPComp::resetIdleFallBack();
Saurabh Shahacf10202013-02-26 10:15:15 -0800225
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700226 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227}
228
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700229static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500230 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700231{
232 int ret = 0;
233 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700234 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700235 switch(event) {
236 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500237 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700238 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500239 ret = hwc_vsync_control(ctx, dpy, enable);
240 if(ret == 0) {
241 ctx->vstate.enable = !!enable;
242 pthread_cond_signal(&ctx->vstate.cond);
243 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700244 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500245 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700246 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700247 default:
248 ret = -EINVAL;
249 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700250 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700251 return ret;
252}
253
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700254static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
255{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500256 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700257 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800258
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500259 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700260 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400261 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500262 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700263 if(blank) {
264 // free up all the overlay pipes in use
265 // when we get a blank for either display
266 // makes sure that all pipes are freed
267 ctx->mOverlay->configBegin();
268 ctx->mOverlay->configDone();
269 ctx->mRotMgr->clear();
270 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700271 switch(dpy) {
272 case HWC_DISPLAY_PRIMARY:
273 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800274 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800275
276 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
277 // Surfaceflinger does not send Blank/unblank event to hwc
278 // for virtual display, handle it explicitly when blank for
279 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800280 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800281 ret = -1;
282 ALOGE("%s:post failed for virtual display !!",
283 __FUNCTION__);
284 } else {
285 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
286 }
287 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700288 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800289 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800290 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
291 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
292 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700293 }
294 break;
295 case HWC_DISPLAY_EXTERNAL:
296 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800297 // call external framebuffer commit on blank,
298 // so that any pipe unsets gets committed
299 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800300 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 ALOGE("%s:post failed for external display !! ",
302 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800303 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304 } else {
305 }
306 break;
307 default:
308 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700309 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800310 // Enable HPD here, as during bootup unblank is called
311 // when SF is completely initialized
312 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500313 if(ret == 0){
314 ctx->dpyAttr[dpy].isActive = !blank;
315 } else {
316 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
317 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700318 return ret;
319 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500320
Naseer Ahmede0205b62013-04-04 13:24:39 -0400321 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500322 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700323 return 0;
324}
325
326static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700327 int param, int* value)
328{
329 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700330 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700331
332 switch (param) {
333 case HWC_BACKGROUND_LAYER_SUPPORTED:
334 // Not supported for now
335 value[0] = 0;
336 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700337 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700338 if(ctx->mMDP.hasOverlay)
339 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700340 value[0] = supported;
341 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700342 default:
343 return -EINVAL;
344 }
345 return 0;
346
347}
348
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800349
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700350static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500351 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700352 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800353 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800354 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700355 uint32_t last = list->numHwLayers - 1;
356 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800357 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500358 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800359 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500360 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800361 if(list->numHwLayers > 1)
362 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800363
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700364 // Dump the layers for primary
365 if(ctx->mHwcDebug[dpy])
366 ctx->mHwcDebug[dpy]->dumpLayers(list);
367
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800368 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800369 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500370 ret = -1;
371 }
372
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700373 //TODO We dont check for SKIP flag on this layer because we need PAN
374 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700375 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500376 if(copybitDone) {
377 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500378 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700379
380 if(hnd) {
381 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
382 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
383 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500384 }
Saurabh Shah43333302013-02-06 13:30:27 -0800385 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800386
387 if (display_commit(ctx, dpy) < 0) {
388 ALOGE("%s: display commit fail!", __FUNCTION__);
389 return -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700390 }
391 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800392
393 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700394 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700395}
396
397static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500398 hwc_display_contents_1_t* list, int dpy)
399{
400 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700401 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700402 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700403
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800404 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800405 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800406 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700407 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700408 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800409 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500410 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800411 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500412 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700413
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800414 if(list->numHwLayers > 1)
415 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700416
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700417 // Dump the layers for external
418 if(ctx->mHwcDebug[dpy])
419 ctx->mHwcDebug[dpy]->dumpLayers(list);
420
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800421 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
422 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700423 ret = -1;
424 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700425
Saurabh Shah2b033392013-03-22 11:29:44 -0700426 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500427 if(copybitDone) {
428 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500429 }
430
Saurabh Shah2b033392013-03-22 11:29:44 -0700431 if(hnd) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500432 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500433 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700434 ret = -1;
435 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700436 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800437
438 if (display_commit(ctx, dpy) < 0) {
439 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700440 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700441 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700442 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800443
444 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700445 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700446}
447
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700448static int hwc_set(hwc_composer_device_1 *dev,
449 size_t numDisplays,
450 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700451{
452 int ret = 0;
453 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400454 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800455 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700456 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700457 switch(i) {
458 case HWC_DISPLAY_PRIMARY:
459 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700460 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700461 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800462 case HWC_DISPLAY_VIRTUAL:
463 /* ToDo: We are using hwc_set_external path for both External and
464 Virtual displays on HWC1.1. Eventually, we will have
465 separate functions when we move to HWC1.2
466 */
467 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700468 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700469 default:
470 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700471 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700472 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400473 // This is only indicative of how many times SurfaceFlinger posts
474 // frames to the display.
475 CALC_FPS();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700476 return ret;
477}
478
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700479int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
480 uint32_t* configs, size_t* numConfigs) {
481 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700482 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700483 //in 1.1 there is no way to choose a config, report as config id # 0
484 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700485 switch(disp) {
486 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700487 if(*numConfigs > 0) {
488 configs[0] = 0;
489 *numConfigs = 1;
490 }
491 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700492 break;
493 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700494 ret = -1; //Not connected
495 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
496 ret = 0; //NO_ERROR
497 if(*numConfigs > 0) {
498 configs[0] = 0;
499 *numConfigs = 1;
500 }
501 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700502 break;
503 }
504 return ret;
505}
506
507int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
508 uint32_t config, const uint32_t* attributes, int32_t* values) {
509
510 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700511 //If hotpluggable displays are inactive return error
512 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
513 return -1;
514 }
515
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700516 //From HWComposer
517 static const uint32_t DISPLAY_ATTRIBUTES[] = {
518 HWC_DISPLAY_VSYNC_PERIOD,
519 HWC_DISPLAY_WIDTH,
520 HWC_DISPLAY_HEIGHT,
521 HWC_DISPLAY_DPI_X,
522 HWC_DISPLAY_DPI_Y,
523 HWC_DISPLAY_NO_ATTRIBUTE,
524 };
525
526 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
527 sizeof(DISPLAY_ATTRIBUTES)[0]);
528
529 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
530 switch (attributes[i]) {
531 case HWC_DISPLAY_VSYNC_PERIOD:
532 values[i] = ctx->dpyAttr[disp].vsync_period;
533 break;
534 case HWC_DISPLAY_WIDTH:
535 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700536 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
537 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700538 break;
539 case HWC_DISPLAY_HEIGHT:
540 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700541 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
542 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700543 break;
544 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400545 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700546 break;
547 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400548 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700549 break;
550 default:
551 ALOGE("Unknown display attribute %d",
552 attributes[i]);
553 return -EINVAL;
554 }
555 }
556 return 0;
557}
558
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500559void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
560{
561 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800562 android::String8 aBuf("");
563 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
564 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
565 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800566 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
567 if(ctx->mMDPComp[dpy])
568 ctx->mMDPComp[dpy]->dump(aBuf);
569 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800570 char ovDump[2048] = {'\0'};
571 ctx->mOverlay->getDump(ovDump, 2048);
572 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800573 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700574 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800575 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800576 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500577}
578
Naseer Ahmed29a26812012-06-14 00:56:20 -0700579static int hwc_device_close(struct hw_device_t *dev)
580{
581 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700582 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700583 return -1;
584 }
585 closeContext((hwc_context_t*)dev);
586 free(dev);
587
588 return 0;
589}
590
591static int hwc_device_open(const struct hw_module_t* module, const char* name,
592 struct hw_device_t** device)
593{
594 int status = -EINVAL;
595
596 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
597 struct hwc_context_t *dev;
598 dev = (hwc_context_t*)malloc(sizeof(*dev));
599 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700600
601 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700602 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700603
604 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700605 dev->device.common.tag = HARDWARE_DEVICE_TAG;
606 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
607 dev->device.common.module = const_cast<hw_module_t*>(module);
608 dev->device.common.close = hwc_device_close;
609 dev->device.prepare = hwc_prepare;
610 dev->device.set = hwc_set;
611 dev->device.eventControl = hwc_eventControl;
612 dev->device.blank = hwc_blank;
613 dev->device.query = hwc_query;
614 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500615 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700616 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
617 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
618 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700619 status = 0;
620 }
621 return status;
622}