blob: b8e697600193dd1ae3ba1c46e1166453ddb60880 [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"
Naseer Ahmed758bfc52012-11-28 17:02:08 -050024
25namespace qhwc {
26
27namespace ovutils = overlay::utils;
28
Saurabh Shahcf053c62012-12-13 12:32:55 -080029IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
30 if(width > MAX_DISPLAY_DIM) {
31 return new FBUpdateHighRes(dpy);
32 }
33 return new FBUpdateLowRes(dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050034}
35
Saurabh Shahcf053c62012-12-13 12:32:55 -080036inline void IFBUpdate::reset() {
37 mModeOn = false;
38}
39
40//================= Low res====================================
41FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
42
43inline void FBUpdateLowRes::reset() {
44 IFBUpdate::reset();
45 mDest = ovutils::OV_INVALID;
46}
47
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080048bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
49 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050050 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080051 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080052 __FUNCTION__);
53 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080055 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -080056 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050057}
58
59// Configure
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080060bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
61 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050063 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050064 if (LIKELY(ctx->mOverlay)) {
65 overlay::Overlay& ov = *(ctx->mOverlay);
66 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080067 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080068 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050069
70 //Request an RGB pipe
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080071 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050072 if(dest == ovutils::OV_INVALID) { //None available
73 return false;
74 }
75
Saurabh Shahcf053c62012-12-13 12:32:55 -080076 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050077
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080078 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +053079
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080080 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050081
82 ovutils::PipeArgs parg(mdpFlags,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 info,
84 zOrder,
85 ovutils::IS_FG_OFF,
86 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 ov.setSource(parg, dest);
88
Naseer Ahmed64b81212013-02-14 10:29:47 -050089 hwc_rect_t sourceCrop;
90 getNonWormholeRegion(list, sourceCrop);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050091 // x,y,w,h
92 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080093 sourceCrop.right - sourceCrop.left,
94 sourceCrop.bottom - sourceCrop.top);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095 ov.setCrop(dcrop, dest);
96
97 int transform = layer->transform;
98 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080099 static_cast<ovutils::eTransform>(transform);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500100 ov.setTransform(orient, dest);
101
Naseer Ahmed64b81212013-02-14 10:29:47 -0500102 hwc_rect_t displayFrame = sourceCrop;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500103 ovutils::Dim dpos(displayFrame.left,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800104 displayFrame.top,
105 displayFrame.right - displayFrame.left,
106 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800107 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
108 if(mDpy)
109 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500110 ov.setPosition(dpos, dest);
111
112 ret = true;
113 if (!ov.commit(dest)) {
114 ALOGE("%s: commit fails", __FUNCTION__);
115 ret = false;
116 }
117 }
118 return ret;
119}
120
Naseer Ahmed64b81212013-02-14 10:29:47 -0500121bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800123 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 return true;
125 }
126 bool ret = true;
127 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800128 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800130 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 ret = false;
132 }
133 return ret;
134}
135
Saurabh Shahcf053c62012-12-13 12:32:55 -0800136//================= High res====================================
137FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
138
139inline void FBUpdateHighRes::reset() {
140 IFBUpdate::reset();
141 mDestLeft = ovutils::OV_INVALID;
142 mDestRight = ovutils::OV_INVALID;
143}
144
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800145bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
146 int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800147 if(!ctx->mMDP.hasOverlay) {
148 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800149 __FUNCTION__);
150 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800151 }
152 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800153 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800154 return mModeOn;
155}
156
157// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500158bool FBUpdateHighRes::configure(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800159 hwc_display_contents_1 *list, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800160 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500161 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800162 if (LIKELY(ctx->mOverlay)) {
163 overlay::Overlay& ov = *(ctx->mOverlay);
164 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800165 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800166 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800167
168 //Request left RGB pipe
169 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
170 if(destL == ovutils::OV_INVALID) { //None available
171 return false;
172 }
173 //Request right RGB pipe
174 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
175 if(destR == ovutils::OV_INVALID) { //None available
176 return false;
177 }
178
179 mDestLeft = destL;
180 mDestRight = destR;
181
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800182 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530183
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800184 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800185
186 ovutils::PipeArgs pargL(mdpFlagsL,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800187 info,
188 zOrder,
189 ovutils::IS_FG_OFF,
190 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800191 ov.setSource(pargL, destL);
192
193 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
194 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
195 ovutils::PipeArgs pargR(mdpFlagsR,
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(pargR, destR);
201
Naseer Ahmed64b81212013-02-14 10:29:47 -0500202 hwc_rect_t sourceCrop;
203 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800204 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205 (sourceCrop.right - sourceCrop.left) / 2,
206 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800207 ovutils::Dim dcropR(
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800208 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
209 sourceCrop.top,
210 (sourceCrop.right - sourceCrop.left) / 2,
211 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800212 ov.setCrop(dcropL, destL);
213 ov.setCrop(dcropR, destR);
214
215 int transform = layer->transform;
216 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800217 static_cast<ovutils::eTransform>(transform);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800218 ov.setTransform(orient, destL);
219 ov.setTransform(orient, destR);
220
Naseer Ahmed64b81212013-02-14 10:29:47 -0500221 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahce416f02013-04-10 13:33:09 -0700222 const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
223 const int height = displayFrame.bottom - displayFrame.top;
224
225 ovutils::Dim dposL(MAX_DISPLAY_DIM - halfWidth,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800226 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700227 halfWidth,
228 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700229 ov.setPosition(dposL, destL);
Saurabh Shahce416f02013-04-10 13:33:09 -0700230
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700231 ovutils::Dim dposR(0,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700233 halfWidth,
234 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700235 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800236
237 ret = true;
238 if (!ov.commit(destL)) {
239 ALOGE("%s: commit fails for left", __FUNCTION__);
240 ret = false;
241 }
242 if (!ov.commit(destR)) {
243 ALOGE("%s: commit fails for right", __FUNCTION__);
244 ret = false;
245 }
246 }
247 return ret;
248}
249
Naseer Ahmed64b81212013-02-14 10:29:47 -0500250bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800251{
252 if(!mModeOn) {
253 return true;
254 }
255 bool ret = true;
256 overlay::Overlay& ov = *(ctx->mOverlay);
257 ovutils::eDest destL = mDestLeft;
258 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800259 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
260 ALOGE("%s: queue failed for left of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800261 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800262 ret = false;
263 }
264 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
265 ALOGE("%s: queue failed for right of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800267 ret = false;
268 }
269 return ret;
270}
271
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500272//---------------------------------------------------------------------
273}; //namespace qhwc