Home | History | Annotate | Download | only in surfaceflinger
      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 
     20 #include "DispSync.h"
     21 #include <gui/GLConsumer.h>
     22 
     23 namespace android {
     24 // ----------------------------------------------------------------------------
     25 
     26 /*
     27  * This is a thin wrapper around GLConsumer.
     28  */
     29 class SurfaceFlingerConsumer : public GLConsumer {
     30 public:
     31     struct ContentsChangedListener: public FrameAvailableListener {
     32         virtual void onSidebandStreamChanged() = 0;
     33     };
     34 
     35     SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
     36             uint32_t tex)
     37         : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
     38           mTransformToDisplayInverse(false)
     39     {}
     40 
     41     class BufferRejecter {
     42         friend class SurfaceFlingerConsumer;
     43         virtual bool reject(const sp<GraphicBuffer>& buf,
     44                 const IGraphicBufferConsumer::BufferItem& item) = 0;
     45 
     46     protected:
     47         virtual ~BufferRejecter() { }
     48     };
     49 
     50     virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item, nsecs_t presentWhen);
     51 
     52     // This version of updateTexImage() takes a functor that may be used to
     53     // reject the newly acquired buffer.  Unlike the GLConsumer version,
     54     // this does not guarantee that the buffer has been bound to the GL
     55     // texture.
     56     status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync);
     57 
     58     // See GLConsumer::bindTextureImageLocked().
     59     status_t bindTextureImage();
     60 
     61     // must be called from SF main thread
     62     bool getTransformToDisplayInverse() const;
     63 
     64     // 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 
     70 private:
     71     nsecs_t computeExpectedPresent(const DispSync& dispSync);
     72 
     73     virtual void onSidebandStreamChanged();
     74 
     75     wp<ContentsChangedListener> mContentsChangedListener;
     76 
     77     // 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;
     81 };
     82 
     83 // ----------------------------------------------------------------------------
     84 }; // namespace android
     85 
     86 #endif // ANDROID_SURFACEFLINGERCONSUMER_H
     87