1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2010 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H 18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H 19*38e8c45fSAndroid Build Coastguard Worker 20*38e8c45fSAndroid Build Coastguard Worker #include <stdint.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <sys/types.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <optional> 23*38e8c45fSAndroid Build Coastguard Worker 24*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h> 25*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h> 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker #include <binder/IInterface.h> 28*38e8c45fSAndroid Build Coastguard Worker 29*38e8c45fSAndroid Build Coastguard Worker #include <ui/BufferQueueDefs.h> 30*38e8c45fSAndroid Build Coastguard Worker #include <ui/Fence.h> 31*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicBuffer.h> 32*38e8c45fSAndroid Build Coastguard Worker #include <ui/PictureProfileHandle.h> 33*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rect.h> 34*38e8c45fSAndroid Build Coastguard Worker #include <ui/Region.h> 35*38e8c45fSAndroid Build Coastguard Worker 36*38e8c45fSAndroid Build Coastguard Worker #include <gui/AdditionalOptions.h> 37*38e8c45fSAndroid Build Coastguard Worker #include <gui/FrameTimestamps.h> 38*38e8c45fSAndroid Build Coastguard Worker #include <gui/HdrMetadata.h> 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker #include <hidl/HybridInterface.h> 41*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h> 42*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h> 43*38e8c45fSAndroid Build Coastguard Worker 44*38e8c45fSAndroid Build Coastguard Worker #include <optional> 45*38e8c45fSAndroid Build Coastguard Worker #include <vector> 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker #include <com_android_graphics_libgui_flags.h> 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker namespace android { 50*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------- 51*38e8c45fSAndroid Build Coastguard Worker 52*38e8c45fSAndroid Build Coastguard Worker class IProducerListener; 53*38e8c45fSAndroid Build Coastguard Worker class NativeHandle; 54*38e8c45fSAndroid Build Coastguard Worker class Surface; 55*38e8c45fSAndroid Build Coastguard Worker 56*38e8c45fSAndroid Build Coastguard Worker using HGraphicBufferProducerV1_0 = 57*38e8c45fSAndroid Build Coastguard Worker ::android::hardware::graphics::bufferqueue::V1_0:: 58*38e8c45fSAndroid Build Coastguard Worker IGraphicBufferProducer; 59*38e8c45fSAndroid Build Coastguard Worker using HGraphicBufferProducerV2_0 = 60*38e8c45fSAndroid Build Coastguard Worker ::android::hardware::graphics::bufferqueue::V2_0:: 61*38e8c45fSAndroid Build Coastguard Worker IGraphicBufferProducer; 62*38e8c45fSAndroid Build Coastguard Worker 63*38e8c45fSAndroid Build Coastguard Worker /* 64*38e8c45fSAndroid Build Coastguard Worker * This class defines the Binder IPC interface for the producer side of 65*38e8c45fSAndroid Build Coastguard Worker * a queue of graphics buffers. It's used to send graphics data from one 66*38e8c45fSAndroid Build Coastguard Worker * component to another. For example, a class that decodes video for 67*38e8c45fSAndroid Build Coastguard Worker * playback might use this to provide frames. This is typically done 68*38e8c45fSAndroid Build Coastguard Worker * indirectly, through Surface. 69*38e8c45fSAndroid Build Coastguard Worker * 70*38e8c45fSAndroid Build Coastguard Worker * The underlying mechanism is a BufferQueue, which implements 71*38e8c45fSAndroid Build Coastguard Worker * BnGraphicBufferProducer. In normal operation, the producer calls 72*38e8c45fSAndroid Build Coastguard Worker * dequeueBuffer() to get an empty buffer, fills it with data, then 73*38e8c45fSAndroid Build Coastguard Worker * calls queueBuffer() to make it available to the consumer. 74*38e8c45fSAndroid Build Coastguard Worker * 75*38e8c45fSAndroid Build Coastguard Worker * This class was previously called ISurfaceTexture. 76*38e8c45fSAndroid Build Coastguard Worker */ 77*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER 78*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferProducer : public IInterface { 79*38e8c45fSAndroid Build Coastguard Worker DECLARE_HYBRID_META_INTERFACE(GraphicBufferProducer, 80*38e8c45fSAndroid Build Coastguard Worker HGraphicBufferProducerV1_0, 81*38e8c45fSAndroid Build Coastguard Worker HGraphicBufferProducerV2_0) 82*38e8c45fSAndroid Build Coastguard Worker #else 83*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferProducer : public RefBase { 84*38e8c45fSAndroid Build Coastguard Worker #endif 85*38e8c45fSAndroid Build Coastguard Worker public: 86*38e8c45fSAndroid Build Coastguard Worker enum { 87*38e8c45fSAndroid Build Coastguard Worker // A flag returned by dequeueBuffer when the client needs to call 88*38e8c45fSAndroid Build Coastguard Worker // requestBuffer immediately thereafter. 89*38e8c45fSAndroid Build Coastguard Worker BUFFER_NEEDS_REALLOCATION = BufferQueueDefs::BUFFER_NEEDS_REALLOCATION, 90*38e8c45fSAndroid Build Coastguard Worker // A flag returned by dequeueBuffer when all mirrored slots should be 91*38e8c45fSAndroid Build Coastguard Worker // released by the client. This flag should always be processed first. 92*38e8c45fSAndroid Build Coastguard Worker RELEASE_ALL_BUFFERS = BufferQueueDefs::RELEASE_ALL_BUFFERS, 93*38e8c45fSAndroid Build Coastguard Worker }; 94*38e8c45fSAndroid Build Coastguard Worker 95*38e8c45fSAndroid Build Coastguard Worker enum { 96*38e8c45fSAndroid Build Coastguard Worker // A parcelable magic indicates using Binder BufferQueue as transport 97*38e8c45fSAndroid Build Coastguard Worker // backend. 98*38e8c45fSAndroid Build Coastguard Worker USE_BUFFER_QUEUE = 0x62717565, // 'bque' 99*38e8c45fSAndroid Build Coastguard Worker // A parcelable magic indicates using BufferHub as transport backend. 100*38e8c45fSAndroid Build Coastguard Worker USE_BUFFER_HUB = 0x62687562, // 'bhub' 101*38e8c45fSAndroid Build Coastguard Worker }; 102*38e8c45fSAndroid Build Coastguard Worker 103*38e8c45fSAndroid Build Coastguard Worker // requestBuffer requests a new buffer for the given index. The server (i.e. 104*38e8c45fSAndroid Build Coastguard Worker // the IGraphicBufferProducer implementation) assigns the newly created 105*38e8c45fSAndroid Build Coastguard Worker // buffer to the given slot index, and the client is expected to mirror the 106*38e8c45fSAndroid Build Coastguard Worker // slot->buffer mapping so that it's not necessary to transfer a 107*38e8c45fSAndroid Build Coastguard Worker // GraphicBuffer for every dequeue operation. 108*38e8c45fSAndroid Build Coastguard Worker // 109*38e8c45fSAndroid Build Coastguard Worker // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 110*38e8c45fSAndroid Build Coastguard Worker // 111*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 112*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 113*38e8c45fSAndroid Build Coastguard Worker // connected. 114*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the two conditions occurred: 115*38e8c45fSAndroid Build Coastguard Worker // * slot was out of range (see above) 116*38e8c45fSAndroid Build Coastguard Worker // * buffer specified by the slot is not dequeued 117*38e8c45fSAndroid Build Coastguard Worker virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0; 118*38e8c45fSAndroid Build Coastguard Worker 119*38e8c45fSAndroid Build Coastguard Worker // setMaxDequeuedBufferCount sets the maximum number of buffers that can be 120*38e8c45fSAndroid Build Coastguard Worker // dequeued by the producer at one time. If this method succeeds, any new 121*38e8c45fSAndroid Build Coastguard Worker // buffer slots will be both unallocated and owned by the BufferQueue object 122*38e8c45fSAndroid Build Coastguard Worker // (i.e. they are not owned by the producer or consumer). Calling this may 123*38e8c45fSAndroid Build Coastguard Worker // also cause some buffer slots to be emptied. If the caller is caching the 124*38e8c45fSAndroid Build Coastguard Worker // contents of the buffer slots, it should empty that cache after calling 125*38e8c45fSAndroid Build Coastguard Worker // this method. 126*38e8c45fSAndroid Build Coastguard Worker // 127*38e8c45fSAndroid Build Coastguard Worker // This function should not be called with a value of maxDequeuedBuffers 128*38e8c45fSAndroid Build Coastguard Worker // that is less than the number of currently dequeued buffer slots. Doing so 129*38e8c45fSAndroid Build Coastguard Worker // will result in a BAD_VALUE error. 130*38e8c45fSAndroid Build Coastguard Worker // 131*38e8c45fSAndroid Build Coastguard Worker // The buffer count should be at least 1 (inclusive), but at most 132*38e8c45fSAndroid Build Coastguard Worker // (NUM_BUFFER_SLOTS - the minimum undequeued buffer count) (exclusive). The 133*38e8c45fSAndroid Build Coastguard Worker // minimum undequeued buffer count can be obtained by calling 134*38e8c45fSAndroid Build Coastguard Worker // query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS). 135*38e8c45fSAndroid Build Coastguard Worker // 136*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 137*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned. 138*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the below conditions occurred: 139*38e8c45fSAndroid Build Coastguard Worker // * bufferCount was out of range (see above). 140*38e8c45fSAndroid Build Coastguard Worker // * client would have more than the requested number of dequeued 141*38e8c45fSAndroid Build Coastguard Worker // buffers after this call. 142*38e8c45fSAndroid Build Coastguard Worker // * this call would cause the maxBufferCount value to be exceeded. 143*38e8c45fSAndroid Build Coastguard Worker // * failure to adjust the number of available slots. 144*38e8c45fSAndroid Build Coastguard Worker virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) = 0; 145*38e8c45fSAndroid Build Coastguard Worker 146*38e8c45fSAndroid Build Coastguard Worker // Set the async flag if the producer intends to asynchronously queue 147*38e8c45fSAndroid Build Coastguard Worker // buffers without blocking. Typically this is used for triple-buffering 148*38e8c45fSAndroid Build Coastguard Worker // and/or when the swap interval is set to zero. 149*38e8c45fSAndroid Build Coastguard Worker // 150*38e8c45fSAndroid Build Coastguard Worker // Enabling async mode will internally allocate an additional buffer to 151*38e8c45fSAndroid Build Coastguard Worker // allow for the asynchronous behavior. If it is not enabled queue/dequeue 152*38e8c45fSAndroid Build Coastguard Worker // calls may block. 153*38e8c45fSAndroid Build Coastguard Worker // 154*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 155*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned. 156*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the following has occurred: 157*38e8c45fSAndroid Build Coastguard Worker // * this call would cause the maxBufferCount value to be 158*38e8c45fSAndroid Build Coastguard Worker // exceeded 159*38e8c45fSAndroid Build Coastguard Worker // * failure to adjust the number of available slots. 160*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAsyncMode(bool async) = 0; 161*38e8c45fSAndroid Build Coastguard Worker 162*38e8c45fSAndroid Build Coastguard Worker // dequeueBuffer requests a new buffer slot for the client to use. Ownership 163*38e8c45fSAndroid Build Coastguard Worker // of the slot is transfered to the client, meaning that the server will not 164*38e8c45fSAndroid Build Coastguard Worker // use the contents of the buffer associated with that slot. 165*38e8c45fSAndroid Build Coastguard Worker // 166*38e8c45fSAndroid Build Coastguard Worker // The slot index returned may or may not contain a buffer (client-side). 167*38e8c45fSAndroid Build Coastguard Worker // If the slot is empty the client should call requestBuffer to assign a new 168*38e8c45fSAndroid Build Coastguard Worker // buffer to that slot. 169*38e8c45fSAndroid Build Coastguard Worker // 170*38e8c45fSAndroid Build Coastguard Worker // Once the client is done filling this buffer, it is expected to transfer 171*38e8c45fSAndroid Build Coastguard Worker // buffer ownership back to the server with either cancelBuffer on 172*38e8c45fSAndroid Build Coastguard Worker // the dequeued slot or to fill in the contents of its associated buffer 173*38e8c45fSAndroid Build Coastguard Worker // contents and call queueBuffer. 174*38e8c45fSAndroid Build Coastguard Worker // 175*38e8c45fSAndroid Build Coastguard Worker // If dequeueBuffer returns the BUFFER_NEEDS_REALLOCATION flag, the client is 176*38e8c45fSAndroid Build Coastguard Worker // expected to call requestBuffer immediately. 177*38e8c45fSAndroid Build Coastguard Worker // 178*38e8c45fSAndroid Build Coastguard Worker // If dequeueBuffer returns the RELEASE_ALL_BUFFERS flag, the client is 179*38e8c45fSAndroid Build Coastguard Worker // expected to release all of the mirrored slot->buffer mappings. 180*38e8c45fSAndroid Build Coastguard Worker // 181*38e8c45fSAndroid Build Coastguard Worker // The fence parameter will be updated to hold the fence associated with 182*38e8c45fSAndroid Build Coastguard Worker // the buffer. The contents of the buffer must not be overwritten until the 183*38e8c45fSAndroid Build Coastguard Worker // fence signals. If the fence is Fence::NO_FENCE, the buffer may be written 184*38e8c45fSAndroid Build Coastguard Worker // immediately. 185*38e8c45fSAndroid Build Coastguard Worker // 186*38e8c45fSAndroid Build Coastguard Worker // The width and height parameters must be no greater than the minimum of 187*38e8c45fSAndroid Build Coastguard Worker // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 188*38e8c45fSAndroid Build Coastguard Worker // An error due to invalid dimensions might not be reported until 189*38e8c45fSAndroid Build Coastguard Worker // updateTexImage() is called. If width and height are both zero, the 190*38e8c45fSAndroid Build Coastguard Worker // default values specified by setDefaultBufferSize() are used instead. 191*38e8c45fSAndroid Build Coastguard Worker // 192*38e8c45fSAndroid Build Coastguard Worker // If the format is 0, the default format will be used. 193*38e8c45fSAndroid Build Coastguard Worker // 194*38e8c45fSAndroid Build Coastguard Worker // The usage argument specifies gralloc buffer usage flags. The values 195*38e8c45fSAndroid Build Coastguard Worker // are enumerated in <gralloc.h>, e.g. GRALLOC_USAGE_HW_RENDER. These 196*38e8c45fSAndroid Build Coastguard Worker // will be merged with the usage flags specified by 197*38e8c45fSAndroid Build Coastguard Worker // IGraphicBufferConsumer::setConsumerUsageBits. 198*38e8c45fSAndroid Build Coastguard Worker // 199*38e8c45fSAndroid Build Coastguard Worker // This call will block until a buffer is available to be dequeued. If 200*38e8c45fSAndroid Build Coastguard Worker // both the producer and consumer are controlled by the app, then this call 201*38e8c45fSAndroid Build Coastguard Worker // can never block and will return WOULD_BLOCK if no buffer is available. 202*38e8c45fSAndroid Build Coastguard Worker // 203*38e8c45fSAndroid Build Coastguard Worker // A non-negative value with flags set (see above) will be returned upon 204*38e8c45fSAndroid Build Coastguard Worker // success. 205*38e8c45fSAndroid Build Coastguard Worker // 206*38e8c45fSAndroid Build Coastguard Worker // Return of a negative means an error has occurred: 207*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 208*38e8c45fSAndroid Build Coastguard Worker // connected. 209*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - both in async mode and buffer count was less than the 210*38e8c45fSAndroid Build Coastguard Worker // max numbers of buffers that can be allocated at once. 211*38e8c45fSAndroid Build Coastguard Worker // * INVALID_OPERATION - cannot attach the buffer because it would cause 212*38e8c45fSAndroid Build Coastguard Worker // too many buffers to be dequeued, either because 213*38e8c45fSAndroid Build Coastguard Worker // the producer already has a single buffer dequeued 214*38e8c45fSAndroid Build Coastguard Worker // and did not set a buffer count, or because a 215*38e8c45fSAndroid Build Coastguard Worker // buffer count was set and this call would cause 216*38e8c45fSAndroid Build Coastguard Worker // it to be exceeded. 217*38e8c45fSAndroid Build Coastguard Worker // * WOULD_BLOCK - no buffer is currently available, and blocking is disabled 218*38e8c45fSAndroid Build Coastguard Worker // since both the producer/consumer are controlled by app 219*38e8c45fSAndroid Build Coastguard Worker // * NO_MEMORY - out of memory, cannot allocate the graphics buffer. 220*38e8c45fSAndroid Build Coastguard Worker // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while 221*38e8c45fSAndroid Build Coastguard Worker // waiting for a buffer to become available. 222*38e8c45fSAndroid Build Coastguard Worker // 223*38e8c45fSAndroid Build Coastguard Worker // All other negative values are an unknown error returned downstream 224*38e8c45fSAndroid Build Coastguard Worker // from the graphics allocator (typically errno). 225*38e8c45fSAndroid Build Coastguard Worker virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h, 226*38e8c45fSAndroid Build Coastguard Worker PixelFormat format, uint64_t usage, uint64_t* outBufferAge, 227*38e8c45fSAndroid Build Coastguard Worker FrameEventHistoryDelta* outTimestamps) = 0; 228*38e8c45fSAndroid Build Coastguard Worker 229*38e8c45fSAndroid Build Coastguard Worker // detachBuffer attempts to remove all ownership of the buffer in the given 230*38e8c45fSAndroid Build Coastguard Worker // slot from the buffer queue. If this call succeeds, the slot will be 231*38e8c45fSAndroid Build Coastguard Worker // freed, and there will be no way to obtain the buffer from this interface. 232*38e8c45fSAndroid Build Coastguard Worker // The freed slot will remain unallocated until either it is selected to 233*38e8c45fSAndroid Build Coastguard Worker // hold a freshly allocated buffer in dequeueBuffer or a buffer is attached 234*38e8c45fSAndroid Build Coastguard Worker // to the slot. The buffer must have already been dequeued, and the caller 235*38e8c45fSAndroid Build Coastguard Worker // must already possesses the sp<GraphicBuffer> (i.e., must have called 236*38e8c45fSAndroid Build Coastguard Worker // requestBuffer). 237*38e8c45fSAndroid Build Coastguard Worker // 238*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 239*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 240*38e8c45fSAndroid Build Coastguard Worker // connected. 241*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - the given slot number is invalid, either because it is 242*38e8c45fSAndroid Build Coastguard Worker // out of the range [0, NUM_BUFFER_SLOTS), or because the slot 243*38e8c45fSAndroid Build Coastguard Worker // it refers to is not currently dequeued and requested. 244*38e8c45fSAndroid Build Coastguard Worker virtual status_t detachBuffer(int slot) = 0; 245*38e8c45fSAndroid Build Coastguard Worker 246*38e8c45fSAndroid Build Coastguard Worker // detachNextBuffer is equivalent to calling dequeueBuffer, requestBuffer, 247*38e8c45fSAndroid Build Coastguard Worker // and detachBuffer in sequence, except for two things: 248*38e8c45fSAndroid Build Coastguard Worker // 249*38e8c45fSAndroid Build Coastguard Worker // 1) It is unnecessary to know the dimensions, format, or usage of the 250*38e8c45fSAndroid Build Coastguard Worker // next buffer. 251*38e8c45fSAndroid Build Coastguard Worker // 2) It will not block, since if it cannot find an appropriate buffer to 252*38e8c45fSAndroid Build Coastguard Worker // return, it will return an error instead. 253*38e8c45fSAndroid Build Coastguard Worker // 254*38e8c45fSAndroid Build Coastguard Worker // Only slots that are free but still contain a GraphicBuffer will be 255*38e8c45fSAndroid Build Coastguard Worker // considered, and the oldest of those will be returned. outBuffer is 256*38e8c45fSAndroid Build Coastguard Worker // equivalent to outBuffer from the requestBuffer call, and outFence is 257*38e8c45fSAndroid Build Coastguard Worker // equivalent to fence from the dequeueBuffer call. 258*38e8c45fSAndroid Build Coastguard Worker // 259*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 260*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 261*38e8c45fSAndroid Build Coastguard Worker // connected. 262*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - either outBuffer or outFence were NULL. 263*38e8c45fSAndroid Build Coastguard Worker // * NO_MEMORY - no slots were found that were both free and contained a 264*38e8c45fSAndroid Build Coastguard Worker // GraphicBuffer. 265*38e8c45fSAndroid Build Coastguard Worker virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, 266*38e8c45fSAndroid Build Coastguard Worker sp<Fence>* outFence) = 0; 267*38e8c45fSAndroid Build Coastguard Worker 268*38e8c45fSAndroid Build Coastguard Worker // attachBuffer attempts to transfer ownership of a buffer to the buffer 269*38e8c45fSAndroid Build Coastguard Worker // queue. If this call succeeds, it will be as if this buffer was dequeued 270*38e8c45fSAndroid Build Coastguard Worker // from the returned slot number. As such, this call will fail if attaching 271*38e8c45fSAndroid Build Coastguard Worker // this buffer would cause too many buffers to be simultaneously dequeued. 272*38e8c45fSAndroid Build Coastguard Worker // 273*38e8c45fSAndroid Build Coastguard Worker // If attachBuffer returns the RELEASE_ALL_BUFFERS flag, the caller is 274*38e8c45fSAndroid Build Coastguard Worker // expected to release all of the mirrored slot->buffer mappings. 275*38e8c45fSAndroid Build Coastguard Worker // 276*38e8c45fSAndroid Build Coastguard Worker // A non-negative value with flags set (see above) will be returned upon 277*38e8c45fSAndroid Build Coastguard Worker // success. 278*38e8c45fSAndroid Build Coastguard Worker // 279*38e8c45fSAndroid Build Coastguard Worker // Return of a negative value means an error has occurred: 280*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 281*38e8c45fSAndroid Build Coastguard Worker // connected. 282*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - outSlot or buffer were NULL, invalid combination of 283*38e8c45fSAndroid Build Coastguard Worker // async mode and buffer count override, or the generation 284*38e8c45fSAndroid Build Coastguard Worker // number of the buffer did not match the buffer queue. 285*38e8c45fSAndroid Build Coastguard Worker // * INVALID_OPERATION - cannot attach the buffer because it would cause 286*38e8c45fSAndroid Build Coastguard Worker // too many buffers to be dequeued, either because 287*38e8c45fSAndroid Build Coastguard Worker // the producer already has a single buffer dequeued 288*38e8c45fSAndroid Build Coastguard Worker // and did not set a buffer count, or because a 289*38e8c45fSAndroid Build Coastguard Worker // buffer count was set and this call would cause 290*38e8c45fSAndroid Build Coastguard Worker // it to be exceeded. 291*38e8c45fSAndroid Build Coastguard Worker // * WOULD_BLOCK - no buffer slot is currently available, and blocking is 292*38e8c45fSAndroid Build Coastguard Worker // disabled since both the producer/consumer are 293*38e8c45fSAndroid Build Coastguard Worker // controlled by the app. 294*38e8c45fSAndroid Build Coastguard Worker // * TIMED_OUT - the timeout set by setDequeueTimeout was exceeded while 295*38e8c45fSAndroid Build Coastguard Worker // waiting for a slot to become available. 296*38e8c45fSAndroid Build Coastguard Worker virtual status_t attachBuffer(int* outSlot, 297*38e8c45fSAndroid Build Coastguard Worker const sp<GraphicBuffer>& buffer) = 0; 298*38e8c45fSAndroid Build Coastguard Worker 299*38e8c45fSAndroid Build Coastguard Worker struct QueueBufferInput : public Flattenable<QueueBufferInput> { QueueBufferInputQueueBufferInput300*38e8c45fSAndroid Build Coastguard Worker explicit inline QueueBufferInput(const Parcel& parcel) { 301*38e8c45fSAndroid Build Coastguard Worker parcel.read(*this); 302*38e8c45fSAndroid Build Coastguard Worker } 303*38e8c45fSAndroid Build Coastguard Worker 304*38e8c45fSAndroid Build Coastguard Worker // timestamp - a monotonically increasing value in nanoseconds 305*38e8c45fSAndroid Build Coastguard Worker // isAutoTimestamp - if the timestamp was synthesized at queue time 306*38e8c45fSAndroid Build Coastguard Worker // dataSpace - description of the contents, interpretation depends on format 307*38e8c45fSAndroid Build Coastguard Worker // crop - a crop rectangle that's used as a hint to the consumer 308*38e8c45fSAndroid Build Coastguard Worker // scalingMode - a set of flags from NATIVE_WINDOW_SCALING_* in <window.h> 309*38e8c45fSAndroid Build Coastguard Worker // transform - a set of flags from NATIVE_WINDOW_TRANSFORM_* in <window.h> 310*38e8c45fSAndroid Build Coastguard Worker // fence - a fence that the consumer must wait on before reading the buffer, 311*38e8c45fSAndroid Build Coastguard Worker // set this to Fence::NO_FENCE if the buffer is ready immediately 312*38e8c45fSAndroid Build Coastguard Worker // sticky - the sticky transform set in Surface (only used by the LEGACY 313*38e8c45fSAndroid Build Coastguard Worker // camera mode). 314*38e8c45fSAndroid Build Coastguard Worker // getFrameTimestamps - whether or not the latest frame timestamps 315*38e8c45fSAndroid Build Coastguard Worker // should be retrieved from the consumer. 316*38e8c45fSAndroid Build Coastguard Worker // slot - the slot index to queue. This is used only by queueBuffers(). 317*38e8c45fSAndroid Build Coastguard Worker // queueBuffer() ignores this value and uses the argument `slot` 318*38e8c45fSAndroid Build Coastguard Worker // instead. 319*38e8c45fSAndroid Build Coastguard Worker inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp, 320*38e8c45fSAndroid Build Coastguard Worker android_dataspace _dataSpace, const Rect& _crop, 321*38e8c45fSAndroid Build Coastguard Worker int _scalingMode, uint32_t _transform, const sp<Fence>& _fence, 322*38e8c45fSAndroid Build Coastguard Worker uint32_t _sticky = 0, bool _getFrameTimestamps = false, 323*38e8c45fSAndroid Build Coastguard Worker int _slot = -1) timestampQueueBufferInput324*38e8c45fSAndroid Build Coastguard Worker : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp), 325*38e8c45fSAndroid Build Coastguard Worker dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode), 326*38e8c45fSAndroid Build Coastguard Worker transform(_transform), stickyTransform(_sticky), 327*38e8c45fSAndroid Build Coastguard Worker fence(_fence), surfaceDamage(), 328*38e8c45fSAndroid Build Coastguard Worker getFrameTimestamps(_getFrameTimestamps), slot(_slot) { } 329*38e8c45fSAndroid Build Coastguard Worker 330*38e8c45fSAndroid Build Coastguard Worker QueueBufferInput() = default; 331*38e8c45fSAndroid Build Coastguard Worker 332*38e8c45fSAndroid Build Coastguard Worker inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, 333*38e8c45fSAndroid Build Coastguard Worker android_dataspace* outDataSpace, 334*38e8c45fSAndroid Build Coastguard Worker Rect* outCrop, int* outScalingMode, 335*38e8c45fSAndroid Build Coastguard Worker uint32_t* outTransform, sp<Fence>* outFence, 336*38e8c45fSAndroid Build Coastguard Worker uint32_t* outStickyTransform = nullptr, 337*38e8c45fSAndroid Build Coastguard Worker bool* outGetFrameTimestamps = nullptr, 338*38e8c45fSAndroid Build Coastguard Worker int* outSlot = nullptr) const { 339*38e8c45fSAndroid Build Coastguard Worker *outTimestamp = timestamp; 340*38e8c45fSAndroid Build Coastguard Worker *outIsAutoTimestamp = bool(isAutoTimestamp); 341*38e8c45fSAndroid Build Coastguard Worker *outDataSpace = dataSpace; 342*38e8c45fSAndroid Build Coastguard Worker *outCrop = crop; 343*38e8c45fSAndroid Build Coastguard Worker *outScalingMode = scalingMode; 344*38e8c45fSAndroid Build Coastguard Worker *outTransform = transform; 345*38e8c45fSAndroid Build Coastguard Worker *outFence = fence; 346*38e8c45fSAndroid Build Coastguard Worker if (outStickyTransform != nullptr) { 347*38e8c45fSAndroid Build Coastguard Worker *outStickyTransform = stickyTransform; 348*38e8c45fSAndroid Build Coastguard Worker } 349*38e8c45fSAndroid Build Coastguard Worker if (outGetFrameTimestamps) { 350*38e8c45fSAndroid Build Coastguard Worker *outGetFrameTimestamps = getFrameTimestamps; 351*38e8c45fSAndroid Build Coastguard Worker } 352*38e8c45fSAndroid Build Coastguard Worker if (outSlot) { 353*38e8c45fSAndroid Build Coastguard Worker *outSlot = slot; 354*38e8c45fSAndroid Build Coastguard Worker } 355*38e8c45fSAndroid Build Coastguard Worker } 356*38e8c45fSAndroid Build Coastguard Worker 357*38e8c45fSAndroid Build Coastguard Worker // Flattenable protocol 358*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t minFlattenedSize(); 359*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 360*38e8c45fSAndroid Build Coastguard Worker size_t getFdCount() const; 361*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 362*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 363*38e8c45fSAndroid Build Coastguard Worker getSurfaceDamageQueueBufferInput364*38e8c45fSAndroid Build Coastguard Worker const Region& getSurfaceDamage() const { return surfaceDamage; } setSurfaceDamageQueueBufferInput365*38e8c45fSAndroid Build Coastguard Worker void setSurfaceDamage(const Region& damage) { surfaceDamage = damage; } 366*38e8c45fSAndroid Build Coastguard Worker getHdrMetadataQueueBufferInput367*38e8c45fSAndroid Build Coastguard Worker const HdrMetadata& getHdrMetadata() const { return hdrMetadata; } setHdrMetadataQueueBufferInput368*38e8c45fSAndroid Build Coastguard Worker void setHdrMetadata(const HdrMetadata& metadata) { hdrMetadata = metadata; } 369*38e8c45fSAndroid Build Coastguard Worker getPictureProfileHandleQueueBufferInput370*38e8c45fSAndroid Build Coastguard Worker const std::optional<PictureProfileHandle>& getPictureProfileHandle() const { 371*38e8c45fSAndroid Build Coastguard Worker return pictureProfileHandle; 372*38e8c45fSAndroid Build Coastguard Worker } setPictureProfileHandleQueueBufferInput373*38e8c45fSAndroid Build Coastguard Worker void setPictureProfileHandle(const PictureProfileHandle& profile) { 374*38e8c45fSAndroid Build Coastguard Worker pictureProfileHandle = profile; 375*38e8c45fSAndroid Build Coastguard Worker } clearPictureProfileHandleQueueBufferInput376*38e8c45fSAndroid Build Coastguard Worker void clearPictureProfileHandle() { pictureProfileHandle = std::nullopt; } 377*38e8c45fSAndroid Build Coastguard Worker 378*38e8c45fSAndroid Build Coastguard Worker int64_t timestamp{0}; 379*38e8c45fSAndroid Build Coastguard Worker int isAutoTimestamp{0}; 380*38e8c45fSAndroid Build Coastguard Worker android_dataspace dataSpace{HAL_DATASPACE_UNKNOWN}; 381*38e8c45fSAndroid Build Coastguard Worker Rect crop; 382*38e8c45fSAndroid Build Coastguard Worker int scalingMode{0}; 383*38e8c45fSAndroid Build Coastguard Worker uint32_t transform{0}; 384*38e8c45fSAndroid Build Coastguard Worker uint32_t stickyTransform{0}; 385*38e8c45fSAndroid Build Coastguard Worker sp<Fence> fence; 386*38e8c45fSAndroid Build Coastguard Worker Region surfaceDamage; 387*38e8c45fSAndroid Build Coastguard Worker bool getFrameTimestamps{false}; 388*38e8c45fSAndroid Build Coastguard Worker int slot{-1}; 389*38e8c45fSAndroid Build Coastguard Worker HdrMetadata hdrMetadata; 390*38e8c45fSAndroid Build Coastguard Worker std::optional<PictureProfileHandle> pictureProfileHandle; 391*38e8c45fSAndroid Build Coastguard Worker }; 392*38e8c45fSAndroid Build Coastguard Worker 393*38e8c45fSAndroid Build Coastguard Worker struct QueueBufferOutput : public Flattenable<QueueBufferOutput> { 394*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput() = default; 395*38e8c45fSAndroid Build Coastguard Worker 396*38e8c45fSAndroid Build Coastguard Worker // Moveable. 397*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput(QueueBufferOutput&& src) = default; 398*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput& operator=(QueueBufferOutput&& src) = default; 399*38e8c45fSAndroid Build Coastguard Worker // Not copyable. 400*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput(const QueueBufferOutput& src) = delete; 401*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput& operator=(const QueueBufferOutput& src) = delete; 402*38e8c45fSAndroid Build Coastguard Worker 403*38e8c45fSAndroid Build Coastguard Worker // Flattenable protocol 404*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t minFlattenedSize(); 405*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 406*38e8c45fSAndroid Build Coastguard Worker size_t getFdCount() const; 407*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 408*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 409*38e8c45fSAndroid Build Coastguard Worker 410*38e8c45fSAndroid Build Coastguard Worker uint32_t width{0}; 411*38e8c45fSAndroid Build Coastguard Worker uint32_t height{0}; 412*38e8c45fSAndroid Build Coastguard Worker uint32_t transformHint{0}; 413*38e8c45fSAndroid Build Coastguard Worker uint32_t numPendingBuffers{0}; 414*38e8c45fSAndroid Build Coastguard Worker uint64_t nextFrameNumber{0}; 415*38e8c45fSAndroid Build Coastguard Worker FrameEventHistoryDelta frameTimestamps; 416*38e8c45fSAndroid Build Coastguard Worker bool bufferReplaced{false}; 417*38e8c45fSAndroid Build Coastguard Worker int maxBufferCount{BufferQueueDefs::NUM_BUFFER_SLOTS}; 418*38e8c45fSAndroid Build Coastguard Worker status_t result{NO_ERROR}; 419*38e8c45fSAndroid Build Coastguard Worker }; 420*38e8c45fSAndroid Build Coastguard Worker 421*38e8c45fSAndroid Build Coastguard Worker // queueBuffer indicates that the client has finished filling in the 422*38e8c45fSAndroid Build Coastguard Worker // contents of the buffer associated with slot and transfers ownership of 423*38e8c45fSAndroid Build Coastguard Worker // that slot back to the server. 424*38e8c45fSAndroid Build Coastguard Worker // 425*38e8c45fSAndroid Build Coastguard Worker // It is not valid to call queueBuffer on a slot that is not owned 426*38e8c45fSAndroid Build Coastguard Worker // by the client or one for which a buffer associated via requestBuffer 427*38e8c45fSAndroid Build Coastguard Worker // (an attempt to do so will fail with a return value of BAD_VALUE). 428*38e8c45fSAndroid Build Coastguard Worker // 429*38e8c45fSAndroid Build Coastguard Worker // In addition, the input must be described by the client (as documented 430*38e8c45fSAndroid Build Coastguard Worker // below). Any other properties (zero point, etc) 431*38e8c45fSAndroid Build Coastguard Worker // are client-dependent, and should be documented by the client. 432*38e8c45fSAndroid Build Coastguard Worker // 433*38e8c45fSAndroid Build Coastguard Worker // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 434*38e8c45fSAndroid Build Coastguard Worker // 435*38e8c45fSAndroid Build Coastguard Worker // Upon success, the output will be filled with meaningful values 436*38e8c45fSAndroid Build Coastguard Worker // (refer to the documentation below). 437*38e8c45fSAndroid Build Coastguard Worker // 438*38e8c45fSAndroid Build Coastguard Worker // Note: QueueBufferInput::slot was added to QueueBufferInput to be used by 439*38e8c45fSAndroid Build Coastguard Worker // queueBuffers(), the batched version of queueBuffer(). The non-batched 440*38e8c45fSAndroid Build Coastguard Worker // method (queueBuffer()) uses `slot` and ignores `input.slot`. 441*38e8c45fSAndroid Build Coastguard Worker // 442*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 443*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 444*38e8c45fSAndroid Build Coastguard Worker // connected. 445*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the below conditions occurred: 446*38e8c45fSAndroid Build Coastguard Worker // * fence was NULL 447*38e8c45fSAndroid Build Coastguard Worker // * scaling mode was unknown 448*38e8c45fSAndroid Build Coastguard Worker // * both in async mode and buffer count was less than the 449*38e8c45fSAndroid Build Coastguard Worker // max numbers of buffers that can be allocated at once 450*38e8c45fSAndroid Build Coastguard Worker // * slot index was out of range (see above). 451*38e8c45fSAndroid Build Coastguard Worker // * the slot was not in the dequeued state 452*38e8c45fSAndroid Build Coastguard Worker // * the slot was enqueued without requesting a buffer 453*38e8c45fSAndroid Build Coastguard Worker // * crop rect is out of bounds of the buffer dimensions 454*38e8c45fSAndroid Build Coastguard Worker virtual status_t queueBuffer(int slot, const QueueBufferInput& input, 455*38e8c45fSAndroid Build Coastguard Worker QueueBufferOutput* output) = 0; 456*38e8c45fSAndroid Build Coastguard Worker 457*38e8c45fSAndroid Build Coastguard Worker // cancelBuffer indicates that the client does not wish to fill in the 458*38e8c45fSAndroid Build Coastguard Worker // buffer associated with slot and transfers ownership of the slot back to 459*38e8c45fSAndroid Build Coastguard Worker // the server. 460*38e8c45fSAndroid Build Coastguard Worker // 461*38e8c45fSAndroid Build Coastguard Worker // The buffer is not queued for use by the consumer. 462*38e8c45fSAndroid Build Coastguard Worker // 463*38e8c45fSAndroid Build Coastguard Worker // The slot must be in the range of [0, NUM_BUFFER_SLOTS). 464*38e8c45fSAndroid Build Coastguard Worker // 465*38e8c45fSAndroid Build Coastguard Worker // The buffer will not be overwritten until the fence signals. The fence 466*38e8c45fSAndroid Build Coastguard Worker // will usually be the one obtained from dequeueBuffer. 467*38e8c45fSAndroid Build Coastguard Worker // 468*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 469*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned or the producer is not 470*38e8c45fSAndroid Build Coastguard Worker // connected. 471*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the below conditions occurred: 472*38e8c45fSAndroid Build Coastguard Worker // * fence was NULL 473*38e8c45fSAndroid Build Coastguard Worker // * slot index was out of range (see above). 474*38e8c45fSAndroid Build Coastguard Worker // * the slot was not in the dequeued state 475*38e8c45fSAndroid Build Coastguard Worker virtual status_t cancelBuffer(int slot, const sp<Fence>& fence) = 0; 476*38e8c45fSAndroid Build Coastguard Worker 477*38e8c45fSAndroid Build Coastguard Worker // query retrieves some information for this surface 478*38e8c45fSAndroid Build Coastguard Worker // 'what' tokens allowed are that of NATIVE_WINDOW_* in <window.h> 479*38e8c45fSAndroid Build Coastguard Worker // 480*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 481*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the buffer queue has been abandoned. 482*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - what was out of range 483*38e8c45fSAndroid Build Coastguard Worker virtual int query(int what, int* value) = 0; 484*38e8c45fSAndroid Build Coastguard Worker 485*38e8c45fSAndroid Build Coastguard Worker // connect attempts to connect a client API to the IGraphicBufferProducer. 486*38e8c45fSAndroid Build Coastguard Worker // This must be called before any other IGraphicBufferProducer methods are 487*38e8c45fSAndroid Build Coastguard Worker // called except for getAllocator. A consumer must be already connected. 488*38e8c45fSAndroid Build Coastguard Worker // 489*38e8c45fSAndroid Build Coastguard Worker // This method will fail if the connect was previously called on the 490*38e8c45fSAndroid Build Coastguard Worker // IGraphicBufferProducer and no corresponding disconnect call was made. 491*38e8c45fSAndroid Build Coastguard Worker // 492*38e8c45fSAndroid Build Coastguard Worker // The listener is an optional binder callback object that can be used if 493*38e8c45fSAndroid Build Coastguard Worker // the producer wants to be notified when the consumer releases a buffer 494*38e8c45fSAndroid Build Coastguard Worker // back to the BufferQueue. It is also used to detect the death of the 495*38e8c45fSAndroid Build Coastguard Worker // producer. If only the latter functionality is desired, there is a 496*38e8c45fSAndroid Build Coastguard Worker // StubProducerListener class in IProducerListener.h that can be used. 497*38e8c45fSAndroid Build Coastguard Worker // 498*38e8c45fSAndroid Build Coastguard Worker // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> 499*38e8c45fSAndroid Build Coastguard Worker // 500*38e8c45fSAndroid Build Coastguard Worker // The producerControlledByApp should be set to true if the producer is hosted 501*38e8c45fSAndroid Build Coastguard Worker // by an untrusted process (typically app_process-forked processes). If both 502*38e8c45fSAndroid Build Coastguard Worker // the producer and the consumer are app-controlled then all buffer queues 503*38e8c45fSAndroid Build Coastguard Worker // will operate in async mode regardless of the async flag. 504*38e8c45fSAndroid Build Coastguard Worker // 505*38e8c45fSAndroid Build Coastguard Worker // Upon success, the output will be filled with meaningful data 506*38e8c45fSAndroid Build Coastguard Worker // (refer to QueueBufferOutput documentation above). 507*38e8c45fSAndroid Build Coastguard Worker // 508*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 509*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - one of the following occurred: 510*38e8c45fSAndroid Build Coastguard Worker // * the buffer queue was abandoned 511*38e8c45fSAndroid Build Coastguard Worker // * no consumer has yet connected 512*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the following has occurred: 513*38e8c45fSAndroid Build Coastguard Worker // * the producer is already connected 514*38e8c45fSAndroid Build Coastguard Worker // * api was out of range (see above). 515*38e8c45fSAndroid Build Coastguard Worker // * output was NULL. 516*38e8c45fSAndroid Build Coastguard Worker // * Failure to adjust the number of available slots. This can 517*38e8c45fSAndroid Build Coastguard Worker // happen because of trying to allocate/deallocate the async 518*38e8c45fSAndroid Build Coastguard Worker // buffer in response to the value of producerControlledByApp. 519*38e8c45fSAndroid Build Coastguard Worker // * DEAD_OBJECT - the token is hosted by an already-dead process 520*38e8c45fSAndroid Build Coastguard Worker // 521*38e8c45fSAndroid Build Coastguard Worker // Additional negative errors may be returned by the internals, they 522*38e8c45fSAndroid Build Coastguard Worker // should be treated as opaque fatal unrecoverable errors. 523*38e8c45fSAndroid Build Coastguard Worker virtual status_t connect(const sp<IProducerListener>& listener, 524*38e8c45fSAndroid Build Coastguard Worker int api, bool producerControlledByApp, QueueBufferOutput* output) = 0; 525*38e8c45fSAndroid Build Coastguard Worker 526*38e8c45fSAndroid Build Coastguard Worker enum class DisconnectMode { 527*38e8c45fSAndroid Build Coastguard Worker // Disconnect only the specified API. 528*38e8c45fSAndroid Build Coastguard Worker Api, 529*38e8c45fSAndroid Build Coastguard Worker // Disconnect any API originally connected from the process calling disconnect. 530*38e8c45fSAndroid Build Coastguard Worker AllLocal 531*38e8c45fSAndroid Build Coastguard Worker }; 532*38e8c45fSAndroid Build Coastguard Worker 533*38e8c45fSAndroid Build Coastguard Worker // disconnect attempts to disconnect a client API from the 534*38e8c45fSAndroid Build Coastguard Worker // IGraphicBufferProducer. Calling this method will cause any subsequent 535*38e8c45fSAndroid Build Coastguard Worker // calls to other IGraphicBufferProducer methods to fail except for 536*38e8c45fSAndroid Build Coastguard Worker // getAllocator and connect. Successfully calling connect after this will 537*38e8c45fSAndroid Build Coastguard Worker // allow the other methods to succeed again. 538*38e8c45fSAndroid Build Coastguard Worker // 539*38e8c45fSAndroid Build Coastguard Worker // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> 540*38e8c45fSAndroid Build Coastguard Worker // 541*38e8c45fSAndroid Build Coastguard Worker // Alternatively if mode is AllLocal, then the API value is ignored, and any API 542*38e8c45fSAndroid Build Coastguard Worker // connected from the same PID calling disconnect will be disconnected. 543*38e8c45fSAndroid Build Coastguard Worker // 544*38e8c45fSAndroid Build Coastguard Worker // Disconnecting from an abandoned IGraphicBufferProducer is legal and 545*38e8c45fSAndroid Build Coastguard Worker // is considered a no-op. 546*38e8c45fSAndroid Build Coastguard Worker // 547*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 548*38e8c45fSAndroid Build Coastguard Worker // * NO_INIT - the producer is not connected 549*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - one of the following has occurred: 550*38e8c45fSAndroid Build Coastguard Worker // * the api specified does not match the one that was connected 551*38e8c45fSAndroid Build Coastguard Worker // * api was out of range (see above). 552*38e8c45fSAndroid Build Coastguard Worker // * DEAD_OBJECT - the token is hosted by an already-dead process 553*38e8c45fSAndroid Build Coastguard Worker virtual status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api) = 0; 554*38e8c45fSAndroid Build Coastguard Worker 555*38e8c45fSAndroid Build Coastguard Worker // Attaches a sideband buffer stream to the IGraphicBufferProducer. 556*38e8c45fSAndroid Build Coastguard Worker // 557*38e8c45fSAndroid Build Coastguard Worker // A sideband stream is a device-specific mechanism for passing buffers 558*38e8c45fSAndroid Build Coastguard Worker // from the producer to the consumer without using dequeueBuffer/ 559*38e8c45fSAndroid Build Coastguard Worker // queueBuffer. If a sideband stream is present, the consumer can choose 560*38e8c45fSAndroid Build Coastguard Worker // whether to acquire buffers from the sideband stream or from the queued 561*38e8c45fSAndroid Build Coastguard Worker // buffers. 562*38e8c45fSAndroid Build Coastguard Worker // 563*38e8c45fSAndroid Build Coastguard Worker // Passing NULL or a different stream handle will detach the previous 564*38e8c45fSAndroid Build Coastguard Worker // handle if any. 565*38e8c45fSAndroid Build Coastguard Worker virtual status_t setSidebandStream(const sp<NativeHandle>& stream) = 0; 566*38e8c45fSAndroid Build Coastguard Worker 567*38e8c45fSAndroid Build Coastguard Worker // Allocates buffers based on the given dimensions/format. 568*38e8c45fSAndroid Build Coastguard Worker // 569*38e8c45fSAndroid Build Coastguard Worker // This function will allocate up to the maximum number of buffers 570*38e8c45fSAndroid Build Coastguard Worker // permitted by the current BufferQueue configuration. It will use the 571*38e8c45fSAndroid Build Coastguard Worker // given format, dimensions, and usage bits, which are interpreted in the 572*38e8c45fSAndroid Build Coastguard Worker // same way as for dequeueBuffer, and the async flag must be set the same 573*38e8c45fSAndroid Build Coastguard Worker // way as for dequeueBuffer to ensure that the correct number of buffers are 574*38e8c45fSAndroid Build Coastguard Worker // allocated. This is most useful to avoid an allocation delay during 575*38e8c45fSAndroid Build Coastguard Worker // dequeueBuffer. If there are already the maximum number of buffers 576*38e8c45fSAndroid Build Coastguard Worker // allocated, this function has no effect. 577*38e8c45fSAndroid Build Coastguard Worker virtual void allocateBuffers(uint32_t width, uint32_t height, 578*38e8c45fSAndroid Build Coastguard Worker PixelFormat format, uint64_t usage) = 0; 579*38e8c45fSAndroid Build Coastguard Worker 580*38e8c45fSAndroid Build Coastguard Worker // Sets whether dequeueBuffer is allowed to allocate new buffers. 581*38e8c45fSAndroid Build Coastguard Worker // 582*38e8c45fSAndroid Build Coastguard Worker // Normally dequeueBuffer does not discriminate between free slots which 583*38e8c45fSAndroid Build Coastguard Worker // already have an allocated buffer and those which do not, and will 584*38e8c45fSAndroid Build Coastguard Worker // allocate a new buffer if the slot doesn't have a buffer or if the slot's 585*38e8c45fSAndroid Build Coastguard Worker // buffer doesn't match the requested size, format, or usage. This method 586*38e8c45fSAndroid Build Coastguard Worker // allows the producer to restrict the eligible slots to those which already 587*38e8c45fSAndroid Build Coastguard Worker // have an allocated buffer of the correct size, format, and usage. If no 588*38e8c45fSAndroid Build Coastguard Worker // eligible slot is available, dequeueBuffer will block or return an error 589*38e8c45fSAndroid Build Coastguard Worker // as usual. 590*38e8c45fSAndroid Build Coastguard Worker virtual status_t allowAllocation(bool allow) = 0; 591*38e8c45fSAndroid Build Coastguard Worker 592*38e8c45fSAndroid Build Coastguard Worker // Sets the current generation number of the BufferQueue. 593*38e8c45fSAndroid Build Coastguard Worker // 594*38e8c45fSAndroid Build Coastguard Worker // This generation number will be inserted into any buffers allocated by the 595*38e8c45fSAndroid Build Coastguard Worker // BufferQueue, and any attempts to attach a buffer with a different 596*38e8c45fSAndroid Build Coastguard Worker // generation number will fail. Buffers already in the queue are not 597*38e8c45fSAndroid Build Coastguard Worker // affected and will retain their current generation number. The generation 598*38e8c45fSAndroid Build Coastguard Worker // number defaults to 0. 599*38e8c45fSAndroid Build Coastguard Worker virtual status_t setGenerationNumber(uint32_t generationNumber) = 0; 600*38e8c45fSAndroid Build Coastguard Worker 601*38e8c45fSAndroid Build Coastguard Worker // Returns the name of the connected consumer. 602*38e8c45fSAndroid Build Coastguard Worker virtual String8 getConsumerName() const = 0; 603*38e8c45fSAndroid Build Coastguard Worker 604*38e8c45fSAndroid Build Coastguard Worker // Used to enable/disable shared buffer mode. 605*38e8c45fSAndroid Build Coastguard Worker // 606*38e8c45fSAndroid Build Coastguard Worker // When shared buffer mode is enabled the first buffer that is queued or 607*38e8c45fSAndroid Build Coastguard Worker // dequeued will be cached and returned to all subsequent calls to 608*38e8c45fSAndroid Build Coastguard Worker // dequeueBuffer and acquireBuffer. This allows the producer and consumer to 609*38e8c45fSAndroid Build Coastguard Worker // simultaneously access the same buffer. 610*38e8c45fSAndroid Build Coastguard Worker virtual status_t setSharedBufferMode(bool sharedBufferMode) = 0; 611*38e8c45fSAndroid Build Coastguard Worker 612*38e8c45fSAndroid Build Coastguard Worker // Used to enable/disable auto-refresh. 613*38e8c45fSAndroid Build Coastguard Worker // 614*38e8c45fSAndroid Build Coastguard Worker // Auto refresh has no effect outside of shared buffer mode. In shared 615*38e8c45fSAndroid Build Coastguard Worker // buffer mode, when enabled, it indicates to the consumer that it should 616*38e8c45fSAndroid Build Coastguard Worker // attempt to acquire buffers even if it is not aware of any being 617*38e8c45fSAndroid Build Coastguard Worker // available. 618*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAutoRefresh(bool autoRefresh) = 0; 619*38e8c45fSAndroid Build Coastguard Worker 620*38e8c45fSAndroid Build Coastguard Worker // Sets how long dequeueBuffer will wait for a buffer to become available 621*38e8c45fSAndroid Build Coastguard Worker // before returning an error (TIMED_OUT). 622*38e8c45fSAndroid Build Coastguard Worker // 623*38e8c45fSAndroid Build Coastguard Worker // This timeout also affects the attachBuffer call, which will block if 624*38e8c45fSAndroid Build Coastguard Worker // there is not a free slot available into which the attached buffer can be 625*38e8c45fSAndroid Build Coastguard Worker // placed. 626*38e8c45fSAndroid Build Coastguard Worker // 627*38e8c45fSAndroid Build Coastguard Worker // By default, the BufferQueue will wait forever, which is indicated by a 628*38e8c45fSAndroid Build Coastguard Worker // timeout of -1. If set (to a value other than -1), this will disable 629*38e8c45fSAndroid Build Coastguard Worker // non-blocking mode and its corresponding spare buffer (which is used to 630*38e8c45fSAndroid Build Coastguard Worker // ensure a buffer is always available). 631*38e8c45fSAndroid Build Coastguard Worker // 632*38e8c45fSAndroid Build Coastguard Worker // Note well: queueBuffer will stop buffer dropping behavior if timeout is 633*38e8c45fSAndroid Build Coastguard Worker // strictly positive. If timeout is zero or negative, previous buffer 634*38e8c45fSAndroid Build Coastguard Worker // dropping behavior will not be changed. 635*38e8c45fSAndroid Build Coastguard Worker // 636*38e8c45fSAndroid Build Coastguard Worker // Return of a value other than NO_ERROR means an error has occurred: 637*38e8c45fSAndroid Build Coastguard Worker // * BAD_VALUE - Failure to adjust the number of available slots. This can 638*38e8c45fSAndroid Build Coastguard Worker // happen because of trying to allocate/deallocate the async 639*38e8c45fSAndroid Build Coastguard Worker // buffer. 640*38e8c45fSAndroid Build Coastguard Worker virtual status_t setDequeueTimeout(nsecs_t timeout) = 0; 641*38e8c45fSAndroid Build Coastguard Worker 642*38e8c45fSAndroid Build Coastguard Worker // Used to enable/disable buffer drop behavior of queueBuffer. 643*38e8c45fSAndroid Build Coastguard Worker // If it's not used, legacy drop behavior will be retained. 644*38e8c45fSAndroid Build Coastguard Worker virtual status_t setLegacyBufferDrop(bool drop); 645*38e8c45fSAndroid Build Coastguard Worker 646*38e8c45fSAndroid Build Coastguard Worker // Returns the last queued buffer along with a fence which must signal 647*38e8c45fSAndroid Build Coastguard Worker // before the contents of the buffer are read. If there are no buffers in 648*38e8c45fSAndroid Build Coastguard Worker // the queue, outBuffer will be populated with nullptr and outFence will be 649*38e8c45fSAndroid Build Coastguard Worker // populated with Fence::NO_FENCE 650*38e8c45fSAndroid Build Coastguard Worker // 651*38e8c45fSAndroid Build Coastguard Worker // outTransformMatrix is not modified if outBuffer is null. 652*38e8c45fSAndroid Build Coastguard Worker // 653*38e8c45fSAndroid Build Coastguard Worker // Returns NO_ERROR or the status of the Binder transaction 654*38e8c45fSAndroid Build Coastguard Worker virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, 655*38e8c45fSAndroid Build Coastguard Worker sp<Fence>* outFence, float outTransformMatrix[16]) = 0; 656*38e8c45fSAndroid Build Coastguard Worker 657*38e8c45fSAndroid Build Coastguard Worker // Returns the last queued buffer along with a fence which must signal 658*38e8c45fSAndroid Build Coastguard Worker // before the contents of the buffer are read. If there are no buffers in 659*38e8c45fSAndroid Build Coastguard Worker // the queue, outBuffer will be populated with nullptr and outFence will be 660*38e8c45fSAndroid Build Coastguard Worker // populated with Fence::NO_FENCE 661*38e8c45fSAndroid Build Coastguard Worker // 662*38e8c45fSAndroid Build Coastguard Worker // outRect & outTransform are not modified if outBuffer is null. 663*38e8c45fSAndroid Build Coastguard Worker // 664*38e8c45fSAndroid Build Coastguard Worker // Returns NO_ERROR or the status of the Binder transaction getLastQueuedBuffer(sp<GraphicBuffer> * outBuffer,sp<Fence> * outFence,Rect * outRect,uint32_t * outTransform)665*38e8c45fSAndroid Build Coastguard Worker virtual status_t getLastQueuedBuffer([[maybe_unused]] sp<GraphicBuffer>* outBuffer, 666*38e8c45fSAndroid Build Coastguard Worker [[maybe_unused]] sp<Fence>* outFence, 667*38e8c45fSAndroid Build Coastguard Worker [[maybe_unused]] Rect* outRect, 668*38e8c45fSAndroid Build Coastguard Worker [[maybe_unused]] uint32_t* outTransform) { 669*38e8c45fSAndroid Build Coastguard Worker // Too many things implement IGraphicBufferProducer... 670*38e8c45fSAndroid Build Coastguard Worker return UNKNOWN_TRANSACTION; 671*38e8c45fSAndroid Build Coastguard Worker } 672*38e8c45fSAndroid Build Coastguard Worker 673*38e8c45fSAndroid Build Coastguard Worker // Gets the frame events that haven't already been retrieved. getFrameTimestamps(FrameEventHistoryDelta *)674*38e8c45fSAndroid Build Coastguard Worker virtual void getFrameTimestamps(FrameEventHistoryDelta* /*outDelta*/) {} 675*38e8c45fSAndroid Build Coastguard Worker 676*38e8c45fSAndroid Build Coastguard Worker // Returns a unique id for this BufferQueue 677*38e8c45fSAndroid Build Coastguard Worker virtual status_t getUniqueId(uint64_t* outId) const = 0; 678*38e8c45fSAndroid Build Coastguard Worker 679*38e8c45fSAndroid Build Coastguard Worker // Returns the consumer usage flags for this BufferQueue. This returns the 680*38e8c45fSAndroid Build Coastguard Worker // full 64-bit usage flags, rather than the truncated 32-bit usage flags 681*38e8c45fSAndroid Build Coastguard Worker // returned by querying the now deprecated 682*38e8c45fSAndroid Build Coastguard Worker // NATIVE_WINDOW_CONSUMER_USAGE_BITS attribute. 683*38e8c45fSAndroid Build Coastguard Worker virtual status_t getConsumerUsage(uint64_t* outUsage) const = 0; 684*38e8c45fSAndroid Build Coastguard Worker 685*38e8c45fSAndroid Build Coastguard Worker // Enable/disable the auto prerotation at buffer allocation when the buffer 686*38e8c45fSAndroid Build Coastguard Worker // size is driven by the consumer. 687*38e8c45fSAndroid Build Coastguard Worker // 688*38e8c45fSAndroid Build Coastguard Worker // When buffer size is driven by the consumer and the transform hint 689*38e8c45fSAndroid Build Coastguard Worker // specifies a 90 or 270 degree rotation, if auto prerotation is enabled, 690*38e8c45fSAndroid Build Coastguard Worker // the width and height used for dequeueBuffer will be additionally swapped. 691*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAutoPrerotation(bool autoPrerotation); 692*38e8c45fSAndroid Build Coastguard Worker 693*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE) 694*38e8c45fSAndroid Build Coastguard Worker // Sets the apps intended frame rate. 695*38e8c45fSAndroid Build Coastguard Worker virtual status_t setFrameRate(float frameRate, int8_t compatibility, 696*38e8c45fSAndroid Build Coastguard Worker int8_t changeFrameRateStrategy); 697*38e8c45fSAndroid Build Coastguard Worker #endif 698*38e8c45fSAndroid Build Coastguard Worker 699*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) 700*38e8c45fSAndroid Build Coastguard Worker virtual status_t setAdditionalOptions(const std::vector<gui::AdditionalOptions>& options); 701*38e8c45fSAndroid Build Coastguard Worker #endif 702*38e8c45fSAndroid Build Coastguard Worker 703*38e8c45fSAndroid Build Coastguard Worker struct RequestBufferOutput : public Flattenable<RequestBufferOutput> { 704*38e8c45fSAndroid Build Coastguard Worker RequestBufferOutput() = default; 705*38e8c45fSAndroid Build Coastguard Worker 706*38e8c45fSAndroid Build Coastguard Worker // Flattenable protocol 707*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t minFlattenedSize(); 708*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 709*38e8c45fSAndroid Build Coastguard Worker size_t getFdCount() const; 710*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 711*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 712*38e8c45fSAndroid Build Coastguard Worker 713*38e8c45fSAndroid Build Coastguard Worker status_t result; 714*38e8c45fSAndroid Build Coastguard Worker sp<GraphicBuffer> buffer; 715*38e8c45fSAndroid Build Coastguard Worker }; 716*38e8c45fSAndroid Build Coastguard Worker 717*38e8c45fSAndroid Build Coastguard Worker // Batched version of requestBuffer(). 718*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of requestBuffer() calls. 719*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 720*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 721*38e8c45fSAndroid Build Coastguard Worker virtual status_t requestBuffers( 722*38e8c45fSAndroid Build Coastguard Worker const std::vector<int32_t>& slots, 723*38e8c45fSAndroid Build Coastguard Worker std::vector<RequestBufferOutput>* outputs); 724*38e8c45fSAndroid Build Coastguard Worker 725*38e8c45fSAndroid Build Coastguard Worker struct DequeueBufferInput : public LightFlattenable<DequeueBufferInput> { 726*38e8c45fSAndroid Build Coastguard Worker DequeueBufferInput() = default; 727*38e8c45fSAndroid Build Coastguard Worker 728*38e8c45fSAndroid Build Coastguard Worker // LightFlattenable protocol isFixedSizeDequeueBufferInput729*38e8c45fSAndroid Build Coastguard Worker inline bool isFixedSize() const { return true; } 730*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 731*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void* buffer, size_t size) const; 732*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const* buffer, size_t size); 733*38e8c45fSAndroid Build Coastguard Worker 734*38e8c45fSAndroid Build Coastguard Worker uint32_t width; 735*38e8c45fSAndroid Build Coastguard Worker uint32_t height; 736*38e8c45fSAndroid Build Coastguard Worker PixelFormat format; 737*38e8c45fSAndroid Build Coastguard Worker uint64_t usage; 738*38e8c45fSAndroid Build Coastguard Worker bool getTimestamps; 739*38e8c45fSAndroid Build Coastguard Worker }; 740*38e8c45fSAndroid Build Coastguard Worker 741*38e8c45fSAndroid Build Coastguard Worker struct DequeueBufferOutput : public Flattenable<DequeueBufferOutput> { 742*38e8c45fSAndroid Build Coastguard Worker DequeueBufferOutput() = default; 743*38e8c45fSAndroid Build Coastguard Worker 744*38e8c45fSAndroid Build Coastguard Worker // Flattenable protocol 745*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t minFlattenedSize(); 746*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 747*38e8c45fSAndroid Build Coastguard Worker size_t getFdCount() const; 748*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 749*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 750*38e8c45fSAndroid Build Coastguard Worker 751*38e8c45fSAndroid Build Coastguard Worker status_t result; 752*38e8c45fSAndroid Build Coastguard Worker int slot = -1; 753*38e8c45fSAndroid Build Coastguard Worker sp<Fence> fence = Fence::NO_FENCE; 754*38e8c45fSAndroid Build Coastguard Worker uint64_t bufferAge; 755*38e8c45fSAndroid Build Coastguard Worker std::optional<FrameEventHistoryDelta> timestamps; 756*38e8c45fSAndroid Build Coastguard Worker }; 757*38e8c45fSAndroid Build Coastguard Worker 758*38e8c45fSAndroid Build Coastguard Worker // Batched version of dequeueBuffer(). 759*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of dequeueBuffer() calls. 760*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 761*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 762*38e8c45fSAndroid Build Coastguard Worker virtual status_t dequeueBuffers( 763*38e8c45fSAndroid Build Coastguard Worker const std::vector<DequeueBufferInput>& inputs, 764*38e8c45fSAndroid Build Coastguard Worker std::vector<DequeueBufferOutput>* outputs); 765*38e8c45fSAndroid Build Coastguard Worker 766*38e8c45fSAndroid Build Coastguard Worker // Batched version of detachBuffer(). 767*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of detachBuffer() calls. 768*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 769*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 770*38e8c45fSAndroid Build Coastguard Worker virtual status_t detachBuffers(const std::vector<int32_t>& slots, 771*38e8c45fSAndroid Build Coastguard Worker std::vector<status_t>* results); 772*38e8c45fSAndroid Build Coastguard Worker 773*38e8c45fSAndroid Build Coastguard Worker 774*38e8c45fSAndroid Build Coastguard Worker struct AttachBufferOutput : public LightFlattenable<AttachBufferOutput> { 775*38e8c45fSAndroid Build Coastguard Worker AttachBufferOutput() = default; 776*38e8c45fSAndroid Build Coastguard Worker 777*38e8c45fSAndroid Build Coastguard Worker // LightFlattenable protocol isFixedSizeAttachBufferOutput778*38e8c45fSAndroid Build Coastguard Worker inline bool isFixedSize() const { return true; } 779*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 780*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void* buffer, size_t size) const; 781*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const* buffer, size_t size); 782*38e8c45fSAndroid Build Coastguard Worker 783*38e8c45fSAndroid Build Coastguard Worker status_t result; 784*38e8c45fSAndroid Build Coastguard Worker int slot; 785*38e8c45fSAndroid Build Coastguard Worker }; 786*38e8c45fSAndroid Build Coastguard Worker // Batched version of attachBuffer(). 787*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of attachBuffer() calls. 788*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 789*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 790*38e8c45fSAndroid Build Coastguard Worker virtual status_t attachBuffers( 791*38e8c45fSAndroid Build Coastguard Worker const std::vector<sp<GraphicBuffer>>& buffers, 792*38e8c45fSAndroid Build Coastguard Worker std::vector<AttachBufferOutput>* outputs); 793*38e8c45fSAndroid Build Coastguard Worker 794*38e8c45fSAndroid Build Coastguard Worker // Batched version of queueBuffer(). 795*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of queueBuffer() calls. 796*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 797*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 798*38e8c45fSAndroid Build Coastguard Worker // 799*38e8c45fSAndroid Build Coastguard Worker // Note: QueueBufferInput::slot was added to QueueBufferInput to include the 800*38e8c45fSAndroid Build Coastguard Worker // `slot` input argument of the non-batched method queueBuffer(). 801*38e8c45fSAndroid Build Coastguard Worker virtual status_t queueBuffers(const std::vector<QueueBufferInput>& inputs, 802*38e8c45fSAndroid Build Coastguard Worker std::vector<QueueBufferOutput>* outputs); 803*38e8c45fSAndroid Build Coastguard Worker 804*38e8c45fSAndroid Build Coastguard Worker struct CancelBufferInput : public Flattenable<CancelBufferInput> { 805*38e8c45fSAndroid Build Coastguard Worker CancelBufferInput() = default; 806*38e8c45fSAndroid Build Coastguard Worker 807*38e8c45fSAndroid Build Coastguard Worker // Flattenable protocol 808*38e8c45fSAndroid Build Coastguard Worker static constexpr size_t minFlattenedSize(); 809*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 810*38e8c45fSAndroid Build Coastguard Worker size_t getFdCount() const; 811*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 812*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 813*38e8c45fSAndroid Build Coastguard Worker 814*38e8c45fSAndroid Build Coastguard Worker int slot; 815*38e8c45fSAndroid Build Coastguard Worker sp<Fence> fence; 816*38e8c45fSAndroid Build Coastguard Worker }; 817*38e8c45fSAndroid Build Coastguard Worker // Batched version of cancelBuffer(). 818*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of cancelBuffer() calls. 819*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 820*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 821*38e8c45fSAndroid Build Coastguard Worker virtual status_t cancelBuffers( 822*38e8c45fSAndroid Build Coastguard Worker const std::vector<CancelBufferInput>& inputs, 823*38e8c45fSAndroid Build Coastguard Worker std::vector<status_t>* results); 824*38e8c45fSAndroid Build Coastguard Worker 825*38e8c45fSAndroid Build Coastguard Worker struct QueryOutput : public LightFlattenable<QueryOutput> { 826*38e8c45fSAndroid Build Coastguard Worker QueryOutput() = default; 827*38e8c45fSAndroid Build Coastguard Worker 828*38e8c45fSAndroid Build Coastguard Worker // LightFlattenable protocol isFixedSizeQueryOutput829*38e8c45fSAndroid Build Coastguard Worker inline bool isFixedSize() const { return true; } 830*38e8c45fSAndroid Build Coastguard Worker size_t getFlattenedSize() const; 831*38e8c45fSAndroid Build Coastguard Worker status_t flatten(void* buffer, size_t size) const; 832*38e8c45fSAndroid Build Coastguard Worker status_t unflatten(void const* buffer, size_t size); 833*38e8c45fSAndroid Build Coastguard Worker 834*38e8c45fSAndroid Build Coastguard Worker status_t result; 835*38e8c45fSAndroid Build Coastguard Worker int64_t value; 836*38e8c45fSAndroid Build Coastguard Worker }; 837*38e8c45fSAndroid Build Coastguard Worker // Batched version of query(). 838*38e8c45fSAndroid Build Coastguard Worker // This method behaves like a sequence of query() calls. 839*38e8c45fSAndroid Build Coastguard Worker // The return value of the batched method will only be about the 840*38e8c45fSAndroid Build Coastguard Worker // transaction. For a local call, the return value will always be NO_ERROR. 841*38e8c45fSAndroid Build Coastguard Worker virtual status_t query(const std::vector<int32_t> inputs, 842*38e8c45fSAndroid Build Coastguard Worker std::vector<QueryOutput>* outputs); 843*38e8c45fSAndroid Build Coastguard Worker 844*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER 845*38e8c45fSAndroid Build Coastguard Worker // Static method exports any IGraphicBufferProducer object to a parcel. It 846*38e8c45fSAndroid Build Coastguard Worker // handles null producer as well. 847*38e8c45fSAndroid Build Coastguard Worker static status_t exportToParcel(const sp<IGraphicBufferProducer>& producer, 848*38e8c45fSAndroid Build Coastguard Worker Parcel* parcel); 849*38e8c45fSAndroid Build Coastguard Worker 850*38e8c45fSAndroid Build Coastguard Worker // Factory method that creates a new IBGP instance from the parcel. 851*38e8c45fSAndroid Build Coastguard Worker static sp<IGraphicBufferProducer> createFromParcel(const Parcel* parcel); 852*38e8c45fSAndroid Build Coastguard Worker 853*38e8c45fSAndroid Build Coastguard Worker protected: 854*38e8c45fSAndroid Build Coastguard Worker // Exports the current producer as a binder parcelable object. Note that the 855*38e8c45fSAndroid Build Coastguard Worker // producer must be disconnected to be exportable. After successful export, 856*38e8c45fSAndroid Build Coastguard Worker // the producer queue can no longer be connected again. Returns NO_ERROR 857*38e8c45fSAndroid Build Coastguard Worker // when the export is successful and writes an implementation defined 858*38e8c45fSAndroid Build Coastguard Worker // parcelable object into the parcel. For traditional Android BufferQueue, 859*38e8c45fSAndroid Build Coastguard Worker // it writes a strong binder object; for BufferHub, it writes a 860*38e8c45fSAndroid Build Coastguard Worker // ProducerQueueParcelable object. 861*38e8c45fSAndroid Build Coastguard Worker virtual status_t exportToParcel(Parcel* parcel); 862*38e8c45fSAndroid Build Coastguard Worker #endif 863*38e8c45fSAndroid Build Coastguard Worker }; 864*38e8c45fSAndroid Build Coastguard Worker 865*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------- 866*38e8c45fSAndroid Build Coastguard Worker #ifndef NO_BINDER 867*38e8c45fSAndroid Build Coastguard Worker class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer> 868*38e8c45fSAndroid Build Coastguard Worker { 869*38e8c45fSAndroid Build Coastguard Worker public: 870*38e8c45fSAndroid Build Coastguard Worker virtual status_t onTransact( uint32_t code, 871*38e8c45fSAndroid Build Coastguard Worker const Parcel& data, 872*38e8c45fSAndroid Build Coastguard Worker Parcel* reply, 873*38e8c45fSAndroid Build Coastguard Worker uint32_t flags = 0); 874*38e8c45fSAndroid Build Coastguard Worker }; 875*38e8c45fSAndroid Build Coastguard Worker #else 876*38e8c45fSAndroid Build Coastguard Worker class BnGraphicBufferProducer : public IGraphicBufferProducer { 877*38e8c45fSAndroid Build Coastguard Worker }; 878*38e8c45fSAndroid Build Coastguard Worker #endif 879*38e8c45fSAndroid Build Coastguard Worker 880*38e8c45fSAndroid Build Coastguard Worker // ---------------------------------------------------------------------------- 881*38e8c45fSAndroid Build Coastguard Worker } // namespace android 882*38e8c45fSAndroid Build Coastguard Worker 883*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H 884