• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34 namespace overlay {
35 
36 class WritebackMgr;
37 
38 class WritebackMem {
39 public:
WritebackMem()40     explicit WritebackMem() : mCurrOffsetIndex(0) {
41         memset(&mOffsets, 0, sizeof(mOffsets));
42     }
~WritebackMem()43     ~WritebackMem() { dealloc(); }
44     bool manageMem(uint32_t size, bool isSecure);
useNextBuffer()45     void useNextBuffer() {
46             mCurrOffsetIndex = (mCurrOffsetIndex + 1) % NUM_BUFS;
47     }
getOffset()48     uint32_t getOffset() const { return mOffsets[mCurrOffsetIndex]; }
getDstFd()49     int getDstFd() const { return mBuf.getFD(); }
50 private:
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
61 class Writeback {
62 public:
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);
getOffset()82     uint32_t getOffset() const { return mWbMem.getOffset(); }
getDstFd()83     int getDstFd() const { return mWbMem.getDstFd(); }
84     /* Subject to GC if writeback isnt used for a drawing round.
85      * Get always if caching the value.
86      */
getFbFd()87     int getFbFd() const { return mFd.getFD(); }
88     int getOutputFormat();
89     bool setOutputFormat(int mdpFormat);
90     bool setSecure(bool isSecure);
91 
92     static Writeback* getInstance();
configBegin()93     static void configBegin() { sUsed = false; }
94     static void configDone();
95     static void clear();
96     //Will take a dump of data structure only if there is an instance existing
97     //Returns true if dump is added to the input buffer, false otherwise
98     static bool getDump(char *buf, size_t len);
99 
100 private:
101     explicit Writeback();
102     bool startSession();
103     bool stopSession();
104     //Actually block_until_write_done for the usage here.
105     bool dequeueBuffer();
106     OvFD mFd;
107     WritebackMem mWbMem;
108     struct msmfb_data mFbData;
109     int mXres;
110     int mYres;
111     int mOpFmt;
112     bool mSecure;
113 
114     static bool sUsed;
115     static Writeback *sWb;
116 };
117 
118 }
119 
120 #endif
121