IGraphicBufferProducer.cpp revision 399184a4cd728ea1421fb0bc1722274a29e38f4a
18ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis/* 28ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Copyright (C) 2010 The Android Open Source Project 38ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * 48ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Licensed under the Apache License, Version 2.0 (the "License"); 58ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * you may not use this file except in compliance with the License. 68ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * You may obtain a copy of the License at 78ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * 88ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * http://www.apache.org/licenses/LICENSE-2.0 98ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * 108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * Unless required by applicable law or agreed to in writing, software 118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * distributed under the License is distributed on an "AS IS" BASIS, 128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * See the License for the specific language governing permissions and 148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis * limitations under the License. 158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis */ 168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <stdint.h> 188ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <sys/types.h> 198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/Errors.h> 21399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall#include <utils/NativeHandle.h> 228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/RefBase.h> 238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/Timers.h> 24399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall#include <utils/Vector.h> 258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <binder/Parcel.h> 278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <binder/IInterface.h> 288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 292adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#include <gui/IGraphicBufferProducer.h> 308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android { 328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisenum { 358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, 368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis SET_BUFFER_COUNT, 378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis DEQUEUE_BUFFER, 388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis QUEUE_BUFFER, 398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis CANCEL_BUFFER, 40eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian QUERY, 41fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis CONNECT, 42fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis DISCONNECT, 43399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall SET_SIDEBAND_STREAM, 448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 458ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 462adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> 478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{ 488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic: 492adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden BpGraphicBufferProducer(const sp<IBinder>& impl) 502adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden : BpInterface<IGraphicBufferProducer>(impl) 518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis { 528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 547b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { 558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 562adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 578ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(bufferIdx); 588a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); 598a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 608a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 618a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis bool nonNull = reply.readInt32(); 638ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis if (nonNull) { 647b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis *buf = new GraphicBuffer(); 652aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu result = reply.read(**buf); 662aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu if(result != NO_ERROR) { 672aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu (*buf).clear(); 682aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu return result; 692aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu } 708ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 718a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 727b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis return result; 738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 748ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual status_t setBufferCount(int bufferCount) 768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis { 778ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 782adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 798ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(bufferCount); 808a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); 818a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 828a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 838a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 848a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 858a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 868ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 878ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 887cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, 89f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { 908ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 912adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 927cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian data.writeInt32(async); 93c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(w); 94c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(h); 95c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(format); 96c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(usage); 978a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); 988a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 998a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1008a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 1018ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *buf = reply.readInt32(); 102ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian bool nonNull = reply.readInt32(); 103ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian if (nonNull) { 1044c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall *fence = new Fence(); 105ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian reply.read(**fence); 106f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall } 1078a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 1088ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return result; 1098ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 111f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian virtual status_t queueBuffer(int buf, 112f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian const QueueBufferInput& input, QueueBufferOutput* output) { 1138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1142adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 116c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall data.write(input); 1178a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); 1188a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1198a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1208a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 121f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1228a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 1238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return result; 1248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1264c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall virtual void cancelBuffer(int buf, const sp<Fence>& fence) { 1278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1282adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 1301df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.write(*fence.get()); 1318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis remote()->transact(CANCEL_BUFFER, data, &reply); 1328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 134eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian virtual int query(int what, int* value) { 135eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian Parcel data, reply; 1362adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 137eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian data.writeInt32(what); 1388a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUERY, data, &reply); 1398a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1408a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1418a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 142eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian value[0] = reply.readInt32(); 1438a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 144eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return result; 145eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } 146eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian 147365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian virtual status_t connect(const sp<IBinder>& token, 148365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian int api, bool producerControlledByApp, QueueBufferOutput* output) { 149fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1502adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 151365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian data.writeStrongBinder(token); 152fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 153595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian data.writeInt32(producerControlledByApp); 1548a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(CONNECT, data, &reply); 1558a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1568a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1578a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 15824202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1598a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 160fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 161fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 1628072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 163fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis virtual status_t disconnect(int api) { 164fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1652adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 166fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 1678a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(DISCONNECT, data, &reply); 1688a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1698a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1708a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 1718a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 172fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 173fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 174399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 175399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { 176399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall Parcel data, reply; 177399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall status_t result; 178399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 179399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if (stream.get()) { 180399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInt32(true); 181399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeNativeHandle(stream->handle()); 182399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } else { 183399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInt32(false); 184399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 185399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { 186399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall result = reply.readInt32(); 187399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 188399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall return result; 189399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 1908ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 1918ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 192466a192d2088f9238d34597d1aa28da41367c1caAndy McFaddenIMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); 1938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------- 1958ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1962adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenstatus_t BnGraphicBufferProducer::onTransact( 1978ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 1988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{ 1998ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis switch(code) { 2008ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case REQUEST_BUFFER: { 2012adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2028ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferIdx = data.readInt32(); 2037b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis sp<GraphicBuffer> buffer; 2047b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis int result = requestBuffer(bufferIdx, &buffer); 2058ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buffer != 0); 2068ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis if (buffer != 0) { 2078ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->write(*buffer); 2088ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 2097b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis reply->writeInt32(result); 2108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case SET_BUFFER_COUNT: { 2132adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferCount = data.readInt32(); 2158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int result = setBufferCount(bufferCount); 2168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2188ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case DEQUEUE_BUFFER: { 2202adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2217cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian bool async = data.readInt32(); 222c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t w = data.readInt32(); 223c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t h = data.readInt32(); 224c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t format = data.readInt32(); 225c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t usage = data.readInt32(); 2268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf; 227f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall sp<Fence> fence; 2287cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage); 2298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buf); 2301df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis reply->writeInt32(fence != NULL); 2311df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis if (fence != NULL) { 232ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian reply->write(*fence); 233f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall } 2348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case QUEUE_BUFFER: { 2382adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 240c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall QueueBufferInput input(data); 241f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian QueueBufferOutput* const output = 242f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reinterpret_cast<QueueBufferOutput *>( 243f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 244c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall status_t result = queueBuffer(buf, input, output); 2458ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2468ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case CANCEL_BUFFER: { 2492adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 2511df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis sp<Fence> fence = new Fence(); 2521df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.read(*fence.get()); 253c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall cancelBuffer(buf, fence); 2548ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 256eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian case QUERY: { 2572adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 258eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int value; 259eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int what = data.readInt32(); 260eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int res = query(what, &value); 261eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(value); 262eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(res); 263eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return NO_ERROR; 264eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } break; 265fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case CONNECT: { 2662adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 267365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian sp<IBinder> token = data.readStrongBinder(); 268fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 269595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian bool producerControlledByApp = data.readInt32(); 27024202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian QueueBufferOutput* const output = 27124202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reinterpret_cast<QueueBufferOutput *>( 27224202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 273365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian status_t res = connect(token, api, producerControlledByApp, output); 274fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 275fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 276fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 277fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case DISCONNECT: { 2782adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 279fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 2802773004a83624ed41cf3f94f2b11878cd8521812Mathias Agopian status_t res = disconnect(api); 281fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 282fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 283fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 284399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall case SET_SIDEBAND_STREAM: { 285399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 286399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall sp<NativeHandle> stream; 287399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if (data.readInt32()) { 288399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall stream = NativeHandle::create(data.readNativeHandle()); 289399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 290399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall status_t result = setSidebandStream(stream); 291399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall reply->writeInt32(result); 292399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall return NO_ERROR; 293399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } break; 2948ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 2958ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return BBinder::onTransact(code, data, reply, flags); 2968ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis} 2978ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 2998ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3002adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenIGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { 301c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall parcel.read(*this); 302c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 303c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 304e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { 305c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall return sizeof(timestamp) 3063c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 307c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(crop) 308c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(scalingMode) 309c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(transform) 3107cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian + sizeof(async) 3111df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis + fence->getFlattenedSize(); 312c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 313c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 314e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { 3151df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis return fence->getFdCount(); 316c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 317c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 318e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::flatten( 319e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void*& buffer, size_t& size, int*& fds, size_t& count) const 320c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 321e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < getFlattenedSize()) { 322e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 323e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 324e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, timestamp); 3253c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::write(buffer, size, isAutoTimestamp); 326e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, crop); 327e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, scalingMode); 328e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, transform); 329e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, async); 330e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->flatten(buffer, size, fds, count); 331c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 332c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 333e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::unflatten( 334e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void const*& buffer, size_t& size, int const*& fds, size_t& count) 335c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 336e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian size_t minNeeded = 337e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian sizeof(timestamp) 3383c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 339e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(crop) 340e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(scalingMode) 341e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(transform) 342e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(async); 343e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 344e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < minNeeded) { 345e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 346e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 347e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 348e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, timestamp); 3493c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::read(buffer, size, isAutoTimestamp); 350e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, crop); 351e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, scalingMode); 352e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, transform); 353e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, async); 354e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 3551df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis fence = new Fence(); 356e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->unflatten(buffer, size, fds, count); 357c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 358c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 3598ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android 360