Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 4 | * |
| 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 Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #define HWC_UI_MIRROR 0 |
| 22 | #include <gralloc_priv.h> |
| 23 | #include <fb_priv.h> |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 24 | #include "hwc_uimirror.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 25 | #include "external.h" |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 26 | |
| 27 | namespace qhwc { |
| 28 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 29 | //Static Members |
| 30 | ovutils::eOverlayState UIMirrorOverlay::sState = ovutils::OV_CLOSED; |
| 31 | bool UIMirrorOverlay::sIsUiMirroringOn = false; |
| 32 | |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | void UIMirrorOverlay::reset() { |
| 34 | sIsUiMirroringOn = false; |
| 35 | sState = ovutils::OV_CLOSED; |
| 36 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 37 | |
| 38 | //Prepare the overlay for the UI mirroring |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 39 | bool UIMirrorOverlay::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 40 | reset(); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 41 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 42 | if(!ctx->mMDP.hasOverlay) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 43 | ALOGD_IF(HWC_UI_MIRROR, "%s, this hw doesnt support mirroring", |
| 44 | __FUNCTION__); |
Naseer Ahmed | f8ec162 | 2012-07-31 18:56:23 -0700 | [diff] [blame] | 45 | return false; |
| 46 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 47 | |
| 48 | sState = ovutils::OV_UI_MIRROR; |
| 49 | ovutils::eOverlayState newState = ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->getState(); |
| 50 | if(newState == ovutils::OV_UI_VIDEO_TV) { |
| 51 | sState = newState; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 52 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 53 | |
| 54 | configure(ctx, fblayer); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 55 | return sIsUiMirroringOn; |
| 56 | } |
| 57 | |
| 58 | // Configure |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 59 | bool UIMirrorOverlay::configure(hwc_context_t *ctx, hwc_layer_1_t *layer) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 60 | { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 61 | if (LIKELY(ctx->mOverlay[HWC_DISPLAY_EXTERNAL])) { |
| 62 | overlay::Overlay& ov = *(ctx->mOverlay[HWC_DISPLAY_EXTERNAL]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 63 | // Set overlay state |
| 64 | ov.setState(sState); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 65 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Saurabh Shah | ae823e7 | 2012-10-05 00:08:11 -0400 | [diff] [blame] | 66 | if (!hnd) { |
| 67 | ALOGE("%s:NULL private handle for layer!", __FUNCTION__); |
| 68 | return false; |
| 69 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 70 | ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size); |
| 71 | // Determine the RGB pipe for UI depending on the state |
| 72 | ovutils::eDest dest = ovutils::OV_PIPE0; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 73 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 74 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
| 75 | if(ctx->mSecureMode) { |
| 76 | ovutils::setMdpFlags(mdpFlags, |
| 77 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 78 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 79 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 80 | ovutils::PipeArgs parg(mdpFlags, |
| 81 | info, |
| 82 | ovutils::ZORDER_0, |
| 83 | ovutils::IS_FG_OFF, |
| 84 | ovutils::ROT_FLAG_DISABLED); |
| 85 | ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg }; |
| 86 | ov.setSource(pargs, dest); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 87 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 88 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 89 | // x,y,w,h |
| 90 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 91 | sourceCrop.right - sourceCrop.left, |
| 92 | sourceCrop.bottom - sourceCrop.top); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 93 | ov.setCrop(dcrop, dest); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 94 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 95 | int transform = layer->transform; |
| 96 | ovutils::eTransform orient = |
| 97 | static_cast<ovutils::eTransform>(transform); |
| 98 | ov.setTransform(orient, dest); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 99 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 100 | hwc_rect_t displayFrame = layer->displayFrame; |
| 101 | ovutils::Dim dpos(displayFrame.left, |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 102 | displayFrame.top, |
| 103 | displayFrame.right - displayFrame.left, |
| 104 | displayFrame.bottom - displayFrame.top); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 105 | ov.setPosition(dpos, dest); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 106 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 107 | if (!ov.commit(dest)) { |
| 108 | ALOGE("%s: commit fails", __FUNCTION__); |
| 109 | sIsUiMirroringOn = false; |
| 110 | return false; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 111 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 112 | sIsUiMirroringOn = true; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 113 | } |
| 114 | return sIsUiMirroringOn; |
| 115 | } |
| 116 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 117 | bool UIMirrorOverlay::draw(hwc_context_t *ctx, hwc_layer_1_t *layer) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 118 | { |
| 119 | if(!sIsUiMirroringOn) { |
| 120 | return true; |
| 121 | } |
| 122 | bool ret = true; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 123 | overlay::Overlay& ov = *(ctx->mOverlay[HWC_DISPLAY_EXTERNAL]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 124 | ovutils::eOverlayState state = ov.getState(); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 125 | ovutils::eDest dest = ovutils::OV_PIPE0; |
| 126 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 127 | switch (state) { |
| 128 | case ovutils::OV_UI_MIRROR: |
| 129 | case ovutils::OV_UI_VIDEO_TV: |
| 130 | if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) { |
| 131 | ALOGE("%s: queueBuffer failed for external", __FUNCTION__); |
| 132 | ret = false; |
| 133 | } |
| 134 | break; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 135 | default: |
| 136 | break; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 137 | } |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | //--------------------------------------------------------------------- |
| 142 | }; //namespace qhwc |