Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 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 | |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 23 | #include <com_android_graphics_libgui_flags.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 24 | #include <compositionengine/DisplaySurface.h> |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 25 | #include <gui/BufferQueue.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 26 | #include <gui/ConsumerBase.h> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 27 | #include <ui/DisplayId.h> |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 28 | #include <ui/Size.h> |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 29 | |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 30 | #include <ui/DisplayIdentification.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 31 | |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 32 | // --------------------------------------------------------------------------- |
| 33 | namespace android { |
| 34 | // --------------------------------------------------------------------------- |
| 35 | |
| 36 | class Rect; |
| 37 | class String8; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 38 | class HWComposer; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 42 | class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface { |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 43 | public: |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 44 | #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 Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 50 | FramebufferSurface(HWComposer& hwc, PhysicalDisplayId displayId, |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 51 | const sp<IGraphicBufferConsumer>& consumer, const ui::Size& size, |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 52 | const ui::Size& maxSize); |
Jim Shargo | 6ccc5e8 | 2024-07-27 03:42:08 +0000 | [diff] [blame] | 53 | #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ) |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 54 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 55 | virtual status_t beginFrame(bool mustRecompose); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 56 | virtual status_t prepareFrame(CompositionType compositionType); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 57 | virtual status_t advanceFrame(float hdrSdrRatio); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 58 | virtual void onFrameCommitted(); |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 59 | virtual void dumpAsString(String8& result) const; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 60 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 61 | virtual void resizeBuffers(const ui::Size&) override; |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 62 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 63 | virtual const sp<Fence>& getClientTargetAcquireFence() const override; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 64 | |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 65 | private: |
Marin Shalamanov | 4a92f55 | 2021-03-29 18:38:27 +0200 | [diff] [blame] | 66 | 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 McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 74 | virtual ~FramebufferSurface() { }; // this class cannot be overloaded |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 75 | |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 76 | virtual void freeBufferLocked(int slotIndex); |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 77 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 78 | virtual void dumpLocked(String8& result, const char* prefix) const; |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 79 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 80 | const PhysicalDisplayId mDisplayId; |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 81 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 82 | // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of |
| 83 | // the device. |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 84 | const ui::Size mMaxSize; |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 85 | |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 86 | // 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 Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 90 | |
Courtney Goeltzenleuchter | 19987a8 | 2017-07-14 12:16:56 -0600 | [diff] [blame] | 91 | // 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 Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 96 | ui::Dataspace mDataspace; |
Courtney Goeltzenleuchter | 19987a8 | 2017-07-14 12:16:56 -0600 | [diff] [blame] | 97 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 98 | // mCurrentBuffer is the current buffer or nullptr to indicate that there is |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 99 | // no current buffer. |
| 100 | sp<GraphicBuffer> mCurrentBuffer; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 101 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 102 | // mCurrentFence is the current buffer's acquire fence |
| 103 | sp<Fence> mCurrentFence; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 104 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 105 | // Hardware composer, owned by SurfaceFlinger. |
| 106 | HWComposer& mHwc; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 107 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 108 | // 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 Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 111 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 112 | // Previous buffer to release after getting an updated retire fence |
| 113 | bool mHasPendingRelease; |
| 114 | int mPreviousBufferSlot; |
| 115 | sp<GraphicBuffer> mPreviousBuffer; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | // --------------------------------------------------------------------------- |
| 119 | }; // namespace android |
| 120 | // --------------------------------------------------------------------------- |
| 121 | |
| 122 | #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H |
| 123 | |