MonitoredProducer.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2014 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_MONITORED_PRODUCER_H
  17. #define ANDROID_MONITORED_PRODUCER_H
  18. #include <gui/IGraphicBufferProducer.h>
  19. namespace android {
  20. class IProducerListener;
  21. class NativeHandle;
  22. class SurfaceFlinger;
  23. class Layer;
  24. // MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will
  25. // be notified upon its destruction
  26. class MonitoredProducer : public BnGraphicBufferProducer {
  27. public:
  28. MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
  29. const sp<SurfaceFlinger>& flinger,
  30. const wp<Layer>& layer);
  31. virtual ~MonitoredProducer();
  32. // From IGraphicBufferProducer
  33. virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
  34. virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers);
  35. virtual status_t setAsyncMode(bool async);
  36. virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
  37. PixelFormat format, uint64_t usage, uint64_t* outBufferAge,
  38. FrameEventHistoryDelta* outTimestamps);
  39. virtual status_t detachBuffer(int slot);
  40. virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
  41. sp<Fence>* outFence);
  42. virtual status_t attachBuffer(int* outSlot,
  43. const sp<GraphicBuffer>& buffer);
  44. virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
  45. QueueBufferOutput* output);
  46. virtual status_t cancelBuffer(int slot, const sp<Fence>& fence);
  47. virtual int query(int what, int* value);
  48. virtual status_t connect(const sp<IProducerListener>& token, int api,
  49. bool producerControlledByApp, QueueBufferOutput* output);
  50. virtual status_t disconnect(int api, DisconnectMode mode);
  51. virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
  52. virtual void allocateBuffers(uint32_t width, uint32_t height,
  53. PixelFormat format, uint64_t usage);
  54. virtual status_t allowAllocation(bool allow);
  55. virtual status_t setGenerationNumber(uint32_t generationNumber);
  56. virtual String8 getConsumerName() const override;
  57. virtual status_t setDequeueTimeout(nsecs_t timeout) override;
  58. virtual status_t setLegacyBufferDrop(bool drop) override;
  59. virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
  60. sp<Fence>* outFence, float outTransformMatrix[16]) override;
  61. virtual IBinder* onAsBinder();
  62. virtual status_t setSharedBufferMode(bool sharedBufferMode) override;
  63. virtual status_t setAutoRefresh(bool autoRefresh) override;
  64. virtual void getFrameTimestamps(FrameEventHistoryDelta *outDelta) override;
  65. virtual status_t getUniqueId(uint64_t* outId) const override;
  66. virtual status_t getConsumerUsage(uint64_t* outUsage) const override;
  67. // The Layer which created this producer, and on which queued Buffer's will be displayed.
  68. sp<Layer> getLayer() const;
  69. private:
  70. sp<IGraphicBufferProducer> mProducer;
  71. sp<SurfaceFlinger> mFlinger;
  72. // The Layer which created this producer, and on which queued Buffer's will be displayed.
  73. wp<Layer> mLayer;
  74. };
  75. }; // namespace android
  76. #endif // ANDROID_MONITORED_PRODUCER_H