summaryrefslogtreecommitdiff
path: root/merrifield/include/DisplayPlane.h
blob: 250d48584a22c5617652433cef30734a1db8c705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
// Copyright (c) 2014 Intel Corporation 
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#ifndef DISPLAYPLANE_H_
#define DISPLAYPLANE_H_

#include <utils/KeyedVector.h>
#include <BufferMapper.h>
#include <Drm.h>

namespace android {
namespace intel {

typedef struct {
    // align with android, using 'int' here
    int x;
    int y;
    int w;
    int h;
} PlanePosition;

enum {
    // support up to 4 overlays
    MAX_OVERLAY_COUNT = 4,
    MAX_SPRITE_COUNT = 4,
};

enum {
     // in version 1.3, HWC_FRAMEBUFFER_TARGET is defined as 3
     HWC_FORCE_FRAMEBUFFER = 255,
};

class ZOrderConfig;

class DisplayPlane {
public:
    // plane type
    enum {
        PLANE_SPRITE = 0,
        PLANE_OVERLAY,
        PLANE_PRIMARY,
        PLANE_CURSOR,
        PLANE_MAX,
    };

    enum {
        // one more than android's back buffer count to allow more space
        // to do map/unmap, as plane reallocation may unmap on-screen layer.
        // each plane will cache the latest MIN_DATA_BUFFER_COUNT buffers
        // in case that these buffers are still in-using by display device
        // other buffers will be released on cache invalidation
        MIN_DATA_BUFFER_COUNT = 4,
    };

protected:
    enum {
        PLANE_POSITION_CHANGED    = 0x00000001UL,
        PLANE_BUFFER_CHANGED      = 0x00000002UL,
        PLANE_SOURCE_CROP_CHANGED = 0x00000004UL,
        PLANE_TRANSFORM_CHANGED   = 0x00000008UL,
    };
public:
    DisplayPlane(int index, int type, int disp);
    virtual ~DisplayPlane();
public:
    virtual int getIndex() const { return mIndex; }
    virtual int getType() const { return mType; }
    virtual bool initCheck() const { return mInitialized; }

    // data destination
    virtual void setPosition(int x, int y, int w, int h);
    virtual void setSourceCrop(int x, int y, int w, int h);
    virtual void setTransform(int transform);
    virtual void setPlaneAlpha(uint8_t alpha, uint32_t blending);

    // data source
    virtual bool setDataBuffer(buffer_handle_t handle);

    virtual void invalidateBufferCache();

    // display device
    virtual bool assignToDevice(int disp);

    // hardware operations
    virtual bool flip(void *ctx);
    virtual void postFlip();

    virtual bool reset();
    virtual bool enable() = 0;
    virtual bool disable() = 0;
    virtual bool isDisabled() = 0;

    // set z order config
    virtual void setZOrderConfig(ZOrderConfig& config,
                                     void *nativeConfig) = 0;

    virtual void setZOrder(int zorder);
    virtual int getZOrder() const;

    virtual void* getContext() const = 0;

    virtual bool initialize(uint32_t bufferCount);
    virtual void deinitialize();

protected:
    virtual void checkPosition(int& x, int& y, int& w, int& h);
    virtual bool setDataBuffer(BufferMapper& mapper) = 0;
private:
    inline BufferMapper* mapBuffer(DataBuffer *buffer);

    inline int findActiveBuffer(BufferMapper *mapper);
    void updateActiveBuffers(BufferMapper *mapper);
    void invalidateActiveBuffers();
protected:
    int mIndex;
    int mType;
    int mZOrder;
    int mDevice;
    bool mInitialized;

    // cached data buffers
    KeyedVector<uint64_t, BufferMapper*> mDataBuffers;
    // holding the most recent buffers
    Vector<BufferMapper*> mActiveBuffers;
    int mCacheCapacity;

    PlanePosition mPosition;
    crop_t mSrcCrop;
    bool mIsProtectedBuffer;
    int mTransform;
    uint8_t mPlaneAlpha;
    uint32_t mBlending;
    buffer_handle_t mCurrentDataBuffer;
    uint32_t mUpdateMasks;
    drmModeModeInfo mModeInfo;
    int mPanelOrientation;
};

} // namespace intel
} // namespace android

#endif /* DISPLAYPLANE_H_ */