IGraphicBufferProducer.cpp revision f0eaf25e9247edf4d124bedaeb863f7abdf35a3e
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> 30f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza#include <gui/IProducerListener.h> 318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android { 338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisenum { 368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, 378ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis SET_BUFFER_COUNT, 388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis DEQUEUE_BUFFER, 399f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza DETACH_BUFFER, 409f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza ATTACH_BUFFER, 418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis QUEUE_BUFFER, 428ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis CANCEL_BUFFER, 43eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian QUERY, 44fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis CONNECT, 45fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis DISCONNECT, 46399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall SET_SIDEBAND_STREAM, 478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 492adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> 508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{ 518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennispublic: 522adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden BpGraphicBufferProducer(const sp<IBinder>& impl) 532adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden : BpInterface<IGraphicBufferProducer>(impl) 548ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis { 558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 568ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 577b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { 588ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 592adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 608ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(bufferIdx); 618a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); 628a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 638a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 648a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis bool nonNull = reply.readInt32(); 668ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis if (nonNull) { 677b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis *buf = new GraphicBuffer(); 682aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu result = reply.read(**buf); 692aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu if(result != NO_ERROR) { 702aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu (*buf).clear(); 712aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu return result; 722aff7025482cc40d2ebd45f81cdb318ac1c6f868Lingyun Zhu } 738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 748a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 757b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis return result; 768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 778ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 788ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis virtual status_t setBufferCount(int bufferCount) 798ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis { 808ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 812adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 828ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(bufferCount); 838a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); 848a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 858a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 868a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 878a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 888a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 898ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 908ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 917cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, 92f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { 938ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 942adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 957cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian data.writeInt32(async); 96c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(w); 97c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(h); 98c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(format); 99c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian data.writeInt32(usage); 1008a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); 1018a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1028a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1038a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 1048ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis *buf = reply.readInt32(); 105ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian bool nonNull = reply.readInt32(); 106ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian if (nonNull) { 1074c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall *fence = new Fence(); 108ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian reply.read(**fence); 109f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall } 1108a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 1118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return result; 1128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1149f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza virtual status_t detachBuffer(int slot) { 1159f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza Parcel data, reply; 1169f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1179f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInt32(slot); 1189f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza status_t result = remote()->transact(DETACH_BUFFER, data, &reply); 1199f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza if (result != NO_ERROR) { 1209f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1219f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1229f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza result = reply.readInt32(); 1239f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1249f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1259f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza 1269f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { 1279f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza Parcel data, reply; 1289f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1299f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.write(*buffer.get()); 1309f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); 1319f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza if (result != NO_ERROR) { 1329f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1339f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1349f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza *slot = reply.readInt32(); 1359f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza result = reply.readInt32(); 1369f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1379f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1389f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza 139f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian virtual status_t queueBuffer(int buf, 140f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian const QueueBufferInput& input, QueueBufferOutput* output) { 1418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1422adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 144c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall data.write(input); 1458a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); 1468a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1478a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1488a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 149f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1508a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 1518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return result; 1528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1538ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1544c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall virtual void cancelBuffer(int buf, const sp<Fence>& fence) { 1558ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1562adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1578ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 1581df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.write(*fence.get()); 1598ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis remote()->transact(CANCEL_BUFFER, data, &reply); 1608ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1618ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 162eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian virtual int query(int what, int* value) { 163eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian Parcel data, reply; 1642adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 165eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian data.writeInt32(what); 1668a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUERY, data, &reply); 1678a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1688a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1698a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 170eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian value[0] = reply.readInt32(); 1718a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 172eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return result; 173eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } 174eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian 175f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza virtual status_t connect(const sp<IProducerListener>& listener, 176365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian int api, bool producerControlledByApp, QueueBufferOutput* output) { 177fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1782adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 179f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza if (listener != NULL) { 180f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza data.writeInt32(1); 181f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza data.writeStrongBinder(listener->asBinder()); 182f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza } else { 183f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza data.writeInt32(0); 184f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza } 185fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 186595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian data.writeInt32(producerControlledByApp); 1878a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(CONNECT, data, &reply); 1888a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1898a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1908a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 19124202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1928a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 193fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 194fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 1958072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 196fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis virtual status_t disconnect(int api) { 197fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1982adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 199fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 2008a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(DISCONNECT, data, &reply); 2018a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 2028a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 2038a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 2048a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 205fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 206fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 207399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 208399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { 209399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall Parcel data, reply; 210399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall status_t result; 211399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 212399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if (stream.get()) { 213399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInt32(true); 214399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeNativeHandle(stream->handle()); 215399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } else { 216399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall data.writeInt32(false); 217399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 218399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { 219399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall result = reply.readInt32(); 220399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 221399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall return result; 222399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 2238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 2248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 225466a192d2088f9238d34597d1aa28da41367c1caAndy McFaddenIMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); 2268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------- 2288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2292adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenstatus_t BnGraphicBufferProducer::onTransact( 2308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 2318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{ 2328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis switch(code) { 2338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case REQUEST_BUFFER: { 2342adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferIdx = data.readInt32(); 2367b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis sp<GraphicBuffer> buffer; 2377b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis int result = requestBuffer(bufferIdx, &buffer); 2388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buffer != 0); 2398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis if (buffer != 0) { 2408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->write(*buffer); 2418ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 2427b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis reply->writeInt32(result); 2438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2448ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2458ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case SET_BUFFER_COUNT: { 2462adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferCount = data.readInt32(); 2488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int result = setBufferCount(bufferCount); 2498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case DEQUEUE_BUFFER: { 2532adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2547cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian bool async = data.readInt32(); 255c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t w = data.readInt32(); 256c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t h = data.readInt32(); 257c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t format = data.readInt32(); 258c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t usage = data.readInt32(); 2598ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf; 260f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall sp<Fence> fence; 2617cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage); 2628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buf); 2631df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis reply->writeInt32(fence != NULL); 2641df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis if (fence != NULL) { 265ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian reply->write(*fence); 266f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall } 2678ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2689f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return NO_ERROR; 2699f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } break; 2709f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza case DETACH_BUFFER: { 2719f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2729f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int slot = data.readInt32(); 2739f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int result = detachBuffer(slot); 2749f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(result); 2759f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return NO_ERROR; 2769f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } break; 2779f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza case ATTACH_BUFFER: { 2789f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2799f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza sp<GraphicBuffer> buffer = new GraphicBuffer(); 2809f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.read(*buffer.get()); 2819f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int slot; 2829f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int result = attachBuffer(&slot, buffer); 2839f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(slot); 2849f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(result); 2858ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2868ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2878ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case QUEUE_BUFFER: { 2882adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2898ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 290c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall QueueBufferInput input(data); 291f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian QueueBufferOutput* const output = 292f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reinterpret_cast<QueueBufferOutput *>( 293f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 294c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall status_t result = queueBuffer(buf, input, output); 2958ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2968ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2978ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2988ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case CANCEL_BUFFER: { 2992adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 3008ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 3011df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis sp<Fence> fence = new Fence(); 3021df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.read(*fence.get()); 303c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall cancelBuffer(buf, fence); 3048ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 3058ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 306eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian case QUERY: { 3072adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 308eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int value; 309eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int what = data.readInt32(); 310eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int res = query(what, &value); 311eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(value); 312eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(res); 313eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return NO_ERROR; 314eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } break; 315fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case CONNECT: { 3162adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 317f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza sp<IProducerListener> listener; 318f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza if (data.readInt32() == 1) { 319f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza listener = IProducerListener::asInterface(data.readStrongBinder()); 320f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza } 321fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 322595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian bool producerControlledByApp = data.readInt32(); 32324202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian QueueBufferOutput* const output = 32424202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reinterpret_cast<QueueBufferOutput *>( 32524202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 326f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza status_t res = connect(listener, api, producerControlledByApp, output); 327fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 328fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 329fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 330fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case DISCONNECT: { 3312adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 332fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 3332773004a83624ed41cf3f94f2b11878cd8521812Mathias Agopian status_t res = disconnect(api); 334fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 335fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 336fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 337399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall case SET_SIDEBAND_STREAM: { 338399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 339399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall sp<NativeHandle> stream; 340399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall if (data.readInt32()) { 341399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall stream = NativeHandle::create(data.readNativeHandle()); 342399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } 343399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall status_t result = setSidebandStream(stream); 344399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall reply->writeInt32(result); 345399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall return NO_ERROR; 346399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall } break; 3478ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 3488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return BBinder::onTransact(code, data, reply, flags); 3498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis} 3508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3518ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 3528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3532adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenIGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { 354c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall parcel.read(*this); 355c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 356c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 357e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { 358c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall return sizeof(timestamp) 3593c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 360c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(crop) 361c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(scalingMode) 362c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(transform) 3637cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian + sizeof(async) 3641df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis + fence->getFlattenedSize(); 365c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 366c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 367e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { 3681df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis return fence->getFdCount(); 369c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 370c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 371e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::flatten( 372e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void*& buffer, size_t& size, int*& fds, size_t& count) const 373c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 374e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < getFlattenedSize()) { 375e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 376e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 377e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, timestamp); 3783c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::write(buffer, size, isAutoTimestamp); 379e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, crop); 380e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, scalingMode); 381e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, transform); 382e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, async); 383e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->flatten(buffer, size, fds, count); 384c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 385c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 386e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::unflatten( 387e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void const*& buffer, size_t& size, int const*& fds, size_t& count) 388c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 389e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian size_t minNeeded = 390e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian sizeof(timestamp) 3913c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 392e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(crop) 393e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(scalingMode) 394e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(transform) 395e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(async); 396e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 397e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < minNeeded) { 398e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 399e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 400e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 401e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, timestamp); 4023c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::read(buffer, size, isAutoTimestamp); 403e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, crop); 404e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, scalingMode); 405e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, transform); 406e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, async); 407e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 4081df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis fence = new Fence(); 409e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->unflatten(buffer, size, fds, count); 410c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 411c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 4128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android 413