blob: 2431dfd7c78c8033b9105208f9882b5ff80ef97b [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
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include "DisplayIdentification.h"
Chia-I Wu06d63de2017-01-04 14:58:51 +080021#include "DisplaySurface.h"
Chia-I Wuaaff73f2017-02-13 12:28:24 -080022#include "HWComposerBufferCache.h"
Chia-I Wu06d63de2017-01-04 14:58:51 +080023
Mathias Agopian3e876012012-06-07 17:52:54 -070024#include <stdint.h>
25#include <sys/types.h>
26
Jamie Gennis1a4d8832012-08-02 20:11:05 -070027#include <gui/ConsumerBase.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070028
Mathias Agopian3e876012012-06-07 17:52:54 -070029// ---------------------------------------------------------------------------
30namespace android {
31// ---------------------------------------------------------------------------
32
33class Rect;
34class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070035class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070036
37// ---------------------------------------------------------------------------
38
Jesse Hall99c7dbb2013-03-14 14:29:29 -070039class FramebufferSurface : public ConsumerBase,
40 public DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070041public:
Dominik Laskowski075d3172018-05-24 15:50:06 -070042 FramebufferSurface(HWComposer& hwc, DisplayId displayId,
43 const sp<IGraphicBufferConsumer>& consumer);
Mathias Agopian3e876012012-06-07 17:52:54 -070044
Dan Stoza71433162014-02-04 16:22:36 -080045 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070046 virtual status_t prepareFrame(CompositionType compositionType);
Jesse Hall99c7dbb2013-03-14 14:29:29 -070047 virtual status_t advanceFrame();
Jesse Hall851cfe82013-03-20 13:44:00 -070048 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080049 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070050
Lloyd Pique2ae2b3b2017-12-14 17:18:17 -080051 virtual void resizeBuffers(const uint32_t width, const uint32_t height);
Michael Lentine47e45402014-07-18 15:34:25 -070052
Dan Stoza9e56aa02015-11-02 13:00:03 -080053 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080054
Mathias Agopian3e876012012-06-07 17:52:54 -070055private:
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070056 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070057
Jamie Gennis1a4d8832012-08-02 20:11:05 -070058 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070059
Mathias Agopian74d211a2013-04-22 16:55:35 +020060 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080061
Mathias Agopianda27af92012-09-13 18:17:13 -070062 // nextBuffer waits for and then latches the next buffer from the
63 // BufferQueue and releases the previously latched buffer to the
64 // BufferQueue. The new buffer is returned in the 'buffer' argument.
Chia-I Wu06d63de2017-01-04 14:58:51 +080065 status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
Peiyong Lin34beb7a2018-03-28 11:57:12 -070066 sp<Fence>& outFence, ui::Dataspace& outDataspace);
Mathias Agopianda27af92012-09-13 18:17:13 -070067
Dominik Laskowski075d3172018-05-24 15:50:06 -070068 const DisplayId mDisplayId;
Mathias Agopianf5a33922012-09-19 18:16:22 -070069
Jamie Gennis1a4d8832012-08-02 20:11:05 -070070 // mCurrentBufferIndex is the slot index of the current buffer or
71 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
72 // or the buffer is not associated with a slot.
73 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070074
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060075 // mDataSpace is the dataspace of the current composition buffer for
76 // this FramebufferSurface. It will be 0 when HWC is doing the
77 // compositing. Otherwise it will display the dataspace of the buffer
78 // use for compositing which can change as wide-color content is
79 // on/off.
Peiyong Lin34beb7a2018-03-28 11:57:12 -070080 ui::Dataspace mDataSpace;
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060081
Peiyong Lin566a3b42018-01-09 18:22:43 -080082 // mCurrentBuffer is the current buffer or nullptr to indicate that there is
Jamie Gennis1a4d8832012-08-02 20:11:05 -070083 // no current buffer.
84 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070085
Dan Stoza9e56aa02015-11-02 13:00:03 -080086 // mCurrentFence is the current buffer's acquire fence
87 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -080088
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070089 // Hardware composer, owned by SurfaceFlinger.
90 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -080091
Chia-I Wuaaff73f2017-02-13 12:28:24 -080092 HWComposerBufferCache mHwcBufferCache;
Chia-I Wu06d63de2017-01-04 14:58:51 +080093
Dan Stoza9e56aa02015-11-02 13:00:03 -080094 // Previous buffer to release after getting an updated retire fence
95 bool mHasPendingRelease;
96 int mPreviousBufferSlot;
97 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -070098};
99
100// ---------------------------------------------------------------------------
101}; // namespace android
102// ---------------------------------------------------------------------------
103
104#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
105