blob: f16ad594be564fd8b7a66ef337c194880ea7eea9 [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
Dan Stozab3d0bdf2014-04-07 16:33:59 -070023MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
Dan Stozab9b08832014-03-13 11:55:57 -070024 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
Marco Nelissen097ca272014-11-14 08:01:01 -080052 mFlinger->postMessageAsync(new MessageCleanUpList(mFlinger, asBinder(this)));
Dan Stozab9b08832014-03-13 11:55:57 -070053}
54
55status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
56 return mProducer->requestBuffer(slot, buf);
57}
58
Pablo Ceballosfa455352015-08-12 17:47:47 -070059status_t MonitoredProducer::setMaxDequeuedBufferCount(
60 int maxDequeuedBuffers) {
61 return mProducer->setMaxDequeuedBufferCount(maxDequeuedBuffers);
62}
63
64status_t MonitoredProducer::setAsyncMode(bool async) {
65 return mProducer->setAsyncMode(async);
66}
67
Dan Stozab9b08832014-03-13 11:55:57 -070068status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence,
Dan Stoza3be1c6b2014-11-18 10:24:03 -080069 bool async, uint32_t w, uint32_t h, PixelFormat format, uint32_t usage) {
Dan Stozab9b08832014-03-13 11:55:57 -070070 return mProducer->dequeueBuffer(slot, fence, async, w, h, format, usage);
71}
72
73status_t MonitoredProducer::detachBuffer(int slot) {
74 return mProducer->detachBuffer(slot);
75}
76
Dan Stozad9822a32014-03-28 15:25:31 -070077status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
78 sp<Fence>* outFence) {
79 return mProducer->detachNextBuffer(outBuffer, outFence);
80}
81
Dan Stozab9b08832014-03-13 11:55:57 -070082status_t MonitoredProducer::attachBuffer(int* outSlot,
83 const sp<GraphicBuffer>& buffer) {
84 return mProducer->attachBuffer(outSlot, buffer);
85}
86
87status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
88 QueueBufferOutput* output) {
89 return mProducer->queueBuffer(slot, input, output);
90}
91
Pablo Ceballos583b1b32015-09-03 18:23:52 -070092status_t MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
93 return mProducer->cancelBuffer(slot, fence);
Dan Stozab9b08832014-03-13 11:55:57 -070094}
95
96int MonitoredProducer::query(int what, int* value) {
97 return mProducer->query(what, value);
98}
99
Dan Stozaf0eaf252014-03-21 13:05:51 -0700100status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
101 int api, bool producerControlledByApp, QueueBufferOutput* output) {
102 return mProducer->connect(listener, api, producerControlledByApp, output);
Dan Stozab9b08832014-03-13 11:55:57 -0700103}
104
105status_t MonitoredProducer::disconnect(int api) {
106 return mProducer->disconnect(api);
107}
108
109status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
110 return mProducer->setSidebandStream(stream);
111}
112
Dan Stoza29a3e902014-06-20 13:13:57 -0700113void MonitoredProducer::allocateBuffers(bool async, uint32_t width,
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800114 uint32_t height, PixelFormat format, uint32_t usage) {
Dan Stoza29a3e902014-06-20 13:13:57 -0700115 mProducer->allocateBuffers(async, width, height, format, usage);
116}
117
Dan Stoza9de72932015-04-16 17:28:43 -0700118status_t MonitoredProducer::allowAllocation(bool allow) {
119 return mProducer->allowAllocation(allow);
120}
121
Dan Stoza812ed062015-06-02 15:45:22 -0700122status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) {
123 return mProducer->setGenerationNumber(generationNumber);
124}
125
Dan Stozac6f30bd2015-06-08 09:32:50 -0700126String8 MonitoredProducer::getConsumerName() const {
127 return mProducer->getConsumerName();
128}
129
Dan Stozab3d0bdf2014-04-07 16:33:59 -0700130IBinder* MonitoredProducer::onAsBinder() {
Marco Nelissen097ca272014-11-14 08:01:01 -0800131 return IInterface::asBinder(mProducer).get();
Dan Stozab3d0bdf2014-04-07 16:33:59 -0700132}
133
Dan Stozab9b08832014-03-13 11:55:57 -0700134// ---------------------------------------------------------------------------
135}; // namespace android