blob: 51b002f991630db32d72a91233fb8b91e761bb68 [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"
Andy McFadden2adaf042012-12-18 09:49:45 -080021#include <gui/GLConsumer.h>
Andy McFaddenbf974ab2012-12-04 16:51:15 -080022
23namespace android {
24// ----------------------------------------------------------------------------
25
26/*
Andy McFadden2adaf042012-12-18 09:49:45 -080027 * This is a thin wrapper around GLConsumer.
Andy McFaddenbf974ab2012-12-04 16:51:15 -080028 */
Andy McFadden2adaf042012-12-18 09:49:45 -080029class SurfaceFlingerConsumer : public GLConsumer {
Andy McFaddenbf974ab2012-12-04 16:51:15 -080030public:
Dan Stozaecc50402015-04-28 14:42:06 -070031 static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8;
32
Jesse Hall399184a2014-03-03 15:42:54 -080033 struct ContentsChangedListener: public FrameAvailableListener {
34 virtual void onSidebandStreamChanged() = 0;
35 };
36
Dan Stozab9b08832014-03-13 11:55:57 -070037 SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
38 uint32_t tex)
Dan Stozae49ba8e2014-06-24 13:09:19 -070039 : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
Pablo Ceballos40845df2016-01-25 17:41:15 -080040 mTransformToDisplayInverse(false), mSurfaceDamage(),
41 mPrevReleaseFence(Fence::NO_FENCE)
Andy McFaddenbf974ab2012-12-04 16:51:15 -080042 {}
43
44 class BufferRejecter {
45 friend class SurfaceFlingerConsumer;
46 virtual bool reject(const sp<GraphicBuffer>& buf,
Dan Stoza11611f92015-03-12 15:12:44 -070047 const BufferItem& item) = 0;
Andy McFaddenbf974ab2012-12-04 16:51:15 -080048
49 protected:
50 virtual ~BufferRejecter() { }
51 };
52
Dan Stozaa4650a52015-05-12 12:56:16 -070053 virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
54 uint64_t maxFrameNumber = 0) override;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070055
Andy McFaddenbf974ab2012-12-04 16:51:15 -080056 // This version of updateTexImage() takes a functor that may be used to
Andy McFadden2adaf042012-12-18 09:49:45 -080057 // reject the newly acquired buffer. Unlike the GLConsumer version,
Andy McFaddenbf974ab2012-12-04 16:51:15 -080058 // this does not guarantee that the buffer has been bound to the GL
59 // texture.
Dan Stozaa4650a52015-05-12 12:56:16 -070060 status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync,
Pablo Ceballosff95aab2016-01-13 17:09:58 -080061 bool* autoRefresh, bool* queuedBuffer,
Dan Stozaa4650a52015-05-12 12:56:16 -070062 uint64_t maxFrameNumber = 0);
Andy McFaddenbf974ab2012-12-04 16:51:15 -080063
Andy McFadden2adaf042012-12-18 09:49:45 -080064 // See GLConsumer::bindTextureImageLocked().
Andy McFadden97eba892012-12-11 15:21:45 -080065 status_t bindTextureImage();
Andy McFadden1585c4d2013-06-28 13:52:40 -070066
Mathias Agopianc1c05de2013-09-17 23:45:22 -070067 // must be called from SF main thread
68 bool getTransformToDisplayInverse() const;
Dan Stozaee44edd2015-03-23 15:50:23 -070069 const Region& getSurfaceDamage() const;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070070
Jesse Hall399184a2014-03-03 15:42:54 -080071 // Sets the contents changed listener. This should be used instead of
72 // ConsumerBase::setFrameAvailableListener().
73 void setContentsChangedListener(const wp<ContentsChangedListener>& listener);
74
75 sp<NativeHandle> getSidebandStream() const;
76
Andy McFadden41d67d72014-04-25 16:58:34 -070077 nsecs_t computeExpectedPresent(const DispSync& dispSync);
Mathias Agopianc1c05de2013-09-17 23:45:22 -070078
Dan Stoza9e56aa02015-11-02 13:00:03 -080079 virtual void setReleaseFence(const sp<Fence>& fence) override;
Pablo Ceballos40845df2016-01-25 17:41:15 -080080 sp<Fence> getPrevReleaseFence() const;
81#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -080082 void releasePendingBuffer();
83#endif
84
Dan Stoza6b9454d2014-11-07 16:00:59 -080085private:
Jesse Hall399184a2014-03-03 15:42:54 -080086 virtual void onSidebandStreamChanged();
87
88 wp<ContentsChangedListener> mContentsChangedListener;
89
Mathias Agopianc1c05de2013-09-17 23:45:22 -070090 // Indicates this buffer must be transformed by the inverse transform of the screen
91 // it is displayed onto. This is applied after GLConsumer::mCurrentTransform.
92 // This must be set/read from SurfaceFlinger's main thread.
93 bool mTransformToDisplayInverse;
Dan Stozaee44edd2015-03-23 15:50:23 -070094
95 // The portion of this surface that has changed since the previous frame
96 Region mSurfaceDamage;
Dan Stoza9e56aa02015-11-02 13:00:03 -080097
98#ifdef USE_HWC2
99 // A release that is pending on the receipt of a new release fence from
100 // presentDisplay
101 PendingRelease mPendingRelease;
102#endif
Pablo Ceballos40845df2016-01-25 17:41:15 -0800103
104 // The release fence of the already displayed buffer (previous frame).
105 sp<Fence> mPrevReleaseFence;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800106};
107
108// ----------------------------------------------------------------------------
109}; // namespace android
110
111#endif // ANDROID_SURFACEFLINGERCONSUMER_H