blob: 5f524c75dafbe012e5c95e9339c3f0d05256f8ac [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
41//================= Low res====================================
42FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
43
44inline void FBUpdateLowRes::reset() {
45 IFBUpdate::reset();
46 mDest = ovutils::OV_INVALID;
47}
48
Naseer Ahmed64b81212013-02-14 10:29:47 -050049bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
50{
Naseer Ahmed758bfc52012-11-28 17:02:08 -050051 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080052 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Naseer Ahmed758bfc52012-11-28 17:02:08 -050053 __FUNCTION__);
54 return false;
55 }
Naseer Ahmed64b81212013-02-14 10:29:47 -050056 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -080057 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
58 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059}
60
61// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -050062bool FBUpdateLowRes::configure(hwc_context_t *ctx,
63 hwc_display_contents_1 *list)
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064{
65 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)) {
68 overlay::Overlay& ov = *(ctx->mOverlay);
69 private_handle_t *hnd = (private_handle_t *)layer->handle;
70 if (!hnd) {
71 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
72 return false;
73 }
Saurabh Shahacf10202013-02-26 10:15:15 -080074 ovutils::Whf info(hnd->width, hnd->height,
75 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050076
77 //Request an RGB pipe
Saurabh Shahcf053c62012-12-13 12:32:55 -080078 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079 if(dest == ovutils::OV_INVALID) { //None available
80 return false;
81 }
82
Saurabh Shahcf053c62012-12-13 12:32:55 -080083 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084
85 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053086 // If any of the layers has pre-multiplied alpha, set Pre multiplied
87 // Flag as the compositied output is alpha pre-multiplied.
88 if(ctx->listStats[mDpy].preMultipliedAlpha == true)
89 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
90
91 ovutils::eZorder z_order =
92 ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
93 ovutils::eIsFg is_fg =
94 ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095
96 ovutils::PipeArgs parg(mdpFlags,
97 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053098 z_order,
99 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800100 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500101 ov.setSource(parg, dest);
102
Naseer Ahmed64b81212013-02-14 10:29:47 -0500103 hwc_rect_t sourceCrop;
104 getNonWormholeRegion(list, sourceCrop);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500105 // x,y,w,h
106 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
107 sourceCrop.right - sourceCrop.left,
108 sourceCrop.bottom - sourceCrop.top);
109 ov.setCrop(dcrop, dest);
110
111 int transform = layer->transform;
112 ovutils::eTransform orient =
113 static_cast<ovutils::eTransform>(transform);
114 ov.setTransform(orient, dest);
115
Naseer Ahmed64b81212013-02-14 10:29:47 -0500116 hwc_rect_t displayFrame = sourceCrop;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 ovutils::Dim dpos(displayFrame.left,
118 displayFrame.top,
119 displayFrame.right - displayFrame.left,
120 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800121 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
122 if(mDpy)
123 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 ov.setPosition(dpos, dest);
125
126 ret = true;
127 if (!ov.commit(dest)) {
128 ALOGE("%s: commit fails", __FUNCTION__);
129 ret = false;
130 }
131 }
132 return ret;
133}
134
Naseer Ahmed64b81212013-02-14 10:29:47 -0500135bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800137 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500138 return true;
139 }
140 bool ret = true;
141 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800142 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500143 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800144 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500145 ret = false;
146 }
147 return ret;
148}
149
Saurabh Shahcf053c62012-12-13 12:32:55 -0800150//================= High res====================================
151FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
152
153inline void FBUpdateHighRes::reset() {
154 IFBUpdate::reset();
155 mDestLeft = ovutils::OV_INVALID;
156 mDestRight = ovutils::OV_INVALID;
157}
158
Naseer Ahmed64b81212013-02-14 10:29:47 -0500159bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
160{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800161 if(!ctx->mMDP.hasOverlay) {
162 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
163 __FUNCTION__);
164 return false;
165 }
166 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500167 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800168 return mModeOn;
169}
170
171// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500172bool FBUpdateHighRes::configure(hwc_context_t *ctx,
173 hwc_display_contents_1 *list)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800174{
175 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)) {
178 overlay::Overlay& ov = *(ctx->mOverlay);
179 private_handle_t *hnd = (private_handle_t *)layer->handle;
180 if (!hnd) {
181 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
182 return false;
183 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800184 ovutils::Whf info(hnd->width, hnd->height,
185 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800186
187 //Request left RGB pipe
188 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
189 if(destL == ovutils::OV_INVALID) { //None available
190 return false;
191 }
192 //Request right RGB pipe
193 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
194 if(destR == ovutils::OV_INVALID) { //None available
195 return false;
196 }
197
198 mDestLeft = destL;
199 mDestRight = destR;
200
201 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530202 //If any layer has pre-multiplied alpha, set Pre multiplied
203 //Flag as the compositied output is alpha pre-multiplied.
204 if(ctx->listStats[mDpy].preMultipliedAlpha == true)
205 ovutils::setMdpFlags(mdpFlagsL, ovutils::OV_MDP_BLEND_FG_PREMULT);
206
207 ovutils::eZorder z_order =
208 ctx->mVidOv[mDpy]->isModeOn()?ovutils::ZORDER_1:ovutils::ZORDER_0;
209 ovutils::eIsFg is_fg =
210 ctx->mVidOv[mDpy]->isModeOn()? ovutils::IS_FG_OFF:ovutils::IS_FG_SET;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800211
212 ovutils::PipeArgs pargL(mdpFlagsL,
213 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530214 z_order,
215 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800216 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800217 ov.setSource(pargL, destL);
218
219 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
220 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
221 ovutils::PipeArgs pargR(mdpFlagsR,
222 info,
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530223 z_order,
224 is_fg,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800225 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800226 ov.setSource(pargR, destR);
227
Naseer Ahmed64b81212013-02-14 10:29:47 -0500228 hwc_rect_t sourceCrop;
229 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800230 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
231 (sourceCrop.right - sourceCrop.left) / 2,
232 sourceCrop.bottom - sourceCrop.top);
233 ovutils::Dim dcropR(
234 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
235 sourceCrop.top,
236 (sourceCrop.right - sourceCrop.left) / 2,
237 sourceCrop.bottom - sourceCrop.top);
238 ov.setCrop(dcropL, destL);
239 ov.setCrop(dcropR, destR);
240
241 int transform = layer->transform;
242 ovutils::eTransform orient =
243 static_cast<ovutils::eTransform>(transform);
244 ov.setTransform(orient, destL);
245 ov.setTransform(orient, destR);
246
Naseer Ahmed64b81212013-02-14 10:29:47 -0500247 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800248 //For FB left, top will always be 0
249 //That should also be the case if using 2 mixers for single display
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700250 ovutils::Dim dposL(displayFrame.left,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800251 displayFrame.top,
252 (displayFrame.right - displayFrame.left) / 2,
253 displayFrame.bottom - displayFrame.top);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700254 ov.setPosition(dposL, destL);
255 ovutils::Dim dposR(0,
256 displayFrame.top,
257 (displayFrame.right - displayFrame.left) / 2,
258 displayFrame.bottom - displayFrame.top);
259 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800260
261 ret = true;
262 if (!ov.commit(destL)) {
263 ALOGE("%s: commit fails for left", __FUNCTION__);
264 ret = false;
265 }
266 if (!ov.commit(destR)) {
267 ALOGE("%s: commit fails for right", __FUNCTION__);
268 ret = false;
269 }
270 }
271 return ret;
272}
273
Naseer Ahmed64b81212013-02-14 10:29:47 -0500274bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800275{
276 if(!mModeOn) {
277 return true;
278 }
279 bool ret = true;
280 overlay::Overlay& ov = *(ctx->mOverlay);
281 ovutils::eDest destL = mDestLeft;
282 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800283 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
284 ALOGE("%s: queue failed for left of dpy = %d",
285 __FUNCTION__, mDpy);
286 ret = false;
287 }
288 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
289 ALOGE("%s: queue failed for right of dpy = %d",
290 __FUNCTION__, mDpy);
291 ret = false;
292 }
293 return ret;
294}
295
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500296//---------------------------------------------------------------------
297}; //namespace qhwc