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