| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 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_GRALLOC3_H |
| 18 | #define ANDROID_UI_GRALLOC3_H |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include <android/hardware/graphics/allocator/3.0/IAllocator.h> |
| 23 | #include <android/hardware/graphics/common/1.1/types.h> |
| 24 | #include <android/hardware/graphics/mapper/3.0/IMapper.h> |
| 25 | #include <ui/Gralloc.h> |
| 26 | #include <ui/PixelFormat.h> |
| 27 | #include <ui/Rect.h> |
| 28 | #include <utils/StrongPointer.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class Gralloc3Mapper : public GrallocMapper { |
| 33 | public: |
| 34 | static void preload(); |
| 35 | |
| 36 | Gralloc3Mapper(); |
| 37 | |
| Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 38 | bool isLoaded() const override; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 39 | |
| John Reck | 0ff95c9 | 2022-12-08 11:45:29 -0500 | [diff] [blame] | 40 | status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 41 | |
| John Reck | 0ff95c9 | 2022-12-08 11:45:29 -0500 | [diff] [blame] | 42 | status_t importBuffer(const native_handle_t* rawHandle, |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 43 | buffer_handle_t* outBufferHandle) const override; |
| 44 | |
| 45 | void freeBuffer(buffer_handle_t bufferHandle) const override; |
| 46 | |
| 47 | status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, uint32_t height, |
| 48 | android::PixelFormat format, uint32_t layerCount, uint64_t usage, |
| 49 | uint32_t stride) const override; |
| 50 | |
| 51 | void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds, |
| 52 | uint32_t* outNumInts) const override; |
| 53 | |
| 54 | status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, |
| Valerie Hau | 0c9fc36 | 2019-01-22 09:17:19 -0800 | [diff] [blame] | 55 | int acquireFence, void** outData, int32_t* outBytesPerPixel, |
| 56 | int32_t* outBytesPerStride) const override; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 57 | |
| 58 | status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, |
| 59 | int acquireFence, android_ycbcr* ycbcr) const override; |
| 60 | |
| 61 | int unlock(buffer_handle_t bufferHandle) const override; |
| 62 | |
| Valerie Hau | ddbfaeb | 2019-02-01 09:54:20 -0800 | [diff] [blame] | 63 | status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format, |
| 64 | uint32_t layerCount, uint64_t usage, bool* outSupported) const override; |
| 65 | |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 66 | private: |
| 67 | // Determines whether the passed info is compatible with the mapper. |
| 68 | status_t validateBufferDescriptorInfo( |
| 69 | hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo* descriptorInfo) const; |
| 70 | |
| 71 | sp<hardware::graphics::mapper::V3_0::IMapper> mMapper; |
| 72 | }; |
| 73 | |
| 74 | class Gralloc3Allocator : public GrallocAllocator { |
| 75 | public: |
| 76 | // An allocator relies on a mapper, and that mapper must be alive at all |
| 77 | // time. |
| 78 | Gralloc3Allocator(const Gralloc3Mapper& mapper); |
| 79 | |
| Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 80 | bool isLoaded() const override; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 81 | |
| Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 82 | std::string dumpDebugInfo(bool less = true) const override; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 83 | |
| Marissa Wall | 22b2de1 | 2019-12-02 18:11:43 -0800 | [diff] [blame] | 84 | status_t allocate(std::string requestorName, uint32_t width, uint32_t height, |
| 85 | PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t bufferCount, |
| 86 | uint32_t* outStride, buffer_handle_t* outBufferHandles, |
| 87 | bool importBuffers = true) const override; |
| Marissa Wall | 925bf7f | 2018-12-29 14:27:11 -0800 | [diff] [blame] | 88 | |
| 89 | private: |
| 90 | const Gralloc3Mapper& mMapper; |
| 91 | sp<hardware::graphics::allocator::V3_0::IAllocator> mAllocator; |
| 92 | }; |
| 93 | |
| 94 | } // namespace android |
| 95 | |
| 96 | #endif // ANDROID_UI_GRALLOC3_H |