blob: 22d2f3564dd83fcb936cb4f00e35f330022cc17e
1 | /* |
2 | // Copyright(c) 2016 Amlogic Corporation |
3 | */ |
4 | |
5 | #ifndef GE2D_COMPOSER_H |
6 | #define GE2D_COMPOSER_H |
7 | |
8 | #include <utils/KeyedVector.h> |
9 | #include <SimpleThread.h> |
10 | #include <Composers.h> |
11 | #include <IDisplayDevice.h> |
12 | #include <inttypes.h> |
13 | |
14 | #include <ge2d_port.h> |
15 | #include <../kernel-headers/linux/ge2d.h> |
16 | |
17 | namespace android { |
18 | namespace amlogic { |
19 | |
20 | class LayerState { |
21 | public: |
22 | LayerState() |
23 | : mBufferHnd(NULL), |
24 | mBlendMode(0), |
25 | mTransform(HAL_TRANSFORM_RESERVED), |
26 | mBufferFd(-1) { |
27 | } |
28 | |
29 | ~LayerState() { |
30 | } |
31 | |
32 | //void setLayerState(HwcLayer* hwcLayer); |
33 | void setLayerState(HwcLayer* hwcLayer) { |
34 | mBlendMode = hwcLayer->getBlendMode(); |
35 | mColor = hwcLayer->getColor(); |
36 | mCompositionType = hwcLayer->getCompositionType(); |
37 | mAcquireFence = hwcLayer->getAcquireFence(); |
38 | mDataSpace = hwcLayer->getDataspace(); |
39 | mPlaneAlpha = hwcLayer->getPlaneAlpha(); |
40 | mTransform = hwcLayer->getTransform(); |
41 | mZ = hwcLayer->getZ(); |
42 | mSourceCrop = hwcLayer->getSourceCrop(); |
43 | mDisplayFrame = hwcLayer->getDisplayFrame(); |
44 | mBufferHnd = hwcLayer->getBufferHandle(); |
45 | |
46 | private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(mBufferHnd); |
47 | mBufferFd = Utils::checkAndDupFd(hnd->ion_hnd); |
48 | } |
49 | |
50 | int32_t mBlendMode; |
51 | hwc_color_t mColor; |
52 | int32_t mCompositionType; |
53 | int32_t mAcquireFence; |
54 | int32_t mDataSpace; |
55 | float mPlaneAlpha; |
56 | int32_t mTransform; |
57 | uint32_t mZ; |
58 | hwc_frect_t mSourceCrop; |
59 | hwc_rect_t mDisplayFrame; |
60 | // hwc_region_t mDamageRegion; |
61 | hwc_region_t mVisibleRegion; |
62 | |
63 | buffer_handle_t mBufferHnd; |
64 | |
65 | // hold this until ge2d finish process. |
66 | int32_t mBufferFd; |
67 | }; |
68 | |
69 | class SlotInfo { |
70 | public: |
71 | SlotInfo() |
72 | : mSlot(-1), |
73 | mFence(-1), |
74 | mVideoLayerId(0), |
75 | mClearBuffer(false), |
76 | mLayersState() { |
77 | mLayersState.setCapacity(HWC2_MAX_LAYERS); |
78 | mLayersState.clear(); |
79 | } |
80 | |
81 | ~SlotInfo() { |
82 | } |
83 | |
84 | const int32_t getSlot() const { return mSlot; }; |
85 | const int32_t getMergedFence() const { return mFence; }; |
86 | const Vector< LayerState* > getLayersState() const { return mLayersState; }; |
87 | |
88 | int32_t mSlot; |
89 | int32_t mFence; |
90 | hwc2_layer_t mVideoLayerId; |
91 | bool mClearBuffer; |
92 | Vector< LayerState* > mLayersState; |
93 | }; |
94 | |
95 | enum { NUM_GE2D_BUFFER_SLOTS = 3 }; |
96 | |
97 | class IDisplayDevice; |
98 | |
99 | class GE2DComposer : public Composers { |
100 | |
101 | public: |
102 | GE2DComposer(IDisplayDevice& disp); |
103 | virtual ~GE2DComposer(); |
104 | |
105 | public: |
106 | typedef Vector< SlotInfo > Fifo; |
107 | |
108 | virtual bool initialize(framebuffer_info_t* fbInfo); |
109 | virtual void deinitialize(); |
110 | virtual const char* getName() const; |
111 | virtual int32_t startCompose(Vector< hwc2_layer_t > hwcLayers, int32_t *offset = 0, int32_t frameCount = 0); |
112 | // virtual void setCurGlesFbSlot(uint32_t slot); |
113 | virtual const buffer_handle_t getBufHnd(); |
114 | virtual void mergeRetireFence(int32_t slot, int32_t retireFence); |
115 | virtual void removeRetireFence(int32_t slot); |
116 | virtual void setVideoOverlayLayerId(hwc2_layer_t layerId); |
117 | virtual void fillRectangle(hwc_rect_t clipRect, uint32_t color, uint32_t offset, int shared_fd); |
118 | private: |
119 | uint32_t findFreeFbSlot(); |
120 | void runGE2DProcess(int32_t slot, Vector< LayerState* > &hwcLayersState); |
121 | void directMemcpy(Fifo::iterator front); // test. |
122 | int32_t allocBuffer(private_module_t* module, size_t size, int32_t usage, buffer_handle_t* pHandle); |
123 | void freeBuffer(private_handle_t const* hnd, private_module_t* m); |
124 | bool isFullScreen(hwc_rect_t displayFrame); |
125 | void tracer(); |
126 | void dumpLayers(private_handle_t const* hnd); |
127 | |
128 | |
129 | IDisplayDevice& mDisplayDevice; |
130 | const char* mName; |
131 | |
132 | // Thread safe, mQueueItems is a FIFO of queued work used in synchronous mode. |
133 | volatile int32_t mQueuedFrames; |
134 | Fifo mQueueItems; |
135 | |
136 | // Fence. |
137 | int32_t mSyncTimelineFd; |
138 | uint32_t mCurrentSyncTime; |
139 | |
140 | int32_t mBufferMask; |
141 | int32_t mNumBuffers; |
142 | SlotInfo mSlots[NUM_GE2D_BUFFER_SLOTS]; |
143 | hwc2_layer_t mVideoLayerId; |
144 | // LayerState mVideoLayerState; |
145 | int32_t mFbSlot; |
146 | int32_t mCurGlesFbSlot; |
147 | framebuffer_info_t* mFbInfo; |
148 | int32_t mSingleFbSize; |
149 | |
150 | buffer_handle_t mGe2dBufHnd; |
151 | int mSharedFd; |
152 | int32_t mGe2dFd; |
153 | |
154 | aml_ge2d_info_t *mSrcBufferInfo; |
155 | bool mDebug; |
156 | |
157 | int32_t mDevice; |
158 | mutable Mutex mLock; |
159 | Condition mCondition; |
160 | bool mExitThread; |
161 | bool mInitialized; |
162 | |
163 | private: |
164 | DECLARE_THREAD(GE2DRenderThread, GE2DComposer); |
165 | }; |
166 | |
167 | } // namespace amlogic |
168 | } // namespace android |
169 | |
170 | |
171 | |
172 | #endif /* GE2D_COMPOSITOR_H */ |
173 | |
174 |