1 /* 2 * Copyright 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 ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H 18 #define ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H 19 20 #include <android/hardware/graphics/allocator/2.0/IAllocator.h> 21 #include <android/hardware/graphics/mapper/2.0/IMapper.h> 22 #include <hardware/gralloc1.h> 23 24 namespace android { 25 namespace hardware { 26 namespace graphics { 27 namespace allocator { 28 namespace V2_0 { 29 namespace implementation { 30 31 using android::hardware::graphics::mapper::V2_0::IMapper; 32 using android::hardware::graphics::mapper::V2_0::BufferDescriptor; 33 using android::hardware::graphics::mapper::V2_0::Error; 34 35 class Gralloc1Allocator : public IAllocator { 36 public: 37 Gralloc1Allocator(const hw_module_t* module); 38 virtual ~Gralloc1Allocator(); 39 40 // IAllocator interface 41 Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override; 42 Return<void> allocate(const BufferDescriptor& descriptor, uint32_t count, 43 allocate_cb hidl_cb) override; 44 45 private: 46 void initCapabilities(); 47 48 template <typename T> 49 void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn); 50 void initDispatch(); 51 52 static Error toError(int32_t error); 53 static uint64_t toProducerUsage(uint64_t usage); 54 static uint64_t toConsumerUsage(uint64_t usage); 55 56 Error createDescriptor(const IMapper::BufferDescriptorInfo& info, 57 gralloc1_buffer_descriptor_t* outDescriptor); 58 Error allocateOne(gralloc1_buffer_descriptor_t descriptor, 59 buffer_handle_t* outBuffer, uint32_t* outStride); 60 61 gralloc1_device_t* mDevice; 62 63 struct { 64 bool layeredBuffers; 65 } mCapabilities; 66 67 struct { 68 GRALLOC1_PFN_DUMP dump; 69 GRALLOC1_PFN_CREATE_DESCRIPTOR createDescriptor; 70 GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor; 71 GRALLOC1_PFN_SET_DIMENSIONS setDimensions; 72 GRALLOC1_PFN_SET_FORMAT setFormat; 73 GRALLOC1_PFN_SET_LAYER_COUNT setLayerCount; 74 GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage; 75 GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage; 76 GRALLOC1_PFN_GET_STRIDE getStride; 77 GRALLOC1_PFN_ALLOCATE allocate; 78 GRALLOC1_PFN_RELEASE release; 79 } mDispatch; 80 }; 81 82 } // namespace implementation 83 } // namespace V2_0 84 } // namespace allocator 85 } // namespace graphics 86 } // namespace hardware 87 } // namespace android 88 89 #endif // ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H 90