blob: 6d0b85f1f89ea3fc8cd1a7a01aea8b34a5f65d2a [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"
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053024#include "hwc_video.h"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050025
26namespace qhwc {
27
28namespace ovutils = overlay::utils;
29
Saurabh Shahcf053c62012-12-13 12:32:55 -080030IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
31 if(width > MAX_DISPLAY_DIM) {
32 return new FBUpdateHighRes(dpy);
33 }
34 return new FBUpdateLowRes(dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050035}
36
Saurabh Shahcf053c62012-12-13 12:32:55 -080037inline void IFBUpdate::reset() {
38 mModeOn = false;
39}
40
Sravan Kumar D.V.Nc6a82502013-03-22 06:20:04 +053041bool IFBUpdate::needFbUpdate(hwc_context_t *ctx,
42 const hwc_display_contents_1_t *list, int dpy) {
43 // if Video Overlay is on and and YUV layers are passed through overlay
44 // , no need to configure FB layer.
45 if(ctx->mVidOv[dpy]->isModeOn() &&
46 (ctx->listStats[dpy].yuvCount == ctx->listStats[dpy].numAppLayers))
47 return false;
48
49 return true;
50}
Saurabh Shahcf053c62012-12-13 12:32:55 -080051//================= Low res====================================
52FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
53
54inline void FBUpdateLowRes::reset() {
55 IFBUpdate::reset();
56 mDest = ovutils::OV_INVALID;
57}
58
Naseer Ahmed64b81212013-02-14 10:29:47 -050059bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
60{
Naseer Ahmed758bfc52012-11-28 17:02:08 -050061 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080062 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063 __FUNCTION__);
64 return false;
65 }
Naseer Ahmed64b81212013-02-14 10:29:47 -050066 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -080067 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
68 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050069}
70
71// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -050072bool FBUpdateLowRes::configure(hwc_context_t *ctx,
73 hwc_display_contents_1 *list)
Naseer Ahmed758bfc52012-11-28 17:02:08 -050074{
75 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050076 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077 if (LIKELY(ctx->mOverlay)) {
Sravan Kumar D.V.Nc6a82502013-03-22 06:20:04 +053078 // When Video overlay is in use and there are no UI layers to
79 // be composed to FB , no need to configure FbUpdate.
80 if(!needFbUpdate(ctx, list, mDpy))
81 return false;
82
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083 overlay::Overlay& ov = *(ctx->mOverlay);
84 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080085 ovutils::Whf info(hnd->width, hnd->height,
86 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087
88 //Request an RGB pipe
Saurabh Shahcf053c62012-12-13 12:32:55 -080089 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 if(dest == ovutils::OV_INVALID) { //None available
91 return false;
92 }
93
Saurabh Shahcf053c62012-12-13 12:32:55 -080094 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095
96 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053097 // If any of the layers has pre-multiplied alpha, set Pre multiplied
98 // Flag as the compositied output is alpha pre-multiplied.
99 if(ctx->listStats[mDpy].preMultipliedAlpha == true)
100 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
101
102 ovutils::eZorder z_order =
103 ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
104 ovutils::eIsFg is_fg =
105 ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500106
107 ovutils::PipeArgs parg(mdpFlags,
108 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530109 z_order,
110 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800111 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500112 ov.setSource(parg, dest);
113
Naseer Ahmed64b81212013-02-14 10:29:47 -0500114 hwc_rect_t sourceCrop;
115 getNonWormholeRegion(list, sourceCrop);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500116 // x,y,w,h
117 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
118 sourceCrop.right - sourceCrop.left,
119 sourceCrop.bottom - sourceCrop.top);
120 ov.setCrop(dcrop, dest);
121
122 int transform = layer->transform;
123 ovutils::eTransform orient =
124 static_cast<ovutils::eTransform>(transform);
125 ov.setTransform(orient, dest);
126
Naseer Ahmed64b81212013-02-14 10:29:47 -0500127 hwc_rect_t displayFrame = sourceCrop;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 ovutils::Dim dpos(displayFrame.left,
129 displayFrame.top,
130 displayFrame.right - displayFrame.left,
131 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800132 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
133 if(mDpy)
134 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 ov.setPosition(dpos, dest);
136
137 ret = true;
138 if (!ov.commit(dest)) {
139 ALOGE("%s: commit fails", __FUNCTION__);
140 ret = false;
141 }
142 }
143 return ret;
144}
145
Naseer Ahmed64b81212013-02-14 10:29:47 -0500146bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800148 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 return true;
150 }
151 bool ret = true;
152 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800153 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800155 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500156 ret = false;
157 }
158 return ret;
159}
160
Saurabh Shahcf053c62012-12-13 12:32:55 -0800161//================= High res====================================
162FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
163
164inline void FBUpdateHighRes::reset() {
165 IFBUpdate::reset();
166 mDestLeft = ovutils::OV_INVALID;
167 mDestRight = ovutils::OV_INVALID;
168}
169
Naseer Ahmed64b81212013-02-14 10:29:47 -0500170bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
171{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800172 if(!ctx->mMDP.hasOverlay) {
173 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
174 __FUNCTION__);
175 return false;
176 }
177 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500178 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800179 return mModeOn;
180}
181
182// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500183bool FBUpdateHighRes::configure(hwc_context_t *ctx,
184 hwc_display_contents_1 *list)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800185{
186 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500187 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800188 if (LIKELY(ctx->mOverlay)) {
Sravan Kumar D.V.Nc6a82502013-03-22 06:20:04 +0530189 // When Video overlay is in use and there are no UI layers to
190 // be composed to FB , no need to configure FbUpdate.
191 if(!needFbUpdate(ctx, list, mDpy))
192 return false;
193
Saurabh Shahcf053c62012-12-13 12:32:55 -0800194 overlay::Overlay& ov = *(ctx->mOverlay);
195 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800196 ovutils::Whf info(hnd->width, hnd->height,
197 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800198
199 //Request left RGB pipe
200 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
201 if(destL == ovutils::OV_INVALID) { //None available
202 return false;
203 }
204 //Request right RGB pipe
205 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
206 if(destR == ovutils::OV_INVALID) { //None available
207 return false;
208 }
209
210 mDestLeft = destL;
211 mDestRight = destR;
212
213 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530214 //If any layer has pre-multiplied alpha, set Pre multiplied
215 //Flag as the compositied output is alpha pre-multiplied.
216 if(ctx->listStats[mDpy].preMultipliedAlpha == true)
217 ovutils::setMdpFlags(mdpFlagsL, ovutils::OV_MDP_BLEND_FG_PREMULT);
218
219 ovutils::eZorder z_order =
220 ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
221 ovutils::eIsFg is_fg =
222 ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800223
224 ovutils::PipeArgs pargL(mdpFlagsL,
225 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530226 z_order,
227 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800228 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800229 ov.setSource(pargL, destL);
230
231 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
232 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
233 ovutils::PipeArgs pargR(mdpFlagsR,
234 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530235 z_order,
236 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800237 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800238 ov.setSource(pargR, destR);
239
Naseer Ahmed64b81212013-02-14 10:29:47 -0500240 hwc_rect_t sourceCrop;
241 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800242 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
243 (sourceCrop.right - sourceCrop.left) / 2,
244 sourceCrop.bottom - sourceCrop.top);
245 ovutils::Dim dcropR(
246 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
247 sourceCrop.top,
248 (sourceCrop.right - sourceCrop.left) / 2,
249 sourceCrop.bottom - sourceCrop.top);
250 ov.setCrop(dcropL, destL);
251 ov.setCrop(dcropR, destR);
252
253 int transform = layer->transform;
254 ovutils::eTransform orient =
255 static_cast<ovutils::eTransform>(transform);
256 ov.setTransform(orient, destL);
257 ov.setTransform(orient, destR);
258
Naseer Ahmed64b81212013-02-14 10:29:47 -0500259 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800260 //For FB left, top will always be 0
261 //That should also be the case if using 2 mixers for single display
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700262 ovutils::Dim dposL(displayFrame.left,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800263 displayFrame.top,
264 (displayFrame.right - displayFrame.left) / 2,
265 displayFrame.bottom - displayFrame.top);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700266 ov.setPosition(dposL, destL);
267 ovutils::Dim dposR(0,
268 displayFrame.top,
269 (displayFrame.right - displayFrame.left) / 2,
270 displayFrame.bottom - displayFrame.top);
271 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800272
273 ret = true;
274 if (!ov.commit(destL)) {
275 ALOGE("%s: commit fails for left", __FUNCTION__);
276 ret = false;
277 }
278 if (!ov.commit(destR)) {
279 ALOGE("%s: commit fails for right", __FUNCTION__);
280 ret = false;
281 }
282 }
283 return ret;
284}
285
Naseer Ahmed64b81212013-02-14 10:29:47 -0500286bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800287{
288 if(!mModeOn) {
289 return true;
290 }
291 bool ret = true;
292 overlay::Overlay& ov = *(ctx->mOverlay);
293 ovutils::eDest destL = mDestLeft;
294 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800295 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
296 ALOGE("%s: queue failed for left of dpy = %d",
297 __FUNCTION__, mDpy);
298 ret = false;
299 }
300 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
301 ALOGE("%s: queue failed for right of dpy = %d",
302 __FUNCTION__, mDpy);
303 ret = false;
304 }
305 return ret;
306}
307
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500308//---------------------------------------------------------------------
309}; //namespace qhwc