IGraphicBufferProducer.cpp revision 9f3053de78630815d60cf48a2cf2348cc5867c45
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> 218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/RefBase.h> 228ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/Vector.h> 238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <utils/Timers.h> 248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <binder/Parcel.h> 268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis#include <binder/IInterface.h> 278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 282adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden#include <gui/IGraphicBufferProducer.h> 298ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 308ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisnamespace android { 318ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 328ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 338ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennisenum { 348ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, 358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis SET_BUFFER_COUNT, 368ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis DEQUEUE_BUFFER, 379f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza DETACH_BUFFER, 389f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza ATTACH_BUFFER, 398ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis QUEUE_BUFFER, 408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis CANCEL_BUFFER, 41eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian QUERY, 42fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis CONNECT, 43fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis DISCONNECT, 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 1119f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza virtual status_t detachBuffer(int slot) { 1129f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza Parcel data, reply; 1139f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1149f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInt32(slot); 1159f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza status_t result = remote()->transact(DETACH_BUFFER, data, &reply); 1169f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza if (result != NO_ERROR) { 1179f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1189f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1199f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza result = reply.readInt32(); 1209f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1219f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1229f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza 1239f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { 1249f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza Parcel data, reply; 1259f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1269f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.write(*buffer.get()); 1279f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); 1289f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza if (result != NO_ERROR) { 1299f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1309f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1319f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza *slot = reply.readInt32(); 1329f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza result = reply.readInt32(); 1339f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return result; 1349f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } 1359f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza 136f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian virtual status_t queueBuffer(int buf, 137f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian const QueueBufferInput& input, QueueBufferOutput* output) { 1388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1392adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1408ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 141c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall data.write(input); 1428a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); 1438a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1448a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1458a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 146f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1478a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 1488ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return result; 1498ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1508ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 1514c00cc11141da7d159eb2323b186ed344115c0f1Jesse Hall virtual void cancelBuffer(int buf, const sp<Fence>& fence) { 1528ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis Parcel data, reply; 1532adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 1548ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis data.writeInt32(buf); 1551df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.write(*fence.get()); 1568ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis remote()->transact(CANCEL_BUFFER, data, &reply); 1578ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 1588ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 159eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian virtual int query(int what, int* value) { 160eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian Parcel data, reply; 1612adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 162eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian data.writeInt32(what); 1638a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(QUERY, data, &reply); 1648a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1658a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1668a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 167eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian value[0] = reply.readInt32(); 1688a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 169eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return result; 170eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } 171eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian 172365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian virtual status_t connect(const sp<IBinder>& token, 173365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian int api, bool producerControlledByApp, QueueBufferOutput* output) { 174fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1752adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 176365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian data.writeStrongBinder(token); 177fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 178595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian data.writeInt32(producerControlledByApp); 1798a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result = remote()->transact(CONNECT, data, &reply); 1808a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1818a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1828a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 18324202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); 1848a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 185fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 186fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 1878072711307aa98ee5ee6f7369860ae38c3e19656Mathias Agopian 188fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis virtual status_t disconnect(int api) { 189fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis Parcel data, reply; 1902adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); 191fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis data.writeInt32(api); 1928a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis status_t result =remote()->transact(DISCONNECT, data, &reply); 1938a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis if (result != NO_ERROR) { 1948a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis return result; 1958a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis } 1968a29ff2a356816694c695db70460f93c7fb4ae6fJamie Gennis result = reply.readInt32(); 197fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return result; 198fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } 1998ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; 2008ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 201466a192d2088f9238d34597d1aa28da41367c1caAndy McFaddenIMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); 2028ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2038ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------- 2048ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 2052adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenstatus_t BnGraphicBufferProducer::onTransact( 2068ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 2078ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis{ 2088ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis switch(code) { 2098ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case REQUEST_BUFFER: { 2102adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferIdx = data.readInt32(); 2127b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis sp<GraphicBuffer> buffer; 2137b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis int result = requestBuffer(bufferIdx, &buffer); 2148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buffer != 0); 2158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis if (buffer != 0) { 2168ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->write(*buffer); 2178ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 2187b305fffc39d0fe0926e7fd2d7f6a524fbce62b7Jamie Gennis reply->writeInt32(result); 2198ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2208ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2218ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case SET_BUFFER_COUNT: { 2222adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2238ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int bufferCount = data.readInt32(); 2248ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int result = setBufferCount(bufferCount); 2258ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2268ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2278ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2288ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case DEQUEUE_BUFFER: { 2292adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2307cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian bool async = data.readInt32(); 231c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t w = data.readInt32(); 232c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t h = data.readInt32(); 233c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t format = data.readInt32(); 234c04f153353cdb0d291297d10452239f791d3fd2bMathias Agopian uint32_t usage = data.readInt32(); 2358ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf; 236f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall sp<Fence> fence; 2377cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage); 2388ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(buf); 2391df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis reply->writeInt32(fence != NULL); 2401df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis if (fence != NULL) { 241ba93b3f8e403636b614a4a379f9421bc70dca84fMathias Agopian reply->write(*fence); 242f78575400977f644cf0b12beb2fa5fc278b6ed4cJesse Hall } 2438ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2449f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return NO_ERROR; 2459f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } break; 2469f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza case DETACH_BUFFER: { 2479f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2489f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int slot = data.readInt32(); 2499f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int result = detachBuffer(slot); 2509f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(result); 2519f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza return NO_ERROR; 2529f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza } break; 2539f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza case ATTACH_BUFFER: { 2549f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2559f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza sp<GraphicBuffer> buffer = new GraphicBuffer(); 2569f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza data.read(*buffer.get()); 2579f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int slot; 2589f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza int result = attachBuffer(&slot, buffer); 2599f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(slot); 2609f3053de78630815d60cf48a2cf2348cc5867c45Dan Stoza reply->writeInt32(result); 2618ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2628ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2638ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case QUEUE_BUFFER: { 2642adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2658ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 266c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall QueueBufferInput input(data); 267f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian QueueBufferOutput* const output = 268f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reinterpret_cast<QueueBufferOutput *>( 269f0bc2f1d8d37977bd3aef3d3326a70e9e69d4246Mathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 270c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall status_t result = queueBuffer(buf, input, output); 2718ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis reply->writeInt32(result); 2728ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2738ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 2748ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis case CANCEL_BUFFER: { 2752adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 2768ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis int buf = data.readInt32(); 2771df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis sp<Fence> fence = new Fence(); 2781df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis data.read(*fence.get()); 279c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall cancelBuffer(buf, fence); 2808ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return NO_ERROR; 2818ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } break; 282eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian case QUERY: { 2832adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 284eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int value; 285eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int what = data.readInt32(); 286eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian int res = query(what, &value); 287eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(value); 288eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian reply->writeInt32(res); 289eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian return NO_ERROR; 290eafabcdc1639fb96062d9e3c39b0ae27b0238ae1Mathias Agopian } break; 291fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case CONNECT: { 2922adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 293365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian sp<IBinder> token = data.readStrongBinder(); 294fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 295595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian bool producerControlledByApp = data.readInt32(); 29624202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian QueueBufferOutput* const output = 29724202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reinterpret_cast<QueueBufferOutput *>( 29824202f5676c32edeef6544cf36e06b9fc970dbdeMathias Agopian reply->writeInplace(sizeof(QueueBufferOutput))); 299365857df8b94c959dea984a63013f6e7730ef976Mathias Agopian status_t res = connect(token, api, producerControlledByApp, output); 300fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 301fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 302fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 303fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis case DISCONNECT: { 3042adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFadden CHECK_INTERFACE(IGraphicBufferProducer, data, reply); 305fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis int api = data.readInt32(); 3062773004a83624ed41cf3f94f2b11878cd8521812Mathias Agopian status_t res = disconnect(api); 307fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis reply->writeInt32(res); 308fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis return NO_ERROR; 309fe0a87b54654a1392650e7f1862df473287d8332Jamie Gennis } break; 3108ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis } 3118ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis return BBinder::onTransact(code, data, reply, flags); 3128ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis} 3138ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3148ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis// ---------------------------------------------------------------------------- 3158ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis 3162adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenIGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { 317c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall parcel.read(*this); 318c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 319c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 320e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { 321c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall return sizeof(timestamp) 3223c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 323c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(crop) 324c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(scalingMode) 325c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall + sizeof(transform) 3267cdd786fa80cf03551291ae8feca7b77583be1c5Mathias Agopian + sizeof(async) 3271df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis + fence->getFlattenedSize(); 328c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 329c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 330e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopiansize_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { 3311df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis return fence->getFdCount(); 332c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 333c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 334e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::flatten( 335e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void*& buffer, size_t& size, int*& fds, size_t& count) const 336c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 337e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < getFlattenedSize()) { 338e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 339e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 340e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, timestamp); 3413c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::write(buffer, size, isAutoTimestamp); 342e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, crop); 343e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, scalingMode); 344e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, transform); 345e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::write(buffer, size, async); 346e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->flatten(buffer, size, fds, count); 347c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 348c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 349e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopianstatus_t IGraphicBufferProducer::QueueBufferInput::unflatten( 350e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian void const*& buffer, size_t& size, int const*& fds, size_t& count) 351c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall{ 352e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian size_t minNeeded = 353e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian sizeof(timestamp) 3543c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden + sizeof(isAutoTimestamp) 355e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(crop) 356e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(scalingMode) 357e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(transform) 358e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian + sizeof(async); 359e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 360e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian if (size < minNeeded) { 361e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return NO_MEMORY; 362e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian } 363e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 364e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, timestamp); 3653c25621ad7d13f64d3ab95a27fa970fbc9998f73Andy McFadden FlattenableUtils::read(buffer, size, isAutoTimestamp); 366e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, crop); 367e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, scalingMode); 368e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, transform); 369e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian FlattenableUtils::read(buffer, size, async); 370e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian 3711df8c345854155cbbcb9f80de9d12d66ea70ac08Jamie Gennis fence = new Fence(); 372e142428a9c8b9d2380032cd4d7b55ee440fe8770Mathias Agopian return fence->unflatten(buffer, size, fds, count); 373c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall} 374c777b0b3b9b0ea5d8e378fccde6935765e28e329Jesse Hall 3758ba32fade11abb73f3fd47ea0953c9528eb5b91fJamie Gennis}; // namespace android 376