blob: 62803919776ff32aeb74c5d822aa3f9fa1043654 [file] [log] [blame]
Saurabh Shahc8118ac2013-06-27 10:03:19 -07001/*
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(); }
Saurabh Shaha9da08f2013-07-03 13:27:53 -070084 int getOutputFormat() const { return mOpFmt; }
Saurabh Shahc8118ac2013-06-27 10:03:19 -070085
86 static Writeback* getInstance();
87 static void configBegin() { sUsed = false; }
88 static void configDone();
89 static void clear();
90
91private:
92 explicit Writeback();
93 bool startSession();
94 bool stopSession();
95 //Actually block_until_write_done for the usage here.
96 bool dequeueBuffer();
Saurabh Shaha9da08f2013-07-03 13:27:53 -070097 void queryOutputFormat();
Saurabh Shahc8118ac2013-06-27 10:03:19 -070098 OvFD mFd;
99 WritebackMem mWbMem;
100 struct msmfb_data mFbData;
101 int mXres;
102 int mYres;
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700103 int mOpFmt;
Saurabh Shahc8118ac2013-06-27 10:03:19 -0700104
105 static bool sUsed;
106 static Writeback *sWb;
107};
108
109}
110
111#endif