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