blob: dd0f9e04b77ab54ecfdcd5921421ab7a51ad48f2 [file] [log] [blame]
Chia-I Wu9ba189d2016-09-22 17:13:08 +08001/*
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
25namespace android {
26
27namespace Gralloc2 {
28
29using hardware::graphics::allocator::V2_0::Error;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080030using hardware::graphics::allocator::V2_0::ProducerUsage;
31using hardware::graphics::allocator::V2_0::ConsumerUsage;
32using hardware::graphics::allocator::V2_0::BufferDescriptor;
33using hardware::graphics::allocator::V2_0::Buffer;
34using hardware::graphics::allocator::V2_0::IAllocator;
Chia-I Wub018bf02016-11-22 13:29:49 +080035using hardware::graphics::allocator::V2_0::IAllocatorClient;
Chia-I Wu5901fda2016-11-17 10:26:37 +080036using hardware::graphics::common::V1_0::PixelFormat;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080037
38// Allocator is a wrapper to IAllocator, a proxy to server-side allocator.
39class Allocator {
40public:
41 Allocator();
42
43 // this will be removed and Allocator will be always valid
Chia-I Wub018bf02016-11-22 13:29:49 +080044 bool valid() const { return (mAllocator != nullptr); }
Chia-I Wu9ba189d2016-09-22 17:13:08 +080045
46 std::string dumpDebugInfo() const;
47
48 Error createBufferDescriptor(
Chia-I Wub018bf02016-11-22 13:29:49 +080049 const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
Chia-I Wu67e376d2016-12-19 11:36:22 +080050 BufferDescriptor* outDescriptor) const;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080051 void destroyBufferDescriptor(BufferDescriptor descriptor) const;
52
Chia-I Wu67e376d2016-12-19 11:36:22 +080053 Error allocate(BufferDescriptor descriptor, Buffer* outBuffer) const;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080054 void free(Buffer buffer) const;
55
56 Error exportHandle(BufferDescriptor descriptor, Buffer buffer,
Chia-I Wu67e376d2016-12-19 11:36:22 +080057 native_handle_t** outBufferHandle) const;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080058
59private:
Chia-I Wub018bf02016-11-22 13:29:49 +080060 sp<IAllocator> mAllocator;
61 sp<IAllocatorClient> mClient;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080062};
63
64} // namespace Gralloc2
65
66} // namespace android
67
68#endif // ANDROID_UI_GRALLOC_ALLOCATOR_H