blob: 7367549964aec0a4629f2120e3cc1c9ede7997bf [file] [log] [blame]
Marissa Wall925bf7f2018-12-29 14:27:11 -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_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
30namespace android {
31
32class Gralloc3Mapper : public GrallocMapper {
33public:
34 static void preload();
35
36 Gralloc3Mapper();
37
Valerie Hau250c6542019-01-31 14:23:43 -080038 bool isLoaded() const override;
Marissa Wall925bf7f2018-12-29 14:27:11 -080039
John Reck0ff95c92022-12-08 11:45:29 -050040 status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const;
Marissa Wall925bf7f2018-12-29 14:27:11 -080041
John Reck0ff95c92022-12-08 11:45:29 -050042 status_t importBuffer(const native_handle_t* rawHandle,
Marissa Wall925bf7f2018-12-29 14:27:11 -080043 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 Hau0c9fc362019-01-22 09:17:19 -080055 int acquireFence, void** outData, int32_t* outBytesPerPixel,
56 int32_t* outBytesPerStride) const override;
Marissa Wall925bf7f2018-12-29 14:27:11 -080057
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 Hauddbfaeb2019-02-01 09:54:20 -080063 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 Wall925bf7f2018-12-29 14:27:11 -080066private:
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
74class Gralloc3Allocator : public GrallocAllocator {
75public:
76 // An allocator relies on a mapper, and that mapper must be alive at all
77 // time.
78 Gralloc3Allocator(const Gralloc3Mapper& mapper);
79
Valerie Hau250c6542019-01-31 14:23:43 -080080 bool isLoaded() const override;
Marissa Wall925bf7f2018-12-29 14:27:11 -080081
Marissa Wall22b2de12019-12-02 18:11:43 -080082 std::string dumpDebugInfo(bool less = true) const override;
Marissa Wall925bf7f2018-12-29 14:27:11 -080083
Marissa Wall22b2de12019-12-02 18:11:43 -080084 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 Wall925bf7f2018-12-29 14:27:11 -080088
89private:
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