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_UI_GRALLOC2_H 18 #define ANDROID_UI_GRALLOC2_H 19 20 #include <string> 21 22 #include <android/hardware/graphics/allocator/2.0/IAllocator.h> 23 #include <android/hardware/graphics/common/1.1/types.h> 24 #include <android/hardware/graphics/mapper/2.0/IMapper.h> 25 #include <android/hardware/graphics/mapper/2.1/IMapper.h> 26 #include <ui/Gralloc.h> 27 #include <ui/PixelFormat.h> 28 #include <ui/Rect.h> 29 #include <utils/StrongPointer.h> 30 31 namespace android { 32 33 class Gralloc2Mapper : public GrallocMapper { 34 public: 35 static void preload(); 36 37 Gralloc2Mapper(); 38 39 bool isLoaded() const override; 40 41 status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override; 42 43 status_t importBuffer(const hardware::hidl_handle& rawHandle, 44 buffer_handle_t* outBufferHandle) const override; 45 46 void freeBuffer(buffer_handle_t bufferHandle) const override; 47 48 status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, uint32_t height, 49 android::PixelFormat format, uint32_t layerCount, uint64_t usage, 50 uint32_t stride) const override; 51 52 void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds, 53 uint32_t* outNumInts) const override; 54 55 status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 56 int acquireFence, void** outData, int32_t* outBytesPerPixel, 57 int32_t* outBytesPerStride) const override; 58 59 status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, 60 int acquireFence, android_ycbcr* ycbcr) const override; 61 62 int unlock(buffer_handle_t bufferHandle) const override; 63 64 private: 65 // Determines whether the passed info is compatible with the mapper. 66 status_t validateBufferDescriptorInfo( 67 hardware::graphics::mapper::V2_1::IMapper::BufferDescriptorInfo* descriptorInfo) const; 68 69 sp<hardware::graphics::mapper::V2_0::IMapper> mMapper; 70 sp<hardware::graphics::mapper::V2_1::IMapper> mMapperV2_1; 71 }; 72 73 class Gralloc2Allocator : public GrallocAllocator { 74 public: 75 // An allocator relies on a mapper, and that mapper must be alive at all 76 // time. 77 Gralloc2Allocator(const Gralloc2Mapper& mapper); 78 79 bool isLoaded() const override; 80 81 std::string dumpDebugInfo(bool less = true) const override; 82 83 status_t allocate(std::string requestorName, uint32_t width, uint32_t height, 84 PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t bufferCount, 85 uint32_t* outStride, buffer_handle_t* outBufferHandles, 86 bool importBuffers = true) const override; 87 88 private: 89 const Gralloc2Mapper& mMapper; 90 sp<hardware::graphics::allocator::V2_0::IAllocator> mAllocator; 91 }; 92 93 } // namespace android 94 95 #endif // ANDROID_UI_GRALLOC2_H 96