1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 18 #define CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 19 20 #include <gui/IGraphicBufferProducer.h> 21 #include <codec2/hidl/1.0/types.h> 22 #include <codec2/hidl/1.2/types.h> 23 #include <C2Work.h> 24 25 struct C2_HIDE _C2BlockPoolData; 26 class C2SurfaceSyncMemory; 27 28 namespace android { 29 namespace hardware { 30 namespace media { 31 namespace c2 { 32 33 34 // BufferQueue-Based Block Operations 35 // ================================== 36 37 // Manage BufferQueue and graphic blocks for both component and codec. 38 // Manage graphic blocks ownership consistently during surface change. 39 struct OutputBufferQueue { 40 41 OutputBufferQueue(); 42 43 ~OutputBufferQueue(); 44 45 // Configure a new surface to render graphic blocks. 46 // Graphic blocks from older surface will be migrated to new surface. 47 bool configure(const sp<IGraphicBufferProducer>& igbp, 48 uint32_t generation, 49 uint64_t bqId, 50 int maxDequeueBufferCount, 51 std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj); 52 53 // Render a graphic block to current surface. 54 status_t outputBuffer( 55 const C2ConstGraphicBlock& block, 56 const BnGraphicBufferProducer::QueueBufferInput& input, 57 BnGraphicBufferProducer::QueueBufferOutput* output); 58 59 // Call holdBufferQueueBlock() on output blocks in the given workList. 60 // The OutputBufferQueue will take the ownership of output blocks. 61 // 62 // Note: This function should be called after WorkBundle has been received 63 // from another process. 64 void holdBufferQueueBlocks( 65 const std::list<std::unique_ptr<C2Work>>& workList); 66 67 // Update # of max dequeue buffer from BQ. If # of max dequeued buffer is shared 68 // via shared memory between HAL and framework, Update # of max dequeued buffer 69 // and synchronize. 70 void updateMaxDequeueBufferCount(int maxDequeueBufferCount); 71 72 private: 73 74 std::mutex mMutex; 75 sp<IGraphicBufferProducer> mIgbp; 76 uint32_t mGeneration; 77 uint64_t mBqId; 78 int32_t mMaxDequeueBufferCount; 79 std::shared_ptr<int> mOwner; 80 // To migrate existing buffers 81 sp<GraphicBuffer> mBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; // find a better way 82 std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; 83 std::shared_ptr<C2SurfaceSyncMemory> mSyncMem; 84 85 bool registerBuffer(const C2ConstGraphicBlock& block); 86 }; 87 88 } // namespace c2 89 } // namespace media 90 } // namespace hardware 91 } // namespace android 92 93 #endif // CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 94