Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
| 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 | |
| 21 | #define HWC_FB_UPDATE 0 |
| 22 | #include <gralloc_priv.h> |
| 23 | #include <fb_priv.h> |
| 24 | #include "hwc_fbupdate.h" |
| 25 | #include "external.h" |
| 26 | |
| 27 | namespace qhwc { |
| 28 | |
| 29 | namespace ovutils = overlay::utils; |
| 30 | |
| 31 | //Static Members |
| 32 | bool FBUpdate::sModeOn[] = {false}; |
| 33 | ovutils::eDest FBUpdate::sDest[] = {ovutils::OV_INVALID}; |
| 34 | |
| 35 | void FBUpdate::reset() { |
| 36 | sModeOn[HWC_DISPLAY_PRIMARY] = false; |
| 37 | sModeOn[HWC_DISPLAY_EXTERNAL] = false; |
| 38 | sDest[HWC_DISPLAY_PRIMARY] = ovutils::OV_INVALID; |
| 39 | sDest[HWC_DISPLAY_EXTERNAL] = ovutils::OV_INVALID; |
| 40 | } |
| 41 | |
| 42 | bool FBUpdate::prepare(hwc_context_t *ctx, hwc_layer_1_t *fblayer, int dpy) { |
| 43 | if(!ctx->mMDP.hasOverlay) { |
| 44 | ALOGD_IF(HWC_FB_UPDATE, "%s, this hw doesnt support mirroring", |
| 45 | __FUNCTION__); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | return (sModeOn[dpy] = configure(ctx, fblayer, dpy)); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | // Configure |
| 54 | bool FBUpdate::configure(hwc_context_t *ctx, hwc_layer_1_t *layer, int dpy) |
| 55 | { |
| 56 | bool ret = false; |
| 57 | if (LIKELY(ctx->mOverlay)) { |
| 58 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 59 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 60 | if (!hnd) { |
| 61 | ALOGE("%s:NULL private handle for layer!", __FUNCTION__); |
| 62 | return false; |
| 63 | } |
| 64 | ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size); |
| 65 | |
| 66 | //Request an RGB pipe |
| 67 | ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, dpy); |
| 68 | if(dest == ovutils::OV_INVALID) { //None available |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | sDest[dpy] = dest; |
| 73 | |
| 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 | } |
| 79 | |
| 80 | ovutils::PipeArgs parg(mdpFlags, |
| 81 | info, |
| 82 | ovutils::ZORDER_0, |
| 83 | ovutils::IS_FG_SET, |
| 84 | ovutils::ROT_FLAG_DISABLED); |
| 85 | ov.setSource(parg, dest); |
| 86 | |
| 87 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 88 | // x,y,w,h |
| 89 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
| 90 | sourceCrop.right - sourceCrop.left, |
| 91 | sourceCrop.bottom - sourceCrop.top); |
| 92 | ov.setCrop(dcrop, dest); |
| 93 | |
| 94 | int transform = layer->transform; |
| 95 | ovutils::eTransform orient = |
| 96 | static_cast<ovutils::eTransform>(transform); |
| 97 | ov.setTransform(orient, dest); |
| 98 | |
| 99 | hwc_rect_t displayFrame = layer->displayFrame; |
| 100 | ovutils::Dim dpos(displayFrame.left, |
| 101 | displayFrame.top, |
| 102 | displayFrame.right - displayFrame.left, |
| 103 | displayFrame.bottom - displayFrame.top); |
| 104 | ov.setPosition(dpos, dest); |
| 105 | |
| 106 | ret = true; |
| 107 | if (!ov.commit(dest)) { |
| 108 | ALOGE("%s: commit fails", __FUNCTION__); |
| 109 | ret = false; |
| 110 | } |
| 111 | } |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | bool FBUpdate::draw(hwc_context_t *ctx, hwc_layer_1_t *layer, int dpy) |
| 116 | { |
| 117 | if(!sModeOn[dpy]) { |
| 118 | return true; |
| 119 | } |
| 120 | bool ret = true; |
| 121 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 122 | ovutils::eDest dest = sDest[dpy]; |
| 123 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 124 | if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) { |
| 125 | ALOGE("%s: queueBuffer failed for external", __FUNCTION__); |
| 126 | ret = false; |
| 127 | } |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | //--------------------------------------------------------------------- |
| 132 | }; //namespace qhwc |