1/* 2* Copyright (c) 2013 The Linux Foundation. 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 The Linux Foundation. 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#ifndef OVERLAY_WRITEBACK_H 30#define OVERLAY_WRITEBACK_H 31 32#include "overlayMem.h" 33 34namespace overlay { 35 36class WritebackMgr; 37 38class WritebackMem { 39public: 40 explicit WritebackMem() : mCurrOffsetIndex(0) { 41 memset(&mOffsets, 0, sizeof(mOffsets)); 42 } 43 ~WritebackMem() { dealloc(); } 44 bool manageMem(uint32_t size, bool isSecure); 45 void useNextBuffer() { 46 mCurrOffsetIndex = (mCurrOffsetIndex + 1) % NUM_BUFS; 47 } 48 uint32_t getOffset() const { return mOffsets[mCurrOffsetIndex]; } 49 int getDstFd() const { return mBuf.getFD(); } 50private: 51 bool alloc(uint32_t size, bool isSecure); 52 bool dealloc(); 53 enum { NUM_BUFS = 2 }; 54 OvMem mBuf; 55 uint32_t mOffsets[NUM_BUFS]; 56 uint32_t mCurrOffsetIndex; 57}; 58 59//Abstracts the WB2 interface of MDP 60//Has modes to either manage memory or work with memory allocated elsewhere 61class Writeback { 62public: 63 ~Writeback(); 64 bool configureDpyInfo(int xres, int yres); 65 bool configureMemory(uint32_t size); 66 /* Blocking write. (queue, commit, dequeue) 67 * This class will do writeback memory management. 68 * This class will call display-commit on writeback mixer. 69 */ 70 bool writeSync(); 71 /* Blocking write. (queue, commit, dequeue) 72 * Client must do writeback memory management. 73 * Client must not call display-commit on writeback mixer. 74 */ 75 bool writeSync(int opFd, uint32_t opOffset); 76 /* Async queue. (Does not write) 77 * Client must do writeback memory management. 78 * Client must call display-commit on their own. 79 * Client must use sync mechanism e.g sync pt. 80 */ 81 bool queueBuffer(int opFd, uint32_t opOffset); 82 uint32_t getOffset() const { return mWbMem.getOffset(); } 83 int getDstFd() const { return mWbMem.getDstFd(); } 84 int getWidth() const { return mXres; } 85 int getHeight() const { return mYres; } 86 /* Subject to GC if writeback isnt used for a drawing round. 87 * Get always if caching the value. 88 */ 89 int getFbFd() const { return mFd.getFD(); } 90 int getOutputFormat(); 91 bool setOutputFormat(int mdpFormat); 92 bool setSecure(bool isSecure); 93 94 static Writeback* getInstance(); 95 static void configBegin() { sUsed = false; } 96 static void configDone(); 97 static void clear(); 98 //Will take a dump of data structure only if there is an instance existing 99 //Returns true if dump is added to the input buffer, false otherwise 100 static bool getDump(char *buf, size_t len); 101 102private: 103 explicit Writeback(); 104 bool startSession(); 105 bool stopSession(); 106 //Actually block_until_write_done for the usage here. 107 bool dequeueBuffer(); 108 OvFD mFd; 109 WritebackMem mWbMem; 110 struct msmfb_data mFbData; 111 int mXres; 112 int mYres; 113 int mOpFmt; 114 bool mSecure; 115 116 static bool sUsed; 117 static Writeback *sWb; 118}; 119 120} 121 122#endif 123