blob: 0605602a107e5dd2c3b06fab34b719a3ab753910 [file] [log] [blame]
Mathias Agopian3e876012012-06-07 17:52:54 -07001/*
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
Jamie Gennis1a4d8832012-08-02 20:11:05 -070023#include <gui/ConsumerBase.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070024
Jesse Hall99c7dbb2013-03-14 14:29:29 -070025#include "DisplaySurface.h"
26
Mathias Agopian3e876012012-06-07 17:52:54 -070027// ---------------------------------------------------------------------------
28namespace android {
29// ---------------------------------------------------------------------------
30
31class Rect;
32class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070033class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070034
35// ---------------------------------------------------------------------------
36
Jesse Hall99c7dbb2013-03-14 14:29:29 -070037class FramebufferSurface : public ConsumerBase,
38 public DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070039public:
Mathias Agopiandb89edc2013-08-02 01:40:18 -070040 FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer);
Mathias Agopian3e876012012-06-07 17:52:54 -070041
Dan Stoza71433162014-02-04 16:22:36 -080042 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070043 virtual status_t prepareFrame(CompositionType compositionType);
Dan Stoza9e56aa02015-11-02 13:00:03 -080044#ifndef USE_HWC2
Jesse Hall99c7dbb2013-03-14 14:29:29 -070045 virtual status_t compositionComplete();
Dan Stoza9e56aa02015-11-02 13:00:03 -080046#endif
Jesse Hall99c7dbb2013-03-14 14:29:29 -070047 virtual status_t advanceFrame();
Jesse Hall851cfe82013-03-20 13:44:00 -070048 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080049 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070050
Michael Lentine47e45402014-07-18 15:34:25 -070051 // 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
Dan Stoza9e56aa02015-11-02 13:00:03 -080055#ifdef USE_HWC2
56 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
57#endif
58
Mathias Agopian3e876012012-06-07 17:52:54 -070059private:
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070060 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070061
Dan Stoza9e56aa02015-11-02 13:00:03 -080062#ifndef USE_HWC2
Dan Stoza8dc55392014-11-04 11:37:46 -080063 virtual void onFrameAvailable(const BufferItem& item);
Dan Stoza9e56aa02015-11-02 13:00:03 -080064#endif
Jamie Gennis1a4d8832012-08-02 20:11:05 -070065 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070066
Mathias Agopian74d211a2013-04-22 16:55:35 +020067 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080068
Mathias Agopianda27af92012-09-13 18:17:13 -070069 // 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.
Dan Stoza9e56aa02015-11-02 13:00:03 -080072#ifdef USE_HWC2
73 status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence,
74 android_dataspace_t& outDataspace);
75#else
Mathias Agopianda27af92012-09-13 18:17:13 -070076 status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence);
Dan Stoza9e56aa02015-11-02 13:00:03 -080077#endif
Mathias Agopianda27af92012-09-13 18:17:13 -070078
Mathias Agopianf5a33922012-09-19 18:16:22 -070079 // mDisplayType must match one of the HWC display types
80 int mDisplayType;
81
Jamie Gennis1a4d8832012-08-02 20:11:05 -070082 // 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;
Mathias Agopian3e876012012-06-07 17:52:54 -070086
Jamie Gennis1a4d8832012-08-02 20:11:05 -070087 // mCurrentBuffer is the current buffer or NULL to indicate that there is
88 // no current buffer.
89 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070090
Dan Stoza9e56aa02015-11-02 13:00:03 -080091#ifdef USE_HWC2
92 // mCurrentFence is the current buffer's acquire fence
93 sp<Fence> mCurrentFence;
94#endif
95
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070096 // Hardware composer, owned by SurfaceFlinger.
97 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -080098
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
Mathias Agopian3e876012012-06-07 17:52:54 -0700105};
106
107// ---------------------------------------------------------------------------
108}; // namespace android
109// ---------------------------------------------------------------------------
110
111#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
112