blob: bfa33cad4e43026b00153b967bfbde3deaf1f046 [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)) {
68 overlay::Overlay& ov = *(ctx->mOverlay);
69 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080070 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072
73 //Request an RGB pipe
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080074 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -070076 ALOGE("%s: No pipes available to configure fb for dpy %d",
77 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078 return false;
79 }
80
Saurabh Shahcf053c62012-12-13 12:32:55 -080081 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053084
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080085 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086
87 ovutils::PipeArgs parg(mdpFlags,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080088 info,
89 zOrder,
90 ovutils::IS_FG_OFF,
91 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 ov.setSource(parg, dest);
93
Naseer Ahmed64b81212013-02-14 10:29:47 -050094 hwc_rect_t sourceCrop;
95 getNonWormholeRegion(list, sourceCrop);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050096 // x,y,w,h
97 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080098 sourceCrop.right - sourceCrop.left,
99 sourceCrop.bottom - sourceCrop.top);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 ov.setCrop(dcrop, dest);
101
102 int transform = layer->transform;
103 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800104 static_cast<ovutils::eTransform>(transform);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500105 ov.setTransform(orient, dest);
106
Naseer Ahmed64b81212013-02-14 10:29:47 -0500107 hwc_rect_t displayFrame = sourceCrop;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500108 ovutils::Dim dpos(displayFrame.left,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800109 displayFrame.top,
110 displayFrame.right - displayFrame.left,
111 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800112 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
113 if(mDpy)
114 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115 ov.setPosition(dpos, dest);
116
117 ret = true;
118 if (!ov.commit(dest)) {
119 ALOGE("%s: commit fails", __FUNCTION__);
120 ret = false;
121 }
122 }
123 return ret;
124}
125
Naseer Ahmed64b81212013-02-14 10:29:47 -0500126bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800128 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 return true;
130 }
131 bool ret = true;
132 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800133 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500134 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800135 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500136 ret = false;
137 }
138 return ret;
139}
140
Saurabh Shahcf053c62012-12-13 12:32:55 -0800141//================= High res====================================
142FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
143
144inline void FBUpdateHighRes::reset() {
145 IFBUpdate::reset();
146 mDestLeft = ovutils::OV_INVALID;
147 mDestRight = ovutils::OV_INVALID;
148}
149
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800150bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
151 int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800152 if(!ctx->mMDP.hasOverlay) {
153 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800154 __FUNCTION__);
155 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800156 }
157 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800158 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800159 return mModeOn;
160}
161
162// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500163bool FBUpdateHighRes::configure(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800164 hwc_display_contents_1 *list, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800165 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500166 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800167 if (LIKELY(ctx->mOverlay)) {
168 overlay::Overlay& ov = *(ctx->mOverlay);
169 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800170 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800172
173 //Request left RGB pipe
174 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
175 if(destL == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700176 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
177 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800178 return false;
179 }
180 //Request right RGB pipe
181 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
182 if(destR == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700183 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
184 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800185 return false;
186 }
187
188 mDestLeft = destL;
189 mDestRight = destR;
190
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800191 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530192
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800193 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800194
195 ovutils::PipeArgs pargL(mdpFlagsL,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800196 info,
197 zOrder,
198 ovutils::IS_FG_OFF,
199 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800200 ov.setSource(pargL, destL);
201
202 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
203 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
204 ovutils::PipeArgs pargR(mdpFlagsR,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205 info,
206 zOrder,
207 ovutils::IS_FG_OFF,
208 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800209 ov.setSource(pargR, destR);
210
Naseer Ahmed64b81212013-02-14 10:29:47 -0500211 hwc_rect_t sourceCrop;
212 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800213 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 (sourceCrop.right - sourceCrop.left) / 2,
215 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800216 ovutils::Dim dcropR(
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
218 sourceCrop.top,
219 (sourceCrop.right - sourceCrop.left) / 2,
220 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800221 ov.setCrop(dcropL, destL);
222 ov.setCrop(dcropR, destR);
223
224 int transform = layer->transform;
225 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226 static_cast<ovutils::eTransform>(transform);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800227 ov.setTransform(orient, destL);
228 ov.setTransform(orient, destR);
229
Naseer Ahmed64b81212013-02-14 10:29:47 -0500230 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahce416f02013-04-10 13:33:09 -0700231 const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
232 const int height = displayFrame.bottom - displayFrame.top;
233
234 ovutils::Dim dposL(MAX_DISPLAY_DIM - halfWidth,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800235 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700236 halfWidth,
237 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700238 ov.setPosition(dposL, destL);
Saurabh Shahce416f02013-04-10 13:33:09 -0700239
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700240 ovutils::Dim dposR(0,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800241 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700242 halfWidth,
243 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700244 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800245
246 ret = true;
247 if (!ov.commit(destL)) {
248 ALOGE("%s: commit fails for left", __FUNCTION__);
249 ret = false;
250 }
251 if (!ov.commit(destR)) {
252 ALOGE("%s: commit fails for right", __FUNCTION__);
253 ret = false;
254 }
255 }
256 return ret;
257}
258
Naseer Ahmed64b81212013-02-14 10:29:47 -0500259bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800260{
261 if(!mModeOn) {
262 return true;
263 }
264 bool ret = true;
265 overlay::Overlay& ov = *(ctx->mOverlay);
266 ovutils::eDest destL = mDestLeft;
267 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800268 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
269 ALOGE("%s: queue failed for left of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800270 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800271 ret = false;
272 }
273 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
274 ALOGE("%s: queue failed for right of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800275 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800276 ret = false;
277 }
278 return ret;
279}
280
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500281//---------------------------------------------------------------------
282}; //namespace qhwc