| 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 |  | 
|  | 59 | status_t MonitoredProducer::setBufferCount(int bufferCount) { | 
|  | 60 | return mProducer->setBufferCount(bufferCount); | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence, | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 64 | bool async, uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) { | 
| Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 65 | return mProducer->dequeueBuffer(slot, fence, async, w, h, format, usage); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | status_t MonitoredProducer::detachBuffer(int slot) { | 
|  | 69 | return mProducer->detachBuffer(slot); | 
|  | 70 | } | 
|  | 71 |  | 
| Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 72 | status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer, | 
|  | 73 | sp<Fence>* outFence) { | 
|  | 74 | return mProducer->detachNextBuffer(outBuffer, outFence); | 
|  | 75 | } | 
|  | 76 |  | 
| Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 77 | status_t MonitoredProducer::attachBuffer(int* outSlot, | 
|  | 78 | const sp<GraphicBuffer>& buffer) { | 
|  | 79 | return mProducer->attachBuffer(outSlot, buffer); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input, | 
|  | 83 | QueueBufferOutput* output) { | 
|  | 84 | return mProducer->queueBuffer(slot, input, output); | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | void MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) { | 
|  | 88 | mProducer->cancelBuffer(slot, fence); | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | int MonitoredProducer::query(int what, int* value) { | 
|  | 92 | return mProducer->query(what, value); | 
|  | 93 | } | 
|  | 94 |  | 
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 95 | status_t MonitoredProducer::connect(const sp<IProducerListener>& listener, | 
|  | 96 | int api, bool producerControlledByApp, QueueBufferOutput* output) { | 
|  | 97 | return mProducer->connect(listener, api, producerControlledByApp, output); | 
| Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
|  | 100 | status_t MonitoredProducer::disconnect(int api) { | 
|  | 101 | return mProducer->disconnect(api); | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) { | 
|  | 105 | return mProducer->setSidebandStream(stream); | 
|  | 106 | } | 
|  | 107 |  | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 108 | void MonitoredProducer::allocateBuffers(bool async, uint32_t width, | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 109 | uint32_t height, PixelFormat format, uint32_t usage) { | 
| Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 110 | mProducer->allocateBuffers(async, width, height, format, usage); | 
|  | 111 | } | 
|  | 112 |  | 
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 113 | status_t MonitoredProducer::allowAllocation(bool allow) { | 
|  | 114 | return mProducer->allowAllocation(allow); | 
|  | 115 | } | 
|  | 116 |  | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 117 | status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) { | 
|  | 118 | return mProducer->setGenerationNumber(generationNumber); | 
|  | 119 | } | 
|  | 120 |  | 
| Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 121 | String8 MonitoredProducer::getConsumerName() const { | 
|  | 122 | return mProducer->getConsumerName(); | 
|  | 123 | } | 
|  | 124 |  | 
| Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 125 | IBinder* MonitoredProducer::onAsBinder() { | 
| Marco Nelissen | 097ca27 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 126 | return IInterface::asBinder(mProducer).get(); | 
| Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 127 | } | 
|  | 128 |  | 
| Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 129 | // --------------------------------------------------------------------------- | 
|  | 130 | }; // namespace android |