blob: 2728cf637e04185763b33b6a2411f7b4265b3d13 [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>
Brian Lindahl439afad2022-11-14 11:16:55 -070024#include <gui/BufferQueue.h>
Jamie Gennis1a4d8832012-08-02 20:11:05 -070025#include <gui/ConsumerBase.h>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020026#include <ui/DisplayId.h>
Brian Lindahla13f2d52020-03-05 11:54:17 +010027#include <ui/Size.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070028
Alec Mouriff793872022-01-13 17:45:06 -080029#include <ui/DisplayIdentification.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070030
Mathias Agopian3e876012012-06-07 17:52:54 -070031// ---------------------------------------------------------------------------
32namespace android {
33// ---------------------------------------------------------------------------
34
35class Rect;
36class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070037class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070038
39// ---------------------------------------------------------------------------
40
Lloyd Pique542307f2018-10-19 13:24:08 -070041class FramebufferSurface : public ConsumerBase, public compositionengine::DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070042public:
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020043 FramebufferSurface(HWComposer& hwc, PhysicalDisplayId displayId,
Marin Shalamanov045b7002021-01-07 16:56:24 +010044 const sp<IGraphicBufferConsumer>& consumer, const ui::Size& size,
Lloyd Pique30db6402023-06-26 18:56:51 +000045 const ui::Size& maxSize);
Mathias Agopian3e876012012-06-07 17:52:54 -070046
Dan Stoza71433162014-02-04 16:22:36 -080047 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070048 virtual status_t prepareFrame(CompositionType compositionType);
Alec Mourif97df4d2023-09-06 02:10:05 +000049 virtual status_t advanceFrame(float hdrSdrRatio);
Jesse Hall851cfe82013-03-20 13:44:00 -070050 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080051 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070052
Marin Shalamanov045b7002021-01-07 16:56:24 +010053 virtual void resizeBuffers(const ui::Size&) override;
Michael Lentine47e45402014-07-18 15:34:25 -070054
Dan Stoza9e56aa02015-11-02 13:00:03 -080055 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080056
Mathias Agopian3e876012012-06-07 17:52:54 -070057private:
Marin Shalamanov4a92f552021-03-29 18:38:27 +020058 friend class FramebufferSurfaceTest;
59
60 // Limits the width and height by the maximum width specified.
61 ui::Size limitSize(const ui::Size&);
62
63 // Used for testing purposes.
64 static ui::Size limitSizeInternal(const ui::Size&, const ui::Size& maxSize);
65
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070066 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070067
Jamie Gennis1a4d8832012-08-02 20:11:05 -070068 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070069
Mathias Agopian74d211a2013-04-22 16:55:35 +020070 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080071
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020072 const PhysicalDisplayId 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.
Marin Shalamanov045b7002021-01-07 16:56:24 +010076 const ui::Size mMaxSize;
Brian Lindahla13f2d52020-03-05 11:54:17 +010077
Jamie Gennis1a4d8832012-08-02 20:11:05 -070078 // mCurrentBufferIndex is the slot index of the current buffer or
79 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
80 // or the buffer is not associated with a slot.
81 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070082
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060083 // mDataSpace is the dataspace of the current composition buffer for
84 // this FramebufferSurface. It will be 0 when HWC is doing the
85 // compositing. Otherwise it will display the dataspace of the buffer
86 // use for compositing which can change as wide-color content is
87 // on/off.
Brian Lindahl439afad2022-11-14 11:16:55 -070088 ui::Dataspace mDataspace;
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060089
Peiyong Lin566a3b42018-01-09 18:22:43 -080090 // mCurrentBuffer is the current buffer or nullptr to indicate that there is
Jamie Gennis1a4d8832012-08-02 20:11:05 -070091 // no current buffer.
92 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070093
Dan Stoza9e56aa02015-11-02 13:00:03 -080094 // mCurrentFence is the current buffer's acquire fence
95 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -080096
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070097 // Hardware composer, owned by SurfaceFlinger.
98 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -080099
Brian Lindahl439afad2022-11-14 11:16:55 -0700100 // Buffers that HWC has seen before, indexed by slot number.
101 // NOTE: The BufferQueue slot number is the same as the HWC slot number.
102 uint64_t mHwcBufferIds[BufferQueue::NUM_BUFFER_SLOTS];
Chia-I Wu06d63de2017-01-04 14:58:51 +0800103
Dan Stoza9e56aa02015-11-02 13:00:03 -0800104 // Previous buffer to release after getting an updated retire fence
105 bool mHasPendingRelease;
106 int mPreviousBufferSlot;
107 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -0700108};
109
110// ---------------------------------------------------------------------------
111}; // namespace android
112// ---------------------------------------------------------------------------
113
114#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
115