blob: 1b81421b3b30b0136403757bbab5c108e88e7969 [file] [log] [blame]
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -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 Ahmed0c8b7b52012-07-20 09:06:13 -07004 *
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
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#define HWC_UI_MIRROR 0
22#include <gralloc_priv.h>
23#include <fb_priv.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070024#include "hwc_uimirror.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070025#include "external.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070026
27namespace qhwc {
28
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070029
Naseer Ahmed51df92a2012-08-14 19:27:48 -070030// Function to get the orientation of UI on primary.
31// When external display is connected, the primary UI is
32// fixed to landscape by the phone window manager.
33// Return the landscape orientation based on w and hw of primary
34int getDeviceOrientation() {
35 int orientation = 0;
36 //Calculate the rect for primary based on whether the supplied
37 //position
38 //is within or outside bounds.
39 const int fbWidth =
40 ovutils::FrameBufferInfo::getInstance()->getWidth();
41 const int fbHeight =
42 ovutils::FrameBufferInfo::getInstance()->getHeight();
43 if(fbWidth >= fbHeight) {
44 // landscape panel
45 orientation = overlay::utils::OVERLAY_TRANSFORM_0;
46 } else {
47 // portrait panel
48 orientation = overlay::utils::OVERLAY_TRANSFORM_ROT_90;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070049 }
50 return orientation;
51}
52
53//Static Members
54ovutils::eOverlayState UIMirrorOverlay::sState = ovutils::OV_CLOSED;
55bool UIMirrorOverlay::sIsUiMirroringOn = false;
56
Saurabh Shah56f610d2012-08-07 15:27:06 -070057void UIMirrorOverlay::reset() {
58 sIsUiMirroringOn = false;
59 sState = ovutils::OV_CLOSED;
60}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070061
62//Prepare the overlay for the UI mirroring
Saurabh Shah3e858eb2012-09-17 16:53:21 -070063bool UIMirrorOverlay::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070064 sState = ovutils::OV_CLOSED;
65 sIsUiMirroringOn = false;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070066
Naseer Ahmed96c4c952012-07-25 18:27:14 -070067 if(!ctx->mMDP.hasOverlay) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070068 ALOGD_IF(HWC_UI_MIRROR, "%s, this hw doesnt support mirroring",
69 __FUNCTION__);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -070070 return false;
71 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -070072 // If external display is active
73 if(isExternalActive(ctx)) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070074 sState = ovutils::OV_UI_MIRROR;
Saurabh Shah3e858eb2012-09-17 16:53:21 -070075 configure(ctx, fblayer);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070076 }
77 return sIsUiMirroringOn;
78}
79
80// Configure
Saurabh Shah3e858eb2012-09-17 16:53:21 -070081bool UIMirrorOverlay::configure(hwc_context_t *ctx, hwc_layer_1_t *layer)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070082{
83 if (LIKELY(ctx->mOverlay)) {
84 overlay::Overlay& ov = *(ctx->mOverlay);
85 // Set overlay state
86 ov.setState(sState);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070087 framebuffer_device_t *fbDev = ctx->mFbDev;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070088 if(fbDev) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -070089 private_handle_t *hnd = (private_handle_t *)layer->handle;
90 ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070091 // Determine the RGB pipe for UI depending on the state
92 ovutils::eDest dest = ovutils::OV_PIPE_ALL;
93 if (sState == ovutils::OV_2D_TRUE_UI_MIRROR) {
94 // True UI mirroring state: external RGB pipe is OV_PIPE2
95 dest = ovutils::OV_PIPE2;
96 } else if (sState == ovutils::OV_UI_MIRROR) {
97 // UI-only mirroring state: external RGB pipe is OV_PIPE0
98 dest = ovutils::OV_PIPE0;
99 }
100
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700101 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700102 if(ctx->mSecureMode) {
103 ovutils::setMdpFlags(mdpFlags,
104 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
105 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700106
107 ovutils::PipeArgs parg(mdpFlags,
108 info,
109 ovutils::ZORDER_0,
110 ovutils::IS_FG_OFF,
111 ovutils::ROT_FLAG_ENABLED);
112 ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
113 ov.setSource(pargs, dest);
114
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700115 hwc_rect_t sourceCrop = layer->sourceCrop;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700116 // x,y,w,h
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700117 ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
118 sourceCrop.right - sourceCrop.left,
119 sourceCrop.bottom - sourceCrop.top);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700120 ov.setCrop(dcrop, dest);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700121
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700122 //Get the current orientation on primary panel
Naseer Ahmed51df92a2012-08-14 19:27:48 -0700123 int transform = getDeviceOrientation();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700124 ovutils::eTransform orient =
125 static_cast<ovutils::eTransform>(transform);
126 ov.setTransform(orient, dest);
127
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700128 hwc_rect_t displayFrame = layer->displayFrame;
129 ovutils::Dim dpos(displayFrame.left,
130 displayFrame.top,
131 displayFrame.right - displayFrame.left,
132 displayFrame.bottom - displayFrame.top);
133 ov.setPosition(dpos, dest);
134
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700135 if (!ov.commit(dest)) {
136 ALOGE("%s: commit fails", __FUNCTION__);
137 return false;
138 }
139 sIsUiMirroringOn = true;
140 }
141 }
142 return sIsUiMirroringOn;
143}
144
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700145bool UIMirrorOverlay::draw(hwc_context_t *ctx, hwc_layer_1_t *layer)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700146{
147 if(!sIsUiMirroringOn) {
148 return true;
149 }
150 bool ret = true;
151 overlay::Overlay& ov = *(ctx->mOverlay);
152 ovutils::eOverlayState state = ov.getState();
153 ovutils::eDest dest = ovutils::OV_PIPE_ALL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700154 framebuffer_device_t *fbDev = ctx->mFbDev;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700155 if(fbDev) {
156 private_module_t* m = reinterpret_cast<private_module_t*>(
157 fbDev->common.module);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700158 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700159 switch (state) {
160 case ovutils::OV_UI_MIRROR:
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700161 //TODO why is this primary fd
162 if (!ov.queueBuffer(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd,
163 hnd->offset, //div by line_length like in PAN?
164 ovutils::OV_PIPE0)) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700165 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700166 ret = false;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700167 }
168 break;
169 case ovutils::OV_2D_TRUE_UI_MIRROR:
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700170 if (!ov.queueBuffer(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd,
171 hnd->offset,
172 ovutils::OV_PIPE2)) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700173 ALOGE("%s: queueBuffer failed for external", __FUNCTION__);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700174 ret = false;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700175 }
176 break;
177
178 default:
179 break;
180 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700181 }
182 return ret;
183}
184
185//---------------------------------------------------------------------
186}; //namespace qhwc