blob: f6010b7c2be2600c7052dbc239d7e85f20b36ba9 [file] [log] [blame]
Dan Stozab9b08832014-03-13 11:55:57 -07001/*
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
21namespace android {
22
23MonitoredProducer::MonitoredProducer(const sp<BnGraphicBufferProducer>& producer,
24 const sp<SurfaceFlinger>& flinger) :
25 mProducer(producer),
26 mFlinger(flinger) {}
27
28MonitoredProducer::~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
52 mFlinger->postMessageAsync(new MessageCleanUpList(mFlinger,
53 static_cast<BnGraphicBufferProducer*>(this)));
54}
55
56status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
57 return mProducer->requestBuffer(slot, buf);
58}
59
60status_t MonitoredProducer::setBufferCount(int bufferCount) {
61 return mProducer->setBufferCount(bufferCount);
62}
63
64status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence,
65 bool async, uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
66 return mProducer->dequeueBuffer(slot, fence, async, w, h, format, usage);
67}
68
69status_t MonitoredProducer::detachBuffer(int slot) {
70 return mProducer->detachBuffer(slot);
71}
72
73status_t MonitoredProducer::attachBuffer(int* outSlot,
74 const sp<GraphicBuffer>& buffer) {
75 return mProducer->attachBuffer(outSlot, buffer);
76}
77
78status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
79 QueueBufferOutput* output) {
80 return mProducer->queueBuffer(slot, input, output);
81}
82
83void MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
84 mProducer->cancelBuffer(slot, fence);
85}
86
87int MonitoredProducer::query(int what, int* value) {
88 return mProducer->query(what, value);
89}
90
Dan Stozaf0eaf252014-03-21 13:05:51 -070091status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
92 int api, bool producerControlledByApp, QueueBufferOutput* output) {
93 return mProducer->connect(listener, api, producerControlledByApp, output);
Dan Stozab9b08832014-03-13 11:55:57 -070094}
95
96status_t MonitoredProducer::disconnect(int api) {
97 return mProducer->disconnect(api);
98}
99
100status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
101 return mProducer->setSidebandStream(stream);
102}
103
104// ---------------------------------------------------------------------------
105}; // namespace android