blob: 593bc091ab9501d854ca39750a044447ead1e830 [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>
Naseer Ahmed29a26812012-06-14 00:56:20 -070028
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029#include <overlay.h>
30#include <fb_priv.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();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800103
104 if(ctx->mCopyBit[i])
105 ctx->mCopyBit[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700106 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 VideoOverlay::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700108}
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
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700124static int hwc_prepare_primary(hwc_composer_device_1 *dev,
125 hwc_display_contents_1_t *list) {
126 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800127 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700128 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800129 ctx->dpyAttr[dpy].isActive) {
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700130
Saurabh Shah86623d72012-09-25 19:39:17 -0700131 uint32_t last = list->numHwLayers - 1;
Saurabh Shah1a8cda02012-10-12 17:00:39 -0700132 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
133 if(fbLayer->handle) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800134 setListStats(ctx, list, dpy);
135 reset_layer_prop(ctx, dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800136 int ret = ctx->mMDPComp->prepare(ctx, list);
137 if(!ret) {
138 // IF MDPcomp fails use this route
Saurabh Shahcf053c62012-12-13 12:32:55 -0800139 VideoOverlay::prepare(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500140 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500141 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800142 ctx->mLayerCache[dpy]->updateLayerCache(list);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800143 // Use Copybit, when MDP comp fails
144 if(!ret && ctx->mCopyBit[dpy])
145 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700146 }
147 }
148 return 0;
149}
150
151static int hwc_prepare_external(hwc_composer_device_1 *dev,
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800152 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700153 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700154
Saurabh Shahae823e72012-10-05 00:08:11 -0400155 if (LIKELY(list && list->numHwLayers > 1) &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800156 ctx->dpyAttr[dpy].isActive &&
157 ctx->dpyAttr[dpy].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700158 uint32_t last = list->numHwLayers - 1;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800159 if(!ctx->dpyAttr[dpy].isPause) {
160 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
161 if(fbLayer->handle) {
162 setListStats(ctx, list, dpy);
163 reset_layer_prop(ctx, dpy);
164 VideoOverlay::prepare(ctx, list, dpy);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500165 ctx->mFBUpdate[dpy]->prepare(ctx, list);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800166 ctx->mLayerCache[dpy]->updateLayerCache(list);
167 if(ctx->mCopyBit[dpy])
168 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
169 ctx->mExtDispConfiguring = false;
170 }
171 } else {
172 // External Display is in Pause state.
173 // ToDo:
174 // Mark all application layers as OVERLAY so that
175 // GPU will not compose. This is done for power
176 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700177 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700178 }
179 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700180}
181
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700182static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
183 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700185 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500187 Locker::Autolock _l(ctx->mBlankLock);
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400188 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700189
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500190 ctx->mOverlay->configBegin();
Saurabh Shah56f610d2012-08-07 15:27:06 -0700191
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800192 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500193 hwc_display_contents_1_t *list = displays[i];
194 switch(i) {
195 case HWC_DISPLAY_PRIMARY:
196 ret = hwc_prepare_primary(dev, list);
197 break;
198 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800199 case HWC_DISPLAY_VIRTUAL:
200 ret = hwc_prepare_external(dev, list, i);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500201 break;
202 default:
203 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700204 }
205 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206
Saurabh Shahcf053c62012-12-13 12:32:55 -0800207 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700208 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209}
210
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700211static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700212 int event, int enabled)
213{
214 int ret = 0;
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400215
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700216 hwc_context_t* ctx = (hwc_context_t*)(dev);
217 private_module_t* m = reinterpret_cast<private_module_t*>(
218 ctx->mFbDev->common.module);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700219 pthread_mutex_lock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700220 switch(event) {
221 case HWC_EVENT_VSYNC:
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700222 if (ctx->vstate.enable == enabled)
223 break;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700224 ctx->vstate.enable = !!enabled;
Naseer Ahmedc7faa702012-10-04 15:10:30 -0400225 pthread_cond_signal(&ctx->vstate.cond);
Iliyan Malcheveac89652012-10-04 10:38:28 -0700226 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
227 (enabled)?"ENABLED":"DISABLED");
228 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700229 default:
230 ret = -EINVAL;
231 }
Iliyan Malcheveac89652012-10-04 10:38:28 -0700232 pthread_mutex_unlock(&ctx->vstate.lock);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700233 return ret;
234}
235
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700236static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
237{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500238 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700239 hwc_context_t* ctx = (hwc_context_t*)(dev);
240 private_module_t* m = reinterpret_cast<private_module_t*>(
241 ctx->mFbDev->common.module);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500242 Locker::Autolock _l(ctx->mBlankLock);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700243 int ret = 0;
244 ALOGD("%s: Doing Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
245 switch(dpy) {
246 case HWC_DISPLAY_PRIMARY:
247 if(blank) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500248 ctx->mOverlay->configBegin();
249 ctx->mOverlay->configDone();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700250 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
251 } else {
252 ret = ioctl(m->framebuffer->fd, FBIOBLANK, FB_BLANK_UNBLANK);
253 }
254 break;
255 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800256 case HWC_DISPLAY_VIRTUAL:
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700257 if(blank) {
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800258 // External/Virtual Display post commits the changes to display
Arun Kumar K.Rba9eed52013-01-04 00:51:29 -0800259 // Call this on blank, so that any pipe unsets gets committed
260 if (!ctx->mExtDisplay->post()) {
261 ret = -1;
262 ALOGE("%s:ctx->mExtDisplay->post fail!! ", __FUNCTION__);
263 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700264 } else {
265 }
266 break;
267 default:
268 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700269 }
Arun Kumar K.Rf6f49a12012-11-27 11:46:50 -0800270 // Enable HPD here, as during bootup unblank is called
271 // when SF is completely initialized
272 ctx->mExtDisplay->setHPD(1);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700273
274 if(ret < 0) {
275 ALOGE("%s: failed. Dpy=%d, blank=%d : %s",
276 __FUNCTION__, dpy, blank, strerror(errno));
277 return ret;
278 }
279 ALOGD("%s: Done Dpy=%d, blank=%d", __FUNCTION__, dpy, blank);
280 ctx->dpyAttr[dpy].isActive = !blank;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700281 return 0;
282}
283
284static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700285 int param, int* value)
286{
287 hwc_context_t* ctx = (hwc_context_t*)(dev);
288 private_module_t* m = reinterpret_cast<private_module_t*>(
289 ctx->mFbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700290 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700291
292 switch (param) {
293 case HWC_BACKGROUND_LAYER_SUPPORTED:
294 // Not supported for now
295 value[0] = 0;
296 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700297 case HWC_VSYNC_PERIOD: //Not used for hwc > 1.1
Saurabh Shah2e2798c2012-08-30 14:47:10 -0700298 value[0] = m->fps;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700299 ALOGI("fps: %d", value[0]);
300 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700301 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700302 if(ctx->mMDP.hasOverlay)
303 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700304 value[0] = supported;
305 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700306 default:
307 return -EINVAL;
308 }
309 return 0;
310
311}
312
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700313static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500314 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700315 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800316 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700317
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800318 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700319 uint32_t last = list->numHwLayers - 1;
320 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800321 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500322 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800323 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500324 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800325 if(list->numHwLayers > 1)
326 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800327 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700328 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
329 ret = -1;
330 }
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800331 if (!ctx->mMDPComp->draw(ctx, list)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500332 ALOGE("%s: MDPComp::draw fail!", __FUNCTION__);
333 ret = -1;
334 }
335
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700336 //TODO We dont check for SKIP flag on this layer because we need PAN
337 //always. Last layer is always FB
Naseer Ahmed64b81212013-02-14 10:29:47 -0500338 private_handle_t *hnd = NULL;
339 if(copybitDone) {
340 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
341 } else {
342 hnd = (private_handle_t *)fbLayer->handle;
343 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500344 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET && hnd) {
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800345 if(!(fbLayer->flags & HWC_SKIP_LAYER) &&
346 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500347 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500348 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
349 ret = -1;
350 }
351 }
Saurabh Shah43333302013-02-06 13:30:27 -0800352 }
353 if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
354 ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800355 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700356 }
357 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800358
359 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700360 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700361}
362
363static int hwc_set_external(hwc_context_t *ctx,
Naseer Ahmed64b81212013-02-14 10:29:47 -0500364 hwc_display_contents_1_t* list, int dpy)
365{
366 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700367 int ret = 0;
Kinjal Bhavsarf83d4482012-10-10 15:56:21 -0700368 Locker::Autolock _l(ctx->mExtSetLock);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700369
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800370 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800371 !ctx->dpyAttr[dpy].isPause &&
Saurabh Shahcf053c62012-12-13 12:32:55 -0800372 ctx->dpyAttr[dpy].connected) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700373 uint32_t last = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700374 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800375 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500376 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800377 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500378 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700379
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800380 if(list->numHwLayers > 1)
381 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700382
Saurabh Shahcf053c62012-12-13 12:32:55 -0800383 if (!VideoOverlay::draw(ctx, list, dpy)) {
Saurabh Shaheaf67912012-10-10 17:33:14 -0700384 ALOGE("%s: VideoOverlay::draw fail!", __FUNCTION__);
385 ret = -1;
386 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700387
Naseer Ahmed64b81212013-02-14 10:29:47 -0500388 private_handle_t *hnd = NULL;
389 if(copybitDone) {
390 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
391 } else {
392 hnd = (private_handle_t *)fbLayer->handle;
393 }
394
Saurabh Shah150806a2012-10-09 15:38:23 -0700395 if(fbLayer->compositionType == HWC_FRAMEBUFFER_TARGET &&
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800396 !(fbLayer->flags & HWC_SKIP_LAYER) && hnd &&
397 (list->numHwLayers > 1)) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500398 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500399 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700400 ret = -1;
401 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700402 }
Saurabh Shaheaf67912012-10-10 17:33:14 -0700403 if (!ctx->mExtDisplay->post()) {
404 ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
Saurabh Shah747af1e2013-02-26 10:25:12 -0800405 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700406 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700407 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800408
409 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700410 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700411}
412
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700413static int hwc_set(hwc_composer_device_1 *dev,
414 size_t numDisplays,
415 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700416{
417 int ret = 0;
418 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed32ff2252012-09-29 01:41:21 -0400419 Locker::Autolock _l(ctx->mBlankLock);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800420 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700421 hwc_display_contents_1_t* list = displays[i];
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700422 switch(i) {
423 case HWC_DISPLAY_PRIMARY:
424 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700425 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700426 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800427 case HWC_DISPLAY_VIRTUAL:
428 /* ToDo: We are using hwc_set_external path for both External and
429 Virtual displays on HWC1.1. Eventually, we will have
430 separate functions when we move to HWC1.2
431 */
432 ret = hwc_set_external(ctx, list, i);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700433 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700434 default:
435 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700436 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700437 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438 return ret;
439}
440
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700441int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
442 uint32_t* configs, size_t* numConfigs) {
443 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700444 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700445 //in 1.1 there is no way to choose a config, report as config id # 0
446 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700447 switch(disp) {
448 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700449 if(*numConfigs > 0) {
450 configs[0] = 0;
451 *numConfigs = 1;
452 }
453 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700454 break;
455 case HWC_DISPLAY_EXTERNAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700456 ret = -1; //Not connected
457 if(ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
458 ret = 0; //NO_ERROR
459 if(*numConfigs > 0) {
460 configs[0] = 0;
461 *numConfigs = 1;
462 }
463 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700464 break;
465 }
466 return ret;
467}
468
469int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
470 uint32_t config, const uint32_t* attributes, int32_t* values) {
471
472 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700473 //If hotpluggable displays are inactive return error
474 if(disp == HWC_DISPLAY_EXTERNAL && !ctx->dpyAttr[disp].connected) {
475 return -1;
476 }
477
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700478 //From HWComposer
479 static const uint32_t DISPLAY_ATTRIBUTES[] = {
480 HWC_DISPLAY_VSYNC_PERIOD,
481 HWC_DISPLAY_WIDTH,
482 HWC_DISPLAY_HEIGHT,
483 HWC_DISPLAY_DPI_X,
484 HWC_DISPLAY_DPI_Y,
485 HWC_DISPLAY_NO_ATTRIBUTE,
486 };
487
488 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
489 sizeof(DISPLAY_ATTRIBUTES)[0]);
490
491 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
492 switch (attributes[i]) {
493 case HWC_DISPLAY_VSYNC_PERIOD:
494 values[i] = ctx->dpyAttr[disp].vsync_period;
495 break;
496 case HWC_DISPLAY_WIDTH:
497 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700498 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
499 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700500 break;
501 case HWC_DISPLAY_HEIGHT:
502 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700503 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
504 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700505 break;
506 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400507 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700508 break;
509 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400510 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700511 break;
512 default:
513 ALOGE("Unknown display attribute %d",
514 attributes[i]);
515 return -EINVAL;
516 }
517 }
518 return 0;
519}
520
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500521void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
522{
523 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800524 android::String8 aBuf("");
525 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
526 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
527 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
528 ctx->mMDPComp->dump(aBuf);
529 char ovDump[2048] = {'\0'};
530 ctx->mOverlay->getDump(ovDump, 2048);
531 dumpsys_log(aBuf, ovDump);
532 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500533}
534
Naseer Ahmed29a26812012-06-14 00:56:20 -0700535static int hwc_device_close(struct hw_device_t *dev)
536{
537 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700538 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700539 return -1;
540 }
541 closeContext((hwc_context_t*)dev);
542 free(dev);
543
544 return 0;
545}
546
547static int hwc_device_open(const struct hw_module_t* module, const char* name,
548 struct hw_device_t** device)
549{
550 int status = -EINVAL;
551
552 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
553 struct hwc_context_t *dev;
554 dev = (hwc_context_t*)malloc(sizeof(*dev));
555 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700556
557 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700559
560 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700561 dev->device.common.tag = HARDWARE_DEVICE_TAG;
562 dev->device.common.version = HWC_DEVICE_API_VERSION_1_1;
563 dev->device.common.module = const_cast<hw_module_t*>(module);
564 dev->device.common.close = hwc_device_close;
565 dev->device.prepare = hwc_prepare;
566 dev->device.set = hwc_set;
567 dev->device.eventControl = hwc_eventControl;
568 dev->device.blank = hwc_blank;
569 dev->device.query = hwc_query;
570 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500571 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700572 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
573 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
574 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700575 status = 0;
576 }
577 return status;
578}