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 "MonitoredProducer.h"
18 #include "Layer.h"
19 #include "SurfaceFlinger.h"
20
21 #include "Scheduler/MessageQueue.h"
22
23 namespace android {
24
MonitoredProducer(const sp<IGraphicBufferProducer> & producer,const sp<SurfaceFlinger> & flinger,const wp<Layer> & layer)25 MonitoredProducer::MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
26 const sp<SurfaceFlinger>& flinger,
27 const wp<Layer>& layer) :
28 mProducer(producer),
29 mFlinger(flinger),
30 mLayer(layer) {}
31
~MonitoredProducer()32 MonitoredProducer::~MonitoredProducer() {
33 // Remove ourselves from SurfaceFlinger's list. We do this asynchronously
34 // because we don't know where this destructor is called from. It could be
35 // called with the mStateLock held, leading to a dead-lock (it actually
36 // happens).
37 sp<LambdaMessage> cleanUpListMessage =
38 new LambdaMessage([flinger = mFlinger, asBinder = wp<IBinder>(onAsBinder())]() {
39 Mutex::Autolock lock(flinger->mStateLock);
40 flinger->mGraphicBufferProducerList.erase(asBinder);
41 });
42
43 mFlinger->postMessageAsync(cleanUpListMessage);
44 }
45
requestBuffer(int slot,sp<GraphicBuffer> * buf)46 status_t MonitoredProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
47 return mProducer->requestBuffer(slot, buf);
48 }
49
setMaxDequeuedBufferCount(int maxDequeuedBuffers)50 status_t MonitoredProducer::setMaxDequeuedBufferCount(
51 int maxDequeuedBuffers) {
52 return mProducer->setMaxDequeuedBufferCount(maxDequeuedBuffers);
53 }
54
setAsyncMode(bool async)55 status_t MonitoredProducer::setAsyncMode(bool async) {
56 return mProducer->setAsyncMode(async);
57 }
58
dequeueBuffer(int * slot,sp<Fence> * fence,uint32_t w,uint32_t h,PixelFormat format,uint64_t usage,uint64_t * outBufferAge,FrameEventHistoryDelta * outTimestamps)59 status_t MonitoredProducer::dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
60 PixelFormat format, uint64_t usage,
61 uint64_t* outBufferAge,
62 FrameEventHistoryDelta* outTimestamps) {
63 return mProducer->dequeueBuffer(slot, fence, w, h, format, usage, outBufferAge, outTimestamps);
64 }
65
detachBuffer(int slot)66 status_t MonitoredProducer::detachBuffer(int slot) {
67 return mProducer->detachBuffer(slot);
68 }
69
detachNextBuffer(sp<GraphicBuffer> * outBuffer,sp<Fence> * outFence)70 status_t MonitoredProducer::detachNextBuffer(sp<GraphicBuffer>* outBuffer,
71 sp<Fence>* outFence) {
72 return mProducer->detachNextBuffer(outBuffer, outFence);
73 }
74
attachBuffer(int * outSlot,const sp<GraphicBuffer> & buffer)75 status_t MonitoredProducer::attachBuffer(int* outSlot,
76 const sp<GraphicBuffer>& buffer) {
77 return mProducer->attachBuffer(outSlot, buffer);
78 }
79
queueBuffer(int slot,const QueueBufferInput & input,QueueBufferOutput * output)80 status_t MonitoredProducer::queueBuffer(int slot, const QueueBufferInput& input,
81 QueueBufferOutput* output) {
82 return mProducer->queueBuffer(slot, input, output);
83 }
84
cancelBuffer(int slot,const sp<Fence> & fence)85 status_t MonitoredProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
86 return mProducer->cancelBuffer(slot, fence);
87 }
88
query(int what,int * value)89 int MonitoredProducer::query(int what, int* value) {
90 return mProducer->query(what, value);
91 }
92
connect(const sp<IProducerListener> & listener,int api,bool producerControlledByApp,QueueBufferOutput * output)93 status_t MonitoredProducer::connect(const sp<IProducerListener>& listener,
94 int api, bool producerControlledByApp, QueueBufferOutput* output) {
95 return mProducer->connect(listener, api, producerControlledByApp, output);
96 }
97
disconnect(int api,DisconnectMode mode)98 status_t MonitoredProducer::disconnect(int api, DisconnectMode mode) {
99 return mProducer->disconnect(api, mode);
100 }
101
setSidebandStream(const sp<NativeHandle> & stream)102 status_t MonitoredProducer::setSidebandStream(const sp<NativeHandle>& stream) {
103 return mProducer->setSidebandStream(stream);
104 }
105
allocateBuffers(uint32_t width,uint32_t height,PixelFormat format,uint64_t usage)106 void MonitoredProducer::allocateBuffers(uint32_t width, uint32_t height,
107 PixelFormat format, uint64_t usage) {
108 mProducer->allocateBuffers(width, height, format, usage);
109 }
110
allowAllocation(bool allow)111 status_t MonitoredProducer::allowAllocation(bool allow) {
112 return mProducer->allowAllocation(allow);
113 }
114
setGenerationNumber(uint32_t generationNumber)115 status_t MonitoredProducer::setGenerationNumber(uint32_t generationNumber) {
116 return mProducer->setGenerationNumber(generationNumber);
117 }
118
getConsumerName() const119 String8 MonitoredProducer::getConsumerName() const {
120 return mProducer->getConsumerName();
121 }
122
setSharedBufferMode(bool sharedBufferMode)123 status_t MonitoredProducer::setSharedBufferMode(bool sharedBufferMode) {
124 return mProducer->setSharedBufferMode(sharedBufferMode);
125 }
126
setAutoRefresh(bool autoRefresh)127 status_t MonitoredProducer::setAutoRefresh(bool autoRefresh) {
128 return mProducer->setAutoRefresh(autoRefresh);
129 }
130
setDequeueTimeout(nsecs_t timeout)131 status_t MonitoredProducer::setDequeueTimeout(nsecs_t timeout) {
132 return mProducer->setDequeueTimeout(timeout);
133 }
134
setLegacyBufferDrop(bool drop)135 status_t MonitoredProducer::setLegacyBufferDrop(bool drop) {
136 return mProducer->setLegacyBufferDrop(drop);
137 }
138
getLastQueuedBuffer(sp<GraphicBuffer> * outBuffer,sp<Fence> * outFence,float outTransformMatrix[16])139 status_t MonitoredProducer::getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
140 sp<Fence>* outFence, float outTransformMatrix[16]) {
141 return mProducer->getLastQueuedBuffer(outBuffer, outFence,
142 outTransformMatrix);
143 }
144
getFrameTimestamps(FrameEventHistoryDelta * outDelta)145 void MonitoredProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
146 mProducer->getFrameTimestamps(outDelta);
147 }
148
getUniqueId(uint64_t * outId) const149 status_t MonitoredProducer::getUniqueId(uint64_t* outId) const {
150 return mProducer->getUniqueId(outId);
151 }
152
getConsumerUsage(uint64_t * outUsage) const153 status_t MonitoredProducer::getConsumerUsage(uint64_t* outUsage) const {
154 return mProducer->getConsumerUsage(outUsage);
155 }
156
onAsBinder()157 IBinder* MonitoredProducer::onAsBinder() {
158 return this;
159 }
160
getLayer() const161 sp<Layer> MonitoredProducer::getLayer() const {
162 return mLayer.promote();
163 }
164
165 // ---------------------------------------------------------------------------
166 }; // namespace android
167