FramebufferSurface.h revision 9e56aa0fdb5f7121b9b975c6c16db103ea4d2fe9
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 <stdint.h>
21#include <sys/types.h>
22
23#include <gui/ConsumerBase.h>
24
25#include "DisplaySurface.h"
26
27// ---------------------------------------------------------------------------
28namespace android {
29// ---------------------------------------------------------------------------
30
31class Rect;
32class String8;
33class HWComposer;
34
35// ---------------------------------------------------------------------------
36
37class FramebufferSurface : public ConsumerBase,
38                           public DisplaySurface {
39public:
40    FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer);
41
42    virtual status_t beginFrame(bool mustRecompose);
43    virtual status_t prepareFrame(CompositionType compositionType);
44#ifndef USE_HWC2
45    virtual status_t compositionComplete();
46#endif
47    virtual status_t advanceFrame();
48    virtual void onFrameCommitted();
49    virtual void dumpAsString(String8& result) const;
50
51    // Cannot resize a buffers in a FramebufferSurface. Only works with virtual
52    // displays.
53    virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { };
54
55#ifdef USE_HWC2
56    virtual const sp<Fence>& getClientTargetAcquireFence() const override;
57#endif
58
59private:
60    virtual ~FramebufferSurface() { }; // this class cannot be overloaded
61
62#ifndef USE_HWC2
63    virtual void onFrameAvailable(const BufferItem& item);
64#endif
65    virtual void freeBufferLocked(int slotIndex);
66
67    virtual void dumpLocked(String8& result, const char* prefix) const;
68
69    // nextBuffer waits for and then latches the next buffer from the
70    // BufferQueue and releases the previously latched buffer to the
71    // BufferQueue.  The new buffer is returned in the 'buffer' argument.
72#ifdef USE_HWC2
73    status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence,
74            android_dataspace_t& outDataspace);
75#else
76    status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence);
77#endif
78
79    // mDisplayType must match one of the HWC display types
80    int mDisplayType;
81
82    // mCurrentBufferIndex is the slot index of the current buffer or
83    // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
84    // or the buffer is not associated with a slot.
85    int mCurrentBufferSlot;
86
87    // mCurrentBuffer is the current buffer or NULL to indicate that there is
88    // no current buffer.
89    sp<GraphicBuffer> mCurrentBuffer;
90
91#ifdef USE_HWC2
92    // mCurrentFence is the current buffer's acquire fence
93    sp<Fence> mCurrentFence;
94#endif
95
96    // Hardware composer, owned by SurfaceFlinger.
97    HWComposer& mHwc;
98
99#ifdef USE_HWC2
100    // Previous buffer to release after getting an updated retire fence
101    bool mHasPendingRelease;
102    int mPreviousBufferSlot;
103    sp<GraphicBuffer> mPreviousBuffer;
104#endif
105};
106
107// ---------------------------------------------------------------------------
108}; // namespace android
109// ---------------------------------------------------------------------------
110
111#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
112
113