blob: 02b9317bcf595d01cf5794b1cb91b004354aeb08 [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 Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
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>
Saurabh Shahc8118ac2013-06-27 10:03:19 -070031#include <overlayWriteback.h>
Naseer Ahmed96c4c952012-07-25 18:27:14 -070032#include <mdp_version.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.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"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070036#include "hwc_dump_layers.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070037#include "external.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070039#include "hwc_ad.h"
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -040040#include "profiler.h"
Naseer Ahmed58780b92013-07-29 17:41:40 -040041#include "hwc_vpuclient.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070042
43using namespace qhwc;
Saurabh Shah85234ec2013-04-12 17:09:00 -070044using namespace overlay;
45
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046#define VSYNC_DEBUG 0
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -070047#define BLANK_DEBUG 1
Naseer Ahmed29a26812012-06-14 00:56:20 -070048
49static int hwc_device_open(const struct hw_module_t* module,
50 const char* name,
51 struct hw_device_t** device);
52
53static struct hw_module_methods_t hwc_module_methods = {
54 open: hwc_device_open
55};
56
Veera Sankaran0dadfb32013-07-22 16:07:48 -070057static void reset_panel(struct hwc_composer_device_1* dev);
58
Naseer Ahmed29a26812012-06-14 00:56:20 -070059hwc_module_t HAL_MODULE_INFO_SYM = {
60 common: {
61 tag: HARDWARE_MODULE_TAG,
62 version_major: 2,
63 version_minor: 0,
64 id: HWC_HARDWARE_MODULE_ID,
65 name: "Qualcomm Hardware Composer Module",
66 author: "CodeAurora Forum",
67 methods: &hwc_module_methods,
68 dso: 0,
69 reserved: {0},
70 }
71};
72
Raj Kamal2464cce2013-09-06 16:20:12 +053073/* In case of non-hybrid WFD session, we are fooling SF by piggybacking on
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070074 * HDMI display ID for virtual. This helper is needed to differentiate their
75 * paths in HAL.
76 * TODO: Not needed once we have WFD client working on top of Google API's */
77
Raj Kamal2464cce2013-09-06 16:20:12 +053078static int getDpyforExternalDisplay(hwc_context_t *ctx, int dpy) {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070079 if(dpy == HWC_DISPLAY_EXTERNAL && ctx->mVirtualonExtActive)
80 return HWC_DISPLAY_VIRTUAL;
81 return dpy;
82}
83
Naseer Ahmed29a26812012-06-14 00:56:20 -070084/*
85 * Save callback functions registered to HWC
86 */
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070087static void hwc_registerProcs(struct hwc_composer_device_1* dev,
Naseer Ahmed29a26812012-06-14 00:56:20 -070088 hwc_procs_t const* procs)
89{
Iliyan Malchev0f9c3972012-10-11 15:16:15 -070090 ALOGI("%s", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 hwc_context_t* ctx = (hwc_context_t*)(dev);
92 if(!ctx) {
93 ALOGE("%s: Invalid context", __FUNCTION__);
94 return;
95 }
Jesse Hall3be78d92012-08-21 15:12:23 -070096 ctx->proc = procs;
97
Naseer Ahmedff4f0252012-10-01 13:03:01 -040098 // Now that we have the functions needed, kick off
99 // the uevent & vsync threads
Jesse Hall3be78d92012-08-21 15:12:23 -0700100 init_uevent_thread(ctx);
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400101 init_vsync_thread(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102}
103
Saurabh Shah649cda62012-09-16 16:05:58 -0700104//Helper
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400105static void reset(hwc_context_t *ctx, int numDisplays,
106 hwc_display_contents_1_t** displays) {
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700107 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400108 hwc_display_contents_1_t *list = displays[i];
109 // XXX:SurfaceFlinger no longer guarantees that this
110 // value is reset on every prepare. However, for the layer
111 // cache we need to reset it.
112 // We can probably rethink that later on
113 if (LIKELY(list && list->numHwLayers > 1)) {
114 for(uint32_t j = 0; j < list->numHwLayers; j++) {
115 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
116 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
117 }
118 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800119
120 if(ctx->mFBUpdate[i])
121 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800122 if(ctx->mCopyBit[i])
123 ctx->mCopyBit[i]->reset();
Amara Venkata Mastan Manoj Kumar310d04f2013-08-13 12:42:34 -0700124 if(ctx->mLayerRotMap[i])
125 ctx->mLayerRotMap[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700126 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700127
128 ctx->mAD->reset();
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700129 MDPComp::reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700130}
131
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500132//clear prev layer prop flags and realloc for current frame
Saurabh Shah2b033392013-03-22 11:29:44 -0700133static void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500134 if(ctx->layerProp[dpy]) {
135 delete[] ctx->layerProp[dpy];
136 ctx->layerProp[dpy] = NULL;
137 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700138 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500139}
140
Saurabh Shah784e9852013-08-21 16:51:21 -0700141static void handleGeomChange(hwc_context_t *ctx, int dpy,
142 hwc_display_contents_1_t *list) {
Terence Hampson65fe4522013-10-17 17:40:03 -0400143 /* No point to calling overlay_set on MDP3 */
144 if(list->flags & HWC_GEOMETRY_CHANGED &&
145 ctx->mMDP.version >= qdutils::MDP_V4_0) {
Saurabh Shah784e9852013-08-21 16:51:21 -0700146 ctx->mOverlay->forceSet(dpy);
147 }
148}
149
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700150static int hwc_prepare_primary(hwc_composer_device_1 *dev,
151 hwc_display_contents_1_t *list) {
Naseer Ahmed099a6932013-09-09 14:25:20 -0400152 ATRACE_CALL();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700153 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800154 const int dpy = HWC_DISPLAY_PRIMARY;
Saurabh Shah2b033392013-03-22 11:29:44 -0700155 if (LIKELY(list && list->numHwLayers > 1) &&
156 ctx->dpyAttr[dpy].isActive) {
157 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah784e9852013-08-21 16:51:21 -0700158 handleGeomChange(ctx, dpy, list);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700159 setListStats(ctx, list, dpy);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400160#ifdef VPU_TARGET
Saurabh Shah220a30c2013-10-29 16:12:12 -0700161 ctx->mVPUClient->prepare(ctx, list);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400162#endif
Saurabh Shah220a30c2013-10-29 16:12:12 -0700163 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
164 const int fbZ = 0;
165 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
166 }
167 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
168 if(ctx->mCopyBit[dpy])
169 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700170 }
171 }
172 return 0;
173}
174
175static int hwc_prepare_external(hwc_composer_device_1 *dev,
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700176 hwc_display_contents_1_t *list) {
Naseer Ahmed099a6932013-09-09 14:25:20 -0400177 ATRACE_CALL();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700178 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700179 const int dpy = HWC_DISPLAY_EXTERNAL;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700180
Saurabh Shah2b033392013-03-22 11:29:44 -0700181 if (LIKELY(list && list->numHwLayers > 1) &&
182 ctx->dpyAttr[dpy].isActive &&
183 ctx->dpyAttr[dpy].connected) {
184 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah784e9852013-08-21 16:51:21 -0700185 handleGeomChange(ctx, dpy, list);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800186 if(!ctx->dpyAttr[dpy].isPause) {
Saurabh Shah220a30c2013-10-29 16:12:12 -0700187 ctx->dpyAttr[dpy].isConfiguring = false;
188 setListStats(ctx, list, dpy);
189 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
190 const int fbZ = 0;
191 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
192 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193
Saurabh Shah220a30c2013-10-29 16:12:12 -0700194 if(ctx->listStats[dpy].isDisplayAnimating) {
195 // Mark all app layers as HWC_OVERLAY for external during
196 // animation, so that SF doesnt draw it on FB
197 for(int i = 0 ;i < ctx->listStats[dpy].numAppLayers; i++) {
198 hwc_layer_1_t *layer = &list->hwLayers[i];
199 layer->compositionType = HWC_OVERLAY;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700200 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800201 }
202 } else {
203 // External Display is in Pause state.
204 // ToDo:
205 // Mark all application layers as OVERLAY so that
206 // GPU will not compose. This is done for power
207 // optimization
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700208 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700209 }
210 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700211}
212
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700213static int hwc_prepare_virtual(hwc_composer_device_1 *dev,
214 hwc_display_contents_1_t *list) {
Naseer Ahmed099a6932013-09-09 14:25:20 -0400215 ATRACE_CALL();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700216
217 hwc_context_t* ctx = (hwc_context_t*)(dev);
218 const int dpy = HWC_DISPLAY_VIRTUAL;
219
220 if (LIKELY(list && list->numHwLayers > 1) &&
221 ctx->dpyAttr[dpy].isActive &&
222 ctx->dpyAttr[dpy].connected) {
223 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah784e9852013-08-21 16:51:21 -0700224 handleGeomChange(ctx, dpy, list);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700225 if(!ctx->dpyAttr[dpy].isPause) {
Saurabh Shah220a30c2013-10-29 16:12:12 -0700226 ctx->dpyAttr[dpy].isConfiguring = false;
227 setListStats(ctx, list, dpy);
228 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
229 const int fbZ = 0;
230 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
231 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700232
Saurabh Shah220a30c2013-10-29 16:12:12 -0700233 if(ctx->listStats[dpy].isDisplayAnimating) {
234 // Mark all app layers as HWC_OVERLAY for virtual during
235 // animation, so that SF doesnt draw it on FB
236 for(int i = 0 ;i < ctx->listStats[dpy].numAppLayers; i++) {
237 hwc_layer_1_t *layer = &list->hwLayers[i];
238 layer->compositionType = HWC_OVERLAY;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700239 }
240 }
241 } else {
242 // Virtual Display is in Pause state.
243 // ToDo:
244 // Mark all application layers as OVERLAY so that
245 // GPU will not compose. This is done for power
246 // optimization
247 }
248 }
249 return 0;
250}
251
252
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700253static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
254 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700255{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700256 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257 hwc_context_t* ctx = (hwc_context_t*)(dev);
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700258
259 if (ctx->mPanelResetStatus) {
260 ALOGW("%s: panel is in bad state. reset the panel", __FUNCTION__);
261 reset_panel(dev);
262 }
263
Saurabh Shah188e4332013-07-18 10:33:22 -0700264 //Will be unlocked at the end of set
Saurabh Shahb39f8152013-08-22 10:21:44 -0700265 ctx->mDrawLock.lock();
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400266 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700267
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500268 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800269 ctx->mRotMgr->configBegin();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700270 overlay::Writeback::configBegin();
271
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800272 for (int32_t i = numDisplays; i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500273 hwc_display_contents_1_t *list = displays[i];
Raj Kamal2464cce2013-09-06 16:20:12 +0530274 int dpy = getDpyforExternalDisplay(ctx, i);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700275 switch(dpy) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500276 case HWC_DISPLAY_PRIMARY:
277 ret = hwc_prepare_primary(dev, list);
278 break;
279 case HWC_DISPLAY_EXTERNAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700280 ret = hwc_prepare_external(dev, list);
281 break;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800282 case HWC_DISPLAY_VIRTUAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700283 ret = hwc_prepare_virtual(dev, list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500284 break;
285 default:
286 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700287 }
288 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500289
Saurabh Shahcf053c62012-12-13 12:32:55 -0800290 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800291 ctx->mRotMgr->configDone();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700292 overlay::Writeback::configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800293
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700294 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295}
296
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700297static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500298 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700299{
Naseer Ahmed099a6932013-09-09 14:25:20 -0400300 ATRACE_CALL();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700301 int ret = 0;
302 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700303 switch(event) {
304 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500305 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700306 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500307 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400308 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500309 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700310 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500311 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700312 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400313#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700314 case HWC_EVENT_ORIENTATION:
315 if(dpy == HWC_DISPLAY_PRIMARY) {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700316 Locker::Autolock _l(ctx->mDrawLock);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700317 // store the primary display orientation
318 // will be used in hwc_video::configure to disable
319 // rotation animation on external display
320 ctx->deviceOrientation = enable;
321 }
322 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400323#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700324 default:
325 ret = -EINVAL;
326 }
327 return ret;
328}
329
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700330static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
331{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500332 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700333 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800334
Saurabh Shahb39f8152013-08-22 10:21:44 -0700335 Locker::Autolock _l(ctx->mDrawLock);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700336 int ret = 0, value = 0;
Raj Kamal2464cce2013-09-06 16:20:12 +0530337
338 /* In case of non-hybrid WFD session, we are fooling SF by
339 * piggybacking on HDMI display ID for virtual.
340 * TODO: Not needed once we have WFD client working on top
341 * of Google API's.
342 */
343 dpy = getDpyforExternalDisplay(ctx,dpy);
344
Naseer Ahmede0205b62013-04-04 13:24:39 -0400345 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500346 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700347 if(blank) {
348 // free up all the overlay pipes in use
349 // when we get a blank for either display
350 // makes sure that all pipes are freed
351 ctx->mOverlay->configBegin();
352 ctx->mOverlay->configDone();
353 ctx->mRotMgr->clear();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700354 overlay::Writeback::clear();
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700355 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700356 switch(dpy) {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700357 case HWC_DISPLAY_PRIMARY:
358 value = blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK;
359 if(ioctl(ctx->dpyAttr[dpy].fd, FBIOBLANK, value) < 0 ) {
360 ALOGE("%s: Failed to handle blank event(%d) for Primary!!",
361 __FUNCTION__, blank );
362 return -1;
363 }
Ramkumar Radhakrishnan893d6ee2013-02-26 10:48:05 -0800364
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700365 if(!blank) {
366 // Enable HPD here, as during bootup unblank is called
367 // when SF is completely initialized
368 ctx->mExtDisplay->setHPD(1);
369 }
370
Raj Kamal2464cce2013-09-06 16:20:12 +0530371 ctx->dpyAttr[dpy].isActive = !blank;
372
373 if(ctx->mVirtualonExtActive) {
374 /* if mVirtualonExtActive is true, display hal will
375 * receive unblank calls for non-hybrid WFD solution
376 * since we piggyback on HDMI.
377 * TODO: Not needed once we have WFD client working on top
378 of Google API's */
379 break;
380 }
381 case HWC_DISPLAY_VIRTUAL:
382 /* There are two ways to reach this block of code.
383
384 * Display hal has received unblank call on HWC_DISPLAY_EXTERNAL
385 and ctx->mVirtualonExtActive is true. In this case, non-hybrid
386 WFD is active. If so, getDpyforExternalDisplay will return dpy
387 as HWC_DISPLAY_VIRTUAL.
388
389 * Display hal has received unblank call on HWC_DISPLAY_PRIMARY
390 and since SF is not aware of VIRTUAL DISPLAY being handle by HWC,
391 it wont send blank / unblank events for it. We piggyback on
392 PRIMARY DISPLAY events to release mdp pipes and
393 activate/deactivate VIRTUAL DISPLAY.
394
395 * TODO: This separate case statement is not needed once we have
396 WFD client working on top of Google API's.
397
398 */
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700399
400 if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected) {
Raj Kamal2464cce2013-09-06 16:20:12 +0530401 if(blank and (!ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause)) {
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700402 int dpy = HWC_DISPLAY_VIRTUAL;
403 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
404 ALOGE("%s: display commit fail for virtual!", __FUNCTION__);
405 ret = -1;
406 }
407 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700408 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = !blank;
409 }
410 break;
411 case HWC_DISPLAY_EXTERNAL:
412 if(blank) {
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700413 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
414 ALOGE("%s: display commit fail for external!", __FUNCTION__);
415 ret = -1;
416 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700417 }
Raj Kamal2464cce2013-09-06 16:20:12 +0530418 ctx->dpyAttr[dpy].isActive = !blank;
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700419 break;
420 default:
421 return -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700422 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700423
Naseer Ahmede0205b62013-04-04 13:24:39 -0400424 ALOGD_IF(BLANK_DEBUG, "%s: Done %s display: %d", __FUNCTION__,
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700425 blank ? "blanking":"unblanking", dpy);
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700426 return ret;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700427}
428
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700429static void reset_panel(struct hwc_composer_device_1* dev)
430{
431 int ret = 0;
432 hwc_context_t* ctx = (hwc_context_t*)(dev);
433
434 if (!ctx->mPanelResetStatus)
435 return;
436
437 ALOGD("%s: calling BLANK DISPLAY", __FUNCTION__);
438 ret = hwc_blank(dev, HWC_DISPLAY_PRIMARY, 1);
439 if (ret < 0) {
440 ALOGE("%s: FBIOBLANK failed to BLANK: %s", __FUNCTION__,
441 strerror(errno));
442 }
443
444 ALOGD("%s: calling UNBLANK DISPLAY and enabling vsync", __FUNCTION__);
445 ret = hwc_blank(dev, HWC_DISPLAY_PRIMARY, 0);
446 if (ret < 0) {
447 ALOGE("%s: FBIOBLANK failed to UNBLANK : %s", __FUNCTION__,
448 strerror(errno));
449 }
450 hwc_vsync_control(ctx, HWC_DISPLAY_PRIMARY, 1);
451
452 ctx->mPanelResetStatus = false;
453}
454
455
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700456static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700457 int param, int* value)
458{
459 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700460 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700461
462 switch (param) {
463 case HWC_BACKGROUND_LAYER_SUPPORTED:
464 // Not supported for now
465 value[0] = 0;
466 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700467 case HWC_DISPLAY_TYPES_SUPPORTED:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700468 if(ctx->mMDP.hasOverlay)
469 supported |= HWC_DISPLAY_EXTERNAL_BIT;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470 value[0] = supported;
471 break;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700472 case HWC_FORMAT_RB_SWAP:
473 value[0] = 1;
474 break;
Sushil Chauhan943797c2013-10-21 17:35:55 -0700475 case HWC_COLOR_FILL:
476 value[0] = 1;
477 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700478 default:
479 return -EINVAL;
480 }
481 return 0;
482
483}
484
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800485
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700486static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500487 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700488 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800489 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800490 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700491 uint32_t last = list->numHwLayers - 1;
492 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800493 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500494 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800495 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500496 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800497 if(list->numHwLayers > 1)
498 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800499
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700500 // Dump the layers for primary
501 if(ctx->mHwcDebug[dpy])
502 ctx->mHwcDebug[dpy]->dumpLayers(list);
503
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800504 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800505 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500506 ret = -1;
507 }
Naseer Ahmed58780b92013-07-29 17:41:40 -0400508#ifdef VPU_TARGET
509 ctx->mVPUClient->draw(ctx, list);
510#endif
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500511
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700512 //TODO We dont check for SKIP flag on this layer because we need PAN
513 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700514 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500515 if(copybitDone) {
516 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500517 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700518
519 if(hnd) {
520 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
521 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
522 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500523 }
Saurabh Shah43333302013-02-06 13:30:27 -0800524 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800525
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700526 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd,
527 ctx->listStats[dpy].roi)) {
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700528 ALOGE("%s: display commit fail for %d dpy!", __FUNCTION__, dpy);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700529 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700530 }
531 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800532
533 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700534 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700535}
536
537static int hwc_set_external(hwc_context_t *ctx,
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700538 hwc_display_contents_1_t* list)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500539{
540 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700541 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700542
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700543 const int dpy = HWC_DISPLAY_EXTERNAL;
544
545
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800546 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700547 ctx->dpyAttr[dpy].connected &&
548 !ctx->dpyAttr[dpy].isPause) {
549 uint32_t last = list->numHwLayers - 1;
550 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
551 int fd = -1; //FenceFD from the Copybit(valid in async mode)
552 bool copybitDone = false;
553 if(ctx->mCopyBit[dpy])
554 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700555
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700556 if(list->numHwLayers > 1)
557 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700558
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700559 // Dump the layers for external
560 if(ctx->mHwcDebug[dpy])
561 ctx->mHwcDebug[dpy]->dumpLayers(list);
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700562
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700563 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
564 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
565 ret = -1;
566 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700567
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700568 int extOnlyLayerIndex =
569 ctx->listStats[dpy].extOnlyLayerIndex;
570
571 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
572 if(extOnlyLayerIndex!= -1) {
573 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
574 hnd = (private_handle_t *)extLayer->handle;
575 } else if(copybitDone) {
576 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
577 }
578
579 if(hnd && !isYuvBuffer(hnd)) {
580 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
581 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700582 ret = -1;
583 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700584 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800585
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700586 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
587 ALOGE("%s: display commit fail for %d dpy!", __FUNCTION__, dpy);
Saurabh Shah2b033392013-03-22 11:29:44 -0700588 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700589 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700590 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800591
592 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700593 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700594}
595
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700596static int hwc_set_virtual(hwc_context_t *ctx,
597 hwc_display_contents_1_t* list)
598{
599 ATRACE_CALL();
600 int ret = 0;
Dileep Kumar Reddi90a8d722013-09-04 16:35:12 +0530601
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700602 const int dpy = HWC_DISPLAY_VIRTUAL;
603
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700604
Dileep Kumar Reddi90a8d722013-09-04 16:35:12 +0530605 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
606 ctx->dpyAttr[dpy].connected &&
607 !ctx->dpyAttr[dpy].isPause) {
608 uint32_t last = list->numHwLayers - 1;
609 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
610 int fd = -1; //FenceFD from the Copybit(valid in async mode)
611 bool copybitDone = false;
612 if(ctx->mCopyBit[dpy])
613 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
614
615 if(list->numHwLayers > 1)
616 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700617
618 // Dump the layers for virtual
619 if(ctx->mHwcDebug[dpy])
620 ctx->mHwcDebug[dpy]->dumpLayers(list);
621
Dileep Kumar Reddi90a8d722013-09-04 16:35:12 +0530622 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
623 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
624 ret = -1;
625 }
626
627 int extOnlyLayerIndex =
628 ctx->listStats[dpy].extOnlyLayerIndex;
629
630 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
631 if(extOnlyLayerIndex!= -1) {
632 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
633 hnd = (private_handle_t *)extLayer->handle;
634 } else if(copybitDone) {
635 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
636 }
637
638 if(hnd && !isYuvBuffer(hnd)) {
639 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
640 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700641 ret = -1;
642 }
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700643 }
644
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700645 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
646 ALOGE("%s: display commit fail for %d dpy!", __FUNCTION__, dpy);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700647 ret = -1;
648 }
649 }
650
651 closeAcquireFds(list);
652
Dileep Kumar Reddi52eab822013-08-27 20:33:07 +0530653 if (list && !ctx->mVirtualonExtActive && (list->retireFenceFd < 0) ) {
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700654 // SF assumes HWC waits for the acquire fence and returns a new fence
655 // that signals when we're done. Since we don't wait, and also don't
656 // touch the buffer, we can just handle the acquire fence back to SF
657 // as the retire fence.
658 list->retireFenceFd = list->outbufAcquireFenceFd;
659 }
660
661 return ret;
662}
663
664
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700665static int hwc_set(hwc_composer_device_1 *dev,
666 size_t numDisplays,
667 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700668{
669 int ret = 0;
670 hwc_context_t* ctx = (hwc_context_t*)(dev);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800671 for (uint32_t i = 0; i <= numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700672 hwc_display_contents_1_t* list = displays[i];
Raj Kamal2464cce2013-09-06 16:20:12 +0530673 int dpy = getDpyforExternalDisplay(ctx, i);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700674 switch(dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700675 case HWC_DISPLAY_PRIMARY:
676 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700677 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700678 case HWC_DISPLAY_EXTERNAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700679 ret = hwc_set_external(ctx, list);
680 break;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800681 case HWC_DISPLAY_VIRTUAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700682 ret = hwc_set_virtual(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700683 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700684 default:
685 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700686 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700687 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400688 // This is only indicative of how many times SurfaceFlinger posts
689 // frames to the display.
690 CALC_FPS();
Saurabh Shah2d998a92013-05-14 17:55:58 -0700691 MDPComp::resetIdleFallBack();
Saurabh Shahd4e65852013-06-17 11:33:53 -0700692 ctx->mVideoTransFlag = false;
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700693 if(ctx->mRotMgr->getNumActiveSessions() == 0)
694 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah188e4332013-07-18 10:33:22 -0700695 //Was locked at the beginning of prepare
Saurabh Shahb39f8152013-08-22 10:21:44 -0700696 ctx->mDrawLock.unlock();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700697 return ret;
698}
699
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700700int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
701 uint32_t* configs, size_t* numConfigs) {
702 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700703 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj Kamal2464cce2013-09-06 16:20:12 +0530704 disp = getDpyforExternalDisplay(ctx, disp);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700705 //in 1.1 there is no way to choose a config, report as config id # 0
706 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700707 switch(disp) {
708 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700709 if(*numConfigs > 0) {
710 configs[0] = 0;
711 *numConfigs = 1;
712 }
713 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700714 break;
715 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700716 case HWC_DISPLAY_VIRTUAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700717 ret = -1; //Not connected
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700718 if(ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700719 ret = 0; //NO_ERROR
720 if(*numConfigs > 0) {
721 configs[0] = 0;
722 *numConfigs = 1;
723 }
724 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700725 break;
726 }
727 return ret;
728}
729
730int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
731 uint32_t config, const uint32_t* attributes, int32_t* values) {
732
733 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj Kamal2464cce2013-09-06 16:20:12 +0530734 disp = getDpyforExternalDisplay(ctx, disp);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700735 //If hotpluggable displays(i.e, HDMI, WFD) are inactive return error
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700736 if( (disp != HWC_DISPLAY_PRIMARY) && !ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700737 return -1;
738 }
739
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700740 //From HWComposer
741 static const uint32_t DISPLAY_ATTRIBUTES[] = {
742 HWC_DISPLAY_VSYNC_PERIOD,
743 HWC_DISPLAY_WIDTH,
744 HWC_DISPLAY_HEIGHT,
745 HWC_DISPLAY_DPI_X,
746 HWC_DISPLAY_DPI_Y,
747 HWC_DISPLAY_NO_ATTRIBUTE,
748 };
749
750 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
751 sizeof(DISPLAY_ATTRIBUTES)[0]);
752
753 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
754 switch (attributes[i]) {
755 case HWC_DISPLAY_VSYNC_PERIOD:
756 values[i] = ctx->dpyAttr[disp].vsync_period;
757 break;
758 case HWC_DISPLAY_WIDTH:
759 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700760 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
761 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700762 break;
763 case HWC_DISPLAY_HEIGHT:
764 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700765 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
766 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700767 break;
768 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400769 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700770 break;
771 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400772 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700773 break;
774 default:
775 ALOGE("Unknown display attribute %d",
776 attributes[i]);
777 return -EINVAL;
778 }
779 }
780 return 0;
781}
782
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500783void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
784{
785 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700786 Locker::Autolock _l(ctx->mDrawLock);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800787 android::String8 aBuf("");
788 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
789 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
790 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700791 for(int dpy = 0; dpy < HWC_NUM_DISPLAY_TYPES; dpy++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800792 if(ctx->mMDPComp[dpy])
793 ctx->mMDPComp[dpy]->dump(aBuf);
794 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800795 char ovDump[2048] = {'\0'};
796 ctx->mOverlay->getDump(ovDump, 2048);
797 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800798 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700799 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800800 dumpsys_log(aBuf, ovDump);
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700801 ovDump[0] = '\0';
Saurabh Shah7c8d34f2013-10-30 15:52:29 -0700802 if(Writeback::getDump(ovDump, 1024)) {
803 dumpsys_log(aBuf, ovDump);
804 ovDump[0] = '\0';
805 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800806 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500807}
808
Naseer Ahmed29a26812012-06-14 00:56:20 -0700809static int hwc_device_close(struct hw_device_t *dev)
810{
811 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700812 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700813 return -1;
814 }
815 closeContext((hwc_context_t*)dev);
816 free(dev);
817
818 return 0;
819}
820
821static int hwc_device_open(const struct hw_module_t* module, const char* name,
822 struct hw_device_t** device)
823{
824 int status = -EINVAL;
825
826 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
827 struct hwc_context_t *dev;
828 dev = (hwc_context_t*)malloc(sizeof(*dev));
829 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700830
831 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700832 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700833
834 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700835 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700836 dev->device.common.version = HWC_DEVICE_API_VERSION_1_3;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700837 dev->device.common.module = const_cast<hw_module_t*>(module);
838 dev->device.common.close = hwc_device_close;
839 dev->device.prepare = hwc_prepare;
840 dev->device.set = hwc_set;
841 dev->device.eventControl = hwc_eventControl;
842 dev->device.blank = hwc_blank;
843 dev->device.query = hwc_query;
844 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500845 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700846 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
847 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
848 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700849 status = 0;
850 }
851 return status;
852}