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 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 23 | #include <compositionengine/DisplaySurface.h> |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 24 | #include <compositionengine/impl/HwcBufferCache.h> |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 25 | #include <gui/ConsumerBase.h> |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 26 | #include <ui/Size.h> |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 27 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 28 | #include "DisplayIdentification.h" |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 29 | |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 30 | // --------------------------------------------------------------------------- |
| 31 | namespace android { |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
| 34 | class Rect; |
| 35 | class String8; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 36 | class HWComposer; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 37 | |
| 38 | // --------------------------------------------------------------------------- |
| 39 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 40 | class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface { |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 41 | public: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 42 | FramebufferSurface(HWComposer& hwc, DisplayId displayId, |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 43 | const sp<IGraphicBufferConsumer>& consumer, uint32_t maxWidth, |
| 44 | uint32_t maxHeight); |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 45 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 46 | virtual status_t beginFrame(bool mustRecompose); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 47 | virtual status_t prepareFrame(CompositionType compositionType); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 48 | virtual status_t advanceFrame(); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 49 | virtual void onFrameCommitted(); |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 50 | virtual void dumpAsString(String8& result) const; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 51 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 52 | virtual void resizeBuffers(uint32_t width, uint32_t height); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 53 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 54 | virtual const sp<Fence>& getClientTargetAcquireFence() const override; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 55 | |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 56 | private: |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 57 | virtual ~FramebufferSurface() { }; // this class cannot be overloaded |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 58 | |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 59 | virtual void freeBufferLocked(int slotIndex); |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 60 | |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 61 | virtual void dumpLocked(String8& result, const char* prefix) const; |
Jesse Hall | 7adb0f8 | 2013-03-06 16:13:49 -0800 | [diff] [blame] | 62 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 63 | // 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 Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 66 | // 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 Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 69 | status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer, |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 70 | sp<Fence>& outFence, ui::Dataspace& outDataspace); |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 71 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 72 | const DisplayId mDisplayId; |
Mathias Agopian | f5a3392 | 2012-09-19 18:16:22 -0700 | [diff] [blame] | 73 | |
Brian Lindahl | a13f2d5 | 2020-03-05 11:54:17 +0100 | [diff] [blame] | 74 | // 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 Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 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; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 86 | |
Courtney Goeltzenleuchter | 19987a8 | 2017-07-14 12:16:56 -0600 | [diff] [blame] | 87 | // 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 Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 92 | ui::Dataspace mDataSpace; |
Courtney Goeltzenleuchter | 19987a8 | 2017-07-14 12:16:56 -0600 | [diff] [blame] | 93 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 94 | // mCurrentBuffer is the current buffer or nullptr to indicate that there is |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 95 | // no current buffer. |
| 96 | sp<GraphicBuffer> mCurrentBuffer; |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 97 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 98 | // mCurrentFence is the current buffer's acquire fence |
| 99 | sp<Fence> mCurrentFence; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 100 | |
Andy McFadden | b0d1dd3 | 2012-09-10 14:08:09 -0700 | [diff] [blame] | 101 | // Hardware composer, owned by SurfaceFlinger. |
| 102 | HWComposer& mHwc; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 103 | |
Lloyd Pique | 76ed703 | 2018-12-04 17:24:28 -0800 | [diff] [blame] | 104 | compositionengine::impl::HwcBufferCache mHwcBufferCache; |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 105 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 106 | // Previous buffer to release after getting an updated retire fence |
| 107 | bool mHasPendingRelease; |
| 108 | int mPreviousBufferSlot; |
| 109 | sp<GraphicBuffer> mPreviousBuffer; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | // --------------------------------------------------------------------------- |
| 113 | }; // namespace android |
| 114 | // --------------------------------------------------------------------------- |
| 115 | |
| 116 | #endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H |
| 117 | |