blob: a1859f33bb80d113aa4c0cf2abbda88e9bdb0d53 [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
Lloyd Pique542307f2018-10-19 13:24:08 -070023#include <compositionengine/DisplaySurface.h>
Lloyd Pique76ed7032018-12-04 17:24:28 -080024#include <compositionengine/impl/HwcBufferCache.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070025#include <gui/ConsumerBase.h>
Brian Lindahla13f2d52020-03-05 11:54:17 +010026#include <ui/Size.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070027
Lloyd Pique542307f2018-10-19 13:24:08 -070028#include "DisplayIdentification.h"
Lloyd Pique542307f2018-10-19 13:24:08 -070029
Mathias Agopian3e876012012-06-07 17:52:54 -070030// ---------------------------------------------------------------------------
31namespace android {
32// ---------------------------------------------------------------------------
33
34class Rect;
35class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070036class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070037
38// ---------------------------------------------------------------------------
39
Lloyd Pique542307f2018-10-19 13:24:08 -070040class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070041public:
Dominik Laskowski075d3172018-05-24 15:50:06 -070042 FramebufferSurface(HWComposer& hwc, DisplayId displayId,
Brian Lindahla13f2d52020-03-05 11:54:17 +010043 const sp<IGraphicBufferConsumer>& consumer, uint32_t maxWidth,
44 uint32_t maxHeight);
Mathias Agopian3e876012012-06-07 17:52:54 -070045
Dan Stoza71433162014-02-04 16:22:36 -080046 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070047 virtual status_t prepareFrame(CompositionType compositionType);
Jesse Hall99c7dbb2013-03-14 14:29:29 -070048 virtual status_t advanceFrame();
Jesse Hall851cfe82013-03-20 13:44:00 -070049 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080050 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070051
Brian Lindahla13f2d52020-03-05 11:54:17 +010052 virtual void resizeBuffers(uint32_t width, uint32_t height);
Michael Lentine47e45402014-07-18 15:34:25 -070053
Dan Stoza9e56aa02015-11-02 13:00:03 -080054 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080055
Mathias Agopian3e876012012-06-07 17:52:54 -070056private:
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070057 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070058
Jamie Gennis1a4d8832012-08-02 20:11:05 -070059 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070060
Mathias Agopian74d211a2013-04-22 16:55:35 +020061 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080062
Brian Lindahla13f2d52020-03-05 11:54:17 +010063 // Limits the width and height by the maximum width specified in the constructor.
64 ui::Size limitFramebufferSize(uint32_t width, uint32_t height);
65
Mathias Agopianda27af92012-09-13 18:17:13 -070066 // nextBuffer waits for and then latches the next buffer from the
67 // BufferQueue and releases the previously latched buffer to the
68 // BufferQueue. The new buffer is returned in the 'buffer' argument.
Chia-I Wu06d63de2017-01-04 14:58:51 +080069 status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
Peiyong Lin34beb7a2018-03-28 11:57:12 -070070 sp<Fence>& outFence, ui::Dataspace& outDataspace);
Mathias Agopianda27af92012-09-13 18:17:13 -070071
Dominik Laskowski075d3172018-05-24 15:50:06 -070072 const DisplayId mDisplayId;
Mathias Agopianf5a33922012-09-19 18:16:22 -070073
Brian Lindahla13f2d52020-03-05 11:54:17 +010074 // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of
75 // the device.
76 const uint32_t mMaxWidth;
77
78 // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of
79 // the device.
80 const uint32_t mMaxHeight;
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
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060087 // mDataSpace is the dataspace of the current composition buffer for
88 // this FramebufferSurface. It will be 0 when HWC is doing the
89 // compositing. Otherwise it will display the dataspace of the buffer
90 // use for compositing which can change as wide-color content is
91 // on/off.
Peiyong Lin34beb7a2018-03-28 11:57:12 -070092 ui::Dataspace mDataSpace;
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060093
Peiyong Lin566a3b42018-01-09 18:22:43 -080094 // mCurrentBuffer is the current buffer or nullptr to indicate that there is
Jamie Gennis1a4d8832012-08-02 20:11:05 -070095 // no current buffer.
96 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070097
Dan Stoza9e56aa02015-11-02 13:00:03 -080098 // mCurrentFence is the current buffer's acquire fence
99 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800100
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700101 // Hardware composer, owned by SurfaceFlinger.
102 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800103
Lloyd Pique76ed7032018-12-04 17:24:28 -0800104 compositionengine::impl::HwcBufferCache mHwcBufferCache;
Chia-I Wu06d63de2017-01-04 14:58:51 +0800105
Dan Stoza9e56aa02015-11-02 13:00:03 -0800106 // Previous buffer to release after getting an updated retire fence
107 bool mHasPendingRelease;
108 int mPreviousBufferSlot;
109 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -0700110};
111
112// ---------------------------------------------------------------------------
113}; // namespace android
114// ---------------------------------------------------------------------------
115
116#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
117