blob: bc705ac1eb227e60652812bae0d5b506deb0e388 [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 Ahmedf48aef62012-07-20 09:05:53 -070033#include "hwc_video.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050034#include "hwc_fbupdate.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050035#include "hwc_mdpcomp.h"
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 Ahmed29a26812012-06-14 00:56:20 -070038
39using namespace qhwc;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050040#define VSYNC_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070041
42static int hwc_device_open(const struct hw_module_t* module,
43 const char* name,
44 struct hw_device_t** device);
45
46static struct hw_module_methods_t hwc_module_methods = {
47 open: hwc_device_open
48};
49
50hwc_module_t HAL_MODULE_INFO_SYM = {
51 common: {
52 tag: HARDWARE_MODULE_TAG,
53 version_major: 2,
54 version_minor: 0,
55 id: HWC_HARDWARE_MODULE_ID,
56 name: "Qualcomm Hardware Composer Module",
57 author: "CodeAurora Forum",
58 methods: &hwc_module_methods,
59 dso: 0,
60 reserved: {0},
61 }
62};
63
64/*
65 * Save callback functions registered to HWC
66 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070067static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 hwc_procs_t const* procs)
69{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070070 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070071 hwc_context_t* ctx = (hwc_context_t*)(dev);
72 if(!ctx) {
73 ALOGE("%s: Invalid context", __FUNCTION__);
74 return;
75 }
Jesse Hall3be78d92012-08-21 15:12:23 -070076 ctx->proc = procs;
77
Naseer Ahmedff4f0252012-10-01 13:03:01 -040078 // Now that we have the functions needed, kick off
79 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070080 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040081 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070082}
83
Saurabh Shah649cda62012-09-16 16:05:58 -070084//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040085static void reset(hwc_context_t *ctx, int numDisplays,
86 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070087 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080088 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040089 hwc_display_contents_1_t *list = displays[i];
90 // XXX:SurfaceFlinger no longer guarantees that this
91 // value is reset on every prepare. However, for the layer
92 // cache we need to reset it.
93 // We can probably rethink that later on
94 if (LIKELY(list && list->numHwLayers > 1)) {
95 for(uint32_t j = 0; j < list->numHwLayers; j++) {
96 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
97 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
98 }
99 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800100
101 if(ctx->mFBUpdate[i])
102 ctx->mFBUpdate[i]->reset();
Saurabh Shahacf10202013-02-26 10:15:15 -0800103 if(ctx->mVidOv[i])
104 ctx->mVidOv[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800105 if(ctx->mCopyBit[i])
106 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700107 }
108}
109
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500110//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700111static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500112 if(ctx->layerProp[dpy]) {
113 delete[] ctx->layerProp[dpy];
114 ctx->layerProp[dpy] = NULL;
115 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700116 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500117}
118
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800119static int display_commit(hwc_context_t *ctx, int dpy) {
120 struct mdp_display_commit commit_info;
121 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
122 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
123 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
124 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
125 return -errno;
126 }
127 return 0;
128}
129
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700130static int hwc_prepare_primary(hwc_composer_device_1 *dev,
131 hwc_display_contents_1_t *list) {
132 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800133 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700134 if (LIKELY(list && list->numHwLayers > 1) &&
135 ctx->dpyAttr[dpy].isActive) {
136 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700137 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700138 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
139 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700140 if(list->numHwLayers > MAX_NUM_LAYERS) {
141 ctx->mFBUpdate[dpy]->prepare(ctx, list);
142 return 0;
143 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800144 setListStats(ctx, list, dpy);
Saurabh Shah2b033392013-03-22 11:29:44 -0700145 bool ret = ctx->mMDPComp->prepare(ctx, list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800146 if(!ret) {
147 // IF MDPcomp fails use this route
Saurabh Shahacf10202013-02-26 10:15:15 -0800148 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500149 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Saurabh Shah2b033392013-03-22 11:29:44 -0700150 // Use Copybit, when MDP comp fails
151 if(ctx->mCopyBit[dpy])
152 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
153 ctx->mLayerCache[dpy]->updateLayerCache(list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500154 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700155 }
156 }
157 return 0;
158}
159
160static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800161 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700162 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700163
Saurabh Shah2b033392013-03-22 11:29:44 -0700164 if (LIKELY(list && list->numHwLayers > 1) &&
165 ctx->dpyAttr[dpy].isActive &&
166 ctx->dpyAttr[dpy].connected) {
167 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700168 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700169 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800170 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800171 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700172 ctx->mExtDispConfiguring = false;
173 if(list->numHwLayers > MAX_NUM_LAYERS) {
174 ctx->mFBUpdate[dpy]->prepare(ctx, list);
175 return 0;
176 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800177 setListStats(ctx, list, dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800178 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500179 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800180 ctx->mLayerCache[dpy]->updateLayerCache(list);
181 if(ctx->mCopyBit[dpy])
182 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
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();
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800205 ctx->mNeedsRotator = false;
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();
224
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700225 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226}
227
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700228static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500229 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700230{
231 int ret = 0;
232 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700233 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234 switch(event) {
235 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500236 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700237 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500238 ret = hwc_vsync_control(ctx, dpy, enable);
239 if(ret == 0) {
240 ctx->vstate.enable = !!enable;
241 pthread_cond_signal(&ctx->vstate.cond);
242 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700243 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500244 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700245 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700246 default:
247 ret = -EINVAL;
248 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700249 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700250 return ret;
251}
252
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700253static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
254{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500255 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700256 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800257
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500258 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700259 int ret = 0;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500260 ALOGD("%s: %s display: %d", __FUNCTION__,
261 blank==1 ? "Blanking":"Unblanking", dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700262 switch(dpy) {
263 case HWC_DISPLAY_PRIMARY:
264 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500265 ctx->mOverlay->configBegin();
266 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800267 ctx->mRotMgr->clear();
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800268 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800269
270 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
271 // Surfaceflinger does not send Blank/unblank event to hwc
272 // for virtual display, handle it explicitly when blank for
273 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800274 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800275 ret = -1;
276 ALOGE("%s:post failed for virtual display !!",
277 __FUNCTION__);
278 } else {
279 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
280 }
281 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700282 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800283 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800284 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
285 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
286 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700287 }
288 break;
289 case HWC_DISPLAY_EXTERNAL:
290 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800291 // call external framebuffer commit on blank,
292 // so that any pipe unsets gets committed
293 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800294 ret = -1;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800295 ALOGE("%s:post failed for external display !! ", __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800296 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700297 } else {
298 }
299 break;
300 default:
301 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700302 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800303 // Enable HPD here, as during bootup unblank is called
304 // when SF is completely initialized
305 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500306 if(ret == 0){
307 ctx->dpyAttr[dpy].isActive = !blank;
308 } else {
309 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
310 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700311 return ret;
312 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500313
314 ALOGD("%s: Done %s display: %d", __FUNCTION__,
315 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700316 return 0;
317}
318
319static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700320 int param, int* value)
321{
322 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700323 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700324
325 switch (param) {
326 case HWC_BACKGROUND_LAYER_SUPPORTED:
327 // Not supported for now
328 value[0] = 0;
329 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700330 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700331 if(ctx->mMDP.hasOverlay)
332 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700333 value[0] = supported;
334 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700335 default:
336 return -EINVAL;
337 }
338 return 0;
339
340}
341
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800342
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700343static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500344 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700345 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800346 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800347 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700348 uint32_t last = list->numHwLayers - 1;
349 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800350 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500351 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800352 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500353 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800354 if(list->numHwLayers > 1)
355 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahacf10202013-02-26 10:15:15 -0800356 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
357 ALOGE("%s: VideoOverlay draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700358 ret = -1;
359 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800360 if (!ctx->mMDPComp->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800361 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500362 ret = -1;
363 }
364
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700365 //TODO We dont check for SKIP flag on this layer because we need PAN
366 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700367 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500368 if(copybitDone) {
369 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500370 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700371
372 if(hnd) {
373 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
374 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
375 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500376 }
Saurabh Shah43333302013-02-06 13:30:27 -0800377 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800378
379 if (display_commit(ctx, dpy) < 0) {
380 ALOGE("%s: display commit fail!", __FUNCTION__);
381 return -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700382 }
383 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800384
385 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700386 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700387}
388
389static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500390 hwc_display_contents_1_t* list, int dpy)
391{
392 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700393 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700394 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700395
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800396 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800397 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800398 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700399 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700400 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800401 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500402 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800403 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500404 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700405
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800406 if(list->numHwLayers > 1)
407 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700408
Saurabh Shahacf10202013-02-26 10:15:15 -0800409 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700410 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
411 ret = -1;
412 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700413
Saurabh Shah2b033392013-03-22 11:29:44 -0700414 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500415 if(copybitDone) {
416 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500417 }
418
Saurabh Shah2b033392013-03-22 11:29:44 -0700419 if(hnd) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500420 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500421 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700422 ret = -1;
423 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700424 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800425
426 if (display_commit(ctx, dpy) < 0) {
427 ALOGE("%s: display commit fail!", __FUNCTION__);
Saurabh Shah2b033392013-03-22 11:29:44 -0700428 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700429 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700430 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800431
432 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700433 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700434}
435
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700436static int hwc_set(hwc_composer_device_1 *dev,
437 size_t numDisplays,
438 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700439{
440 int ret = 0;
441 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400442 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800443 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700444 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700445 switch(i) {
446 case HWC_DISPLAY_PRIMARY:
447 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700448 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700449 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800450 case HWC_DISPLAY_VIRTUAL:
451 /* ToDo: We are using hwc_set_external path for both External and
452 Virtual displays on HWC1.1. Eventually, we will have
453 separate functions when we move to HWC1.2
454 */
455 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700456 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700457 default:
458 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700459 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700460 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 return ret;
462}
463
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700464int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
465 uint32_t* configs, size_t* numConfigs) {
466 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700467 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700468 //in 1.1 there is no way to choose a config, report as config id # 0
469 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470 switch(disp) {
471 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700472 if(*numConfigs > 0) {
473 configs[0] = 0;
474 *numConfigs = 1;
475 }
476 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700477 break;
478 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700479 ret = -1; //Not connected
480 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
481 ret = 0; //NO_ERROR
482 if(*numConfigs > 0) {
483 configs[0] = 0;
484 *numConfigs = 1;
485 }
486 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700487 break;
488 }
489 return ret;
490}
491
492int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
493 uint32_t config, const uint32_t* attributes, int32_t* values) {
494
495 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700496 //If hotpluggable displays are inactive return error
497 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
498 return -1;
499 }
500
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700501 //From HWComposer
502 static const uint32_t DISPLAY_ATTRIBUTES[] = {
503 HWC_DISPLAY_VSYNC_PERIOD,
504 HWC_DISPLAY_WIDTH,
505 HWC_DISPLAY_HEIGHT,
506 HWC_DISPLAY_DPI_X,
507 HWC_DISPLAY_DPI_Y,
508 HWC_DISPLAY_NO_ATTRIBUTE,
509 };
510
511 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
512 sizeof(DISPLAY_ATTRIBUTES)[0]);
513
514 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
515 switch (attributes[i]) {
516 case HWC_DISPLAY_VSYNC_PERIOD:
517 values[i] = ctx->dpyAttr[disp].vsync_period;
518 break;
519 case HWC_DISPLAY_WIDTH:
520 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700521 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
522 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700523 break;
524 case HWC_DISPLAY_HEIGHT:
525 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700526 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
527 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700528 break;
529 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400530 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700531 break;
532 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400533 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700534 break;
535 default:
536 ALOGE("Unknown display attribute %d",
537 attributes[i]);
538 return -EINVAL;
539 }
540 }
541 return 0;
542}
543
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500544void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
545{
546 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800547 android::String8 aBuf("");
548 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
549 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
550 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
551 ctx->mMDPComp->dump(aBuf);
552 char ovDump[2048] = {'\0'};
553 ctx->mOverlay->getDump(ovDump, 2048);
554 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800555 ovDump[0] = '\0';
556 ctx->mRotMgr->getDump(ovDump, 2048);
557 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800558 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500559}
560
Naseer Ahmed29a26812012-06-14 00:56:20 -0700561static int hwc_device_close(struct hw_device_t *dev)
562{
563 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700564 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700565 return -1;
566 }
567 closeContext((hwc_context_t*)dev);
568 free(dev);
569
570 return 0;
571}
572
573static int hwc_device_open(const struct hw_module_t* module, const char* name,
574 struct hw_device_t** device)
575{
576 int status = -EINVAL;
577
578 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
579 struct hwc_context_t *dev;
580 dev = (hwc_context_t*)malloc(sizeof(*dev));
581 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700582
583 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700584 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700585
586 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700587 dev->device.common.tag = HARDWARE_DEVICE_TAG;
588 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
589 dev->device.common.module = const_cast<hw_module_t*>(module);
590 dev->device.common.close = hwc_device_close;
591 dev->device.prepare = hwc_prepare;
592 dev->device.set = hwc_set;
593 dev->device.eventControl = hwc_eventControl;
594 dev->device.blank = hwc_blank;
595 dev->device.query = hwc_query;
596 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500597 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700598 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
599 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
600 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700601 status = 0;
602 }
603 return status;
604}