blob: 312335132264fe7767f819c15bf390bc4198afe9 [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>
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
Lloyd Pique542307f2018-10-19 13:24:08 -070029#include "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,
45 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);
Jesse Hall99c7dbb2013-03-14 14:29:29 -070049 virtual status_t advanceFrame();
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
Mathias Agopianda27af92012-09-13 18:17:13 -070072 // nextBuffer waits for and then latches the next buffer from the
73 // BufferQueue and releases the previously latched buffer to the
74 // BufferQueue. The new buffer is returned in the 'buffer' argument.
Chia-I Wu06d63de2017-01-04 14:58:51 +080075 status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
Peiyong Lin34beb7a2018-03-28 11:57:12 -070076 sp<Fence>& outFence, ui::Dataspace& outDataspace);
Mathias Agopianda27af92012-09-13 18:17:13 -070077
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020078 const PhysicalDisplayId mDisplayId;
Mathias Agopianf5a33922012-09-19 18:16:22 -070079
Brian Lindahla13f2d52020-03-05 11:54:17 +010080 // Framebuffer size has a dimension limitation in pixels based on the graphics capabilities of
81 // the device.
Marin Shalamanov045b7002021-01-07 16:56:24 +010082 const ui::Size mMaxSize;
Brian Lindahla13f2d52020-03-05 11:54:17 +010083
Jamie Gennis1a4d8832012-08-02 20:11:05 -070084 // mCurrentBufferIndex is the slot index of the current buffer or
85 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
86 // or the buffer is not associated with a slot.
87 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070088
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060089 // mDataSpace is the dataspace of the current composition buffer for
90 // this FramebufferSurface. It will be 0 when HWC is doing the
91 // compositing. Otherwise it will display the dataspace of the buffer
92 // use for compositing which can change as wide-color content is
93 // on/off.
Peiyong Lin34beb7a2018-03-28 11:57:12 -070094 ui::Dataspace mDataSpace;
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060095
Peiyong Lin566a3b42018-01-09 18:22:43 -080096 // mCurrentBuffer is the current buffer or nullptr to indicate that there is
Jamie Gennis1a4d8832012-08-02 20:11:05 -070097 // no current buffer.
98 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070099
Dan Stoza9e56aa02015-11-02 13:00:03 -0800100 // mCurrentFence is the current buffer's acquire fence
101 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800102
Andy McFaddenb0d1dd32012-09-10 14:08:09 -0700103 // Hardware composer, owned by SurfaceFlinger.
104 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800105
Lloyd Pique76ed7032018-12-04 17:24:28 -0800106 compositionengine::impl::HwcBufferCache mHwcBufferCache;
Chia-I Wu06d63de2017-01-04 14:58:51 +0800107
Dan Stoza9e56aa02015-11-02 13:00:03 -0800108 // Previous buffer to release after getting an updated retire fence
109 bool mHasPendingRelease;
110 int mPreviousBufferSlot;
111 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -0700112};
113
114// ---------------------------------------------------------------------------
115}; // namespace android
116// ---------------------------------------------------------------------------
117
118#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
119