blob: fccfcdec4a6f0aa4f20e476ec6d601412e5f25c9 [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
111static void reset_layer_prop(hwc_context_t* ctx, int dpy) {
112 int layer_count = ctx->listStats[dpy].numAppLayers;
113
114 if(ctx->layerProp[dpy]) {
115 delete[] ctx->layerProp[dpy];
116 ctx->layerProp[dpy] = NULL;
117 }
118
119 if(layer_count) {
120 ctx->layerProp[dpy] = new LayerProp[layer_count];
121 }
122}
123
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800124static int display_commit(hwc_context_t *ctx, int dpy) {
125 struct mdp_display_commit commit_info;
126 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
127 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
128 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
129 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
130 return -errno;
131 }
132 return 0;
133}
134
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700135static int hwc_prepare_primary(hwc_composer_device_1 *dev,
136 hwc_display_contents_1_t *list) {
137 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800138 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shahbf1e02a2013-02-26 13:38:05 -0800139 if (LIKELY(list && list->numHwLayers > 1 &&
140 list->numHwLayers <= MAX_NUM_LAYERS) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shah86623d72012-09-25 19:39:17 -0700141 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700142 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
143 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800144 setListStats(ctx, list, dpy);
145 reset_layer_prop(ctx, dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800146 int ret = ctx->mMDPComp->prepare(ctx, list);
147 if(!ret) {
148 // IF MDPcomp fails use this route
Saurabh Shahacf10202013-02-26 10:15:15 -0800149 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500150 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500151 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800152 ctx->mLayerCache[dpy]->updateLayerCache(list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800153 // Use Copybit, when MDP comp fails
154 if(!ret && ctx->mCopyBit[dpy])
155 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700156 }
157 }
158 return 0;
159}
160
161static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800162 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700163 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700164
Saurabh Shahbf1e02a2013-02-26 13:38:05 -0800165 if (LIKELY(list && list->numHwLayers > 1 &&
166 list->numHwLayers <= MAX_NUM_LAYERS) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800167 ctx->dpyAttr[dpy].isActive &&
168 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700169 uint32_t last = list->numHwLayers - 1;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800170 if(!ctx->dpyAttr[dpy].isPause) {
171 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
172 if(fbLayer->handle) {
173 setListStats(ctx, list, dpy);
174 reset_layer_prop(ctx, dpy);
Saurabh Shahacf10202013-02-26 10:15:15 -0800175 ctx->mVidOv[dpy]->prepare(ctx, list);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500176 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800177 ctx->mLayerCache[dpy]->updateLayerCache(list);
178 if(ctx->mCopyBit[dpy])
179 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
180 ctx->mExtDispConfiguring = false;
181 }
182 } else {
183 // External Display is in Pause state.
184 // ToDo:
185 // Mark all application layers as OVERLAY so that
186 // GPU will not compose. This is done for power
187 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700188 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700189 }
190 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700191}
192
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700193static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
194 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700195{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700196 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700197 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500198 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400199 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700200
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500201 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800202 ctx->mRotMgr->configBegin();
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800203 ctx->mNeedsRotator = false;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700204
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800205 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500206 hwc_display_contents_1_t *list = displays[i];
207 switch(i) {
208 case HWC_DISPLAY_PRIMARY:
209 ret = hwc_prepare_primary(dev, list);
210 break;
211 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800212 case HWC_DISPLAY_VIRTUAL:
213 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500214 break;
215 default:
216 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 }
218 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219
Saurabh Shahcf053c62012-12-13 12:32:55 -0800220 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800221 ctx->mRotMgr->configDone();
222
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700223 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700224}
225
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700226static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500227 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700228{
229 int ret = 0;
230 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700231 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700232 switch(event) {
233 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500234 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700235 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500236 ret = hwc_vsync_control(ctx, dpy, enable);
237 if(ret == 0) {
238 ctx->vstate.enable = !!enable;
239 pthread_cond_signal(&ctx->vstate.cond);
240 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700241 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500242 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700243 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700244 default:
245 ret = -EINVAL;
246 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700247 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248 return ret;
249}
250
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700251static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
252{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500253 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700254 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800255
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700257 int ret = 0;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500258 ALOGD("%s: %s display: %d", __FUNCTION__,
259 blank==1 ? "Blanking":"Unblanking", dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700260 switch(dpy) {
261 case HWC_DISPLAY_PRIMARY:
262 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500263 ctx->mOverlay->configBegin();
264 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800265 ctx->mRotMgr->clear();
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800266 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800267
268 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
269 // Surfaceflinger does not send Blank/unblank event to hwc
270 // for virtual display, handle it explicitly when blank for
271 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800272 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800273 ret = -1;
274 ALOGE("%s:post failed for virtual display !!",
275 __FUNCTION__);
276 } else {
277 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
278 }
279 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700280 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800281 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800282 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
283 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
284 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700285 }
286 break;
287 case HWC_DISPLAY_EXTERNAL:
288 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800289 // call external framebuffer commit on blank,
290 // so that any pipe unsets gets committed
291 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800292 ret = -1;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800293 ALOGE("%s:post failed for external display !! ", __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800294 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700295 } else {
296 }
297 break;
298 default:
299 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700300 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800301 // Enable HPD here, as during bootup unblank is called
302 // when SF is completely initialized
303 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500304 if(ret == 0){
305 ctx->dpyAttr[dpy].isActive = !blank;
306 } else {
307 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
308 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700309 return ret;
310 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500311
312 ALOGD("%s: Done %s display: %d", __FUNCTION__,
313 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700314 return 0;
315}
316
317static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700318 int param, int* value)
319{
320 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700321 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700322
323 switch (param) {
324 case HWC_BACKGROUND_LAYER_SUPPORTED:
325 // Not supported for now
326 value[0] = 0;
327 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700328 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700329 if(ctx->mMDP.hasOverlay)
330 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700331 value[0] = supported;
332 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700333 default:
334 return -EINVAL;
335 }
336 return 0;
337
338}
339
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800340
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700341static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500342 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700343 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800344 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800345 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700346 uint32_t last = list->numHwLayers - 1;
347 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800348 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500349 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800350 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500351 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800352 if(list->numHwLayers > 1)
353 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahacf10202013-02-26 10:15:15 -0800354 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
355 ALOGE("%s: VideoOverlay draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700356 ret = -1;
357 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800358 if (!ctx->mMDPComp->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800359 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500360 ret = -1;
361 }
362
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700363 //TODO We dont check for SKIP flag on this layer because we need PAN
364 //always. Last layer is always FB
Naseer Ahmed64b81212013-02-14 10:29:47 -0500365 private_handle_t *hnd = NULL;
366 if(copybitDone) {
367 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
368 } else {
369 hnd = (private_handle_t *)fbLayer->handle;
370 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500371 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800372 if(!(fbLayer->flags & HWC_SKIP_LAYER) &&
373 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500374 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800375 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500376 ret = -1;
377 }
378 }
Saurabh Shah43333302013-02-06 13:30:27 -0800379 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800380
381 if (display_commit(ctx, dpy) < 0) {
382 ALOGE("%s: display commit fail!", __FUNCTION__);
383 return -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700384 }
385 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800386
387 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700388 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700389}
390
391static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500392 hwc_display_contents_1_t* list, int dpy)
393{
394 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700395 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700396 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700397
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800398 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800399 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800400 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700401 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700402 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800403 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500404 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800405 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500406 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700407
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800408 if(list->numHwLayers > 1)
409 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700410
Saurabh Shahacf10202013-02-26 10:15:15 -0800411 if (!ctx->mVidOv[dpy]->draw(ctx, list)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700412 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
413 ret = -1;
414 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700415
Naseer Ahmed64b81212013-02-14 10:29:47 -0500416 private_handle_t *hnd = NULL;
417 if(copybitDone) {
418 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
419 } else {
420 hnd = (private_handle_t *)fbLayer->handle;
421 }
422
Saurabh Shah150806a2012-10-09 15:38:23 -0700423 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800424 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd &&
425 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500426 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500427 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700428 ret = -1;
429 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700430 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800431
432 if (display_commit(ctx, dpy) < 0) {
433 ALOGE("%s: display commit fail!", __FUNCTION__);
434 return -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700435 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700436 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800437
438 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700439 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700440}
441
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700442static int hwc_set(hwc_composer_device_1 *dev,
443 size_t numDisplays,
444 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700445{
446 int ret = 0;
447 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400448 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800449 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700450 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700451 switch(i) {
452 case HWC_DISPLAY_PRIMARY:
453 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700454 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700455 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800456 case HWC_DISPLAY_VIRTUAL:
457 /* ToDo: We are using hwc_set_external path for both External and
458 Virtual displays on HWC1.1. Eventually, we will have
459 separate functions when we move to HWC1.2
460 */
461 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700462 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700463 default:
464 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700465 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700466 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700467 return ret;
468}
469
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
471 uint32_t* configs, size_t* numConfigs) {
472 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700473 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700474 //in 1.1 there is no way to choose a config, report as config id # 0
475 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700476 switch(disp) {
477 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700478 if(*numConfigs > 0) {
479 configs[0] = 0;
480 *numConfigs = 1;
481 }
482 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700483 break;
484 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700485 ret = -1; //Not connected
486 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
487 ret = 0; //NO_ERROR
488 if(*numConfigs > 0) {
489 configs[0] = 0;
490 *numConfigs = 1;
491 }
492 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700493 break;
494 }
495 return ret;
496}
497
498int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
499 uint32_t config, const uint32_t* attributes, int32_t* values) {
500
501 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700502 //If hotpluggable displays are inactive return error
503 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
504 return -1;
505 }
506
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700507 //From HWComposer
508 static const uint32_t DISPLAY_ATTRIBUTES[] = {
509 HWC_DISPLAY_VSYNC_PERIOD,
510 HWC_DISPLAY_WIDTH,
511 HWC_DISPLAY_HEIGHT,
512 HWC_DISPLAY_DPI_X,
513 HWC_DISPLAY_DPI_Y,
514 HWC_DISPLAY_NO_ATTRIBUTE,
515 };
516
517 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
518 sizeof(DISPLAY_ATTRIBUTES)[0]);
519
520 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
521 switch (attributes[i]) {
522 case HWC_DISPLAY_VSYNC_PERIOD:
523 values[i] = ctx->dpyAttr[disp].vsync_period;
524 break;
525 case HWC_DISPLAY_WIDTH:
526 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700527 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
528 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700529 break;
530 case HWC_DISPLAY_HEIGHT:
531 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700532 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
533 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700534 break;
535 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400536 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700537 break;
538 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400539 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700540 break;
541 default:
542 ALOGE("Unknown display attribute %d",
543 attributes[i]);
544 return -EINVAL;
545 }
546 }
547 return 0;
548}
549
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500550void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
551{
552 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800553 android::String8 aBuf("");
554 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
555 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
556 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
557 ctx->mMDPComp->dump(aBuf);
558 char ovDump[2048] = {'\0'};
559 ctx->mOverlay->getDump(ovDump, 2048);
560 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800561 ovDump[0] = '\0';
562 ctx->mRotMgr->getDump(ovDump, 2048);
563 dumpsys_log(aBuf, ovDump);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800564 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500565}
566
Naseer Ahmed29a26812012-06-14 00:56:20 -0700567static int hwc_device_close(struct hw_device_t *dev)
568{
569 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700570 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700571 return -1;
572 }
573 closeContext((hwc_context_t*)dev);
574 free(dev);
575
576 return 0;
577}
578
579static int hwc_device_open(const struct hw_module_t* module, const char* name,
580 struct hw_device_t** device)
581{
582 int status = -EINVAL;
583
584 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
585 struct hwc_context_t *dev;
586 dev = (hwc_context_t*)malloc(sizeof(*dev));
587 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700588
589 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700590 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700591
592 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700593 dev->device.common.tag = HARDWARE_DEVICE_TAG;
594 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
595 dev->device.common.module = const_cast<hw_module_t*>(module);
596 dev->device.common.close = hwc_device_close;
597 dev->device.prepare = hwc_prepare;
598 dev->device.set = hwc_set;
599 dev->device.eventControl = hwc_eventControl;
600 dev->device.blank = hwc_blank;
601 dev->device.query = hwc_query;
602 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500603 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700604 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
605 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
606 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700607 status = 0;
608 }
609 return status;
610}