blob: a0dbbe386c50eb6177ada14f00f74ef2f842a6e4 [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
49bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer) {
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 }
Saurabh Shahcf053c62012-12-13 12:32:55 -080055 mModeOn = configure(ctx, fblayer);
56 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
57 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050058}
59
60// Configure
Saurabh Shahcf053c62012-12-13 12:32:55 -080061bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer)
Naseer Ahmed758bfc52012-11-28 17:02:08 -050062{
63 bool ret = false;
64 if (LIKELY(ctx->mOverlay)) {
65 overlay::Overlay& ov = *(ctx->mOverlay);
66 private_handle_t *hnd = (private_handle_t *)layer->handle;
67 if (!hnd) {
68 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
69 return false;
70 }
71 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
72
73 //Request an RGB pipe
Saurabh Shahcf053c62012-12-13 12:32:55 -080074 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050075 if(dest == ovutils::OV_INVALID) { //None available
76 return false;
77 }
78
Saurabh Shahcf053c62012-12-13 12:32:55 -080079 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080
81 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050082
83 ovutils::PipeArgs parg(mdpFlags,
84 info,
85 ovutils::ZORDER_0,
86 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080087 ovutils::ROT_FLAGS_NONE);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050088 ov.setSource(parg, dest);
89
90 hwc_rect_t sourceCrop = layer->sourceCrop;
91 // x,y,w,h
92 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
93 sourceCrop.right - sourceCrop.left,
94 sourceCrop.bottom - sourceCrop.top);
95 ov.setCrop(dcrop, dest);
96
97 int transform = layer->transform;
98 ovutils::eTransform orient =
99 static_cast<ovutils::eTransform>(transform);
100 ov.setTransform(orient, dest);
101
102 hwc_rect_t displayFrame = layer->displayFrame;
103 ovutils::Dim dpos(displayFrame.left,
104 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
Saurabh Shahcf053c62012-12-13 12:32:55 -0800121bool FBUpdateLowRes::draw(hwc_context_t *ctx, hwc_layer_1_t *layer)
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 private_handle_t *hnd = (private_handle_t *)layer->handle;
130 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800131 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 ret = false;
133 }
134 return ret;
135}
136
Saurabh Shahcf053c62012-12-13 12:32:55 -0800137//================= High res====================================
138FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
139
140inline void FBUpdateHighRes::reset() {
141 IFBUpdate::reset();
142 mDestLeft = ovutils::OV_INVALID;
143 mDestRight = ovutils::OV_INVALID;
144}
145
146bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer) {
147 if(!ctx->mMDP.hasOverlay) {
148 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
149 __FUNCTION__);
150 return false;
151 }
152 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
153 mModeOn = configure(ctx, fblayer);
154 return mModeOn;
155}
156
157// Configure
158bool FBUpdateHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer)
159{
160 bool ret = false;
161 if (LIKELY(ctx->mOverlay)) {
162 overlay::Overlay& ov = *(ctx->mOverlay);
163 private_handle_t *hnd = (private_handle_t *)layer->handle;
164 if (!hnd) {
165 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
166 return false;
167 }
168 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
169
170 //Request left RGB pipe
171 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
172 if(destL == ovutils::OV_INVALID) { //None available
173 return false;
174 }
175 //Request right RGB pipe
176 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
177 if(destR == ovutils::OV_INVALID) { //None available
178 return false;
179 }
180
181 mDestLeft = destL;
182 mDestRight = destR;
183
184 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800185
186 ovutils::PipeArgs pargL(mdpFlagsL,
187 info,
188 ovutils::ZORDER_0,
189 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800190 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,
196 info,
197 ovutils::ZORDER_0,
198 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800199 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800200 ov.setSource(pargR, destR);
201
202 hwc_rect_t sourceCrop = layer->sourceCrop;
203 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
204 (sourceCrop.right - sourceCrop.left) / 2,
205 sourceCrop.bottom - sourceCrop.top);
206 ovutils::Dim dcropR(
207 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
208 sourceCrop.top,
209 (sourceCrop.right - sourceCrop.left) / 2,
210 sourceCrop.bottom - sourceCrop.top);
211 ov.setCrop(dcropL, destL);
212 ov.setCrop(dcropR, destR);
213
214 int transform = layer->transform;
215 ovutils::eTransform orient =
216 static_cast<ovutils::eTransform>(transform);
217 ov.setTransform(orient, destL);
218 ov.setTransform(orient, destR);
219
220 hwc_rect_t displayFrame = layer->displayFrame;
221 //For FB left, top will always be 0
222 //That should also be the case if using 2 mixers for single display
223 ovutils::Dim dpos(displayFrame.left,
224 displayFrame.top,
225 (displayFrame.right - displayFrame.left) / 2,
226 displayFrame.bottom - displayFrame.top);
227 ov.setPosition(dpos, destL);
228 ov.setPosition(dpos, destR);
229
230 ret = true;
231 if (!ov.commit(destL)) {
232 ALOGE("%s: commit fails for left", __FUNCTION__);
233 ret = false;
234 }
235 if (!ov.commit(destR)) {
236 ALOGE("%s: commit fails for right", __FUNCTION__);
237 ret = false;
238 }
239 }
240 return ret;
241}
242
243bool FBUpdateHighRes::draw(hwc_context_t *ctx, hwc_layer_1_t *layer)
244{
245 if(!mModeOn) {
246 return true;
247 }
248 bool ret = true;
249 overlay::Overlay& ov = *(ctx->mOverlay);
250 ovutils::eDest destL = mDestLeft;
251 ovutils::eDest destR = mDestRight;
252 private_handle_t *hnd = (private_handle_t *)layer->handle;
253 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
254 ALOGE("%s: queue failed for left of dpy = %d",
255 __FUNCTION__, mDpy);
256 ret = false;
257 }
258 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
259 ALOGE("%s: queue failed for right of dpy = %d",
260 __FUNCTION__, mDpy);
261 ret = false;
262 }
263 return ret;
264}
265
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500266//---------------------------------------------------------------------
267}; //namespace qhwc