Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 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 | |
| 17 | #include "MessageQueue.h" |
| 18 | #include "MonitoredProducer.h" |
| 19 | #include "SurfaceFlinger.h" |
| 20 | |
| 21 | namespace android { |
| 22 | |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 23 | MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 24 | const sp<SurfaceFlinger>& flinger) : |
| 25 | mProducer(producer), |
| 26 | mFlinger(flinger) {} |
| 27 | |
| 28 | MonitoredProducer::~MonitoredProducer() { |
| 29 | // Remove ourselves from SurfaceFlinger's list. We do this asynchronously |
| 30 | // because we don't know where this destructor is called from. It could be |
| 31 | // called with the mStateLock held, leading to a dead-lock (it actually |
| 32 | // happens). |
| 33 | class MessageCleanUpList : public MessageBase { |
| 34 | public: |
| 35 | MessageCleanUpList(const sp<SurfaceFlinger>& flinger, |
| 36 | const wp<IBinder>& producer) |
| 37 | : mFlinger(flinger), mProducer(producer) {} |
| 38 | |
| 39 | virtual ~MessageCleanUpList() {} |
| 40 | |
| 41 | virtual bool handler() { |
| 42 | Mutex::Autolock _l(mFlinger->mStateLock); |
| 43 | mFlinger->mGraphicBufferProducerList.remove(mProducer); |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | sp<SurfaceFlinger> mFlinger; |
| 49 | wp<IBinder> mProducer; |
| 50 | }; |
| 51 | |
Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 52 | mFlinger->postMessageAsync(new MessageCleanUpList(mFlinger, asBinder(this))); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) { |
| 56 | return mProducer->requestBuffer(slot, buf); |
| 57 | } |
| 58 | |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 59 | status_t MonitoredProducer::setMaxDequeuedBufferCount( |
| 60 | int maxDequeuedBuffers) { |
| 61 | return mProducer->setMaxDequeuedBufferCount(maxDequeuedBuffers); |
| 62 | } |
| 63 | |
| 64 | status_t MonitoredProducer::setAsyncMode(bool async) { |
| 65 | return mProducer->setAsyncMode(async); |
| 66 | } |
| 67 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 68 | status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence, |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 69 | uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) { |
| 70 | return mProducer->dequeueBuffer(slot, fence, w, h, format, usage); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | status_t MonitoredProducer::detachBuffer(int slot) { |
| 74 | return mProducer->detachBuffer(slot); |
| 75 | } |
| 76 | |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 77 | status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 78 | sp<Fence>* outFence) { |
| 79 | return mProducer->detachNextBuffer(outBuffer, outFence); |
| 80 | } |
| 81 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 82 | status_t MonitoredProducer::attachBuffer(int* outSlot, |
| 83 | const sp<GraphicBuffer>& buffer) { |
| 84 | return mProducer->attachBuffer(outSlot, buffer); |
| 85 | } |
| 86 | |
| 87 | status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input, |
| 88 | QueueBufferOutput* output) { |
| 89 | return mProducer->queueBuffer(slot, input, output); |
| 90 | } |
| 91 | |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 92 | status_t MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) { |
| 93 | return mProducer->cancelBuffer(slot, fence); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | int MonitoredProducer::query(int what, int* value) { |
| 97 | return mProducer->query(what, value); |
| 98 | } |
| 99 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 100 | status_t MonitoredProducer::connect(const sp<IProducerListener>& listener, |
| 101 | int api, bool producerControlledByApp, QueueBufferOutput* output) { |
| 102 | return mProducer->connect(listener, api, producerControlledByApp, output); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | status_t MonitoredProducer::disconnect(int api) { |
| 106 | return mProducer->disconnect(api); |
| 107 | } |
| 108 | |
| 109 | status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) { |
| 110 | return mProducer->setSidebandStream(stream); |
| 111 | } |
| 112 | |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 113 | void MonitoredProducer::allocateBuffers(uint32_t width, uint32_t height, |
| 114 | PixelFormat format, uint32_t usage) { |
| 115 | mProducer->allocateBuffers(width, height, format, usage); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 118 | status_t MonitoredProducer::allowAllocation(bool allow) { |
| 119 | return mProducer->allowAllocation(allow); |
| 120 | } |
| 121 | |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 122 | status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) { |
| 123 | return mProducer->setGenerationNumber(generationNumber); |
| 124 | } |
| 125 | |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 126 | String8 MonitoredProducer::getConsumerName() const { |
| 127 | return mProducer->getConsumerName(); |
| 128 | } |
| 129 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 130 | uint64_t MonitoredProducer::getNextFrameNumber() const { |
| 131 | return mProducer->getNextFrameNumber(); |
| 132 | } |
| 133 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame^] | 134 | status_t MonitoredProducer::setSingleBufferMode(bool singleBufferMode) { |
| 135 | return mProducer->setSingleBufferMode(singleBufferMode); |
| 136 | } |
| 137 | |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 138 | IBinder* MonitoredProducer::onAsBinder() { |
Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 139 | return IInterface::asBinder(mProducer).get(); |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 142 | // --------------------------------------------------------------------------- |
| 143 | }; // namespace android |