overlayCtrlData.h revision f621867a9f77ca62c71b65cbdc3cf8d8877d2b32
1/* 2* Copyright (c) 2012, Code Aurora Forum. All rights reserved. 3* 4* Redistribution and use in source and binary forms, with or without 5* modification, are permitted provided that the following conditions are 6* met: 7* * Redistributions of source code must retain the above copyright 8* notice, this list of conditions and the following disclaimer. 9* * Redistributions in binary form must reproduce the above 10* copyright notice, this list of conditions and the following 11* disclaimer in the documentation and/or other materials provided 12* with the distribution. 13* * Neither the name of Code Aurora Forum, Inc. nor the names of its 14* contributors may be used to endorse or promote products derived 15* from this software without specific prior written permission. 16* 17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*/ 29 30#ifndef OVERLAY_CTRLDATA_H 31#define OVERLAY_CTRLDATA_H 32 33#include "overlayUtils.h" 34#include "overlayMdp.h" 35#include "gralloc_priv.h" // INTERLACE_MASK 36 37namespace ovutils = overlay::utils; 38 39namespace overlay { 40 41/* 42* Sequence to use: 43* init 44* start 45* setXXX 46* close 47* */ 48class Ctrl : utils::NoCopy { 49public: 50 51 /* ctor */ 52 explicit Ctrl(); 53 /* dtor close */ 54 ~Ctrl(); 55 /* init fd etc*/ 56 bool init(uint32_t fbnum); 57 /* close underlying mdp */ 58 bool close(); 59 60 /* set source using whf, orient and wait flag */ 61 bool setSource(const utils::PipeArgs& args); 62 /* set crop info and pass it down to mdp */ 63 bool setCrop(const utils::Dim& d); 64 /* set orientation */ 65 bool setTransform(const utils::eTransform& p, const bool&); 66 /* set mdp position using dim */ 67 bool setPosition(const utils::Dim& dim); 68 /* mdp set overlay/commit changes */ 69 bool commit(); 70 71 /* ctrl id */ 72 int getPipeId() const; 73 /* ctrl fd */ 74 int getFd() const; 75 utils::Dim getAspectRatio(const utils::Whf& whf) const; 76 utils::Dim getAspectRatio(const utils::Dim& dim) const; 77 78 /* access for screen info */ 79 utils::ScreenInfo getScreenInfo() const; 80 81 /* retrieve cached crop data */ 82 utils::Dim getCrop() const; 83 84 /* dump the state of the object */ 85 void dump() const; 86 87private: 88 /* Retrieve screen info from underlying mdp */ 89 bool getScreenInfo(utils::ScreenInfo& info); 90 91 // mdp ctrl struct(info e.g.) 92 MdpCtrl mMdp; 93 94 /* Screen info */ 95 utils::ScreenInfo mInfo; 96}; 97 98 99class Data : utils::NoCopy { 100public: 101 /* init, reset */ 102 explicit Data(); 103 104 /* calls close */ 105 ~Data(); 106 107 /* init fd etc */ 108 bool init(uint32_t fbnum); 109 110 /* calls underlying mdp close */ 111 bool close(); 112 113 /* set overlay pipe id in the mdp struct */ 114 void setPipeId(int id); 115 116 /* get overlay id in the mdp struct */ 117 int getPipeId() const; 118 119 /* queue buffer to the overlay */ 120 bool queueBuffer(int fd, uint32_t offset); 121 122 /* sump the state of the obj */ 123 void dump() const; 124 125private: 126 // mdp data struct 127 MdpData mMdp; 128}; 129 130/* This class just creates a Ctrl Data pair to be used by a pipe. 131 * Although this was legacy design, this separation still makes sense, since we 132 * need to use the Ctrl channel in hwc_prepare (i.e config stage) and Data 133 * channel in hwc_set (i.e draw stage) 134 */ 135struct CtrlData { 136 Ctrl ctrl; 137 Data data; 138}; 139 140//-------------Inlines------------------------------- 141 142inline Ctrl::Ctrl() { 143 mMdp.reset(); 144} 145 146inline Ctrl::~Ctrl() { 147 close(); 148} 149 150inline bool Ctrl::close() { 151 if(!mMdp.close()) 152 return false; 153 return true; 154} 155 156inline bool Ctrl::commit() { 157 if(!mMdp.set()) { 158 ALOGE("Ctrl commit failed set overlay"); 159 return false; 160 } 161 return true; 162} 163 164inline bool Ctrl::getScreenInfo(utils::ScreenInfo& info) { 165 if(!mMdp.getScreenInfo(info)){ 166 ALOGE("Ctrl failed to get screen info"); 167 return false; 168 } 169 return true; 170} 171 172inline int Ctrl::getPipeId() const { 173 return mMdp.getPipeId(); 174} 175 176inline int Ctrl::getFd() const { 177 return mMdp.getFd(); 178} 179 180inline utils::ScreenInfo Ctrl::getScreenInfo() const { 181 return mInfo; 182} 183 184inline utils::Dim Ctrl::getCrop() const { 185 return mMdp.getSrcRectDim(); 186} 187 188inline Data::Data() { 189 mMdp.reset(); 190} 191 192inline Data::~Data() { close(); } 193 194inline void Data::setPipeId(int id) { mMdp.setPipeId(id); } 195 196inline int Data::getPipeId() const { return mMdp.getPipeId(); } 197 198inline bool Data::init(uint32_t fbnum) { 199 if(!mMdp.init(fbnum)) { 200 ALOGE("Data cannot init mdp"); 201 return false; 202 } 203 return true; 204} 205 206inline bool Data::close() { 207 if(!mMdp.close()) { 208 ALOGE("Data close failed"); 209 return false; 210 } 211 return true; 212} 213 214inline bool Data::queueBuffer(int fd, uint32_t offset) { 215 return mMdp.play(fd, offset); 216} 217 218inline void Data::dump() const { 219 ALOGE("== Dump Data MDP start =="); 220 mMdp.dump(); 221 ALOGE("== Dump Data MDP end =="); 222} 223 224 225} // overlay 226 227#endif 228