overlayWriteback.h revision 103c736926cace1ff5a6d154715b375ff1018f8e
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, bool isSecure);
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    /* Subject to GC if writeback isnt used for a drawing round.
85     * Get always if caching the value.
86     */
87    int getFbFd() const { return mFd.getFD(); }
88    int getOutputFormat();
89    bool setOutputFormat(int mdpFormat);
90    void getDump(char *buf, size_t len) const;
91
92    static Writeback* getInstance();
93    static void configBegin() { sUsed = false; }
94    static void configDone();
95    static void clear();
96
97private:
98    explicit Writeback();
99    bool startSession();
100    bool stopSession();
101    //Actually block_until_write_done for the usage here.
102    bool dequeueBuffer();
103    OvFD mFd;
104    WritebackMem mWbMem;
105    struct msmfb_data mFbData;
106    int mXres;
107    int mYres;
108    int mOpFmt;
109
110    static bool sUsed;
111    static Writeback *sWb;
112};
113
114}
115
116#endif
117