blob: 439432e4816c7d91fd7b8ece281a31b0d99010a7 [file] [log] [blame]
Naseer Ahmed758bfc52012-11-28 17:02:08 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7 *
8 * 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 */
20
Saurabh Shahcf053c62012-12-13 12:32:55 -080021#define DEBUG_FBUPDATE 0
Naseer Ahmed758bfc52012-11-28 17:02:08 -050022#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include "hwc_fbupdate.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070024#include "mdp_version.h"
25
26using namespace qdutils;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050027
28namespace qhwc {
29
30namespace ovutils = overlay::utils;
31
Saurabh Shahcf053c62012-12-13 12:32:55 -080032IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
33 if(width > MAX_DISPLAY_DIM) {
34 return new FBUpdateHighRes(dpy);
35 }
36 return new FBUpdateLowRes(dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050037}
38
Saurabh Shahcf053c62012-12-13 12:32:55 -080039inline void IFBUpdate::reset() {
40 mModeOn = false;
41}
42
43//================= Low res====================================
44FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
45
46inline void FBUpdateLowRes::reset() {
47 IFBUpdate::reset();
48 mDest = ovutils::OV_INVALID;
49}
50
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080051bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
52 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080054 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080055 __FUNCTION__);
56 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050057 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080058 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -080059 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050060}
61
62// Configure
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080063bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
64 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050065 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050066 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050067 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -080068 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
69 // ext only layer present..
70 if(extOnlyLayerIndex != -1) {
71 layer = &list->hwLayers[extOnlyLayerIndex];
72 layer->compositionType = HWC_OVERLAY;
73 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074 overlay::Overlay& ov = *(ctx->mOverlay);
75 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080076 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080077 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078
79 //Request an RGB pipe
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050081 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -070082 ALOGE("%s: No pipes available to configure fb for dpy %d",
83 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084 return false;
85 }
86
Saurabh Shahcf053c62012-12-13 12:32:55 -080087 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050088
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080089 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053090
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080091 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092
93 ovutils::PipeArgs parg(mdpFlags,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080094 info,
95 zOrder,
96 ovutils::IS_FG_OFF,
97 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098 ov.setSource(parg, dest);
99
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800100 hwc_rect_t sourceCrop = layer->sourceCrop;
101 hwc_rect_t displayFrame = layer->displayFrame;
102 if(extOnlyLayerIndex == -1) {
103 getNonWormholeRegion(list, sourceCrop);
104 displayFrame = sourceCrop;
105 }
106
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 // x,y,w,h
108 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800109 sourceCrop.right - sourceCrop.left,
110 sourceCrop.bottom - sourceCrop.top);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500111 ov.setCrop(dcrop, dest);
112
113 int transform = layer->transform;
114 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800115 static_cast<ovutils::eTransform>(transform);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 ov.setTransform(orient, dest);
117
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 ovutils::Dim dpos(displayFrame.left,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 displayFrame.top,
120 displayFrame.right - displayFrame.left,
121 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800122 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
123 if(mDpy)
124 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 ov.setPosition(dpos, dest);
126
127 ret = true;
128 if (!ov.commit(dest)) {
129 ALOGE("%s: commit fails", __FUNCTION__);
130 ret = false;
131 }
132 }
133 return ret;
134}
135
Naseer Ahmed64b81212013-02-14 10:29:47 -0500136bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500137{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800138 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 return true;
140 }
141 bool ret = true;
142 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800143 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500144 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800145 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500146 ret = false;
147 }
148 return ret;
149}
150
Saurabh Shahcf053c62012-12-13 12:32:55 -0800151//================= High res====================================
152FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
153
154inline void FBUpdateHighRes::reset() {
155 IFBUpdate::reset();
156 mDestLeft = ovutils::OV_INVALID;
157 mDestRight = ovutils::OV_INVALID;
158}
159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800160bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
161 int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800162 if(!ctx->mMDP.hasOverlay) {
163 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800164 __FUNCTION__);
165 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800166 }
167 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800168 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800169 return mModeOn;
170}
171
172// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500173bool FBUpdateHighRes::configure(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800174 hwc_display_contents_1 *list, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800175 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500176 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800177 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800178 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
179 // ext only layer present..
180 if(extOnlyLayerIndex != -1) {
181 layer = &list->hwLayers[extOnlyLayerIndex];
182 layer->compositionType = HWC_OVERLAY;
183 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800184 overlay::Overlay& ov = *(ctx->mOverlay);
185 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800186 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800188
189 //Request left RGB pipe
190 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
191 if(destL == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700192 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
193 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800194 return false;
195 }
196 //Request right RGB pipe
197 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
198 if(destR == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700199 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
200 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800201 return false;
202 }
203
204 mDestLeft = destL;
205 mDestRight = destR;
206
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530208
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800210
211 ovutils::PipeArgs pargL(mdpFlagsL,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800212 info,
213 zOrder,
214 ovutils::IS_FG_OFF,
215 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800216 ov.setSource(pargL, destL);
217
218 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
219 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
220 ovutils::PipeArgs pargR(mdpFlagsR,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800221 info,
222 zOrder,
223 ovutils::IS_FG_OFF,
224 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800225 ov.setSource(pargR, destR);
226
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800227 hwc_rect_t sourceCrop = layer->sourceCrop;
228 hwc_rect_t displayFrame = layer->displayFrame;
229 if(extOnlyLayerIndex == -1) {
230 getNonWormholeRegion(list, sourceCrop);
231 displayFrame = sourceCrop;
232 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800233 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800234 (sourceCrop.right - sourceCrop.left) / 2,
235 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800236 ovutils::Dim dcropR(
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800237 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
238 sourceCrop.top,
239 (sourceCrop.right - sourceCrop.left) / 2,
240 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800241 ov.setCrop(dcropL, destL);
242 ov.setCrop(dcropR, destR);
243
244 int transform = layer->transform;
245 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800246 static_cast<ovutils::eTransform>(transform);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800247 ov.setTransform(orient, destL);
248 ov.setTransform(orient, destR);
249
Saurabh Shahce416f02013-04-10 13:33:09 -0700250 const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
251 const int height = displayFrame.bottom - displayFrame.top;
252
Saurabh Shahca317592013-05-02 14:53:58 -0700253 const int halfDpy = ctx->dpyAttr[mDpy].xres / 2;
254 ovutils::Dim dposL(halfDpy - halfWidth,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800255 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700256 halfWidth,
257 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700258 ov.setPosition(dposL, destL);
Saurabh Shahce416f02013-04-10 13:33:09 -0700259
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700260 ovutils::Dim dposR(0,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700262 halfWidth,
263 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700264 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800265
266 ret = true;
267 if (!ov.commit(destL)) {
268 ALOGE("%s: commit fails for left", __FUNCTION__);
269 ret = false;
270 }
271 if (!ov.commit(destR)) {
272 ALOGE("%s: commit fails for right", __FUNCTION__);
273 ret = false;
274 }
275 }
276 return ret;
277}
278
Naseer Ahmed64b81212013-02-14 10:29:47 -0500279bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800280{
281 if(!mModeOn) {
282 return true;
283 }
284 bool ret = true;
285 overlay::Overlay& ov = *(ctx->mOverlay);
286 ovutils::eDest destL = mDestLeft;
287 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800288 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
289 ALOGE("%s: queue failed for left of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800290 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800291 ret = false;
292 }
293 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
294 ALOGE("%s: queue failed for right of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800295 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800296 ret = false;
297 }
298 return ret;
299}
300
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500301//---------------------------------------------------------------------
302}; //namespace qhwc