Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1 | /* |
| 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 McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 20 | #include "DispSync.h" |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 21 | #include <gui/GLConsumer.h> |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 26 | class Layer; |
| 27 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 28 | /* |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 29 | * This is a thin wrapper around GLConsumer. |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 30 | */ |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 31 | class SurfaceFlingerConsumer : public GLConsumer { |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 32 | public: |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 33 | static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8; |
| 34 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 35 | struct ContentsChangedListener: public FrameAvailableListener { |
| 36 | virtual void onSidebandStreamChanged() = 0; |
| 37 | }; |
| 38 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 39 | SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer, |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 40 | uint32_t tex, const Layer* layer) |
Dan Stoza | e49ba8e | 2014-06-24 13:09:19 -0700 | [diff] [blame] | 41 | : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false), |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 42 | mTransformToDisplayInverse(false), mSurfaceDamage(), |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 43 | mPrevReleaseFence(Fence::NO_FENCE), mLayer(layer) |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 44 | {} |
| 45 | |
| 46 | class BufferRejecter { |
| 47 | friend class SurfaceFlingerConsumer; |
| 48 | virtual bool reject(const sp<GraphicBuffer>& buf, |
Dan Stoza | 11611f9 | 2015-03-12 15:12:44 -0700 | [diff] [blame] | 49 | const BufferItem& item) = 0; |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 50 | |
| 51 | protected: |
| 52 | virtual ~BufferRejecter() { } |
| 53 | }; |
| 54 | |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 55 | virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen, |
| 56 | uint64_t maxFrameNumber = 0) override; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 57 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 58 | // This version of updateTexImage() takes a functor that may be used to |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 59 | // reject the newly acquired buffer. Unlike the GLConsumer version, |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 60 | // this does not guarantee that the buffer has been bound to the GL |
| 61 | // texture. |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 62 | status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync, |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 63 | bool* autoRefresh, bool* queuedBuffer, |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 64 | uint64_t maxFrameNumber = 0); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 65 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 66 | // See GLConsumer::bindTextureImageLocked(). |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 67 | status_t bindTextureImage(); |
Andy McFadden | 1585c4d | 2013-06-28 13:52:40 -0700 | [diff] [blame] | 68 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 69 | bool getTransformToDisplayInverse() const; |
Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 70 | |
| 71 | // must be called from SF main thread |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 72 | const Region& getSurfaceDamage() const; |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 73 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 74 | // Sets the contents changed listener. This should be used instead of |
| 75 | // ConsumerBase::setFrameAvailableListener(). |
| 76 | void setContentsChangedListener(const wp<ContentsChangedListener>& listener); |
| 77 | |
| 78 | sp<NativeHandle> getSidebandStream() const; |
| 79 | |
Andy McFadden | 41d67d7 | 2014-04-25 16:58:34 -0700 | [diff] [blame] | 80 | nsecs_t computeExpectedPresent(const DispSync& dispSync); |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 81 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 82 | virtual void setReleaseFence(const sp<Fence>& fence) override; |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 83 | sp<Fence> getPrevReleaseFence() const; |
| 84 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 85 | void releasePendingBuffer(); |
| 86 | #endif |
| 87 | |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 88 | virtual bool getFrameTimestamps(uint64_t frameNumber, |
| 89 | FrameTimestamps* outTimestamps) const override; |
| 90 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 91 | private: |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 92 | virtual void onSidebandStreamChanged(); |
| 93 | |
| 94 | wp<ContentsChangedListener> mContentsChangedListener; |
| 95 | |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 96 | // Indicates this buffer must be transformed by the inverse transform of the screen |
| 97 | // it is displayed onto. This is applied after GLConsumer::mCurrentTransform. |
| 98 | // This must be set/read from SurfaceFlinger's main thread. |
| 99 | bool mTransformToDisplayInverse; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 100 | |
| 101 | // The portion of this surface that has changed since the previous frame |
| 102 | Region mSurfaceDamage; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 103 | |
| 104 | #ifdef USE_HWC2 |
| 105 | // A release that is pending on the receipt of a new release fence from |
| 106 | // presentDisplay |
| 107 | PendingRelease mPendingRelease; |
| 108 | #endif |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 109 | |
| 110 | // The release fence of the already displayed buffer (previous frame). |
| 111 | sp<Fence> mPrevReleaseFence; |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 112 | |
| 113 | // The layer for this SurfaceFlingerConsumer |
| 114 | wp<const Layer> mLayer; |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | // ---------------------------------------------------------------------------- |
| 118 | }; // namespace android |
| 119 | |
| 120 | #endif // ANDROID_SURFACEFLINGERCONSUMER_H |