• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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_DRIVER_H
8 #define CROS_GRALLOC_DRIVER_H
9 
10 #include "cros_gralloc_buffer.h"
11 
12 #include <functional>
13 #include <mutex>
14 #include <unordered_map>
15 
16 class cros_gralloc_driver
17 {
18       public:
19 	cros_gralloc_driver();
20 	~cros_gralloc_driver();
21 
22 	int32_t init();
23 	bool is_supported(const struct cros_gralloc_buffer_descriptor *descriptor);
24 	int32_t allocate(const struct cros_gralloc_buffer_descriptor *descriptor,
25 			 buffer_handle_t *out_handle);
26 
27 	int32_t retain(buffer_handle_t handle);
28 	int32_t release(buffer_handle_t handle);
29 
30 	int32_t lock(buffer_handle_t handle, int32_t acquire_fence, bool close_acquire_fence,
31 		     const struct rectangle *rect, uint32_t map_flags,
32 		     uint8_t *addr[DRV_MAX_PLANES]);
33 	int32_t unlock(buffer_handle_t handle, int32_t *release_fence);
34 
35 	int32_t invalidate(buffer_handle_t handle);
36 	int32_t flush(buffer_handle_t handle, int32_t *release_fence);
37 
38 	int32_t get_backing_store(buffer_handle_t handle, uint64_t *out_store);
39 	int32_t resource_info(buffer_handle_t handle, uint32_t strides[DRV_MAX_PLANES],
40 			      uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
41 
42 	int32_t get_reserved_region(buffer_handle_t handle, void **reserved_region_addr,
43 				    uint64_t *reserved_region_size);
44 
45 	uint32_t get_resolved_drm_format(uint32_t drm_format, uint64_t usage);
46 
47 	void for_each_handle(const std::function<void(cros_gralloc_handle_t)> &function);
48 
49       private:
50 	cros_gralloc_driver(cros_gralloc_driver const &);
51 	cros_gralloc_driver operator=(cros_gralloc_driver const &);
52 	cros_gralloc_buffer *get_buffer(cros_gralloc_handle_t hnd);
53 	void emplace_buffer(struct bo *bo, struct cros_gralloc_handle *hnd);
54 
55 	struct driver *drv_;
56 	std::mutex mutex_;
57 	std::unordered_map<uint32_t, cros_gralloc_buffer *> buffers_;
58 	std::unordered_map<cros_gralloc_handle_t, std::pair<cros_gralloc_buffer *, int32_t>>
59 	    handles_;
60 };
61 
62 #endif
63