blob: e79523d02fa2e9f51aba94b69316d9fdcd21681e [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>
23#include <fb_priv.h>
24#include "hwc_fbupdate.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;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086
87 ovutils::PipeArgs parg(mdpFlags,
88 info,
89 ovutils::ZORDER_0,
90 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080091 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,
98 sourceCrop.right - sourceCrop.left,
99 sourceCrop.bottom - sourceCrop.top);
100 ov.setCrop(dcrop, dest);
101
102 int transform = layer->transform;
103 ovutils::eTransform orient =
104 static_cast<ovutils::eTransform>(transform);
105 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,
109 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
Naseer Ahmed64b81212013-02-14 10:29:47 -0500150bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list)
151{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800152 if(!ctx->mMDP.hasOverlay) {
153 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
154 __FUNCTION__);
155 return false;
156 }
157 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500158 mModeOn = configure(ctx, list);
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,
164 hwc_display_contents_1 *list)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800165{
166 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500167 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800168 if (LIKELY(ctx->mOverlay)) {
169 overlay::Overlay& ov = *(ctx->mOverlay);
170 private_handle_t *hnd = (private_handle_t *)layer->handle;
171 if (!hnd) {
172 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
173 return false;
174 }
Saurabh Shahacf10202013-02-26 10:15:15 -0800175 ovutils::Whf info(hnd->width, hnd->height,
176 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800177
178 //Request left RGB pipe
179 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
180 if(destL == ovutils::OV_INVALID) { //None available
181 return false;
182 }
183 //Request right RGB pipe
184 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
185 if(destR == ovutils::OV_INVALID) { //None available
186 return false;
187 }
188
189 mDestLeft = destL;
190 mDestRight = destR;
191
192 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800193
194 ovutils::PipeArgs pargL(mdpFlagsL,
195 info,
196 ovutils::ZORDER_0,
197 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800198 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800199 ov.setSource(pargL, destL);
200
201 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
202 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
203 ovutils::PipeArgs pargR(mdpFlagsR,
204 info,
205 ovutils::ZORDER_0,
206 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800207 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800208 ov.setSource(pargR, destR);
209
Naseer Ahmed64b81212013-02-14 10:29:47 -0500210 hwc_rect_t sourceCrop;
211 getNonWormholeRegion(list, sourceCrop);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800212 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
213 (sourceCrop.right - sourceCrop.left) / 2,
214 sourceCrop.bottom - sourceCrop.top);
215 ovutils::Dim dcropR(
216 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
217 sourceCrop.top,
218 (sourceCrop.right - sourceCrop.left) / 2,
219 sourceCrop.bottom - sourceCrop.top);
220 ov.setCrop(dcropL, destL);
221 ov.setCrop(dcropR, destR);
222
223 int transform = layer->transform;
224 ovutils::eTransform orient =
225 static_cast<ovutils::eTransform>(transform);
226 ov.setTransform(orient, destL);
227 ov.setTransform(orient, destR);
228
Naseer Ahmed64b81212013-02-14 10:29:47 -0500229 hwc_rect_t displayFrame = sourceCrop;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800230 //For FB left, top will always be 0
231 //That should also be the case if using 2 mixers for single display
232 ovutils::Dim dpos(displayFrame.left,
233 displayFrame.top,
234 (displayFrame.right - displayFrame.left) / 2,
235 displayFrame.bottom - displayFrame.top);
236 ov.setPosition(dpos, destL);
237 ov.setPosition(dpos, destR);
238
239 ret = true;
240 if (!ov.commit(destL)) {
241 ALOGE("%s: commit fails for left", __FUNCTION__);
242 ret = false;
243 }
244 if (!ov.commit(destR)) {
245 ALOGE("%s: commit fails for right", __FUNCTION__);
246 ret = false;
247 }
248 }
249 return ret;
250}
251
Naseer Ahmed64b81212013-02-14 10:29:47 -0500252bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800253{
254 if(!mModeOn) {
255 return true;
256 }
257 bool ret = true;
258 overlay::Overlay& ov = *(ctx->mOverlay);
259 ovutils::eDest destL = mDestLeft;
260 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800261 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
262 ALOGE("%s: queue failed for left of dpy = %d",
263 __FUNCTION__, mDpy);
264 ret = false;
265 }
266 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
267 ALOGE("%s: queue failed for right of dpy = %d",
268 __FUNCTION__, mDpy);
269 ret = false;
270 }
271 return ret;
272}
273
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500274//---------------------------------------------------------------------
275}; //namespace qhwc