blob: 4186b7aac4d435e054c362f8cc6d6b32f24cda04 [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"
Chia-I Wuaaff73f2017-02-13 12:28:24 -080021#include "HWComposerBufferCache.h"
Chia-I Wu06d63de2017-01-04 14:58:51 +080022
Mathias Agopian3e876012012-06-07 17:52:54 -070023#include <stdint.h>
24#include <sys/types.h>
25
Jamie Gennis1a4d8832012-08-02 20:11:05 -070026#include <gui/ConsumerBase.h>
Mathias Agopian3e876012012-06-07 17:52:54 -070027
Mathias Agopian3e876012012-06-07 17:52:54 -070028// ---------------------------------------------------------------------------
29namespace android {
30// ---------------------------------------------------------------------------
31
32class Rect;
33class String8;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070034class HWComposer;
Mathias Agopian3e876012012-06-07 17:52:54 -070035
36// ---------------------------------------------------------------------------
37
Jesse Hall99c7dbb2013-03-14 14:29:29 -070038class FramebufferSurface : public ConsumerBase,
39 public DisplaySurface {
Mathias Agopian3e876012012-06-07 17:52:54 -070040public:
Mathias Agopiandb89edc2013-08-02 01:40:18 -070041 FramebufferSurface(HWComposer& hwc, int disp, const sp<IGraphicBufferConsumer>& consumer);
Mathias Agopian3e876012012-06-07 17:52:54 -070042
Dan Stoza71433162014-02-04 16:22:36 -080043 virtual status_t beginFrame(bool mustRecompose);
Jesse Hall38efe862013-04-06 23:12:29 -070044 virtual status_t prepareFrame(CompositionType compositionType);
Jesse Hall99c7dbb2013-03-14 14:29:29 -070045 virtual status_t advanceFrame();
Jesse Hall851cfe82013-03-20 13:44:00 -070046 virtual void onFrameCommitted();
Dan Stozaf10c46e2014-11-11 10:32:31 -080047 virtual void dumpAsString(String8& result) const;
Mathias Agopiana4912602012-07-12 14:25:33 -070048
Michael Lentine47e45402014-07-18 15:34:25 -070049 // Cannot resize a buffers in a FramebufferSurface. Only works with virtual
50 // displays.
51 virtual void resizeBuffers(const uint32_t /*w*/, const uint32_t /*h*/) { };
52
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,
66 sp<Fence>& outFence, android_dataspace_t& outDataspace);
Mathias Agopianda27af92012-09-13 18:17:13 -070067
Mathias Agopianf5a33922012-09-19 18:16:22 -070068 // mDisplayType must match one of the HWC display types
69 int mDisplayType;
70
Jamie Gennis1a4d8832012-08-02 20:11:05 -070071 // mCurrentBufferIndex is the slot index of the current buffer or
72 // INVALID_BUFFER_SLOT to indicate that either there is no current buffer
73 // or the buffer is not associated with a slot.
74 int mCurrentBufferSlot;
Mathias Agopian3e876012012-06-07 17:52:54 -070075
Courtney Goeltzenleuchter19987a82017-07-14 12:16:56 -060076 // mDataSpace is the dataspace of the current composition buffer for
77 // this FramebufferSurface. It will be 0 when HWC is doing the
78 // compositing. Otherwise it will display the dataspace of the buffer
79 // use for compositing which can change as wide-color content is
80 // on/off.
81 android_dataspace mDataSpace;
82
Jamie Gennis1a4d8832012-08-02 20:11:05 -070083 // mCurrentBuffer is the current buffer or NULL to indicate that there is
84 // no current buffer.
85 sp<GraphicBuffer> mCurrentBuffer;
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070086
Dan Stoza9e56aa02015-11-02 13:00:03 -080087 // mCurrentFence is the current buffer's acquire fence
88 sp<Fence> mCurrentFence;
Dan Stoza9e56aa02015-11-02 13:00:03 -080089
Andy McFaddenb0d1dd32012-09-10 14:08:09 -070090 // Hardware composer, owned by SurfaceFlinger.
91 HWComposer& mHwc;
Dan Stoza9e56aa02015-11-02 13:00:03 -080092
Chia-I Wuaaff73f2017-02-13 12:28:24 -080093 HWComposerBufferCache mHwcBufferCache;
Chia-I Wu06d63de2017-01-04 14:58:51 +080094
Dan Stoza9e56aa02015-11-02 13:00:03 -080095 // Previous buffer to release after getting an updated retire fence
96 bool mHasPendingRelease;
97 int mPreviousBufferSlot;
98 sp<GraphicBuffer> mPreviousBuffer;
Mathias Agopian3e876012012-06-07 17:52:54 -070099};
100
101// ---------------------------------------------------------------------------
102}; // namespace android
103// ---------------------------------------------------------------------------
104
105#endif // ANDROID_SF_FRAMEBUFFER_SURFACE_H
106