Home | History | Annotate | Download | only in liboverlay
      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:
     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(); }
     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, 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 
     91     static Writeback* getInstance();
     92     static void configBegin() { sUsed = false; }
     93     static void configDone();
     94     static void clear();
     95     //Will take a dump of data structure only if there is an instance existing
     96     //Returns true if dump is added to the input buffer, false otherwise
     97     static bool getDump(char *buf, size_t len);
     98 
     99 private:
    100     explicit Writeback();
    101     bool startSession();
    102     bool stopSession();
    103     //Actually block_until_write_done for the usage here.
    104     bool dequeueBuffer();
    105     OvFD mFd;
    106     WritebackMem mWbMem;
    107     struct msmfb_data mFbData;
    108     int mXres;
    109     int mYres;
    110     int mOpFmt;
    111 
    112     static bool sUsed;
    113     static Writeback *sWb;
    114 };
    115 
    116 }
    117 
    118 #endif
    119