1 /* 2 * Copyright (C) 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 STAGEFRIGHT_CODEC2_BQ_BUFFER_PRIV_H_ 18 #define STAGEFRIGHT_CODEC2_BQ_BUFFER_PRIV_H_ 19 20 #include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h> 21 22 #include <C2Buffer.h> 23 24 #include <functional> 25 26 class C2BufferQueueBlockPool : public C2BlockPool { 27 public: 28 C2BufferQueueBlockPool(const std::shared_ptr<C2Allocator> &allocator, const local_id_t localId); 29 30 virtual ~C2BufferQueueBlockPool() override; 31 getAllocatorId()32 virtual C2Allocator::id_t getAllocatorId() const override { 33 return mAllocator->getId(); 34 }; 35 getLocalId()36 virtual local_id_t getLocalId() const override { 37 return mLocalId; 38 }; 39 40 virtual c2_status_t fetchGraphicBlock( 41 uint32_t width, 42 uint32_t height, 43 uint32_t format, 44 C2MemoryUsage usage, 45 std::shared_ptr<C2GraphicBlock> *block /* nonnull */) override; 46 47 typedef std::function<void(uint64_t producer, int32_t slot, int64_t nsecs)> OnRenderCallback; 48 49 /** 50 * Sets render callback. 51 * 52 * \param renderCallbak callback to call for all dequeue buffer. 53 */ 54 virtual void setRenderCallback(const OnRenderCallback &renderCallback = OnRenderCallback()); 55 56 typedef ::android::hardware::graphics::bufferqueue::V2_0:: 57 IGraphicBufferProducer HGraphicBufferProducer; 58 /** 59 * Configures an IGBP in order to create blocks. A newly created block is 60 * dequeued from the configured IGBP. Unique Id of IGBP and the slot number of 61 * blocks are passed via native_handle. Managing IGBP is responsibility of caller. 62 * When IGBP is not configured, block will be created via allocator. 63 * Since zero is not used for Unique Id of IGBP, if IGBP is not configured or producer 64 * is configured as nullptr, unique id which is bundled in native_handle is zero. 65 * 66 * \param producer the IGBP, which will be used to fetch blocks 67 */ 68 virtual void configureProducer(const android::sp<HGraphicBufferProducer> &producer); 69 70 private: 71 const std::shared_ptr<C2Allocator> mAllocator; 72 const local_id_t mLocalId; 73 74 class Impl; 75 std::shared_ptr<Impl> mImpl; 76 77 friend struct C2BufferQueueBlockPoolData; 78 }; 79 80 #endif // STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_ 81