blob: 92bf04306415f686821a6fe9f6465259a837a3de [file] [log] [blame]
Marissa Walld380e2c2018-12-29 14:17:29 -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_H
18#define ANDROID_UI_GRALLOC_H
19
20#include <string>
21
22#include <hidl/HidlSupport.h>
23#include <ui/PixelFormat.h>
24#include <ui/Rect.h>
25#include <utils/StrongPointer.h>
26
27namespace android {
28
29// A wrapper to IMapper
30class GrallocMapper {
31public:
32 virtual ~GrallocMapper();
33
Marissa Wall925bf7f2018-12-29 14:27:11 -080034 virtual bool isSupported() const = 0;
35
Marissa Walld380e2c2018-12-29 14:17:29 -080036 virtual status_t createDescriptor(void* bufferDescriptorInfo,
37 void* outBufferDescriptor) const = 0;
38
39 // Import a buffer that is from another HAL, another process, or is
40 // cloned.
41 //
42 // The returned handle must be freed with freeBuffer.
43 virtual status_t importBuffer(const hardware::hidl_handle& rawHandle,
44 buffer_handle_t* outBufferHandle) const = 0;
45
46 virtual void freeBuffer(buffer_handle_t bufferHandle) const = 0;
47
48 virtual status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width,
49 uint32_t height, android::PixelFormat format,
50 uint32_t layerCount, uint64_t usage,
51 uint32_t stride) const = 0;
52
53 virtual void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds,
54 uint32_t* outNumInts) const = 0;
55
56 // The ownership of acquireFence is always transferred to the callee, even
57 // on errors.
58 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
59 int acquireFence, void** outData) const = 0;
60
61 // The ownership of acquireFence is always transferred to the callee, even
62 // on errors.
63 virtual status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
64 int acquireFence, android_ycbcr* ycbcr) const = 0;
65
66 // unlock returns a fence sync object (or -1) and the fence sync object is
67 // owned by the caller
68 virtual int unlock(buffer_handle_t bufferHandle) const = 0;
69};
70
71// A wrapper to IAllocator
72class GrallocAllocator {
73public:
74 virtual ~GrallocAllocator();
75
Marissa Wall925bf7f2018-12-29 14:27:11 -080076 virtual bool isSupported() const = 0;
77
Marissa Walld380e2c2018-12-29 14:17:29 -080078 virtual std::string dumpDebugInfo() const = 0;
79
80 /*
81 * The returned buffers are already imported and must not be imported
82 * again. outBufferHandles must point to a space that can contain at
83 * least "bufferCount" buffer_handle_t.
84 */
85 virtual status_t allocate(uint32_t width, uint32_t height, PixelFormat format,
86 uint32_t layerCount, uint64_t usage, uint32_t bufferCount,
87 uint32_t* outStride, buffer_handle_t* outBufferHandles) const = 0;
88};
89
90} // namespace android
91
92#endif // ANDROID_UI_GRALLOC_H