blob: b9be4d48b2a1333c71f9db8f73d79443c3c49eba [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
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070022#include <cutils/properties.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <gralloc_priv.h>
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070024#include <overlayRotator.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050025#include "hwc_fbupdate.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070026#include "mdp_version.h"
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070027#include "external.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070028
29using namespace qdutils;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070031using overlay::Rotator;
32
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033namespace qhwc {
34
35namespace ovutils = overlay::utils;
36
Saurabh Shahcf053c62012-12-13 12:32:55 -080037IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
38 if(width > MAX_DISPLAY_DIM) {
39 return new FBUpdateHighRes(dpy);
40 }
41 return new FBUpdateLowRes(dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050042}
43
Saurabh Shahcf053c62012-12-13 12:32:55 -080044inline void IFBUpdate::reset() {
45 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070046 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080047}
48
49//================= Low res====================================
50FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
51
52inline void FBUpdateLowRes::reset() {
53 IFBUpdate::reset();
54 mDest = ovutils::OV_INVALID;
55}
56
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080057bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
58 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080060 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061 __FUNCTION__);
62 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -080065 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066}
67
68// Configure
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080069bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
70 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050072 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050073 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -080074 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
75 // ext only layer present..
76 if(extOnlyLayerIndex != -1) {
77 layer = &list->hwLayers[extOnlyLayerIndex];
78 layer->compositionType = HWC_OVERLAY;
79 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080 overlay::Overlay& ov = *(ctx->mOverlay);
81 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080082 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084
85 //Request an RGB pipe
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -070088 ALOGE("%s: No pipes available to configure fb for dpy %d",
89 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 return false;
91 }
92
Saurabh Shahcf053c62012-12-13 12:32:55 -080093 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050094
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080095 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070096 ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080097 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098
Arun Kumar K.Ra2978452013-02-07 01:34:24 -080099 hwc_rect_t sourceCrop = layer->sourceCrop;
100 hwc_rect_t displayFrame = layer->displayFrame;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700101 int transform = layer->transform;
102 int fbWidth = ctx->dpyAttr[mDpy].xres;
103 int fbHeight = ctx->dpyAttr[mDpy].yres;
104 int rotFlags = ovutils::ROT_FLAGS_NONE;
105
106 ovutils::eTransform orient =
107 static_cast<ovutils::eTransform>(transform);
108 if(mDpy && ctx->mExtOrientation) {
109 // If there is a external orientation set, use that
110 transform = ctx->mExtOrientation;
111 orient = static_cast<ovutils::eTransform >(ctx->mExtOrientation);
112 }
113
114 // Dont do wormhole calculation when extorientation is set on External
115 if((!mDpy || (mDpy && !ctx->mExtOrientation))
116 && extOnlyLayerIndex == -1) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800117 getNonWormholeRegion(list, sourceCrop);
118 displayFrame = sourceCrop;
119 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500120 ovutils::Dim dpos(displayFrame.left,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 displayFrame.top,
122 displayFrame.right - displayFrame.left,
123 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800124 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700125 if(mDpy && !ctx->mExtOrientation)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800126 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700128 if(mDpy) {
129 getAspectRatioPosition(ctx, mDpy, ctx->mExtOrientation, dpos.x,
130 dpos.y, dpos.w, dpos.h);
131 // Convert dim to hwc_rect_t
132 displayFrame.left = dpos.x;
133 displayFrame.top = dpos.y;
134 displayFrame.right = dpos.w + displayFrame.left;
135 displayFrame.bottom = dpos.h + displayFrame.top;
136 }
137 setMdpFlags(layer, mdpFlags, 0);
138 // For External use rotator if there is a rotation value set
139 if(mDpy && (ctx->mExtOrientation & HWC_TRANSFORM_ROT_90)) {
140 mRot = ctx->mRotMgr->getNext();
141 if(mRot == NULL) return -1;
142 //Configure rotator for pre-rotation
143 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
144 ALOGE("%s: configRotator Failed!", __FUNCTION__);
145 mRot = NULL;
146 return -1;
147 }
148 info.format = (mRot)->getDstFormat();
149 updateSource(orient, info, sourceCrop);
150 rotFlags |= ovutils::ROT_PREROTATED;
151 }
152 //For the mdp, since either we are pre-rotating or MDP does flips
153 orient = ovutils::OVERLAY_TRANSFORM_0;
154 transform = 0;
155 ovutils::PipeArgs parg(mdpFlags, info, zOrder, isFg,
156 static_cast<ovutils::eRotFlags>(rotFlags));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700158 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
159 NULL, mDest) < 0) {
160 ALOGE("%s: ConfigMdp failed for low res", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500161 ret = false;
162 }
163 }
164 return ret;
165}
166
Naseer Ahmed64b81212013-02-14 10:29:47 -0500167bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500168{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800169 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500170 return true;
171 }
172 bool ret = true;
173 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800174 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700175 int fd = hnd->fd;
176 uint32_t offset = hnd->offset;
177 if(mRot) {
178 if(!mRot->queueBuffer(fd, offset))
179 return false;
180 fd = mRot->getDstMemId();
181 offset = mRot->getDstOffset();
182 }
183 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800184 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500185 ret = false;
186 }
187 return ret;
188}
189
Saurabh Shahcf053c62012-12-13 12:32:55 -0800190//================= High res====================================
191FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
192
193inline void FBUpdateHighRes::reset() {
194 IFBUpdate::reset();
195 mDestLeft = ovutils::OV_INVALID;
196 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700197 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800198}
199
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800200bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
201 int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800202 if(!ctx->mMDP.hasOverlay) {
203 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800204 __FUNCTION__);
205 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800206 }
207 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800208 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800209 return mModeOn;
210}
211
212// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500213bool FBUpdateHighRes::configure(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800214 hwc_display_contents_1 *list, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800215 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500216 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800217 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800218 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
219 // ext only layer present..
220 if(extOnlyLayerIndex != -1) {
221 layer = &list->hwLayers[extOnlyLayerIndex];
222 layer->compositionType = HWC_OVERLAY;
223 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800224 overlay::Overlay& ov = *(ctx->mOverlay);
225 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800226 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800227 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800228
229 //Request left RGB pipe
230 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
231 if(destL == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700232 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
233 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800234 return false;
235 }
236 //Request right RGB pipe
237 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
238 if(destR == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700239 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
240 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800241 return false;
242 }
243
244 mDestLeft = destL;
245 mDestRight = destR;
246
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800247 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530248
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800249 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800250
251 ovutils::PipeArgs pargL(mdpFlagsL,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 info,
253 zOrder,
254 ovutils::IS_FG_OFF,
255 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800256 ov.setSource(pargL, destL);
257
258 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
259 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
260 ovutils::PipeArgs pargR(mdpFlagsR,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261 info,
262 zOrder,
263 ovutils::IS_FG_OFF,
264 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800265 ov.setSource(pargR, destR);
266
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800267 hwc_rect_t sourceCrop = layer->sourceCrop;
268 hwc_rect_t displayFrame = layer->displayFrame;
269 if(extOnlyLayerIndex == -1) {
270 getNonWormholeRegion(list, sourceCrop);
271 displayFrame = sourceCrop;
272 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800273 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800274 (sourceCrop.right - sourceCrop.left) / 2,
275 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800276 ovutils::Dim dcropR(
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800277 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
278 sourceCrop.top,
279 (sourceCrop.right - sourceCrop.left) / 2,
280 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800281 ov.setCrop(dcropL, destL);
282 ov.setCrop(dcropR, destR);
283
284 int transform = layer->transform;
285 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800286 static_cast<ovutils::eTransform>(transform);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800287 ov.setTransform(orient, destL);
288 ov.setTransform(orient, destR);
289
Saurabh Shahce416f02013-04-10 13:33:09 -0700290 const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
291 const int height = displayFrame.bottom - displayFrame.top;
292
Saurabh Shahca317592013-05-02 14:53:58 -0700293 const int halfDpy = ctx->dpyAttr[mDpy].xres / 2;
294 ovutils::Dim dposL(halfDpy - halfWidth,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800295 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700296 halfWidth,
297 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700298 ov.setPosition(dposL, destL);
Saurabh Shahce416f02013-04-10 13:33:09 -0700299
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700300 ovutils::Dim dposR(0,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800301 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700302 halfWidth,
303 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700304 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800305
306 ret = true;
307 if (!ov.commit(destL)) {
308 ALOGE("%s: commit fails for left", __FUNCTION__);
309 ret = false;
310 }
311 if (!ov.commit(destR)) {
312 ALOGE("%s: commit fails for right", __FUNCTION__);
313 ret = false;
314 }
315 }
316 return ret;
317}
318
Naseer Ahmed64b81212013-02-14 10:29:47 -0500319bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800320{
321 if(!mModeOn) {
322 return true;
323 }
324 bool ret = true;
325 overlay::Overlay& ov = *(ctx->mOverlay);
326 ovutils::eDest destL = mDestLeft;
327 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800328 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
329 ALOGE("%s: queue failed for left of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800330 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800331 ret = false;
332 }
333 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
334 ALOGE("%s: queue failed for right of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800335 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800336 ret = false;
337 }
338 return ret;
339}
340
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500341//---------------------------------------------------------------------
342}; //namespace qhwc