blob: 893fee03274c1b5e9e4c831a99d556a276d64cb9 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +05303 * Copyright (C) 2012-2014, 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"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080041#include "hwc_virtual.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) {
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530107
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530108 ctx->numActiveDisplays = 0;
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530109 ctx->isPaddingRound = false;
110
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800111 for(int i = 0; i < numDisplays; i++) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400112 hwc_display_contents_1_t *list = displays[i];
113 // XXX:SurfaceFlinger no longer guarantees that this
114 // value is reset on every prepare. However, for the layer
115 // cache we need to reset it.
116 // We can probably rethink that later on
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530117 if (LIKELY(list && list->numHwLayers > 0)) {
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400118 for(uint32_t j = 0; j < list->numHwLayers; j++) {
119 if(list->hwLayers[j].compositionType != HWC_FRAMEBUFFER_TARGET)
120 list->hwLayers[j].compositionType = HWC_FRAMEBUFFER;
121 }
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530122
123 /* For display devices like SSD and screenrecord, we cannot
124 * rely on isActive and connected attributes of dpyAttr to
125 * determine if the displaydevice is active. Hence in case if
126 * the layer-list is non-null and numHwLayers > 0, we assume
127 * the display device to be active.
128 */
129 ctx->numActiveDisplays += 1;
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530130
131 if((ctx->mPrevHwLayerCount[i] == 1) and (list->numHwLayers > 1)) {
132 /* If the previous cycle for dpy 'i' has 0 AppLayers and the
133 * current cycle has atleast 1 AppLayer, padding round needs
134 * to be invoked on current cycle to free up the resources.
135 */
136 ctx->isPaddingRound = true;
137 }
138 ctx->mPrevHwLayerCount[i] = list->numHwLayers;
139 } else {
140 ctx->mPrevHwLayerCount[i] = 0;
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400141 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800142
143 if(ctx->mFBUpdate[i])
144 ctx->mFBUpdate[i]->reset();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800145 if(ctx->mCopyBit[i])
146 ctx->mCopyBit[i]->reset();
Amara Venkata Mastan Manoj Kumar310d04f2013-08-13 12:42:34 -0700147 if(ctx->mLayerRotMap[i])
148 ctx->mLayerRotMap[i]->reset();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700149 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700150
151 ctx->mAD->reset();
Saurabh Shah8c5c8522013-08-29 17:32:49 -0700152 MDPComp::reset();
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800153 if(ctx->mHWCVirtual)
154 ctx->mHWCVirtual->destroy(ctx, numDisplays, displays);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500155}
156
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530157bool isEqual(float f1, float f2) {
158 return ((int)(f1*100) == (int)(f2*100)) ? true : false;
159}
160
161static void scaleDisplayFrame(hwc_context_t *ctx, int dpy,
162 hwc_display_contents_1_t *list) {
163 float origXres = ctx->dpyAttr[dpy].xres_orig;
164 float origYres = ctx->dpyAttr[dpy].yres_orig;
165 float fakeXres = ctx->dpyAttr[dpy].xres;
166 float fakeYres = ctx->dpyAttr[dpy].yres;
167 float xresRatio = origXres / fakeXres;
168 float yresRatio = origYres / fakeYres;
169 for (size_t i = 0; i < list->numHwLayers; i++) {
170 hwc_layer_1_t *layer = &list->hwLayers[i];
171 hwc_rect_t& displayFrame = layer->displayFrame;
172 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
173 float layerWidth = displayFrame.right - displayFrame.left;
174 float layerHeight = displayFrame.bottom - displayFrame.top;
175 float sourceWidth = sourceCrop.right - sourceCrop.left;
176 float sourceHeight = sourceCrop.bottom - sourceCrop.top;
177
178 if (isEqual(layerWidth / sourceWidth, xresRatio) &&
179 isEqual(layerHeight / sourceHeight, yresRatio))
180 break;
181
182 displayFrame.left = xresRatio * displayFrame.left;
183 displayFrame.top = yresRatio * displayFrame.top;
184 displayFrame.right = displayFrame.left + layerWidth * xresRatio;
185 displayFrame.bottom = displayFrame.top + layerHeight * yresRatio;
186 }
187}
188
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700189static int hwc_prepare_primary(hwc_composer_device_1 *dev,
190 hwc_display_contents_1_t *list) {
Naseer Ahmed099a6932013-09-09 14:25:20 -0400191 ATRACE_CALL();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700192 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800193 const int dpy = HWC_DISPLAY_PRIMARY;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400194 bool fbComp = false;
Saurabh Shah2b033392013-03-22 11:29:44 -0700195 if (LIKELY(list && list->numHwLayers > 1) &&
196 ctx->dpyAttr[dpy].isActive) {
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530197
198 if (ctx->dpyAttr[dpy].customFBSize)
199 scaleDisplayFrame(ctx, dpy, list);
200
Saurabh Shah2b033392013-03-22 11:29:44 -0700201 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700202 setListStats(ctx, list, dpy);
Zohaib Alam1bb65612013-09-28 03:38:20 -0400203
Naseer Ahmed330a2822014-03-05 11:57:23 -0500204 fbComp = (ctx->mMDPComp[dpy]->prepare(ctx, list) < 0);
Zohaib Alam1bb65612013-09-28 03:38:20 -0400205
206 if (fbComp) {
Saurabh Shah220a30c2013-10-29 16:12:12 -0700207 const int fbZ = 0;
Saurabh Shaha36be922013-12-16 18:18:39 -0800208 ctx->mFBUpdate[dpy]->prepareAndValidate(ctx, list, fbZ);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700209 }
Zohaib Alam1bb65612013-09-28 03:38:20 -0400210
Saurabh Shah220a30c2013-10-29 16:12:12 -0700211 if (ctx->mMDP.version < qdutils::MDP_V4_0) {
212 if(ctx->mCopyBit[dpy])
213 ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700214 }
215 }
216 return 0;
217}
218
219static int hwc_prepare_external(hwc_composer_device_1 *dev,
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700220 hwc_display_contents_1_t *list) {
Naseer Ahmed099a6932013-09-09 14:25:20 -0400221 ATRACE_CALL();
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700222 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700223 const int dpy = HWC_DISPLAY_EXTERNAL;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700224
Saurabh Shah2b033392013-03-22 11:29:44 -0700225 if (LIKELY(list && list->numHwLayers > 1) &&
226 ctx->dpyAttr[dpy].isActive &&
227 ctx->dpyAttr[dpy].connected) {
228 reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800229 if(!ctx->dpyAttr[dpy].isPause) {
Saurabh Shah220a30c2013-10-29 16:12:12 -0700230 ctx->dpyAttr[dpy].isConfiguring = false;
231 setListStats(ctx, list, dpy);
232 if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
233 const int fbZ = 0;
Saurabh Shaha36be922013-12-16 18:18:39 -0800234 ctx->mFBUpdate[dpy]->prepareAndValidate(ctx, list, fbZ);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700235 }
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800236 } else {
Raj Kamaled5a13a2013-12-10 22:19:12 +0530237 /* External Display is in Pause state.
238 * Mark all application layers as OVERLAY so that
239 * GPU will not compose.
240 */
241 for(size_t i = 0 ;i < (size_t)(list->numHwLayers - 1); i++) {
242 hwc_layer_1_t *layer = &list->hwLayers[i];
243 layer->compositionType = HWC_OVERLAY;
244 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700245 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700246 }
247 return 0;
Saurabh Shah649cda62012-09-16 16:05:58 -0700248}
249
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700250static int hwc_prepare(hwc_composer_device_1 *dev, size_t numDisplays,
251 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252{
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700253 int ret = 0;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700254 hwc_context_t* ctx = (hwc_context_t*)(dev);
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700255
256 if (ctx->mPanelResetStatus) {
257 ALOGW("%s: panel is in bad state. reset the panel", __FUNCTION__);
258 reset_panel(dev);
259 }
260
Saurabh Shah188e4332013-07-18 10:33:22 -0700261 //Will be unlocked at the end of set
Saurabh Shahb39f8152013-08-22 10:21:44 -0700262 ctx->mDrawLock.lock();
Naseer Ahmedb1c76322012-10-17 00:32:50 -0400263 reset(ctx, numDisplays, displays);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700264
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500265 ctx->mOverlay->configBegin();
Saurabh Shahacf10202013-02-26 10:15:15 -0800266 ctx->mRotMgr->configBegin();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700267 overlay::Writeback::configBegin();
268
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530269 for (int32_t i = (numDisplays-1); i >= 0; i--) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500270 hwc_display_contents_1_t *list = displays[i];
Raj Kamal2464cce2013-09-06 16:20:12 +0530271 int dpy = getDpyforExternalDisplay(ctx, i);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700272 switch(dpy) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500273 case HWC_DISPLAY_PRIMARY:
274 ret = hwc_prepare_primary(dev, list);
275 break;
276 case HWC_DISPLAY_EXTERNAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700277 ret = hwc_prepare_external(dev, list);
278 break;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800279 case HWC_DISPLAY_VIRTUAL:
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800280 if(ctx->mHWCVirtual)
281 ret = ctx->mHWCVirtual->prepare(dev, list);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500282 break;
283 default:
284 ret = -EINVAL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700285 }
286 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500287
Saurabh Shahcf053c62012-12-13 12:32:55 -0800288 ctx->mOverlay->configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800289 ctx->mRotMgr->configDone();
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700290 overlay::Writeback::configDone();
Saurabh Shahacf10202013-02-26 10:15:15 -0800291
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700292 return ret;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700293}
294
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700295static int hwc_eventControl(struct hwc_composer_device_1* dev, int dpy,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500296 int event, int enable)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700297{
Naseer Ahmed099a6932013-09-09 14:25:20 -0400298 ATRACE_CALL();
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700299 int ret = 0;
300 hwc_context_t* ctx = (hwc_context_t*)(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700301 switch(event) {
302 case HWC_EVENT_VSYNC:
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500303 if (ctx->vstate.enable == enable)
Omprakash Dhyade1ef881c2012-10-03 02:26:55 -0700304 break;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500305 ret = hwc_vsync_control(ctx, dpy, enable);
Naseer Ahmed8bb8f9d2013-05-11 07:29:45 -0400306 if(ret == 0)
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500307 ctx->vstate.enable = !!enable;
Iliyan Malcheveac89652012-10-04 10:38:28 -0700308 ALOGD_IF (VSYNC_DEBUG, "VSYNC state changed to %s",
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500309 (enable)?"ENABLED":"DISABLED");
Iliyan Malcheveac89652012-10-04 10:38:28 -0700310 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400311#ifdef QCOM_BSP
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700312 case HWC_EVENT_ORIENTATION:
313 if(dpy == HWC_DISPLAY_PRIMARY) {
Saurabh Shahb39f8152013-08-22 10:21:44 -0700314 Locker::Autolock _l(ctx->mDrawLock);
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700315 // store the primary display orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700316 ctx->deviceOrientation = enable;
317 }
318 break;
Naseer Ahmededbe5182013-05-28 19:56:11 -0400319#endif
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700320 default:
321 ret = -EINVAL;
322 }
323 return ret;
324}
325
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700326static int hwc_blank(struct hwc_composer_device_1* dev, int dpy, int blank)
327{
Naseer Ahmed64b81212013-02-14 10:29:47 -0500328 ATRACE_CALL();
Naseer Ahmed934790c2012-08-16 18:11:09 -0700329 hwc_context_t* ctx = (hwc_context_t*)(dev);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800330
Saurabh Shahb39f8152013-08-22 10:21:44 -0700331 Locker::Autolock _l(ctx->mDrawLock);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700332 int ret = 0, value = 0;
Raj Kamal2464cce2013-09-06 16:20:12 +0530333
334 /* In case of non-hybrid WFD session, we are fooling SF by
335 * piggybacking on HDMI display ID for virtual.
336 * TODO: Not needed once we have WFD client working on top
337 * of Google API's.
338 */
339 dpy = getDpyforExternalDisplay(ctx,dpy);
340
Naseer Ahmede0205b62013-04-04 13:24:39 -0400341 ALOGD_IF(BLANK_DEBUG, "%s: %s display: %d", __FUNCTION__,
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500342 blank==1 ? "Blanking":"Unblanking", dpy);
Arun Kumar K.Re7408372013-03-28 18:41:06 -0700343 if(blank) {
344 // free up all the overlay pipes in use
345 // when we get a blank for either display
346 // makes sure that all pipes are freed
347 ctx->mOverlay->configBegin();
348 ctx->mOverlay->configDone();
349 ctx->mRotMgr->clear();
Tatenda Chipeperekwa9f33f6f2014-01-15 10:47:09 -0800350 // If VDS is connected, do not clear WB object as it
351 // will end up detaching IOMMU. This is required
352 // to send black frame to WFD sink on power suspend.
353 // Note: With this change, we keep the WriteBack object
354 // alive on power suspend for AD use case.
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
Neti Ravi Kumar8f470d82014-02-18 12:19:44 +0530434 if (!ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
435 ALOGD ("%s : Display OFF - Skip BLANK & UNBLANK", __FUNCTION__);
436 ctx->mPanelResetStatus = false;
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700437 return;
Neti Ravi Kumar8f470d82014-02-18 12:19:44 +0530438 }
Veera Sankaran0dadfb32013-07-22 16:07:48 -0700439
440 ALOGD("%s: calling BLANK DISPLAY", __FUNCTION__);
441 ret = hwc_blank(dev, HWC_DISPLAY_PRIMARY, 1);
442 if (ret < 0) {
443 ALOGE("%s: FBIOBLANK failed to BLANK: %s", __FUNCTION__,
444 strerror(errno));
445 }
446
447 ALOGD("%s: calling UNBLANK DISPLAY and enabling vsync", __FUNCTION__);
448 ret = hwc_blank(dev, HWC_DISPLAY_PRIMARY, 0);
449 if (ret < 0) {
450 ALOGE("%s: FBIOBLANK failed to UNBLANK : %s", __FUNCTION__,
451 strerror(errno));
452 }
453 hwc_vsync_control(ctx, HWC_DISPLAY_PRIMARY, 1);
454
455 ctx->mPanelResetStatus = false;
456}
457
458
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700459static int hwc_query(struct hwc_composer_device_1* dev,
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700460 int param, int* value)
461{
462 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700463 int supported = HWC_DISPLAY_PRIMARY_BIT;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700464
465 switch (param) {
466 case HWC_BACKGROUND_LAYER_SUPPORTED:
467 // Not supported for now
468 value[0] = 0;
469 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700470 case HWC_DISPLAY_TYPES_SUPPORTED:
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800471 if(ctx->mMDP.hasOverlay) {
472 supported |= HWC_DISPLAY_VIRTUAL_BIT;
radhakrishna2e792f92014-03-13 11:39:33 +0530473 if(!(qdutils::MDPVersion::getInstance().is8x26() ||
474 qdutils::MDPVersion::getInstance().is8x16()))
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800475 supported |= HWC_DISPLAY_EXTERNAL_BIT;
476 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700477 value[0] = supported;
478 break;
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -0700479 case HWC_FORMAT_RB_SWAP:
480 value[0] = 1;
481 break;
Sushil Chauhan943797c2013-10-21 17:35:55 -0700482 case HWC_COLOR_FILL:
483 value[0] = 1;
484 break;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700485 default:
486 return -EINVAL;
487 }
488 return 0;
489
490}
491
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800492
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700493static int hwc_set_primary(hwc_context_t *ctx, hwc_display_contents_1_t* list) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500494 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700495 int ret = 0;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800496 const int dpy = HWC_DISPLAY_PRIMARY;
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800497 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700498 uint32_t last = list->numHwLayers - 1;
499 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800500 int fd = -1; //FenceFD from the Copybit(valid in async mode)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500501 bool copybitDone = false;
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800502 if(ctx->mCopyBit[dpy])
Naseer Ahmed64b81212013-02-14 10:29:47 -0500503 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800504 if(list->numHwLayers > 1)
505 hwc_sync(ctx, list, dpy, fd);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800506
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700507 // Dump the layers for primary
508 if(ctx->mHwcDebug[dpy])
509 ctx->mHwcDebug[dpy]->dumpLayers(list);
510
Naseer Ahmed330a2822014-03-05 11:57:23 -0500511 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800512 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500513 ret = -1;
514 }
515
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700516 //TODO We dont check for SKIP flag on this layer because we need PAN
517 //always. Last layer is always FB
Saurabh Shah2b033392013-03-22 11:29:44 -0700518 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
Terence Hampsonc67b0372013-10-09 11:32:21 -0400519 if(copybitDone && ctx->mMDP.version >= qdutils::MDP_V4_0) {
Naseer Ahmed64b81212013-02-14 10:29:47 -0500520 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
Naseer Ahmed64b81212013-02-14 10:29:47 -0500521 }
Saurabh Shah2b033392013-03-22 11:29:44 -0700522
523 if(hnd) {
524 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
525 ALOGE("%s: FBUpdate draw failed", __FUNCTION__);
526 ret = -1;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500527 }
Saurabh Shah43333302013-02-06 13:30:27 -0800528 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800529
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700530 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd,
531 ctx->listStats[dpy].roi)) {
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700532 ALOGE("%s: display commit fail for %d dpy!", __FUNCTION__, dpy);
Ramkumar Radhakrishnan68a51922013-05-11 16:51:49 -0700533 ret = -1;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700534 }
Zohaib Alam1bb65612013-09-28 03:38:20 -0400535
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700536 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800537
538 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700539 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700540}
541
542static int hwc_set_external(hwc_context_t *ctx,
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700543 hwc_display_contents_1_t* list)
Naseer Ahmed64b81212013-02-14 10:29:47 -0500544{
545 ATRACE_CALL();
Saurabh Shaheaf67912012-10-10 17:33:14 -0700546 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700547
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700548 const int dpy = HWC_DISPLAY_EXTERNAL;
549
550
Amara Venkata Mastan Manoj Kumar57e3c812013-01-11 13:36:33 -0800551 if (LIKELY(list) && ctx->dpyAttr[dpy].isActive &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700552 ctx->dpyAttr[dpy].connected &&
553 !ctx->dpyAttr[dpy].isPause) {
554 uint32_t last = list->numHwLayers - 1;
555 hwc_layer_1_t *fbLayer = &list->hwLayers[last];
556 int fd = -1; //FenceFD from the Copybit(valid in async mode)
557 bool copybitDone = false;
558 if(ctx->mCopyBit[dpy])
559 copybitDone = ctx->mCopyBit[dpy]->draw(ctx, list, dpy, &fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700560
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700561 if(list->numHwLayers > 1)
562 hwc_sync(ctx, list, dpy, fd);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700563
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700564 // Dump the layers for external
565 if(ctx->mHwcDebug[dpy])
566 ctx->mHwcDebug[dpy]->dumpLayers(list);
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700567
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700568 if (!ctx->mMDPComp[dpy]->draw(ctx, list)) {
569 ALOGE("%s: MDPComp draw failed", __FUNCTION__);
570 ret = -1;
571 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700572
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -0700573 int extOnlyLayerIndex =
574 ctx->listStats[dpy].extOnlyLayerIndex;
575
576 private_handle_t *hnd = (private_handle_t *)fbLayer->handle;
577 if(extOnlyLayerIndex!= -1) {
578 hwc_layer_1_t *extLayer = &list->hwLayers[extOnlyLayerIndex];
579 hnd = (private_handle_t *)extLayer->handle;
580 } else if(copybitDone) {
581 hnd = ctx->mCopyBit[dpy]->getCurrentRenderBuffer();
582 }
583
584 if(hnd && !isYuvBuffer(hnd)) {
585 if (!ctx->mFBUpdate[dpy]->draw(ctx, hnd)) {
586 ALOGE("%s: FBUpdate::draw fail!", __FUNCTION__);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700587 ret = -1;
588 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700589 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800590
Amara Venkata Mastan Manoj Kumar95e8bc62013-08-20 18:24:16 -0700591 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
592 ALOGE("%s: display commit fail for %d dpy!", __FUNCTION__, dpy);
Saurabh Shah2b033392013-03-22 11:29:44 -0700593 ret = -1;
Saurabh Shaheaf67912012-10-10 17:33:14 -0700594 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700595 }
Saurabh Shah747af1e2013-02-26 10:25:12 -0800596
597 closeAcquireFds(list);
Saurabh Shaheaf67912012-10-10 17:33:14 -0700598 return ret;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700599}
600
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700601static int hwc_set(hwc_composer_device_1 *dev,
602 size_t numDisplays,
603 hwc_display_contents_1_t** displays)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700604{
605 int ret = 0;
606 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530607 for (uint32_t i = 0; i < numDisplays; i++) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700608 hwc_display_contents_1_t* list = displays[i];
Raj Kamal2464cce2013-09-06 16:20:12 +0530609 int dpy = getDpyforExternalDisplay(ctx, i);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700610 switch(dpy) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700611 case HWC_DISPLAY_PRIMARY:
612 ret = hwc_set_primary(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700613 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700614 case HWC_DISPLAY_EXTERNAL:
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700615 ret = hwc_set_external(ctx, list);
616 break;
Amara Venkata Mastan Manoj Kumar11a380d2013-01-17 09:30:56 -0800617 case HWC_DISPLAY_VIRTUAL:
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800618 if(ctx->mHWCVirtual)
619 ret = ctx->mHWCVirtual->set(ctx, list);
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700620 break;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700621 default:
622 ret = -EINVAL;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700623 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700624 }
Naseer Ahmed0d05d4f2013-03-28 14:49:07 -0400625 // This is only indicative of how many times SurfaceFlinger posts
626 // frames to the display.
627 CALC_FPS();
Saurabh Shah2d998a92013-05-14 17:55:58 -0700628 MDPComp::resetIdleFallBack();
Saurabh Shahd4e65852013-06-17 11:33:53 -0700629 ctx->mVideoTransFlag = false;
Saurabh Shah2b6e5192013-10-22 17:22:04 -0700630 if(ctx->mRotMgr->getNumActiveSessions() == 0)
631 Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
Saurabh Shah188e4332013-07-18 10:33:22 -0700632 //Was locked at the beginning of prepare
Saurabh Shahb39f8152013-08-22 10:21:44 -0700633 ctx->mDrawLock.unlock();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700634 return ret;
635}
636
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700637int hwc_getDisplayConfigs(struct hwc_composer_device_1* dev, int disp,
638 uint32_t* configs, size_t* numConfigs) {
639 int ret = 0;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700640 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj Kamal2464cce2013-09-06 16:20:12 +0530641 disp = getDpyforExternalDisplay(ctx, disp);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700642 //in 1.1 there is no way to choose a config, report as config id # 0
643 //This config is passed to getDisplayAttributes. Ignore for now.
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700644 switch(disp) {
645 case HWC_DISPLAY_PRIMARY:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700646 if(*numConfigs > 0) {
647 configs[0] = 0;
648 *numConfigs = 1;
649 }
650 ret = 0; //NO_ERROR
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700651 break;
652 case HWC_DISPLAY_EXTERNAL:
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700653 case HWC_DISPLAY_VIRTUAL:
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700654 ret = -1; //Not connected
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700655 if(ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700656 ret = 0; //NO_ERROR
657 if(*numConfigs > 0) {
658 configs[0] = 0;
659 *numConfigs = 1;
660 }
661 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700662 break;
663 }
664 return ret;
665}
666
667int hwc_getDisplayAttributes(struct hwc_composer_device_1* dev, int disp,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800668 uint32_t /*config*/, const uint32_t* attributes, int32_t* values) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700669
670 hwc_context_t* ctx = (hwc_context_t*)(dev);
Raj Kamal2464cce2013-09-06 16:20:12 +0530671 disp = getDpyforExternalDisplay(ctx, disp);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700672 //If hotpluggable displays(i.e, HDMI, WFD) are inactive return error
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700673 if( (disp != HWC_DISPLAY_PRIMARY) && !ctx->dpyAttr[disp].connected) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700674 return -1;
675 }
676
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700677 //From HWComposer
678 static const uint32_t DISPLAY_ATTRIBUTES[] = {
679 HWC_DISPLAY_VSYNC_PERIOD,
680 HWC_DISPLAY_WIDTH,
681 HWC_DISPLAY_HEIGHT,
682 HWC_DISPLAY_DPI_X,
683 HWC_DISPLAY_DPI_Y,
684 HWC_DISPLAY_NO_ATTRIBUTE,
685 };
686
687 const int NUM_DISPLAY_ATTRIBUTES = (sizeof(DISPLAY_ATTRIBUTES) /
688 sizeof(DISPLAY_ATTRIBUTES)[0]);
689
690 for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) {
691 switch (attributes[i]) {
692 case HWC_DISPLAY_VSYNC_PERIOD:
693 values[i] = ctx->dpyAttr[disp].vsync_period;
694 break;
695 case HWC_DISPLAY_WIDTH:
696 values[i] = ctx->dpyAttr[disp].xres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700697 ALOGD("%s disp = %d, width = %d",__FUNCTION__, disp,
698 ctx->dpyAttr[disp].xres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700699 break;
700 case HWC_DISPLAY_HEIGHT:
701 values[i] = ctx->dpyAttr[disp].yres;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700702 ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
703 ctx->dpyAttr[disp].yres);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700704 break;
705 case HWC_DISPLAY_DPI_X:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400706 values[i] = (int32_t) (ctx->dpyAttr[disp].xdpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700707 break;
708 case HWC_DISPLAY_DPI_Y:
Naseer Ahmed7b80d9c2012-09-26 20:14:38 -0400709 values[i] = (int32_t) (ctx->dpyAttr[disp].ydpi*1000.0);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700710 break;
711 default:
712 ALOGE("Unknown display attribute %d",
713 attributes[i]);
714 return -EINVAL;
715 }
716 }
717 return 0;
718}
719
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500720void hwc_dump(struct hwc_composer_device_1* dev, char *buff, int buff_len)
721{
722 hwc_context_t* ctx = (hwc_context_t*)(dev);
Saurabh Shahb39f8152013-08-22 10:21:44 -0700723 Locker::Autolock _l(ctx->mDrawLock);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800724 android::String8 aBuf("");
725 dumpsys_log(aBuf, "Qualcomm HWC state:\n");
726 dumpsys_log(aBuf, " MDPVersion=%d\n", ctx->mMDP.version);
727 dumpsys_log(aBuf, " DisplayPanel=%c\n", ctx->mMDP.panel);
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700728 for(int dpy = 0; dpy < HWC_NUM_DISPLAY_TYPES; dpy++) {
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800729 if(ctx->mMDPComp[dpy])
730 ctx->mMDPComp[dpy]->dump(aBuf);
731 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800732 char ovDump[2048] = {'\0'};
733 ctx->mOverlay->getDump(ovDump, 2048);
734 dumpsys_log(aBuf, ovDump);
Saurabh Shahacf10202013-02-26 10:15:15 -0800735 ovDump[0] = '\0';
Saurabh Shahae61b2b2013-04-10 16:37:25 -0700736 ctx->mRotMgr->getDump(ovDump, 1024);
Saurabh Shahacf10202013-02-26 10:15:15 -0800737 dumpsys_log(aBuf, ovDump);
Saurabh Shah7ef9ec92013-10-29 10:32:23 -0700738 ovDump[0] = '\0';
Saurabh Shah7c8d34f2013-10-30 15:52:29 -0700739 if(Writeback::getDump(ovDump, 1024)) {
740 dumpsys_log(aBuf, ovDump);
741 ovDump[0] = '\0';
742 }
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800743 strlcpy(buff, aBuf.string(), buff_len);
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500744}
745
Naseer Ahmed29a26812012-06-14 00:56:20 -0700746static int hwc_device_close(struct hw_device_t *dev)
747{
748 if(!dev) {
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700749 ALOGE("%s: NULL device pointer", __FUNCTION__);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700750 return -1;
751 }
752 closeContext((hwc_context_t*)dev);
753 free(dev);
754
755 return 0;
756}
757
758static int hwc_device_open(const struct hw_module_t* module, const char* name,
759 struct hw_device_t** device)
760{
761 int status = -EINVAL;
762
763 if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {
764 struct hwc_context_t *dev;
765 dev = (hwc_context_t*)malloc(sizeof(*dev));
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800766 if(dev == NULL)
767 return status;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700768 memset(dev, 0, sizeof(*dev));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700769
770 //Initialize hwc context
Naseer Ahmed29a26812012-06-14 00:56:20 -0700771 initContext(dev);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700772
773 //Setup HWC methods
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700774 dev->device.common.tag = HARDWARE_DEVICE_TAG;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700775 dev->device.common.version = HWC_DEVICE_API_VERSION_1_3;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700776 dev->device.common.module = const_cast<hw_module_t*>(module);
777 dev->device.common.close = hwc_device_close;
778 dev->device.prepare = hwc_prepare;
779 dev->device.set = hwc_set;
780 dev->device.eventControl = hwc_eventControl;
781 dev->device.blank = hwc_blank;
782 dev->device.query = hwc_query;
783 dev->device.registerProcs = hwc_registerProcs;
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500784 dev->device.dump = hwc_dump;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700785 dev->device.getDisplayConfigs = hwc_getDisplayConfigs;
786 dev->device.getDisplayAttributes = hwc_getDisplayAttributes;
787 *device = &dev->device.common;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700788 status = 0;
789 }
790 return status;
791}