Home | History | Annotate | Download | only in include
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef DISPLAYPLANE_H_
     17 #define DISPLAYPLANE_H_
     18 
     19 #include <utils/KeyedVector.h>
     20 #include <BufferMapper.h>
     21 #include <Drm.h>
     22 
     23 namespace android {
     24 namespace intel {
     25 
     26 typedef struct {
     27     // align with android, using 'int' here
     28     int x;
     29     int y;
     30     int w;
     31     int h;
     32 } PlanePosition;
     33 
     34 enum {
     35     // support up to 4 overlays
     36     MAX_OVERLAY_COUNT = 4,
     37     MAX_SPRITE_COUNT = 4,
     38 };
     39 
     40 enum {
     41      // in version 1.3, HWC_FRAMEBUFFER_TARGET is defined as 3
     42      HWC_FORCE_FRAMEBUFFER = 255,
     43 };
     44 
     45 class ZOrderConfig;
     46 
     47 class DisplayPlane {
     48 public:
     49     // plane type
     50     enum {
     51         PLANE_SPRITE = 0,
     52         PLANE_OVERLAY,
     53         PLANE_PRIMARY,
     54         PLANE_CURSOR,
     55         PLANE_MAX,
     56     };
     57 
     58     enum {
     59         // one more than android's back buffer count to allow more space
     60         // to do map/unmap, as plane reallocation may unmap on-screen layer.
     61         // each plane will cache the latest MIN_DATA_BUFFER_COUNT buffers
     62         // in case that these buffers are still in-using by display device
     63         // other buffers will be released on cache invalidation
     64         MIN_DATA_BUFFER_COUNT = 4,
     65     };
     66 
     67 protected:
     68     enum {
     69         PLANE_POSITION_CHANGED    = 0x00000001UL,
     70         PLANE_BUFFER_CHANGED      = 0x00000002UL,
     71         PLANE_SOURCE_CROP_CHANGED = 0x00000004UL,
     72         PLANE_TRANSFORM_CHANGED   = 0x00000008UL,
     73     };
     74 public:
     75     DisplayPlane(int index, int type, int disp);
     76     virtual ~DisplayPlane();
     77 public:
     78     virtual int getIndex() const { return mIndex; }
     79     virtual int getType() const { return mType; }
     80     virtual bool initCheck() const { return mInitialized; }
     81 
     82     // data destination
     83     virtual void setPosition(int x, int y, int w, int h);
     84     virtual void setSourceCrop(int x, int y, int w, int h);
     85     virtual void setTransform(int transform);
     86     virtual void setPlaneAlpha(uint8_t alpha, uint32_t blending);
     87 
     88     // data source
     89     virtual bool setDataBuffer(buffer_handle_t handle);
     90 
     91     virtual void invalidateBufferCache();
     92 
     93     // display device
     94     virtual bool assignToDevice(int disp);
     95 
     96     // hardware operations
     97     virtual bool flip(void *ctx);
     98     virtual void postFlip();
     99 
    100     virtual bool reset();
    101     virtual bool enable() = 0;
    102     virtual bool disable() = 0;
    103     virtual bool isDisabled() = 0;
    104 
    105     // set z order config
    106     virtual void setZOrderConfig(ZOrderConfig& config,
    107                                      void *nativeConfig) = 0;
    108 
    109     virtual void setZOrder(int zorder);
    110     virtual int getZOrder() const;
    111 
    112     virtual void* getContext() const = 0;
    113 
    114     virtual bool initialize(uint32_t bufferCount);
    115     virtual void deinitialize();
    116 
    117 protected:
    118     virtual void checkPosition(int& x, int& y, int& w, int& h);
    119     virtual bool setDataBuffer(BufferMapper& mapper) = 0;
    120 private:
    121     inline BufferMapper* mapBuffer(DataBuffer *buffer);
    122 
    123     inline int findActiveBuffer(BufferMapper *mapper);
    124     void updateActiveBuffers(BufferMapper *mapper);
    125     void invalidateActiveBuffers();
    126 protected:
    127     int mIndex;
    128     int mType;
    129     int mZOrder;
    130     int mDevice;
    131     bool mInitialized;
    132 
    133     // cached data buffers
    134     KeyedVector<uint64_t, BufferMapper*> mDataBuffers;
    135     // holding the most recent buffers
    136     Vector<BufferMapper*> mActiveBuffers;
    137     int mCacheCapacity;
    138 
    139     PlanePosition mPosition;
    140     crop_t mSrcCrop;
    141     bool mIsProtectedBuffer;
    142     int mTransform;
    143     uint8_t mPlaneAlpha;
    144     uint32_t mBlending;
    145     buffer_handle_t mCurrentDataBuffer;
    146     uint32_t mUpdateMasks;
    147     drmModeModeInfo mModeInfo;
    148     int mPanelOrientation;
    149 };
    150 
    151 } // namespace intel
    152 } // namespace android
    153 
    154 #endif /* DISPLAYPLANE_H_ */
    155