blob: 42f5c85c4325403e417d81a9fab46d015ced4dae [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"
Saurabh Shah56f610d2012-08-07 15:27:06 -070035#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080036#include "hwc_copybit.h"
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -040037#include "profiler.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 Ahmede0205b62013-04-04 13:24:39 -040041#define BLANK_DEBUG 0
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43static int hwc_device_open(const struct hw_module_t* module,
44 const char* name,
45 struct hw_device_t** device);
46
47static struct hw_module_methods_t hwc_module_methods = {
48 open: hwc_device_open
49};
50
51hwc_module_t HAL_MODULE_INFO_SYM = {
52 common: {
53 tag: HARDWARE_MODULE_TAG,
54 version_major: 2,
55 version_minor: 0,
56 id: HWC_HARDWARE_MODULE_ID,
57 name: "Qualcomm Hardware Composer Module",
58 author: "CodeAurora Forum",
59 methods: &hwc_module_methods,
60 dso: 0,
61 reserved: {0},
62 }
63};
64
65/*
66 * Save callback functions registered to HWC
67 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070068static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 hwc_procs_t const* procs)
70{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070071 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 hwc_context_t* ctx = (hwc_context_t*)(dev);
73 if(!ctx) {
74 ALOGE("%s: Invalid context", __FUNCTION__);
75 return;
76 }
Jesse Hall3be78d92012-08-21 15:12:23 -070077 ctx->proc = procs;
78
Naseer Ahmedff4f0252012-10-01 13:03:01 -040079 // Now that we have the functions needed, kick off
80 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -070081 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -040082 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070083}
84
Saurabh Shah649cda62012-09-16 16:05:58 -070085//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -040086static void reset(hwc_context_t *ctx, int numDisplays,
87 hwc_display_contents_1_t** displays) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070088 memset(ctx->listStats, 0, sizeof(ctx->listStats));
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -080089 for(int i = 0; i < MAX_DISPLAYS; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -040090 hwc_display_contents_1_t *list = displays[i];
91 // XXX:SurfaceFlinger no longer guarantees that this
92 // value is reset on every prepare. However, for the layer
93 // cache we need to reset it.
94 // We can probably rethink that later on
95 if (LIKELY(list && list->numHwLayers > 1)) {
96 for(uint32_t j = 0; j < list->numHwLayers; j++) {
97 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
98 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
99 }
100 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800101
102 if(ctx->mFBUpdate[i])
103 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800104 if(ctx->mCopyBit[i])
105 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700106 }
107}
108
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500109//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700110static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500111 if(ctx->layerProp[dpy]) {
112 delete[] ctx->layerProp[dpy];
113 ctx->layerProp[dpy] = NULL;
114 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700115 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500116}
117
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800118static int display_commit(hwc_context_t *ctx, int dpy) {
119 struct mdp_display_commit commit_info;
120 memset(&commit_info, 0, sizeof(struct mdp_display_commit));
121 commit_info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
122 if(ioctl(ctx->dpyAttr[dpy].fd, MSMFB_DISPLAY_COMMIT, &commit_info) == -1) {
123 ALOGE("%s: MSMFB_DISPLAY_COMMIT for primary failed", __FUNCTION__);
124 return -errno;
125 }
126 return 0;
127}
128
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700129static int hwc_prepare_primary(hwc_composer_device_1 *dev,
130 hwc_display_contents_1_t *list) {
131 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800132 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700133 if (LIKELY(list && list->numHwLayers > 1) &&
134 ctx->dpyAttr[dpy].isActive) {
135 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah86623d72012-09-25 19:39:17 -0700136 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700137 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
138 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800139 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800140 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
141 if(fbZOrder >= 0)
142 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
143
144 /* Temporarily commenting out C2D until we support partial
145 copybit composition for mixed mode MDP
146
147 // Use Copybit, when MDP comp fails
148 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
149 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
150 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700151 }
152 }
153 return 0;
154}
155
156static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800157 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700158 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700159
Saurabh Shah2b033392013-03-22 11:29:44 -0700160 if (LIKELY(list && list->numHwLayers > 1) &&
161 ctx->dpyAttr[dpy].isActive &&
162 ctx->dpyAttr[dpy].connected) {
163 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700164 uint32_t last = list->numHwLayers - 1;
Saurabh Shah2b033392013-03-22 11:29:44 -0700165 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800166 if(!ctx->dpyAttr[dpy].isPause) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800167 if(fbLayer->handle) {
Saurabh Shah2b033392013-03-22 11:29:44 -0700168 ctx->mExtDispConfiguring = false;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800169 setListStats(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800170 int fbZOrder = ctx->mMDPComp[dpy]->prepare(ctx, list);
171 if(fbZOrder >= 0)
172 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
173
174 /* Temporarily commenting out C2D until we support partial
175 copybit composition for mixed mode MDP
176
177 if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800178 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800179 */
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800180 }
181 } else {
182 // External Display is in Pause state.
183 // ToDo:
184 // Mark all application layers as OVERLAY so that
185 // GPU will not compose. This is done for power
186 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700187 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700188 }
189 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700190}
191
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700192static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
193 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700195 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500197 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400198 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700199
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500200 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800201 ctx->mRotMgr->configBegin();
Jeykumar Sankarana37fdbf2013-03-06 18:59:28 -0800202 ctx->mNeedsRotator = false;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700203
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800204 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500205 hwc_display_contents_1_t *list = displays[i];
206 switch(i) {
207 case HWC_DISPLAY_PRIMARY:
208 ret = hwc_prepare_primary(dev, list);
209 break;
210 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800211 case HWC_DISPLAY_VIRTUAL:
212 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500213 break;
214 default:
215 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 }
217 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500218
Saurabh Shahcf053c62012-12-13 12:32:55 -0800219 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800220 ctx->mRotMgr->configDone();
221
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700222 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223}
224
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700225static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500226 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700227{
228 int ret = 0;
229 hwc_context_t* ctx = (hwc_context_t*)(dev);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700230 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700231 switch(event) {
232 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500233 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700234 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500235 ret = hwc_vsync_control(ctx, dpy, enable);
236 if(ret == 0) {
237 ctx->vstate.enable = !!enable;
238 pthread_cond_signal(&ctx->vstate.cond);
239 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700240 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500241 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700242 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700243 default:
244 ret = -EINVAL;
245 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700246 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700247 return ret;
248}
249
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700250static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
251{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500252 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700253 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800254
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700256 int ret = 0;
Naseer Ahmede0205b62013-04-04 13:24:39 -0400257 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500258 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700259 if(blank) {
260 // free up all the overlay pipes in use
261 // when we get a blank for either display
262 // makes sure that all pipes are freed
263 ctx->mOverlay->configBegin();
264 ctx->mOverlay->configDone();
265 ctx->mRotMgr->clear();
266 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700267 switch(dpy) {
268 case HWC_DISPLAY_PRIMARY:
269 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800270 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK,FB_BLANK_POWERDOWN);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800271
272 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
273 // Surfaceflinger does not send Blank/unblank event to hwc
274 // for virtual display, handle it explicitly when blank for
275 // primary is invoked, so that any pipes unset get committed
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800276 if (display_commit(ctx, HWC_DISPLAY_VIRTUAL) < 0) {
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800277 ret = -1;
278 ALOGE("%s:post failed for virtual display !!",
279 __FUNCTION__);
280 } else {
281 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
282 }
283 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700284 } else {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800285 ret = ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, FB_BLANK_UNBLANK);
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800286 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected == true) {
287 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
288 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700289 }
290 break;
291 case HWC_DISPLAY_EXTERNAL:
292 if(blank) {
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800293 // call external framebuffer commit on blank,
294 // so that any pipe unsets gets committed
295 if (display_commit(ctx, dpy) < 0) {
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800296 ret = -1;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800297 ALOGE("%s:post failed for external display !! ",
298 __FUNCTION__);
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800299 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700300 } else {
301 }
302 break;
303 default:
304 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700305 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800306 // Enable HPD here, as during bootup unblank is called
307 // when SF is completely initialized
308 ctx->mExtDisplay->setHPD(1);
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500309 if(ret == 0){
310 ctx->dpyAttr[dpy].isActive = !blank;
311 } else {
312 ALOGE("%s: Failed in %s display: %d error:%s", __FUNCTION__,
313 blank==1 ? "blanking":"unblanking", dpy, strerror(errno));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700314 return ret;
315 }
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500316
Naseer Ahmede0205b62013-04-04 13:24:39 -0400317 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500318 blank==1 ? "blanking":"unblanking", dpy);
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700319 return 0;
320}
321
322static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700323 int param, int* value)
324{
325 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700326 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700327
328 switch (param) {
329 case HWC_BACKGROUND_LAYER_SUPPORTED:
330 // Not supported for now
331 value[0] = 0;
332 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700333 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700334 if(ctx->mMDP.hasOverlay)
335 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700336 value[0] = supported;
337 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700338 default:
339 return -EINVAL;
340 }
341 return 0;
342
343}
344
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800345
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700346static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500347 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700348 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800349 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800350 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700351 uint32_t last = list->numHwLayers - 1;
352 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800353 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500354 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800355 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500356 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800357 if(list->numHwLayers > 1)
358 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800359
360 if (!ctx->mMDPComp[dpy]->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
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800409 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
410 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700411 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 Ahmed0d05d4f2013-03-28 14:49:07 -0400461 // This is only indicative of how many times SurfaceFlinger posts
462 // frames to the display.
463 CALC_FPS();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700464 return ret;
465}
466
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700467int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
468 uint32_t* configs, size_t* numConfigs) {
469 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700470 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700471 //in 1.1 there is no way to choose a config, report as config id # 0
472 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700473 switch(disp) {
474 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700475 if(*numConfigs > 0) {
476 configs[0] = 0;
477 *numConfigs = 1;
478 }
479 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700480 break;
481 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700482 ret = -1; //Not connected
483 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
484 ret = 0; //NO_ERROR
485 if(*numConfigs > 0) {
486 configs[0] = 0;
487 *numConfigs = 1;
488 }
489 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700490 break;
491 }
492 return ret;
493}
494
495int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
496 uint32_t config, const uint32_t* attributes, int32_t* values) {
497
498 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700499 //If hotpluggable displays are inactive return error
500 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
501 return -1;
502 }
503
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700504 //From HWComposer
505 static const uint32_t DISPLAY_ATTRIBUTES[] = {
506 HWC_DISPLAY_VSYNC_PERIOD,
507 HWC_DISPLAY_WIDTH,
508 HWC_DISPLAY_HEIGHT,
509 HWC_DISPLAY_DPI_X,
510 HWC_DISPLAY_DPI_Y,
511 HWC_DISPLAY_NO_ATTRIBUTE,
512 };
513
514 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
515 sizeof(DISPLAY_ATTRIBUTES)[0]);
516
517 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
518 switch (attributes[i]) {
519 case HWC_DISPLAY_VSYNC_PERIOD:
520 values[i] = ctx->dpyAttr[disp].vsync_period;
521 break;
522 case HWC_DISPLAY_WIDTH:
523 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700524 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
525 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700526 break;
527 case HWC_DISPLAY_HEIGHT:
528 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700529 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
530 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700531 break;
532 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400533 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700534 break;
535 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400536 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700537 break;
538 default:
539 ALOGE("Unknown display attribute %d",
540 attributes[i]);
541 return -EINVAL;
542 }
543 }
544 return 0;
545}
546
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500547void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
548{
549 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800550 android::String8 aBuf("");
551 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
552 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
553 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800554 for(int dpy = 0; dpy < MAX_DISPLAYS; dpy++) {
555 if(ctx->mMDPComp[dpy])
556 ctx->mMDPComp[dpy]->dump(aBuf);
557 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800558 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}