blob: 9b8de088cd754fe5ba5e473d9b1acce1ff51a973 [file] [log] [blame]
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001/*
2 * Copyright (C) 2012 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_SURFACEFLINGERCONSUMER_H
18#define ANDROID_SURFACEFLINGERCONSUMER_H
19
Andy McFadden41d67d72014-04-25 16:58:34 -070020#include "DispSync.h"
Mathias Agopiana9347642017-02-13 16:42:28 -080021
22#include <ui/Region.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080023#include <gui/GLConsumer.h>
Andy McFaddenbf974ab2012-12-04 16:51:15 -080024
25namespace android {
26// ----------------------------------------------------------------------------
27
Pablo Ceballosce796e72016-02-04 19:10:51 -080028class Layer;
29
Andy McFaddenbf974ab2012-12-04 16:51:15 -080030/*
Andy McFadden2adaf042012-12-18 09:49:45 -080031 * This is a thin wrapper around GLConsumer.
Andy McFaddenbf974ab2012-12-04 16:51:15 -080032 */
Andy McFadden2adaf042012-12-18 09:49:45 -080033class SurfaceFlingerConsumer : public GLConsumer {
Andy McFaddenbf974ab2012-12-04 16:51:15 -080034public:
Dan Stozaecc50402015-04-28 14:42:06 -070035 static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8;
36
Jesse Hall399184a2014-03-03 15:42:54 -080037 struct ContentsChangedListener: public FrameAvailableListener {
Chia-I Wu06d63de2017-01-04 14:58:51 +080038 virtual void onBuffersReleased() = 0;
Jesse Hall399184a2014-03-03 15:42:54 -080039 virtual void onSidebandStreamChanged() = 0;
40 };
41
Dan Stozab9b08832014-03-13 11:55:57 -070042 SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
Brian Andersond6927fb2016-07-23 23:37:30 -070043 uint32_t tex, Layer* layer)
Dan Stozae49ba8e2014-06-24 13:09:19 -070044 : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
Brian Anderson3546a3f2016-07-14 11:51:14 -070045 mTransformToDisplayInverse(false), mSurfaceDamage(), mLayer(layer)
Andy McFaddenbf974ab2012-12-04 16:51:15 -080046 {}
47
48 class BufferRejecter {
49 friend class SurfaceFlingerConsumer;
50 virtual bool reject(const sp<GraphicBuffer>& buf,
Dan Stoza11611f92015-03-12 15:12:44 -070051 const BufferItem& item) = 0;
Andy McFaddenbf974ab2012-12-04 16:51:15 -080052
53 protected:
54 virtual ~BufferRejecter() { }
55 };
56
Dan Stozaa4650a52015-05-12 12:56:16 -070057 virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
58 uint64_t maxFrameNumber = 0) override;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070059
Andy McFaddenbf974ab2012-12-04 16:51:15 -080060 // This version of updateTexImage() takes a functor that may be used to
Andy McFadden2adaf042012-12-18 09:49:45 -080061 // reject the newly acquired buffer. Unlike the GLConsumer version,
Andy McFaddenbf974ab2012-12-04 16:51:15 -080062 // this does not guarantee that the buffer has been bound to the GL
63 // texture.
Dan Stozaa4650a52015-05-12 12:56:16 -070064 status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync,
Pablo Ceballosff95aab2016-01-13 17:09:58 -080065 bool* autoRefresh, bool* queuedBuffer,
Brian Anderson3546a3f2016-07-14 11:51:14 -070066 uint64_t maxFrameNumber);
Andy McFaddenbf974ab2012-12-04 16:51:15 -080067
Andy McFadden2adaf042012-12-18 09:49:45 -080068 // See GLConsumer::bindTextureImageLocked().
Andy McFadden97eba892012-12-11 15:21:45 -080069 status_t bindTextureImage();
Andy McFadden1585c4d2013-06-28 13:52:40 -070070
Mathias Agopianc1c05de2013-09-17 23:45:22 -070071 bool getTransformToDisplayInverse() const;
Robert Carr367c5682016-06-20 11:55:28 -070072
73 // must be called from SF main thread
Dan Stozaee44edd2015-03-23 15:50:23 -070074 const Region& getSurfaceDamage() const;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070075
Jesse Hall399184a2014-03-03 15:42:54 -080076 // Sets the contents changed listener. This should be used instead of
77 // ConsumerBase::setFrameAvailableListener().
78 void setContentsChangedListener(const wp<ContentsChangedListener>& listener);
79
80 sp<NativeHandle> getSidebandStream() const;
81
Andy McFadden41d67d72014-04-25 16:58:34 -070082 nsecs_t computeExpectedPresent(const DispSync& dispSync);
Mathias Agopianc1c05de2013-09-17 23:45:22 -070083
Brian Anderson3546a3f2016-07-14 11:51:14 -070084 sp<Fence> getPrevFinalReleaseFence() const;
Fabien Sanglard9d96de42016-10-11 00:15:18 +000085#ifdef USE_HWC2
Brian Anderson3546a3f2016-07-14 11:51:14 -070086 virtual void setReleaseFence(const sp<Fence>& fence) override;
Dan Stoza9e56aa02015-11-02 13:00:03 -080087 void releasePendingBuffer();
Fabien Sanglard9d96de42016-10-11 00:15:18 +000088#endif
Dan Stoza9e56aa02015-11-02 13:00:03 -080089
Brian Anderson3890c392016-07-25 12:48:08 -070090 virtual void addAndGetFrameTimestamps(
Brian Andersond6927fb2016-07-23 23:37:30 -070091 const NewFrameEventsEntry* newTimestamps,
Brian Anderson3890c392016-07-25 12:48:08 -070092 FrameEventHistoryDelta* outDelta) override;
Pablo Ceballosce796e72016-02-04 19:10:51 -080093
Dan Stoza6b9454d2014-11-07 16:00:59 -080094private:
Chia-I Wu06d63de2017-01-04 14:58:51 +080095 virtual void onBuffersReleased();
Jesse Hall399184a2014-03-03 15:42:54 -080096 virtual void onSidebandStreamChanged();
97
98 wp<ContentsChangedListener> mContentsChangedListener;
99
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700100 // Indicates this buffer must be transformed by the inverse transform of the screen
101 // it is displayed onto. This is applied after GLConsumer::mCurrentTransform.
102 // This must be set/read from SurfaceFlinger's main thread.
103 bool mTransformToDisplayInverse;
Dan Stozaee44edd2015-03-23 15:50:23 -0700104
105 // The portion of this surface that has changed since the previous frame
106 Region mSurfaceDamage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800107
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000108#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800109 // A release that is pending on the receipt of a new release fence from
110 // presentDisplay
111 PendingRelease mPendingRelease;
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000112#endif
Pablo Ceballos40845df2016-01-25 17:41:15 -0800113
Pablo Ceballosce796e72016-02-04 19:10:51 -0800114 // The layer for this SurfaceFlingerConsumer
Brian Andersond6927fb2016-07-23 23:37:30 -0700115 const wp<Layer> mLayer;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800116};
117
118// ----------------------------------------------------------------------------
119}; // namespace android
120
121#endif // ANDROID_SURFACEFLINGERCONSUMER_H