blob: 37626591a73997b1af3ac2e0d62390cfffdef931 [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
Pablo Ceballosce796e72016-02-04 19:10:51 -080026class Layer;
27
Andy McFaddenbf974ab2012-12-04 16:51:15 -080028/*
Andy McFadden2adaf042012-12-18 09:49:45 -080029 * This is a thin wrapper around GLConsumer.
Andy McFaddenbf974ab2012-12-04 16:51:15 -080030 */
Andy McFadden2adaf042012-12-18 09:49:45 -080031class SurfaceFlingerConsumer : public GLConsumer {
Andy McFaddenbf974ab2012-12-04 16:51:15 -080032public:
Dan Stozaecc50402015-04-28 14:42:06 -070033 static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8;
34
Jesse Hall399184a2014-03-03 15:42:54 -080035 struct ContentsChangedListener: public FrameAvailableListener {
36 virtual void onSidebandStreamChanged() = 0;
37 };
38
Dan Stozab9b08832014-03-13 11:55:57 -070039 SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
Pablo Ceballosce796e72016-02-04 19:10:51 -080040 uint32_t tex, const Layer* layer)
Dan Stozae49ba8e2014-06-24 13:09:19 -070041 : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
Pablo Ceballos40845df2016-01-25 17:41:15 -080042 mTransformToDisplayInverse(false), mSurfaceDamage(),
Pablo Ceballosce796e72016-02-04 19:10:51 -080043 mPrevReleaseFence(Fence::NO_FENCE), mLayer(layer)
Andy McFaddenbf974ab2012-12-04 16:51:15 -080044 {}
45
46 class BufferRejecter {
47 friend class SurfaceFlingerConsumer;
48 virtual bool reject(const sp<GraphicBuffer>& buf,
Dan Stoza11611f92015-03-12 15:12:44 -070049 const BufferItem& item) = 0;
Andy McFaddenbf974ab2012-12-04 16:51:15 -080050
51 protected:
52 virtual ~BufferRejecter() { }
53 };
54
Dan Stozaa4650a52015-05-12 12:56:16 -070055 virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
56 uint64_t maxFrameNumber = 0) override;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070057
Andy McFaddenbf974ab2012-12-04 16:51:15 -080058 // This version of updateTexImage() takes a functor that may be used to
Andy McFadden2adaf042012-12-18 09:49:45 -080059 // reject the newly acquired buffer. Unlike the GLConsumer version,
Andy McFaddenbf974ab2012-12-04 16:51:15 -080060 // this does not guarantee that the buffer has been bound to the GL
61 // texture.
Dan Stozaa4650a52015-05-12 12:56:16 -070062 status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync,
Pablo Ceballosff95aab2016-01-13 17:09:58 -080063 bool* autoRefresh, bool* queuedBuffer,
Dan Stozaa4650a52015-05-12 12:56:16 -070064 uint64_t maxFrameNumber = 0);
Andy McFaddenbf974ab2012-12-04 16:51:15 -080065
Andy McFadden2adaf042012-12-18 09:49:45 -080066 // See GLConsumer::bindTextureImageLocked().
Andy McFadden97eba892012-12-11 15:21:45 -080067 status_t bindTextureImage();
Andy McFadden1585c4d2013-06-28 13:52:40 -070068
Mathias Agopianc1c05de2013-09-17 23:45:22 -070069 // must be called from SF main thread
70 bool getTransformToDisplayInverse() const;
Dan Stozaee44edd2015-03-23 15:50:23 -070071 const Region& getSurfaceDamage() const;
Mathias Agopianc1c05de2013-09-17 23:45:22 -070072
Jesse Hall399184a2014-03-03 15:42:54 -080073 // Sets the contents changed listener. This should be used instead of
74 // ConsumerBase::setFrameAvailableListener().
75 void setContentsChangedListener(const wp<ContentsChangedListener>& listener);
76
77 sp<NativeHandle> getSidebandStream() const;
78
Andy McFadden41d67d72014-04-25 16:58:34 -070079 nsecs_t computeExpectedPresent(const DispSync& dispSync);
Mathias Agopianc1c05de2013-09-17 23:45:22 -070080
Dan Stoza9e56aa02015-11-02 13:00:03 -080081 virtual void setReleaseFence(const sp<Fence>& fence) override;
Pablo Ceballos40845df2016-01-25 17:41:15 -080082 sp<Fence> getPrevReleaseFence() const;
83#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -080084 void releasePendingBuffer();
85#endif
86
Pablo Ceballosce796e72016-02-04 19:10:51 -080087 virtual bool getFrameTimestamps(uint64_t frameNumber,
88 FrameTimestamps* outTimestamps) const override;
89
Dan Stoza6b9454d2014-11-07 16:00:59 -080090private:
Jesse Hall399184a2014-03-03 15:42:54 -080091 virtual void onSidebandStreamChanged();
92
93 wp<ContentsChangedListener> mContentsChangedListener;
94
Mathias Agopianc1c05de2013-09-17 23:45:22 -070095 // Indicates this buffer must be transformed by the inverse transform of the screen
96 // it is displayed onto. This is applied after GLConsumer::mCurrentTransform.
97 // This must be set/read from SurfaceFlinger's main thread.
98 bool mTransformToDisplayInverse;
Dan Stozaee44edd2015-03-23 15:50:23 -070099
100 // The portion of this surface that has changed since the previous frame
101 Region mSurfaceDamage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800102
103#ifdef USE_HWC2
104 // A release that is pending on the receipt of a new release fence from
105 // presentDisplay
106 PendingRelease mPendingRelease;
107#endif
Pablo Ceballos40845df2016-01-25 17:41:15 -0800108
109 // The release fence of the already displayed buffer (previous frame).
110 sp<Fence> mPrevReleaseFence;
Pablo Ceballosce796e72016-02-04 19:10:51 -0800111
112 // The layer for this SurfaceFlingerConsumer
113 wp<const Layer> mLayer;
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800114};
115
116// ----------------------------------------------------------------------------
117}; // namespace android
118
119#endif // ANDROID_SURFACEFLINGERCONSUMER_H