blob: 13f3cddda53b62c5ba5301e9427a6a6587309890 [file] [log] [blame]
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmedf48aef62012-07-20 09:05:53 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Naseer Ahmed72cf9762012-07-21 12:17:13 -070018#define VIDEO_DEBUG 0
19#include <overlay.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070020#include "hwc_video.h"
Saurabh Shah3e858eb2012-09-17 16:53:21 -070021#include "hwc_utils.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080022#include "qdMetaData.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070023
24namespace qhwc {
25
Naseer Ahmed758bfc52012-11-28 17:02:08 -050026namespace ovutils = overlay::utils;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070027
28//Static Members
Saurabh Shahc4d034f2012-09-27 15:55:15 -070029bool VideoOverlay::sIsModeOn[] = {false};
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030ovutils::eDest VideoOverlay::sDest[] = {ovutils::OV_INVALID};
Naseer Ahmedf48aef62012-07-20 09:05:53 -070031
32//Cache stats, figure out the state, config overlay
Saurabh Shah3e858eb2012-09-17 16:53:21 -070033bool VideoOverlay::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
34 int dpy) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -070035
Saurabh Shah3e858eb2012-09-17 16:53:21 -070036 int yuvIndex = ctx->listStats[dpy].yuvIndex;
Saurabh Shahc4d034f2012-09-27 15:55:15 -070037 sIsModeOn[dpy] = false;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070038
Naseer Ahmed96c4c952012-07-25 18:27:14 -070039 if(!ctx->mMDP.hasOverlay) {
Naseer Ahmed31da0b12012-07-31 18:55:33 -070040 ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__);
41 return false;
42 }
Saurabh Shahc4d034f2012-09-27 15:55:15 -070043
Naseer Ahmed54821fe2012-11-28 18:44:38 -050044 if(isSecuring(ctx)) {
45 ALOGD_IF(VIDEO_DEBUG,"%s: MDP Secure is active", __FUNCTION__);
46 return false;
47 }
48
Saurabh Shahc4d034f2012-09-27 15:55:15 -070049 if(yuvIndex == -1 || ctx->listStats[dpy].yuvCount != 1) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070050 return false;
51 }
Naseer Ahmed4c588a22012-07-31 19:12:17 -070052
Saurabh Shah3e858eb2012-09-17 16:53:21 -070053 //index guaranteed to be not -1 at this point
Naseer Ahmed758bfc52012-11-28 17:02:08 -050054 hwc_layer_1_t *layer = &list->hwLayers[yuvIndex];
Sushil Chauhan2515abf2013-01-08 16:40:05 -080055 if (isSecureModePolicy(ctx->mMDP.version)) {
56 private_handle_t *hnd = (private_handle_t *)layer->handle;
57 if(ctx->mSecureMode) {
58 if (! isSecureBuffer(hnd)) {
59 ALOGD_IF(VIDEO_DEBUG, "%s: Handle non-secure video layer"
60 "during secure playback gracefully", __FUNCTION__);
61 return false;
62 }
63 } else {
64 if (isSecureBuffer(hnd)) {
65 ALOGD_IF(VIDEO_DEBUG, "%s: Handle secure video layer"
66 "during non-secure playback gracefully", __FUNCTION__);
67 return false;
68 }
Naseer Ahmedcb5f25b2012-10-04 15:56:00 -040069 }
Naseer Ahmed68b88cf2012-10-02 14:15:12 -040070 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 if(configure(ctx, dpy, layer)) {
72 markFlags(layer);
Saurabh Shahc4d034f2012-09-27 15:55:15 -070073 sIsModeOn[dpy] = true;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074 }
75
Saurabh Shahc4d034f2012-09-27 15:55:15 -070076 return sIsModeOn[dpy];
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077}
78
Naseer Ahmed758bfc52012-11-28 17:02:08 -050079void VideoOverlay::markFlags(hwc_layer_1_t *layer) {
80 if(layer) {
81 layer->compositionType = HWC_OVERLAY;
82 layer->hints |= HWC_HINT_CLEAR_FB;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070083 }
84}
85
Naseer Ahmed758bfc52012-11-28 17:02:08 -050086bool VideoOverlay::configure(hwc_context_t *ctx, int dpy,
87 hwc_layer_1_t *layer) {
88 overlay::Overlay& ov = *(ctx->mOverlay);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -070089 private_handle_t *hnd = (private_handle_t *)layer->handle;
90 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070091
Naseer Ahmed758bfc52012-11-28 17:02:08 -050092 //Request a VG pipe
93 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, dpy);
94 if(dest == ovutils::OV_INVALID) { //None available
95 return false;
96 }
97
98 sDest[dpy] = dest;
99
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700100 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700101 if (isSecureBuffer(hnd)) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700102 ovutils::setMdpFlags(mdpFlags,
103 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
104 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700105
Saurabh Shah91a6a992012-08-20 15:25:28 -0700106 if(layer->blending == HWC_BLENDING_PREMULT) {
107 ovutils::setMdpFlags(mdpFlags,
108 ovutils::OV_MDP_BLEND_FG_PREMULT);
109 }
110
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800111 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
Ramkumar Radhakrishnan12b103b2013-01-09 17:47:56 -0800112 if (metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
113 metadata->interlaced) {
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800114 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_DEINTERLACE);
115 }
116
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700117 ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 if (ctx->listStats[dpy].numAppLayers == 1) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700119 isFgFlag = ovutils::IS_FG_SET;
120 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700121
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700122 ovutils::PipeArgs parg(mdpFlags,
123 info,
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500124 ovutils::ZORDER_1,
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700125 isFgFlag,
126 ovutils::ROT_FLAG_DISABLED);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500128 ov.setSource(parg, dest);
129
130 int transform = layer->transform;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700131 ovutils::eTransform orient =
132 static_cast<ovutils::eTransform>(transform);
133
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700134 hwc_rect_t sourceCrop = layer->sourceCrop;
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700135 hwc_rect_t displayFrame = layer->displayFrame;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700136
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700137 //Calculate the rect for primary based on whether the supplied position
138 //is within or outside bounds.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139 const int fbWidth = ctx->dpyAttr[dpy].xres;
140 const int fbHeight = ctx->dpyAttr[dpy].yres;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700141
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700142 if( displayFrame.left < 0 ||
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 displayFrame.top < 0 ||
144 displayFrame.right > fbWidth ||
145 displayFrame.bottom > fbHeight) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700146 calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight,
147 transform);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148 }
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700149
Saurabh Shah1023ce22012-09-05 18:45:59 -0700150 // source crop x,y,w,h
151 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
152 sourceCrop.right - sourceCrop.left,
153 sourceCrop.bottom - sourceCrop.top);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700154 //Only for Primary
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155 ov.setCrop(dcrop, dest);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700156
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500157 ov.setTransform(orient, dest);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700158
Saurabh Shah1023ce22012-09-05 18:45:59 -0700159 // position x,y,w,h
160 ovutils::Dim dpos(displayFrame.left,
161 displayFrame.top,
162 displayFrame.right - displayFrame.left,
163 displayFrame.bottom - displayFrame.top);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164 ov.setPosition(dpos, dest);
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700165
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166 if (!ov.commit(dest)) {
Naseer Ahmed2cc53dd2012-07-31 19:11:48 -0700167 ALOGE("%s: commit fails", __FUNCTION__);
168 return false;
169 }
170 return true;
171}
172
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700173bool VideoOverlay::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
174 int dpy)
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700175{
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700176 if(!sIsModeOn[dpy]) {
177 return true;
178 }
179
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700180 int yuvIndex = ctx->listStats[dpy].yuvIndex;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700181 if(yuvIndex == -1) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182 return true;
183 }
184
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700185 private_handle_t *hnd = (private_handle_t *)
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700186 list->hwLayers[yuvIndex].handle;
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700187
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188 bool ret = true;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500189 overlay::Overlay& ov = *(ctx->mOverlay);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500191 if (!ov.queueBuffer(hnd->fd, hnd->offset,
192 sDest[dpy])) {
193 ALOGE("%s: queueBuffer failed for dpy=%d", __FUNCTION__, dpy);
194 ret = false;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700195 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500196
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700197 return ret;
198}
199
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700200}; //namespace qhwc