blob: 2166a5b33de60121e5da36fd274155c2b23fac14 [file] [log] [blame]
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08003 * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained for
6 * attribution purposes only
Naseer Ahmedf48aef62012-07-20 09:05:53 -07007 *
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
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#define VIDEO_DEBUG 0
22#include <overlay.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070023#include "hwc_video.h"
Saurabh Shah3e858eb2012-09-17 16:53:21 -070024#include "hwc_utils.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080025#include "qdMetaData.h"
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -080026#include "mdp_version.h"
Saurabh Shahacf10202013-02-26 10:15:15 -080027#include <overlayRotator.h>
28
29using overlay::Rotator;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070030
31namespace qhwc {
32
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033namespace ovutils = overlay::utils;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070034
Saurabh Shahacf10202013-02-26 10:15:15 -080035//===========IVideoOverlay=========================
36IVideoOverlay* IVideoOverlay::getObject(const int& width, const int& dpy) {
37 if(width > MAX_DISPLAY_DIM) {
38 return new VideoOverlayHighRes(dpy);
39 }
40 return new VideoOverlayLowRes(dpy);
41}
42
43//===========VideoOverlayLowRes=========================
44
45VideoOverlayLowRes::VideoOverlayLowRes(const int& dpy): IVideoOverlay(dpy) {}
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046
47//Cache stats, figure out the state, config overlay
Saurabh Shahacf10202013-02-26 10:15:15 -080048bool VideoOverlayLowRes::prepare(hwc_context_t *ctx,
49 hwc_display_contents_1_t *list) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -070050
Saurabh Shahacf10202013-02-26 10:15:15 -080051 if(ctx->listStats[mDpy].yuvCount > 1)
Jeykumar Sankarancf537002013-01-21 21:19:15 -080052 return false;
53
Saurabh Shahacf10202013-02-26 10:15:15 -080054 int yuvIndex = ctx->listStats[mDpy].yuvIndices[0];
55 int hw_w = ctx->dpyAttr[mDpy].xres;
56 mModeOn = false;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080057
58 if(hw_w > MAX_DISPLAY_DIM) {
59 ALOGD_IF(VIDEO_DEBUG,"%s, \
60 Cannot use video path for High Res Panels", __FUNCTION__);
61 return false;
62 }
63
Naseer Ahmed96c4c952012-07-25 18:27:14 -070064 if(!ctx->mMDP.hasOverlay) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -070065 ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__);
66 return false;
67 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -070068
Naseer Ahmed54821fe2012-11-28 18:44:38 -050069 if(isSecuring(ctx)) {
70 ALOGD_IF(VIDEO_DEBUG,"%s: MDP Secure is active", __FUNCTION__);
71 return false;
72 }
73
Saurabh Shahacf10202013-02-26 10:15:15 -080074 if(yuvIndex == -1 || ctx->listStats[mDpy].yuvCount != 1) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070075 return false;
76 }
Naseer Ahmed4c588a22012-07-31 19:12:17 -070077
Saurabh Shah3e858eb2012-09-17 16:53:21 -070078 //index guaranteed to be not -1 at this point
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079 hwc_layer_1_t *layer = &list->hwLayers[yuvIndex];
Sushil Chauhan2515abf2013-01-08 16:40:05 -080080 if (isSecureModePolicy(ctx->mMDP.version)) {
81 private_handle_t *hnd = (private_handle_t *)layer->handle;
82 if(ctx->mSecureMode) {
83 if (! isSecureBuffer(hnd)) {
84 ALOGD_IF(VIDEO_DEBUG, "%s: Handle non-secure video layer"
85 "during secure playback gracefully", __FUNCTION__);
86 return false;
87 }
88 } else {
89 if (isSecureBuffer(hnd)) {
90 ALOGD_IF(VIDEO_DEBUG, "%s: Handle secure video layer"
91 "during non-secure playback gracefully", __FUNCTION__);
92 return false;
93 }
Naseer Ahmedcb5f25b2012-10-04 15:56:00 -040094 }
Naseer Ahmed68b88cf2012-10-02 14:15:12 -040095 }
Saurabh Shahacf10202013-02-26 10:15:15 -080096
97 if(configure(ctx, layer)) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098 markFlags(layer);
Saurabh Shahacf10202013-02-26 10:15:15 -080099 mModeOn = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100 }
101
Saurabh Shahacf10202013-02-26 10:15:15 -0800102 return mModeOn;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103}
104
Saurabh Shahacf10202013-02-26 10:15:15 -0800105void VideoOverlayLowRes::markFlags(hwc_layer_1_t *layer) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500106 if(layer) {
107 layer->compositionType = HWC_OVERLAY;
108 layer->hints |= HWC_HINT_CLEAR_FB;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109 }
110}
111
Saurabh Shahacf10202013-02-26 10:15:15 -0800112bool VideoOverlayLowRes::configure(hwc_context_t *ctx,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500113 hwc_layer_1_t *layer) {
Saurabh Shahacf10202013-02-26 10:15:15 -0800114
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500115 overlay::Overlay& ov = *(ctx->mOverlay);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700116 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800117 ovutils::Whf info(hnd->width, hnd->height,
118 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700119
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500120 //Request a VG pipe
Saurabh Shahacf10202013-02-26 10:15:15 -0800121 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 if(dest == ovutils::OV_INVALID) { //None available
123 return false;
124 }
125
Saurabh Shahacf10202013-02-26 10:15:15 -0800126 mDest = dest;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700127 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shahacf10202013-02-26 10:15:15 -0800128 ovutils::eZorder zOrder = ovutils::ZORDER_1;
129 ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
130 if (ctx->listStats[mDpy].numAppLayers == 1) {
131 isFg = ovutils::IS_FG_SET;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700132 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700133
Saurabh Shahacf10202013-02-26 10:15:15 -0800134 return (configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest,
135 &mRot) == 0 );
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700136}
137
Saurabh Shahacf10202013-02-26 10:15:15 -0800138bool VideoOverlayLowRes::draw(hwc_context_t *ctx,
139 hwc_display_contents_1_t *list) {
140 if(!mModeOn) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700141 return true;
142 }
143
Saurabh Shahacf10202013-02-26 10:15:15 -0800144 int yuvIndex = ctx->listStats[mDpy].yuvIndices[0];
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700145 if(yuvIndex == -1) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146 return true;
147 }
148
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700149 private_handle_t *hnd = (private_handle_t *)
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700150 list->hwLayers[yuvIndex].handle;
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700151
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahacf10202013-02-26 10:15:15 -0800153 int fd = hnd->fd;
154 uint32_t offset = hnd->offset;
155 Rotator *rot = mRot;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156
Saurabh Shahacf10202013-02-26 10:15:15 -0800157 if(rot) {
158 if(!rot->queueBuffer(fd, offset))
159 return false;
160 fd = rot->getDstMemId();
161 offset = rot->getDstOffset();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163
Saurabh Shahacf10202013-02-26 10:15:15 -0800164 if (!ov.queueBuffer(fd, offset, mDest)) {
165 ALOGE("%s: queueBuffer failed for dpy=%d", __FUNCTION__, mDpy);
166 return false;
167 }
168
169 return true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700170}
171
Saurabh Shahacf10202013-02-26 10:15:15 -0800172//===========VideoOverlayHighRes=========================
173
174VideoOverlayHighRes::VideoOverlayHighRes(const int& dpy): IVideoOverlay(dpy) {}
175
176//Cache stats, figure out the state, config overlay
177bool VideoOverlayHighRes::prepare(hwc_context_t *ctx,
178 hwc_display_contents_1_t *list) {
179
180 int yuvIndex = ctx->listStats[mDpy].yuvIndices[0];
181 int hw_w = ctx->dpyAttr[mDpy].xres;
182 mModeOn = false;
183
184 if(!ctx->mMDP.hasOverlay) {
185 ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__);
186 return false;
187 }
188
189 if(yuvIndex == -1 || ctx->listStats[mDpy].yuvCount != 1) {
190 return false;
191 }
192
193 //index guaranteed to be not -1 at this point
194 hwc_layer_1_t *layer = &list->hwLayers[yuvIndex];
195 if(configure(ctx, layer)) {
196 markFlags(layer);
197 mModeOn = true;
198 }
199
200 return mModeOn;
201}
202
203void VideoOverlayHighRes::markFlags(hwc_layer_1_t *layer) {
204 if(layer) {
205 layer->compositionType = HWC_OVERLAY;
206 layer->hints |= HWC_HINT_CLEAR_FB;
207 }
208}
209
210bool VideoOverlayHighRes::configure(hwc_context_t *ctx,
211 hwc_layer_1_t *layer) {
212
213 int hw_w = ctx->dpyAttr[mDpy].xres;
214 overlay::Overlay& ov = *(ctx->mOverlay);
215 private_handle_t *hnd = (private_handle_t *)layer->handle;
216 ovutils::Whf info(hnd->width, hnd->height,
217 ovutils::getMdpFormat(hnd->format), hnd->size);
218
219 //Request a VG pipe
220 mDestL = ovutils::OV_INVALID;
221 mDestR = ovutils::OV_INVALID;
222 hwc_rect_t dst = layer->displayFrame;
223 if(dst.left > hw_w/2) {
224 mDestR = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
225 if(mDestR == ovutils::OV_INVALID)
226 return false;
227 } else if (dst.right <= hw_w/2) {
228 mDestL = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
229 if(mDestL == ovutils::OV_INVALID)
230 return false;
231 } else {
232 mDestL = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
233 mDestR = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy);
234 if(mDestL == ovutils::OV_INVALID ||
235 mDestR == ovutils::OV_INVALID)
236 return false;
237 }
238
239 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
240 ovutils::eZorder zOrder = ovutils::ZORDER_1;
241 ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
242 if (ctx->listStats[mDpy].numAppLayers == 1) {
243 isFg = ovutils::IS_FG_SET;
244 }
245
246 return (configureHighRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, mDestL,
247 mDestR, &mRot) == 0 );
248}
249
250bool VideoOverlayHighRes::draw(hwc_context_t *ctx,
251 hwc_display_contents_1_t *list) {
252 if(!mModeOn) {
253 return true;
254 }
255
256 int yuvIndex = ctx->listStats[mDpy].yuvIndices[0];
257 if(yuvIndex == -1) {
258 return true;
259 }
260
261 private_handle_t *hnd = (private_handle_t *)
262 list->hwLayers[yuvIndex].handle;
263
264 overlay::Overlay& ov = *(ctx->mOverlay);
265 int fd = hnd->fd;
266 uint32_t offset = hnd->offset;
267 Rotator *rot = mRot;
268
269 if(rot) {
270 if(!rot->queueBuffer(fd, offset))
271 return false;
272 fd = rot->getDstMemId();
273 offset = rot->getDstOffset();
274 }
275
276 if(mDestL != ovutils::OV_INVALID) {
277 if (!ov.queueBuffer(fd, offset, mDestL)) {
278 ALOGE("%s: queueBuffer failed for dpy=%d's left mixer",
279 __FUNCTION__, mDpy);
280 return false;
281 }
282 }
283
284 if(mDestR != ovutils::OV_INVALID) {
285 if (!ov.queueBuffer(fd, offset, mDestR)) {
286 ALOGE("%s: queueBuffer failed for dpy=%d's right mixer"
287 , __FUNCTION__, mDpy);
288 return false;
289 }
290 }
291
292 return true;
293}
294
295
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700296}; //namespace qhwc