blob: 3be9d81d2ab1e675054a5c4692158a7d06e1f1a9 [file] [log] [blame]
Naseer Ahmed4c588a22012-07-31 19:12:17 -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 Ahmed4c588a22012-07-31 19:12:17 -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
18#include "hwc_extonly.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070019#include "external.h"
Naseer Ahmed4c588a22012-07-31 19:12:17 -070020
21namespace qhwc {
22
23#define EXTONLY_DEBUG 0
24
25//Static Members
26ovutils::eOverlayState ExtOnly::sState = ovutils::OV_CLOSED;
27int ExtOnly::sExtCount = 0;
28int ExtOnly::sExtIndex = -1;
29bool ExtOnly::sIsExtBlock = false;
30bool ExtOnly::sIsModeOn = false;
31
32//Cache stats, figure out the state, config overlay
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070033bool ExtOnly::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list) {
Naseer Ahmed4c588a22012-07-31 19:12:17 -070034 sIsModeOn = false;
35 if(!ctx->mMDP.hasOverlay) {
36 ALOGD_IF(EXTONLY_DEBUG,"%s, this hw doesnt support overlay",
37 __FUNCTION__);
38 return false;
39 }
40 if(sExtIndex == -1) {
41 return false;
42 }
43 chooseState(ctx);
44 //if the state chosen above is CLOSED, skip this block.
45 if(sState != ovutils::OV_CLOSED) {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070046 hwc_layer_1_t *extLayer = &list->hwLayers[sExtIndex];
Naseer Ahmed4c588a22012-07-31 19:12:17 -070047 if(configure(ctx, extLayer)) {
48 markFlags(extLayer);
49 sIsModeOn = true;
50 }
51 }
52
53 ALOGD_IF(EXTONLY_DEBUG, "%s: stats: extCount = %d, extIndex = %d,"
54 "IsExtBlock = %d, IsModeOn = %d",
55 __func__, sExtCount, sExtIndex,
56 sIsExtBlock, sIsModeOn);
57
58 return sIsModeOn;
59}
60
61void ExtOnly::chooseState(hwc_context_t *ctx) {
62 ALOGD_IF(EXTONLY_DEBUG, "%s: old state = %s", __FUNCTION__,
63 ovutils::getStateString(sState));
64
65 ovutils::eOverlayState newState = ovutils::OV_CLOSED;
66
67 if(sExtCount > 0 &&
68 ctx->mExtDisplay->getExternalDisplay()) {
69 newState = ovutils::OV_DUAL_DISP;
70 }
71
72 sState = newState;
73 ALOGD_IF(EXTONLY_DEBUG, "%s: new chosen state = %s", __FUNCTION__,
74 ovutils::getStateString(sState));
75}
76
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070077void ExtOnly::markFlags(hwc_layer_1_t *layer) {
Naseer Ahmed4c588a22012-07-31 19:12:17 -070078 switch(sState) {
79 case ovutils::OV_DUAL_DISP:
80 layer->compositionType = HWC_OVERLAY;
81 break;
82 default:
83 break;
84 }
85}
86
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070087bool ExtOnly::configure(hwc_context_t *ctx, hwc_layer_1_t *layer) {
Naseer Ahmed4c588a22012-07-31 19:12:17 -070088
89 overlay::Overlay& ov = *(ctx->mOverlay);
90 ov.setState(sState);
91 private_handle_t *hnd = (private_handle_t *)layer->handle;
92 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
93 ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
94 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
95 ovutils::PipeArgs parg(mdpFlags,
96 info,
97 ovutils::ZORDER_0,
98 isFgFlag,
99 ovutils::ROT_FLAG_DISABLED);
100 ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
101 ov.setSource(pargs, ovutils::OV_PIPE0);
102
103 hwc_rect_t sourceCrop = layer->sourceCrop;
104 // x,y,w,h
105 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
106 sourceCrop.right - sourceCrop.left,
107 sourceCrop.bottom - sourceCrop.top);
108 ov.setCrop(dcrop, ovutils::OV_PIPE0);
109
110 ov.setTransform(0, ovutils::OV_PIPE0);
111
112 //Setting position same as crop
113 //FIXME stretch to full screen
114 ov.setPosition(dcrop, ovutils::OV_PIPE0);
115
116 if (!ov.commit(ovutils::OV_PIPE0)) {
117 ALOGE("%s: commit fails", __FUNCTION__);
118 return false;
119 }
120 return true;
121}
122
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700123bool ExtOnly::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list)
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700124{
125 if(!sIsModeOn || sExtIndex == -1) {
126 return true;
127 }
128
129 private_handle_t *hnd = (private_handle_t *)
130 list->hwLayers[sExtIndex].handle;
131
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700132 bool ret = true;
133 overlay::Overlay& ov = *(ctx->mOverlay);
134 ovutils::eOverlayState state = ov.getState();
135
136 switch (state) {
137 case ovutils::OV_DUAL_DISP:
138 // Play external
139 if (!ov.queueBuffer(hnd->fd, hnd->offset, ovutils::OV_PIPE0)) {
140 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
141 ret = false;
142 }
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700143 break;
144 default:
145 ALOGE("%s Unused state %s", __FUNCTION__,
146 ovutils::getStateString(state));
147 break;
148 }
149
150 return ret;
151}
152
153}; //namespace qhwc