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; |
| 66 | ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size); |
| 67 | // Determine the RGB pipe for UI depending on the state |
| 68 | ovutils::eDest dest = ovutils::OV_PIPE0; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 69 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 70 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
| 71 | if(ctx->mSecureMode) { |
| 72 | ovutils::setMdpFlags(mdpFlags, |
| 73 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 74 | } |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 75 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 76 | ovutils::PipeArgs parg(mdpFlags, |
| 77 | info, |
| 78 | ovutils::ZORDER_0, |
| 79 | ovutils::IS_FG_OFF, |
| 80 | ovutils::ROT_FLAG_DISABLED); |
| 81 | ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg }; |
| 82 | ov.setSource(pargs, dest); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 83 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 84 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 85 | // x,y,w,h |
| 86 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 87 | sourceCrop.right - sourceCrop.left, |
| 88 | sourceCrop.bottom - sourceCrop.top); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 89 | ov.setCrop(dcrop, dest); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 90 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 91 | int transform = layer->transform; |
| 92 | ovutils::eTransform orient = |
| 93 | static_cast<ovutils::eTransform>(transform); |
| 94 | ov.setTransform(orient, dest); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 95 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 96 | hwc_rect_t displayFrame = layer->displayFrame; |
| 97 | ovutils::Dim dpos(displayFrame.left, |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 98 | displayFrame.top, |
| 99 | displayFrame.right - displayFrame.left, |
| 100 | displayFrame.bottom - displayFrame.top); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 101 | ov.setPosition(dpos, dest); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 102 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 103 | if (!ov.commit(dest)) { |
| 104 | ALOGE("%s: commit fails", __FUNCTION__); |
| 105 | sIsUiMirroringOn = false; |
| 106 | return false; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 107 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 108 | sIsUiMirroringOn = true; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 109 | } |
| 110 | return sIsUiMirroringOn; |
| 111 | } |
| 112 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 113 | bool UIMirrorOverlay::draw(hwc_context_t *ctx, hwc_layer_1_t *layer) |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 114 | { |
| 115 | if(!sIsUiMirroringOn) { |
| 116 | return true; |
| 117 | } |
| 118 | bool ret = true; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 119 | overlay::Overlay& ov = *(ctx->mOverlay[HWC_DISPLAY_EXTERNAL]); |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 120 | ovutils::eOverlayState state = ov.getState(); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame^] | 121 | ovutils::eDest dest = ovutils::OV_PIPE0; |
| 122 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 123 | switch (state) { |
| 124 | case ovutils::OV_UI_MIRROR: |
| 125 | case ovutils::OV_UI_VIDEO_TV: |
| 126 | if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) { |
| 127 | ALOGE("%s: queueBuffer failed for external", __FUNCTION__); |
| 128 | ret = false; |
| 129 | } |
| 130 | break; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 131 | default: |
| 132 | break; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 133 | } |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | //--------------------------------------------------------------------- |
| 138 | }; //namespace qhwc |