blob: 0965f5277212164f803b7e05b7a1ecfaa2d6b057 [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
40 status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override;
41
42 status_t importBuffer(const hardware::hidl_handle& rawHandle,
43 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
82 std::string dumpDebugInfo() const override;
83
84 status_t allocate(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
85 uint64_t usage, uint32_t bufferCount, uint32_t* outStride,
86 buffer_handle_t* outBufferHandles) const override;
87
88private:
89 const Gralloc3Mapper& mMapper;
90 sp<hardware::graphics::allocator::V3_0::IAllocator> mAllocator;
91};
92
93} // namespace android
94
95#endif // ANDROID_UI_GRALLOC3_H