xref: /aosp_15_r20/external/minigbm/cros_gralloc/cros_gralloc_helpers.h (revision d95af8df99a05bcb8679a54dc3ab8e5cd312b38e)
1 /*
2  * Copyright 2016 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #ifndef CROS_GRALLOC_HELPERS_H
8 #define CROS_GRALLOC_HELPERS_H
9 
10 #include "../drv.h"
11 #include "cros_gralloc_handle.h"
12 
13 #include <aidl/android/hardware/graphics/common/BlendMode.h>
14 #include <aidl/android/hardware/graphics/common/Dataspace.h>
15 #include <log/log.h>
16 #include <system/graphics.h>
17 #include <system/window.h>
18 
19 #include <string>
20 
21 // Reserve the GRALLOC_USAGE_PRIVATE_0 bit from hardware/gralloc.h for buffers
22 // used for front rendering. minigbm backend later decides to use
23 // BO_USE_FRONT_RENDERING or BO_USE_LINEAR upon buffer allocaton.
24 #define BUFFER_USAGE_FRONT_RENDERING_PRIVATE (1U << 28)
25 
26 // Adopt BufferUsage::FRONT_BUFFER from api level 33
27 #define BUFFER_USAGE_FRONT_RENDERING (1ULL << 32)
28 
29 #define BUFFER_USAGE_FRONT_RENDERING_MASK                                                          \
30 	(BUFFER_USAGE_FRONT_RENDERING | BUFFER_USAGE_FRONT_RENDERING_PRIVATE)
31 
32 #define CROS_GRALLOC_BUFFER_METADATA_MAX_NAME_SIZE 1024
33 
34 struct cros_gralloc_buffer_descriptor {
35 	uint32_t width;
36 	uint32_t height;
37 	int32_t droid_format;
38 	int64_t droid_usage;
39 	uint32_t drm_format;
40 	uint64_t use_flags;
41 	// If true, allocate an additional shared memory region for buffer metadata.
42 	bool enable_metadata_fd = false;
43 	// If the additional shared memory region for buffer metadata is present, the
44 	// additional amount of space reserved for client use.
45 	uint64_t client_metadata_size = 0;
46 	std::string name;
47 	aidl::android::hardware::graphics::common::Dataspace dataspace =
48 	    aidl::android::hardware::graphics::common::Dataspace::UNKNOWN;
49 	aidl::android::hardware::graphics::common::BlendMode blend =
50 	    aidl::android::hardware::graphics::common::BlendMode::INVALID;
51 };
52 
53 constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA;
54 constexpr uint32_t handle_data_size =
55     ((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int));
56 
57 uint32_t cros_gralloc_convert_format(int32_t format);
58 
59 uint64_t cros_gralloc_convert_usage(uint64_t usage);
60 
61 uint32_t cros_gralloc_convert_map_usage(uint64_t usage);
62 
63 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle);
64 
65 int32_t cros_gralloc_sync_wait(int32_t fence, bool close_fence);
66 
67 std::string get_drm_format_string(uint32_t drm_format);
68 
69 #endif
70