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 * \todo Get this from the buffer 49 */ 50 void _UnwrapNativeCodec2GrallocMetadata( 51 const C2Handle *const handle, 52 uint32_t *width, uint32_t *height, uint32_t *format, uint64_t *usage, uint32_t *stride, 53 uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot); 54 55 class C2AllocatorGralloc : public C2Allocator { 56 public: 57 virtual id_t getId() const override; 58 59 virtual C2String getName() const override; 60 61 virtual std::shared_ptr<const Traits> getTraits() const override; 62 63 virtual c2_status_t newGraphicAllocation( 64 uint32_t width, uint32_t height, uint32_t format, C2MemoryUsage usage, 65 std::shared_ptr<C2GraphicAllocation> *allocation) override; 66 67 virtual c2_status_t priorGraphicAllocation( 68 const C2Handle *handle, 69 std::shared_ptr<C2GraphicAllocation> *allocation) override; 70 71 C2AllocatorGralloc(id_t id, bool bufferQueue = false); 72 73 c2_status_t status() const; 74 75 virtual ~C2AllocatorGralloc() override; 76 77 static bool isValid(const C2Handle* const o); 78 79 private: 80 class Impl; 81 Impl *mImpl; 82 }; 83 84 } // namespace android 85 86 #endif // STAGEFRIGHT_CODEC2_ALLOCATOR_GRALLOC_H_ 87