blob: 6ca64a24373db6117f84b8ea623943ce2fdade07 [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
Jim Shargo6ccc5e82024-07-27 03:42:08 +000023#include <com_android_graphics_libgui_flags.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070024#include <compositionengine/DisplaySurface.h>
Brian Lindahl439afad2022-11-14 11:16:55 -070025#include <gui/BufferQueue.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070026#include <gui/ConsumerBase.h>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020027#include <ui/DisplayId.h>
Brian Lindahla13f2d52020-03-05 11:54:17 +010028#include <ui/Size.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070029
Alec Mouriff793872022-01-13 17:45:06 -080030#include <ui/DisplayIdentification.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070031
Mathias Agopian3e876012012-06-07 17:52:54 -070032// ---------------------------------------------------------------------------
33namespace android {
34// ---------------------------------------------------------------------------
35
36class Rect;
37class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070038class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070039
40// ---------------------------------------------------------------------------
41
Lloyd Pique542307f2018-10-19 13:24:08 -070042class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070043public:
Jim Shargo6ccc5e82024-07-27 03:42:08 +000044#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
45 FramebufferSurface(HWComposer& hwc, PhysicalDisplayId displayId,
46 const sp<IGraphicBufferProducer>& producer,
47 const sp<IGraphicBufferConsumer>& consumer, const ui::Size& size,
48 const ui::Size& maxSize);
49#else
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020050 FramebufferSurface(HWComposer& hwc, PhysicalDisplayId displayId,
Marin Shalamanov045b7002021-01-07 16:56:24 +010051 const sp<IGraphicBufferConsumer>& consumer, const ui::Size& size,
Lloyd Pique30db6402023-06-26 18:56:51 +000052 const ui::Size& maxSize);
Jim Shargo6ccc5e82024-07-27 03:42:08 +000053#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
Mathias Agopian3e876012012-06-07 17:52:54 -070054
Dan Stoza71433162014-02-04 16:22:36 -080055 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070056 virtual status_t prepareFrame(CompositionType compositionType);
Alec Mourif97df4d2023-09-06 02:10:05 +000057 virtual status_t advanceFrame(float hdrSdrRatio);
Jesse Hall851cfe82013-03-20 13:44:00 -070058 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080059 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070060
Marin Shalamanov045b7002021-01-07 16:56:24 +010061 virtual void resizeBuffers(const ui::Size&) override;
Michael Lentine47e45402014-07-18 15:34:25 -070062
Dan Stoza9e56aa02015-11-02 13:00:03 -080063 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080064
Mathias Agopian3e876012012-06-07 17:52:54 -070065private:
Marin Shalamanov4a92f552021-03-29 18:38:27 +020066 friend class FramebufferSurfaceTest;
67
68 // Limits the width and height by the maximum width specified.
69 ui::Size limitSize(const ui::Size&);
70
71 // Used for testing purposes.
72 static ui::Size limitSizeInternal(const ui::Size&, const ui::Size& maxSize);
73
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070074 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070075
Jamie Gennis1a4d8832012-08-02 20:11:05 -070076 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070077
Mathias Agopian74d211a2013-04-22 16:55:35 +020078 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080079
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020080 const PhysicalDisplayId mDisplayId;
Mathias Agopianf5a33922012-09-19 18:16:22 -070081
Brian Lindahla13f2d52020-03-05 11:54:17 +010082 // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of
83 // the device.
Marin Shalamanov045b7002021-01-07 16:56:24 +010084 const ui::Size mMaxSize;
Brian Lindahla13f2d52020-03-05 11:54:17 +010085
Jamie Gennis1a4d8832012-08-02 20:11:05 -070086 // mCurrentBufferIndex is the slot index of the current buffer or
87 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
88 // or the buffer is not associated with a slot.
89 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070090
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060091 // mDataSpace is the dataspace of the current composition buffer for
92 // this FramebufferSurface. It will be 0 when HWC is doing the
93 // compositing. Otherwise it will display the dataspace of the buffer
94 // use for compositing which can change as wide-color content is
95 // on/off.
Brian Lindahl439afad2022-11-14 11:16:55 -070096 ui::Dataspace mDataspace;
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060097
Peiyong Lin566a3b42018-01-09 18:22:43 -080098 // mCurrentBuffer is the current buffer or nullptr to indicate that there is
Jamie Gennis1a4d8832012-08-02 20:11:05 -070099 // no current buffer.
100 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700101
Dan Stoza9e56aa02015-11-02 13:00:03 -0800102 // mCurrentFence is the current buffer's acquire fence
103 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800104
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700105 // Hardware composer, owned by SurfaceFlinger.
106 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800107
Brian Lindahl439afad2022-11-14 11:16:55 -0700108 // Buffers that HWC has seen before, indexed by slot number.
109 // NOTE: The BufferQueue slot number is the same as the HWC slot number.
110 uint64_t mHwcBufferIds[BufferQueue::NUM_BUFFER_SLOTS];
Chia-I Wu06d63de2017-01-04 14:58:51 +0800111
Dan Stoza9e56aa02015-11-02 13:00:03 -0800112 // Previous buffer to release after getting an updated retire fence
113 bool mHasPendingRelease;
114 int mPreviousBufferSlot;
115 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -0700116};
117
118// ---------------------------------------------------------------------------
119}; // namespace android
120// ---------------------------------------------------------------------------
121
122#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
123