1 /* 2 * Copyright (C) 2016 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_ALLOCATOR_GRALLOC_H_ 18 #define STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_ 19 20 #include <functional> 21 22 #include <C2Buffer.h> 23 24 namespace android { 25 26 /** 27 * Unwrap the native handle from a Codec2 handle allocated by C2AllocatorGralloc. 28 * 29 * @param handle a handle allocated by C2AllocatorGralloc. This includes handles returned for a 30 * graphic block allocation handle returned. 31 * 32 * @return a new NON-OWNING native handle that must be deleted using native_handle_delete. 33 */ 34 native_handle_t *UnwrapNativeCodec2GrallocHandle(const C2Handle *const handle); 35 36 /** 37 * Wrap the gralloc handle and metadata into Codec2 handle recognized by 38 * C2AllocatorGralloc. 39 * 40 * @return a new NON-OWNING C2Handle that must be deleted using native_handle_delete. 41 */ 42 C2Handle *WrapNativeCodec2GrallocHandle( 43 const native_handle_t *const handle, 44 uint32_t width, uint32_t height, uint32_t format, uint64_t usage, uint32_t stride, 45 uint32_t generation = 0, uint64_t igbp_id = 0, uint32_t igbp_slot = 0); 46 47 /** 48 * When the gralloc handle is migrated to another bufferqueue, update 49 * bufferqueue information. 50 * 51 * @return {@code true} when native_handle is a wrapped codec2 handle. 52 */ 53 bool MigrateNativeCodec2GrallocHandle( 54 native_handle_t *handle, 55 uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot); 56 57 /** 58 * \todo Get this from the buffer 59 */ 60 void _UnwrapNativeCodec2GrallocMetadata( 61 const C2Handle *const handle, 62 uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride, 63 uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot); 64 65 class C2AllocatorGralloc : public C2Allocator { 66 public: 67 virtual id_t getId() const override; 68 69 virtual C2String getName() const override; 70 71 virtual std::shared_ptr<const Traits> getTraits() const override; 72 73 virtual c2_status_t newGraphicAllocation( 74 uint32_t width, uint32_t height, uint32_t format, C2MemoryUsage usage, 75 std::shared_ptr<C2GraphicAllocation> *allocation) override; 76 77 virtual c2_status_t priorGraphicAllocation( 78 const C2Handle *handle, 79 std::shared_ptr<C2GraphicAllocation> *allocation) override; 80 81 C2AllocatorGralloc(id_t id, bool bufferQueue = false); 82 83 c2_status_t status() const; 84 85 virtual ~C2AllocatorGralloc() override; 86 87 static bool isValid(const C2Handle* const o); 88 89 private: 90 class Impl; 91 Impl *mImpl; 92 }; 93 94 } // namespace android 95 96 #endif // STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_ 97