blob: 5633980ee1256f60e1f3ffec1e4b1c15c48492cd [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:
Jesse Hall399184a2014-03-03 15:42:54 -080031 struct ContentsChangedListener: public FrameAvailableListener {
32 virtual void onSidebandStreamChanged() = 0;
33 };
34
Dan Stozab9b08832014-03-13 11:55:57 -070035 SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
36 uint32_t tex)
Dan Stozae49ba8e2014-06-24 13:09:19 -070037 : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
Andy McFadden41d67d72014-04-25 16:58:34 -070038 mTransformToDisplayInverse(false)
Andy McFaddenbf974ab2012-12-04 16:51:15 -080039 {}
40
41 class BufferRejecter {
42 friend class SurfaceFlingerConsumer;
43 virtual bool reject(const sp<GraphicBuffer>& buf,
Mathias Agopiandb89edc2013-08-02 01:40:18 -070044 const IGraphicBufferConsumer::BufferItem& item) = 0;
Andy McFaddenbf974ab2012-12-04 16:51:15 -080045
46 protected:
47 virtual ~BufferRejecter() { }
48 };
49
Mathias Agopianc1c05de2013-09-17 23:45:22 -070050 virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item, nsecs_t presentWhen);
51
Andy McFaddenbf974ab2012-12-04 16:51:15 -080052 // This version of updateTexImage() takes a functor that may be used to
Andy McFadden2adaf042012-12-18 09:49:45 -080053 // reject the newly acquired buffer. Unlike the GLConsumer version,
Andy McFaddenbf974ab2012-12-04 16:51:15 -080054 // this does not guarantee that the buffer has been bound to the GL
55 // texture.
Andy McFadden41d67d72014-04-25 16:58:34 -070056 status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync);
Andy McFaddenbf974ab2012-12-04 16:51:15 -080057
Andy McFadden2adaf042012-12-18 09:49:45 -080058 // See GLConsumer::bindTextureImageLocked().
Andy McFadden97eba892012-12-11 15:21:45 -080059 status_t bindTextureImage();
Andy McFadden1585c4d2013-06-28 13:52:40 -070060
Mathias Agopianc1c05de2013-09-17 23:45:22 -070061 // must be called from SF main thread
62 bool getTransformToDisplayInverse() const;
63
Jesse Hall399184a2014-03-03 15:42:54 -080064 // Sets the contents changed listener. This should be used instead of
65 // ConsumerBase::setFrameAvailableListener().
66 void setContentsChangedListener(const wp<ContentsChangedListener>& listener);
67
68 sp<NativeHandle> getSidebandStream() const;
69
Andy McFadden1585c4d2013-06-28 13:52:40 -070070private:
Andy McFadden41d67d72014-04-25 16:58:34 -070071 nsecs_t computeExpectedPresent(const DispSync& dispSync);
Mathias Agopianc1c05de2013-09-17 23:45:22 -070072
Jesse Hall399184a2014-03-03 15:42:54 -080073 virtual void onSidebandStreamChanged();
74
75 wp<ContentsChangedListener> mContentsChangedListener;
76
Mathias Agopianc1c05de2013-09-17 23:45:22 -070077 // Indicates this buffer must be transformed by the inverse transform of the screen
78 // it is displayed onto. This is applied after GLConsumer::mCurrentTransform.
79 // This must be set/read from SurfaceFlinger's main thread.
80 bool mTransformToDisplayInverse;
Andy McFaddenbf974ab2012-12-04 16:51:15 -080081};
82
83// ----------------------------------------------------------------------------
84}; // namespace android
85
86#endif // ANDROID_SURFACEFLINGERCONSUMER_H