blob: 5eea6b60565d16bd587577404dd5b8e499d00893 [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
Chia-I Wu06d63de2017-01-04 14:58:51 +080020#include "DisplaySurface.h"
21
Mathias Agopian3e876012012-06-07 17:52:54 -070022#include <stdint.h>
23#include <sys/types.h>
24
Jamie Gennis1a4d8832012-08-02 20:11:05 -070025#include <gui/ConsumerBase.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070026
Chia-I Wu06d63de2017-01-04 14:58:51 +080027#include <memory>
Jesse Hall99c7dbb2013-03-14 14:29:29 -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;
Chia-I Wu06d63de2017-01-04 14:58:51 +080036class HWComposerBufferCache;
Mathias Agopian3e876012012-06-07 17:52:54 -070037
38// ---------------------------------------------------------------------------
39
Jesse Hall99c7dbb2013-03-14 14:29:29 -070040class FramebufferSurface : public ConsumerBase,
41 public DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070042public:
Mathias Agopiandb89edc2013-08-02 01:40:18 -070043 FramebufferSurface(HWComposer& hwc, int disp, 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);
Fabien Sanglard9d96de42016-10-11 00:15:18 +000047#ifndef USE_HWC2
48 virtual status_t compositionComplete();
49#endif
Jesse Hall99c7dbb2013-03-14 14:29:29 -070050 virtual status_t advanceFrame();
Jesse Hall851cfe82013-03-20 13:44:00 -070051 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080052 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070053
Michael Lentine47e45402014-07-18 15:34:25 -070054 // Cannot resize a buffers in a FramebufferSurface. Only works with virtual
55 // displays.
56 virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { };
57
Dan Stoza9e56aa02015-11-02 13:00:03 -080058 virtual const sp<Fence>& getClientTargetAcquireFence() const override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080059
Mathias Agopian3e876012012-06-07 17:52:54 -070060private:
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070061 virtual ~FramebufferSurface() { }; // this class cannot be overloaded
Jamie Gennis1a4d8832012-08-02 20:11:05 -070062
Fabien Sanglard9d96de42016-10-11 00:15:18 +000063#ifndef USE_HWC2
64 virtual void onFrameAvailable(const BufferItem& item);
65#endif
Jamie Gennis1a4d8832012-08-02 20:11:05 -070066 virtual void freeBufferLocked(int slotIndex);
Mathias Agopian3e876012012-06-07 17:52:54 -070067
Mathias Agopian74d211a2013-04-22 16:55:35 +020068 virtual void dumpLocked(String8& result, const char* prefix) const;
Jesse Hall7adb0f82013-03-06 16:13:49 -080069
Mathias Agopianda27af92012-09-13 18:17:13 -070070 // nextBuffer waits for and then latches the next buffer from the
71 // BufferQueue and releases the previously latched buffer to the
72 // BufferQueue. The new buffer is returned in the 'buffer' argument.
Fabien Sanglard9d96de42016-10-11 00:15:18 +000073#ifdef USE_HWC2
Chia-I Wu06d63de2017-01-04 14:58:51 +080074 status_t nextBuffer(uint32_t& outSlot, sp<GraphicBuffer>& outBuffer,
75 sp<Fence>& outFence, android_dataspace_t& outDataspace);
Fabien Sanglard9d96de42016-10-11 00:15:18 +000076#else
77 status_t nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>& outFence);
78#endif
Mathias Agopianda27af92012-09-13 18:17:13 -070079
Mathias Agopianf5a33922012-09-19 18:16:22 -070080 // mDisplayType must match one of the HWC display types
81 int mDisplayType;
82
Jamie Gennis1a4d8832012-08-02 20:11:05 -070083 // mCurrentBufferIndex is the slot index of the current buffer or
84 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
85 // or the buffer is not associated with a slot.
86 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070087
Jamie Gennis1a4d8832012-08-02 20:11:05 -070088 // mCurrentBuffer is the current buffer or NULL to indicate that there is
89 // no current buffer.
90 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070091
Dan Stoza9e56aa02015-11-02 13:00:03 -080092 // mCurrentFence is the current buffer's acquire fence
93 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -080094
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070095 // Hardware composer, owned by SurfaceFlinger.
96 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -080097
Fabien Sanglard9d96de42016-10-11 00:15:18 +000098#ifdef USE_HWC2
Chia-I Wu06d63de2017-01-04 14:58:51 +080099 std::unique_ptr<HWComposerBufferCache> mHwcBufferCache =
100 std::make_unique<HWComposerBufferCache>();
101
Dan Stoza9e56aa02015-11-02 13:00:03 -0800102 // Previous buffer to release after getting an updated retire fence
103 bool mHasPendingRelease;
104 int mPreviousBufferSlot;
105 sp<GraphicBuffer> mPreviousBuffer;
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000106#endif
Mathias Agopian3e876012012-06-07 17:52:54 -0700107};
108
109// ---------------------------------------------------------------------------
110}; // namespace android
111// ---------------------------------------------------------------------------
112
113#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
114