blob: 23b78ed8271fac75807912639abf9b8c06d1df7b [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;
30using hardware::graphics::allocator::V2_0::PixelFormat;
31using hardware::graphics::allocator::V2_0::ProducerUsage;
32using hardware::graphics::allocator::V2_0::ConsumerUsage;
33using hardware::graphics::allocator::V2_0::BufferDescriptor;
34using hardware::graphics::allocator::V2_0::Buffer;
35using hardware::graphics::allocator::V2_0::IAllocator;
36
37// Allocator is a wrapper to IAllocator, a proxy to server-side allocator.
38class Allocator {
39public:
40 Allocator();
41
42 // this will be removed and Allocator will be always valid
43 bool valid() const { return (mService != nullptr); }
44
45 std::string dumpDebugInfo() const;
46
47 Error createBufferDescriptor(
48 const IAllocator::BufferDescriptorInfo& descriptorInfo,
49 BufferDescriptor& descriptor) const;
50 void destroyBufferDescriptor(BufferDescriptor descriptor) const;
51
52 Error allocate(BufferDescriptor descriptor, Buffer& buffer) const;
53 void free(Buffer buffer) const;
54
55 Error exportHandle(BufferDescriptor descriptor, Buffer buffer,
56 native_handle_t*& bufferHandle) const;
57
58private:
59 sp<IAllocator> mService;
60};
61
62} // namespace Gralloc2
63
64} // namespace android
65
66#endif // ANDROID_UI_GRALLOC_ALLOCATOR_H