SurfaceFlingerConsumer.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef ANDROID_SURFACEFLINGERCONSUMER_H
  17. #define ANDROID_SURFACEFLINGERCONSUMER_H
  18. #include "DispSync.h"
  19. #include <gui/GLConsumer.h>
  20. namespace android {
  21. // ----------------------------------------------------------------------------
  22. /*
  23. * This is a thin wrapper around GLConsumer.
  24. */
  25. class SurfaceFlingerConsumer : public GLConsumer {
  26. public:
  27. static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8;
  28. struct ContentsChangedListener: public FrameAvailableListener {
  29. virtual void onSidebandStreamChanged() = 0;
  30. };
  31. SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
  32. uint32_t tex)
  33. : GLConsumer(consumer, tex, GLConsumer::TEXTURE_EXTERNAL, false, false),
  34. mTransformToDisplayInverse(false), mSurfaceDamage()
  35. {}
  36. class BufferRejecter {
  37. friend class SurfaceFlingerConsumer;
  38. virtual bool reject(const sp<GraphicBuffer>& buf,
  39. const BufferItem& item) = 0;
  40. protected:
  41. virtual ~BufferRejecter() { }
  42. };
  43. virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
  44. uint64_t maxFrameNumber = 0) override;
  45. // This version of updateTexImage() takes a functor that may be used to
  46. // reject the newly acquired buffer. Unlike the GLConsumer version,
  47. // this does not guarantee that the buffer has been bound to the GL
  48. // texture.
  49. status_t updateTexImage(BufferRejecter* rejecter, const DispSync& dispSync,
  50. uint64_t maxFrameNumber = 0);
  51. // See GLConsumer::bindTextureImageLocked().
  52. status_t bindTextureImage();
  53. // must be called from SF main thread
  54. bool getTransformToDisplayInverse() const;
  55. const Region& getSurfaceDamage() const;
  56. // Sets the contents changed listener. This should be used instead of
  57. // ConsumerBase::setFrameAvailableListener().
  58. void setContentsChangedListener(const wp<ContentsChangedListener>& listener);
  59. sp<NativeHandle> getSidebandStream() const;
  60. nsecs_t computeExpectedPresent(const DispSync& dispSync);
  61. private:
  62. virtual void onSidebandStreamChanged();
  63. wp<ContentsChangedListener> mContentsChangedListener;
  64. // Indicates this buffer must be transformed by the inverse transform of the screen
  65. // it is displayed onto. This is applied after GLConsumer::mCurrentTransform.
  66. // This must be set/read from SurfaceFlinger's main thread.
  67. bool mTransformToDisplayInverse;
  68. // The portion of this surface that has changed since the previous frame
  69. Region mSurfaceDamage;
  70. };
  71. // ----------------------------------------------------------------------------
  72. }; // namespace android
  73. #endif // ANDROID_SURFACEFLINGERCONSUMER_H