MonitoredProducer.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "MessageQueue.h"
  17. #include "MonitoredProducer.h"
  18. #include "SurfaceFlinger.h"
  19. namespace android {
  20. MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
  21. const sp<SurfaceFlinger>& flinger) :
  22. mProducer(producer),
  23. mFlinger(flinger) {}
  24. MonitoredProducer::~MonitoredProducer() {
  25. // Remove ourselves from SurfaceFlinger's list. We do this asynchronously
  26. // because we don't know where this destructor is called from. It could be
  27. // called with the mStateLock held, leading to a dead-lock (it actually
  28. // happens).
  29. class MessageCleanUpList : public MessageBase {
  30. public:
  31. MessageCleanUpList(const sp<SurfaceFlinger>& flinger,
  32. const wp<IBinder>& producer)
  33. : mFlinger(flinger), mProducer(producer) {}
  34. virtual ~MessageCleanUpList() {}
  35. virtual bool handler() {
  36. Mutex::Autolock _l(mFlinger->mStateLock);
  37. mFlinger->mGraphicBufferProducerList.remove(mProducer);
  38. return true;
  39. }
  40. private:
  41. sp<SurfaceFlinger> mFlinger;
  42. wp<IBinder> mProducer;
  43. };
  44. mFlinger->postMessageAsync(new MessageCleanUpList(mFlinger, asBinder(this)));
  45. }
  46. status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
  47. return mProducer->requestBuffer(slot, buf);
  48. }
  49. status_t MonitoredProducer::setBufferCount(int bufferCount) {
  50. return mProducer->setBufferCount(bufferCount);
  51. }
  52. status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence,
  53. bool async, uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) {
  54. return mProducer->dequeueBuffer(slot, fence, async, w, h, format, usage);
  55. }
  56. status_t MonitoredProducer::detachBuffer(int slot) {
  57. return mProducer->detachBuffer(slot);
  58. }
  59. status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
  60. sp<Fence>* outFence) {
  61. return mProducer->detachNextBuffer(outBuffer, outFence);
  62. }
  63. status_t MonitoredProducer::attachBuffer(int* outSlot,
  64. const sp<GraphicBuffer>& buffer) {
  65. return mProducer->attachBuffer(outSlot, buffer);
  66. }
  67. status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
  68. QueueBufferOutput* output) {
  69. return mProducer->queueBuffer(slot, input, output);
  70. }
  71. void MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
  72. mProducer->cancelBuffer(slot, fence);
  73. }
  74. int MonitoredProducer::query(int what, int* value) {
  75. return mProducer->query(what, value);
  76. }
  77. status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
  78. int api, bool producerControlledByApp, QueueBufferOutput* output) {
  79. return mProducer->connect(listener, api, producerControlledByApp, output);
  80. }
  81. status_t MonitoredProducer::disconnect(int api) {
  82. return mProducer->disconnect(api);
  83. }
  84. status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
  85. return mProducer->setSidebandStream(stream);
  86. }
  87. void MonitoredProducer::allocateBuffers(bool async, uint32_t width,
  88. uint32_t height, PixelFormat format, uint32_t usage) {
  89. mProducer->allocateBuffers(async, width, height, format, usage);
  90. }
  91. status_t MonitoredProducer::allowAllocation(bool allow) {
  92. return mProducer->allowAllocation(allow);
  93. }
  94. status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) {
  95. return mProducer->setGenerationNumber(generationNumber);
  96. }
  97. String8 MonitoredProducer::getConsumerName() const {
  98. return mProducer->getConsumerName();
  99. }
  100. IBinder* MonitoredProducer::onAsBinder() {
  101. return IInterface::asBinder(mProducer).get();
  102. }
  103. // ---------------------------------------------------------------------------
  104. }; // namespace android