Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +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_GRALLOC_ALLOCATOR_H |
| 18 | #define ANDROID_UI_GRALLOC_ALLOCATOR_H |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include <android/hardware/graphics/allocator/2.0/IAllocator.h> |
| 23 | #include <utils/StrongPointer.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | namespace Gralloc2 { |
| 28 | |
| 29 | using hardware::graphics::allocator::V2_0::Error; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 30 | using hardware::graphics::allocator::V2_0::ProducerUsage; |
| 31 | using hardware::graphics::allocator::V2_0::ConsumerUsage; |
| 32 | using hardware::graphics::allocator::V2_0::BufferDescriptor; |
| 33 | using hardware::graphics::allocator::V2_0::Buffer; |
| 34 | using hardware::graphics::allocator::V2_0::IAllocator; |
Chia-I Wu | b018bf0 | 2016-11-22 13:29:49 +0800 | [diff] [blame] | 35 | using hardware::graphics::allocator::V2_0::IAllocatorClient; |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 36 | using hardware::graphics::common::V1_0::PixelFormat; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 37 | |
| 38 | // Allocator is a wrapper to IAllocator, a proxy to server-side allocator. |
| 39 | class Allocator { |
| 40 | public: |
| 41 | Allocator(); |
| 42 | |
| 43 | // this will be removed and Allocator will be always valid |
Chia-I Wu | b018bf0 | 2016-11-22 13:29:49 +0800 | [diff] [blame] | 44 | bool valid() const { return (mAllocator != nullptr); } |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 45 | |
| 46 | std::string dumpDebugInfo() const; |
| 47 | |
| 48 | Error createBufferDescriptor( |
Chia-I Wu | b018bf0 | 2016-11-22 13:29:49 +0800 | [diff] [blame] | 49 | const IAllocatorClient::BufferDescriptorInfo& descriptorInfo, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 50 | BufferDescriptor* outDescriptor) const; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 51 | void destroyBufferDescriptor(BufferDescriptor descriptor) const; |
| 52 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 53 | Error allocate(BufferDescriptor descriptor, Buffer* outBuffer) const; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 54 | void free(Buffer buffer) const; |
| 55 | |
| 56 | Error exportHandle(BufferDescriptor descriptor, Buffer buffer, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 57 | native_handle_t** outBufferHandle) const; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 58 | |
| 59 | private: |
Chia-I Wu | b018bf0 | 2016-11-22 13:29:49 +0800 | [diff] [blame] | 60 | sp<IAllocator> mAllocator; |
| 61 | sp<IAllocatorClient> mClient; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // namespace Gralloc2 |
| 65 | |
| 66 | } // namespace android |
| 67 | |
| 68 | #endif // ANDROID_UI_GRALLOC_ALLOCATOR_H |