1 /*
2  * Copyright (C) 2007 The Android Open Source Project
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 #ifndef ANDROID_SF_FRAMEBUFFER_SURFACE_H
18 #define ANDROID_SF_FRAMEBUFFER_SURFACE_H
19 
20 #include "DisplaySurface.h"
21 #include "HWComposerBufferCache.h"
22 
23 #include <stdint.h>
24 #include <sys/types.h>
25 
26 #include <gui/ConsumerBase.h>
27 
28 // ---------------------------------------------------------------------------
29 namespace android {
30 // ---------------------------------------------------------------------------
31 
32 class Rect;
33 class String8;
34 class HWComposer;
35 
36 // ---------------------------------------------------------------------------
37 
38 class FramebufferSurface : public ConsumerBase,
39                            public DisplaySurface {
40 public:
41     FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer);
42 
43     virtual status_t beginFrame(bool mustRecompose);
44     virtual status_t prepareFrame(CompositionType compositionType);
45     virtual status_t advanceFrame();
46     virtual void onFrameCommitted();
47     virtual void dumpAsString(String8& result) const;
48 
49     virtual void resizeBuffers(const uint32_t width, const uint32_t height);
50 
51     virtual const sp<Fence>& getClientTargetAcquireFence() const override;
52 
53 private:
~FramebufferSurface()54     virtual ~FramebufferSurface() { }; // this class cannot be overloaded
55 
56     virtual void freeBufferLocked(int slotIndex);
57 
58     virtual void dumpLocked(String8& result, const char* prefix) const;
59 
60     // nextBuffer waits for and then latches the next buffer from the
61     // BufferQueue and releases the previously latched buffer to the
62     // BufferQueue.  The new buffer is returned in the 'buffer' argument.
63     status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
64             sp<Fence>& outFence, ui::Dataspace& outDataspace);
65 
66     // mDisplayType must match one of the HWC display types
67     int mDisplayType;
68 
69     // mCurrentBufferIndex is the slot index of the current buffer or
70     // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
71     // or the buffer is not associated with a slot.
72     int mCurrentBufferSlot;
73 
74     // mDataSpace is the dataspace of the current composition buffer for
75     // this FramebufferSurface. It will be 0 when HWC is doing the
76     // compositing. Otherwise it will display the dataspace of the buffer
77     // use for compositing which can change as wide-color content is
78     // on/off.
79     ui::Dataspace mDataSpace;
80 
81     // mCurrentBuffer is the current buffer or nullptr to indicate that there is
82     // no current buffer.
83     sp<GraphicBuffer> mCurrentBuffer;
84 
85     // mCurrentFence is the current buffer's acquire fence
86     sp<Fence> mCurrentFence;
87 
88     // Hardware composer, owned by SurfaceFlinger.
89     HWComposer& mHwc;
90 
91     HWComposerBufferCache mHwcBufferCache;
92 
93     // Previous buffer to release after getting an updated retire fence
94     bool mHasPendingRelease;
95     int mPreviousBufferSlot;
96     sp<GraphicBuffer> mPreviousBuffer;
97 };
98 
99 // ---------------------------------------------------------------------------
100 }; // namespace android
101 // ---------------------------------------------------------------------------
102 
103 #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
104 
105