MonitoredProducer.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "MonitoredProducer.h"
  17. #include "Layer.h"
  18. #include "SurfaceFlinger.h"
  19. #include "Scheduler/MessageQueue.h"
  20. namespace android {
  21. MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
  22. const sp<SurfaceFlinger>& flinger,
  23. const wp<Layer>& layer) :
  24. mProducer(producer),
  25. mFlinger(flinger),
  26. mLayer(layer) {}
  27. MonitoredProducer::~MonitoredProducer() {
  28. // Remove ourselves from SurfaceFlinger's list. We do this asynchronously
  29. // because we don't know where this destructor is called from. It could be
  30. // called with the mStateLock held, leading to a dead-lock (it actually
  31. // happens).
  32. sp<LambdaMessage> cleanUpListMessage =
  33. new LambdaMessage([flinger = mFlinger, asBinder = wp<IBinder>(onAsBinder())]() {
  34. Mutex::Autolock lock(flinger->mStateLock);
  35. flinger->mGraphicBufferProducerList.erase(asBinder);
  36. });
  37. mFlinger->postMessageAsync(cleanUpListMessage);
  38. }
  39. status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
  40. return mProducer->requestBuffer(slot, buf);
  41. }
  42. status_t MonitoredProducer::setMaxDequeuedBufferCount(
  43. int maxDequeuedBuffers) {
  44. return mProducer->setMaxDequeuedBufferCount(maxDequeuedBuffers);
  45. }
  46. status_t MonitoredProducer::setAsyncMode(bool async) {
  47. return mProducer->setAsyncMode(async);
  48. }
  49. status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
  50. PixelFormat format, uint64_t usage,
  51. uint64_t* outBufferAge,
  52. FrameEventHistoryDelta* outTimestamps) {
  53. return mProducer->dequeueBuffer(slot, fence, w, h, format, usage, outBufferAge, outTimestamps);
  54. }
  55. status_t MonitoredProducer::detachBuffer(int slot) {
  56. return mProducer->detachBuffer(slot);
  57. }
  58. status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
  59. sp<Fence>* outFence) {
  60. return mProducer->detachNextBuffer(outBuffer, outFence);
  61. }
  62. status_t MonitoredProducer::attachBuffer(int* outSlot,
  63. const sp<GraphicBuffer>& buffer) {
  64. return mProducer->attachBuffer(outSlot, buffer);
  65. }
  66. status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
  67. QueueBufferOutput* output) {
  68. return mProducer->queueBuffer(slot, input, output);
  69. }
  70. status_t MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
  71. return mProducer->cancelBuffer(slot, fence);
  72. }
  73. int MonitoredProducer::query(int what, int* value) {
  74. return mProducer->query(what, value);
  75. }
  76. status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
  77. int api, bool producerControlledByApp, QueueBufferOutput* output) {
  78. return mProducer->connect(listener, api, producerControlledByApp, output);
  79. }
  80. status_t MonitoredProducer::disconnect(int api, DisconnectMode mode) {
  81. return mProducer->disconnect(api, mode);
  82. }
  83. status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
  84. return mProducer->setSidebandStream(stream);
  85. }
  86. void MonitoredProducer::allocateBuffers(uint32_t width, uint32_t height,
  87. PixelFormat format, uint64_t usage) {
  88. mProducer->allocateBuffers(width, height, format, usage);
  89. }
  90. status_t MonitoredProducer::allowAllocation(bool allow) {
  91. return mProducer->allowAllocation(allow);
  92. }
  93. status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) {
  94. return mProducer->setGenerationNumber(generationNumber);
  95. }
  96. String8 MonitoredProducer::getConsumerName() const {
  97. return mProducer->getConsumerName();
  98. }
  99. status_t MonitoredProducer::setSharedBufferMode(bool sharedBufferMode) {
  100. return mProducer->setSharedBufferMode(sharedBufferMode);
  101. }
  102. status_t MonitoredProducer::setAutoRefresh(bool autoRefresh) {
  103. return mProducer->setAutoRefresh(autoRefresh);
  104. }
  105. status_t MonitoredProducer::setDequeueTimeout(nsecs_t timeout) {
  106. return mProducer->setDequeueTimeout(timeout);
  107. }
  108. status_t MonitoredProducer::setLegacyBufferDrop(bool drop) {
  109. return mProducer->setLegacyBufferDrop(drop);
  110. }
  111. status_t MonitoredProducer::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
  112. sp<Fence>* outFence, float outTransformMatrix[16]) {
  113. return mProducer->getLastQueuedBuffer(outBuffer, outFence,
  114. outTransformMatrix);
  115. }
  116. void MonitoredProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
  117. mProducer->getFrameTimestamps(outDelta);
  118. }
  119. status_t MonitoredProducer::getUniqueId(uint64_t* outId) const {
  120. return mProducer->getUniqueId(outId);
  121. }
  122. status_t MonitoredProducer::getConsumerUsage(uint64_t* outUsage) const {
  123. return mProducer->getConsumerUsage(outUsage);
  124. }
  125. IBinder* MonitoredProducer::onAsBinder() {
  126. return this;
  127. }
  128. sp<Layer> MonitoredProducer::getLayer() const {
  129. return mLayer.promote();
  130. }
  131. // ---------------------------------------------------------------------------
  132. }; // namespace android