2014-03-13 18:55:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MessageQueue.h"
|
|
|
|
#include "MonitoredProducer.h"
|
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2014-04-07 23:33:59 +00:00
|
|
|
MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
|
2014-03-13 18:55:57 +00:00
|
|
|
const sp<SurfaceFlinger>& flinger) :
|
|
|
|
mProducer(producer),
|
|
|
|
mFlinger(flinger) {}
|
|
|
|
|
|
|
|
MonitoredProducer::~MonitoredProducer() {
|
|
|
|
// Remove ourselves from SurfaceFlinger's list. We do this asynchronously
|
|
|
|
// because we don't know where this destructor is called from. It could be
|
|
|
|
// called with the mStateLock held, leading to a dead-lock (it actually
|
|
|
|
// happens).
|
|
|
|
class MessageCleanUpList : public MessageBase {
|
|
|
|
public:
|
|
|
|
MessageCleanUpList(const sp<SurfaceFlinger>& flinger,
|
|
|
|
const wp<IBinder>& producer)
|
|
|
|
: mFlinger(flinger), mProducer(producer) {}
|
|
|
|
|
|
|
|
virtual ~MessageCleanUpList() {}
|
|
|
|
|
|
|
|
virtual bool handler() {
|
|
|
|
Mutex::Autolock _l(mFlinger->mStateLock);
|
|
|
|
mFlinger->mGraphicBufferProducerList.remove(mProducer);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sp<SurfaceFlinger> mFlinger;
|
|
|
|
wp<IBinder> mProducer;
|
|
|
|
};
|
|
|
|
|
2014-11-14 16:01:01 +00:00
|
|
|
mFlinger->postMessageAsync(new MessageCleanUpList(mFlinger, asBinder(this)));
|
2014-03-13 18:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
|
|
|
|
return mProducer->requestBuffer(slot, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::setBufferCount(int bufferCount) {
|
|
|
|
return mProducer->setBufferCount(bufferCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence,
|
2014-11-18 18:24:03 +00:00
|
|
|
bool async, uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) {
|
2014-03-13 18:55:57 +00:00
|
|
|
return mProducer->dequeueBuffer(slot, fence, async, w, h, format, usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::detachBuffer(int slot) {
|
|
|
|
return mProducer->detachBuffer(slot);
|
|
|
|
}
|
|
|
|
|
2014-03-28 22:25:31 +00:00
|
|
|
status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
|
|
|
|
sp<Fence>* outFence) {
|
|
|
|
return mProducer->detachNextBuffer(outBuffer, outFence);
|
|
|
|
}
|
|
|
|
|
2014-03-13 18:55:57 +00:00
|
|
|
status_t MonitoredProducer::attachBuffer(int* outSlot,
|
|
|
|
const sp<GraphicBuffer>& buffer) {
|
|
|
|
return mProducer->attachBuffer(outSlot, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
|
|
|
|
QueueBufferOutput* output) {
|
|
|
|
return mProducer->queueBuffer(slot, input, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
|
|
|
|
mProducer->cancelBuffer(slot, fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MonitoredProducer::query(int what, int* value) {
|
|
|
|
return mProducer->query(what, value);
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:05:51 +00:00
|
|
|
status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
|
|
|
|
int api, bool producerControlledByApp, QueueBufferOutput* output) {
|
|
|
|
return mProducer->connect(listener, api, producerControlledByApp, output);
|
2014-03-13 18:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::disconnect(int api) {
|
|
|
|
return mProducer->disconnect(api);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
|
|
|
|
return mProducer->setSidebandStream(stream);
|
|
|
|
}
|
|
|
|
|
2014-06-20 20:13:57 +00:00
|
|
|
void MonitoredProducer::allocateBuffers(bool async, uint32_t width,
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t height, PixelFormat format, uint32_t usage) {
|
2014-06-20 20:13:57 +00:00
|
|
|
mProducer->allocateBuffers(async, width, height, format, usage);
|
|
|
|
}
|
|
|
|
|
2014-04-07 23:33:59 +00:00
|
|
|
IBinder* MonitoredProducer::onAsBinder() {
|
2014-11-14 16:01:01 +00:00
|
|
|
return IInterface::asBinder(mProducer).get();
|
2014-04-07 23:33:59 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:55:57 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|