• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef USE_HWC2
46     virtual status_t compositionComplete();
47 #endif
48     virtual status_t advanceFrame();
49     virtual void onFrameCommitted();
50     virtual void dumpAsString(String8& result) const;
51 
52     // Cannot resize a buffers in a FramebufferSurface. Only works with virtual
53     // displays.
resizeBuffers(const uint32_t,const uint32_t)54     virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { };
55 
56     virtual const sp<Fence>& getClientTargetAcquireFence() const override;
57 
58 private:
~FramebufferSurface()59     virtual ~FramebufferSurface() { }; // this class cannot be overloaded
60 
61 #ifndef USE_HWC2
62     virtual void onFrameAvailable(const BufferItem& item);
63 #endif
64     virtual void freeBufferLocked(int slotIndex);
65 
66     virtual void dumpLocked(String8& result, const char* prefix) const;
67 
68     // nextBuffer waits for and then latches the next buffer from the
69     // BufferQueue and releases the previously latched buffer to the
70     // BufferQueue.  The new buffer is returned in the 'buffer' argument.
71 #ifdef USE_HWC2
72     status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
73             sp<Fence>& outFence, android_dataspace_t& outDataspace);
74 #else
75     status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence);
76 #endif
77 
78     // mDisplayType must match one of the HWC display types
79     int mDisplayType;
80 
81     // mCurrentBufferIndex is the slot index of the current buffer or
82     // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
83     // or the buffer is not associated with a slot.
84     int mCurrentBufferSlot;
85 
86     // mCurrentBuffer is the current buffer or NULL to indicate that there is
87     // no current buffer.
88     sp<GraphicBuffer> mCurrentBuffer;
89 
90     // mCurrentFence is the current buffer's acquire fence
91     sp<Fence> mCurrentFence;
92 
93     // Hardware composer, owned by SurfaceFlinger.
94     HWComposer& mHwc;
95 
96 #ifdef USE_HWC2
97     HWComposerBufferCache mHwcBufferCache;
98 
99     // Previous buffer to release after getting an updated retire fence
100     bool mHasPendingRelease;
101     int mPreviousBufferSlot;
102     sp<GraphicBuffer> mPreviousBuffer;
103 #endif
104 };
105 
106 // ---------------------------------------------------------------------------
107 }; // namespace android
108 // ---------------------------------------------------------------------------
109 
110 #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
111 
112