blob: 18f75ebffa9dd6a7ce3d285dc1461ca589c56bb0 [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);
107 ov.setPosition(dpos, dest);
108
109 ret = true;
110 if (!ov.commit(dest)) {
111 ALOGE("%s: commit fails", __FUNCTION__);
112 ret = false;
113 }
114 }
115 return ret;
116}
117
Saurabh Shahcf053c62012-12-13 12:32:55 -0800118bool FBUpdateLowRes::draw(hwc_context_t *ctx, hwc_layer_1_t *layer)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800120 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 return true;
122 }
123 bool ret = true;
124 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800125 ovutils::eDest dest = mDest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126 private_handle_t *hnd = (private_handle_t *)layer->handle;
127 if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800128 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 ret = false;
130 }
131 return ret;
132}
133
Saurabh Shahcf053c62012-12-13 12:32:55 -0800134//================= High res====================================
135FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
136
137inline void FBUpdateHighRes::reset() {
138 IFBUpdate::reset();
139 mDestLeft = ovutils::OV_INVALID;
140 mDestRight = ovutils::OV_INVALID;
141}
142
143bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer) {
144 if(!ctx->mMDP.hasOverlay) {
145 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
146 __FUNCTION__);
147 return false;
148 }
149 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
150 mModeOn = configure(ctx, fblayer);
151 return mModeOn;
152}
153
154// Configure
155bool FBUpdateHighRes::configure(hwc_context_t *ctx, hwc_layer_1_t *layer)
156{
157 bool ret = false;
158 if (LIKELY(ctx->mOverlay)) {
159 overlay::Overlay& ov = *(ctx->mOverlay);
160 private_handle_t *hnd = (private_handle_t *)layer->handle;
161 if (!hnd) {
162 ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
163 return false;
164 }
165 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
166
167 //Request left RGB pipe
168 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
169 if(destL == ovutils::OV_INVALID) { //None available
170 return false;
171 }
172 //Request right RGB pipe
173 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
174 if(destR == ovutils::OV_INVALID) { //None available
175 return false;
176 }
177
178 mDestLeft = destL;
179 mDestRight = destR;
180
181 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800182
183 ovutils::PipeArgs pargL(mdpFlagsL,
184 info,
185 ovutils::ZORDER_0,
186 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800187 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800188 ov.setSource(pargL, destL);
189
190 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
191 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
192 ovutils::PipeArgs pargR(mdpFlagsR,
193 info,
194 ovutils::ZORDER_0,
195 ovutils::IS_FG_SET,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800196 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800197 ov.setSource(pargR, destR);
198
199 hwc_rect_t sourceCrop = layer->sourceCrop;
200 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
201 (sourceCrop.right - sourceCrop.left) / 2,
202 sourceCrop.bottom - sourceCrop.top);
203 ovutils::Dim dcropR(
204 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
205 sourceCrop.top,
206 (sourceCrop.right - sourceCrop.left) / 2,
207 sourceCrop.bottom - sourceCrop.top);
208 ov.setCrop(dcropL, destL);
209 ov.setCrop(dcropR, destR);
210
211 int transform = layer->transform;
212 ovutils::eTransform orient =
213 static_cast<ovutils::eTransform>(transform);
214 ov.setTransform(orient, destL);
215 ov.setTransform(orient, destR);
216
217 hwc_rect_t displayFrame = layer->displayFrame;
218 //For FB left, top will always be 0
219 //That should also be the case if using 2 mixers for single display
220 ovutils::Dim dpos(displayFrame.left,
221 displayFrame.top,
222 (displayFrame.right - displayFrame.left) / 2,
223 displayFrame.bottom - displayFrame.top);
224 ov.setPosition(dpos, destL);
225 ov.setPosition(dpos, destR);
226
227 ret = true;
228 if (!ov.commit(destL)) {
229 ALOGE("%s: commit fails for left", __FUNCTION__);
230 ret = false;
231 }
232 if (!ov.commit(destR)) {
233 ALOGE("%s: commit fails for right", __FUNCTION__);
234 ret = false;
235 }
236 }
237 return ret;
238}
239
240bool FBUpdateHighRes::draw(hwc_context_t *ctx, hwc_layer_1_t *layer)
241{
242 if(!mModeOn) {
243 return true;
244 }
245 bool ret = true;
246 overlay::Overlay& ov = *(ctx->mOverlay);
247 ovutils::eDest destL = mDestLeft;
248 ovutils::eDest destR = mDestRight;
249 private_handle_t *hnd = (private_handle_t *)layer->handle;
250 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
251 ALOGE("%s: queue failed for left of dpy = %d",
252 __FUNCTION__, mDpy);
253 ret = false;
254 }
255 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
256 ALOGE("%s: queue failed for right of dpy = %d",
257 __FUNCTION__, mDpy);
258 ret = false;
259 }
260 return ret;
261}
262
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500263//---------------------------------------------------------------------
264}; //namespace qhwc