blob: 7a740ee7bcac027ab531f5610b1fd03bb691cce4 [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
Naseer Ahmed64b81212013-02-14 10:29:47 -050048bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
49{
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",
Naseer Ahmed758bfc52012-11-28 17:02:08 -050052 __FUNCTION__);
53 return false;
54 }
Naseer Ahmed64b81212013-02-14 10:29:47 -050055 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -080056 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
57 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058}
59
60// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -050061bool FBUpdateLowRes::configure(hwc_context_t *ctx,
62 hwc_display_contents_1 *list)
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063{
64 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050065 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066 if (LIKELY(ctx->mOverlay)) {
67 overlay::Overlay& ov = *(ctx->mOverlay);
68 private_handle_t *hnd = (private_handle_t *)layer->handle;
69 if (!hnd) {
70 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
71 return false;
72 }
Saurabh Shahacf10202013-02-26 10:15:15 -080073 ovutils::Whf info(hnd->width, hnd->height,
74 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075
76 //Request an RGB pipe
Saurabh Shahcf053c62012-12-13 12:32:55 -080077 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050078 if(dest == ovutils::OV_INVALID) { //None available
79 return false;
80 }
81
Saurabh Shahcf053c62012-12-13 12:32:55 -080082 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050083
84 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050085
86 ovutils::PipeArgs parg(mdpFlags,
87 info,
88 ovutils::ZORDER_0,
89 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080090 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050091 ov.setSource(parg, dest);
92
Naseer Ahmed64b81212013-02-14 10:29:47 -050093 hwc_rect_t sourceCrop;
94 getNonWormholeRegion(list, sourceCrop);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050095 // x,y,w,h
96 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
97 sourceCrop.right - sourceCrop.left,
98 sourceCrop.bottom - sourceCrop.top);
99 ov.setCrop(dcrop, dest);
100
101 int transform = layer->transform;
102 ovutils::eTransform orient =
103 static_cast<ovutils::eTransform>(transform);
104 ov.setTransform(orient, dest);
105
Naseer Ahmed64b81212013-02-14 10:29:47 -0500106 hwc_rect_t displayFrame = sourceCrop;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500107 ovutils::Dim dpos(displayFrame.left,
108 displayFrame.top,
109 displayFrame.right - displayFrame.left,
110 displayFrame.bottom - displayFrame.top);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800111 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
112 if(mDpy)
113 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500114 ov.setPosition(dpos, dest);
115
116 ret = true;
117 if (!ov.commit(dest)) {
118 ALOGE("%s: commit fails", __FUNCTION__);
119 ret = false;
120 }
121 }
122 return ret;
123}
124
Naseer Ahmed64b81212013-02-14 10:29:47 -0500125bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800127 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 return true;
129 }
130 bool ret = true;
131 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800132 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800134 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500135 ret = false;
136 }
137 return ret;
138}
139
Saurabh Shahcf053c62012-12-13 12:32:55 -0800140//================= High res====================================
141FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
142
143inline void FBUpdateHighRes::reset() {
144 IFBUpdate::reset();
145 mDestLeft = ovutils::OV_INVALID;
146 mDestRight = ovutils::OV_INVALID;
147}
148
Naseer Ahmed64b81212013-02-14 10:29:47 -0500149bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
150{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800151 if(!ctx->mMDP.hasOverlay) {
152 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
153 __FUNCTION__);
154 return false;
155 }
156 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500157 mModeOn = configure(ctx, list);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800158 return mModeOn;
159}
160
161// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500162bool FBUpdateHighRes::configure(hwc_context_t *ctx,
163 hwc_display_contents_1 *list)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800164{
165 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;
170 if (!hnd) {
171 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
172 return false;
173 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800174 ovutils::Whf info(hnd->width, hnd->height,
175 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800176
177 //Request left RGB pipe
178 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
179 if(destL == ovutils::OV_INVALID) { //None available
180 return false;
181 }
182 //Request right RGB pipe
183 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
184 if(destR == ovutils::OV_INVALID) { //None available
185 return false;
186 }
187
188 mDestLeft = destL;
189 mDestRight = destR;
190
191 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800192
193 ovutils::PipeArgs pargL(mdpFlagsL,
194 info,
195 ovutils::ZORDER_0,
196 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800197 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800198 ov.setSource(pargL, destL);
199
200 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
201 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
202 ovutils::PipeArgs pargR(mdpFlagsR,
203 info,
204 ovutils::ZORDER_0,
205 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800206 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800207 ov.setSource(pargR, destR);
208
Naseer Ahmed64b81212013-02-14 10:29:47 -0500209 hwc_rect_t sourceCrop;
210 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800211 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
212 (sourceCrop.right - sourceCrop.left) / 2,
213 sourceCrop.bottom - sourceCrop.top);
214 ovutils::Dim dcropR(
215 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
216 sourceCrop.top,
217 (sourceCrop.right - sourceCrop.left) / 2,
218 sourceCrop.bottom - sourceCrop.top);
219 ov.setCrop(dcropL, destL);
220 ov.setCrop(dcropR, destR);
221
222 int transform = layer->transform;
223 ovutils::eTransform orient =
224 static_cast<ovutils::eTransform>(transform);
225 ov.setTransform(orient, destL);
226 ov.setTransform(orient, destR);
227
Naseer Ahmed64b81212013-02-14 10:29:47 -0500228 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800229 //For FB left, top will always be 0
230 //That should also be the case if using 2 mixers for single display
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700231 ovutils::Dim dposL(displayFrame.left,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800232 displayFrame.top,
233 (displayFrame.right - displayFrame.left) / 2,
234 displayFrame.bottom - displayFrame.top);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700235 ov.setPosition(dposL, destL);
236 ovutils::Dim dposR(0,
237 displayFrame.top,
238 (displayFrame.right - displayFrame.left) / 2,
239 displayFrame.bottom - displayFrame.top);
240 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800241
242 ret = true;
243 if (!ov.commit(destL)) {
244 ALOGE("%s: commit fails for left", __FUNCTION__);
245 ret = false;
246 }
247 if (!ov.commit(destR)) {
248 ALOGE("%s: commit fails for right", __FUNCTION__);
249 ret = false;
250 }
251 }
252 return ret;
253}
254
Naseer Ahmed64b81212013-02-14 10:29:47 -0500255bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800256{
257 if(!mModeOn) {
258 return true;
259 }
260 bool ret = true;
261 overlay::Overlay& ov = *(ctx->mOverlay);
262 ovutils::eDest destL = mDestLeft;
263 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800264 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
265 ALOGE("%s: queue failed for left of dpy = %d",
266 __FUNCTION__, mDpy);
267 ret = false;
268 }
269 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
270 ALOGE("%s: queue failed for right of dpy = %d",
271 __FUNCTION__, mDpy);
272 ret = false;
273 }
274 return ret;
275}
276
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500277//---------------------------------------------------------------------
278}; //namespace qhwc