• 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_BUFFER_H
8 #define CROS_GRALLOC_BUFFER_H
9 
10 #include <memory>
11 
12 #include "cros_gralloc_helpers.h"
13 
14 class cros_gralloc_buffer
15 {
16       public:
17 	static std::unique_ptr<cros_gralloc_buffer>
18 	create(struct bo *acquire_bo, const struct cros_gralloc_handle *borrowed_handle);
19 
20 	~cros_gralloc_buffer();
21 
22 	uint32_t get_id() const;
23 	uint32_t get_width() const;
24 	uint32_t get_pixel_stride() const;
25 	uint32_t get_height() const;
26 	uint32_t get_format() const;
27 	uint64_t get_format_modifier() const;
28 	uint64_t get_total_size() const;
29 	uint32_t get_num_planes() const;
30 	uint32_t get_plane_offset(uint32_t plane) const;
31 	uint32_t get_plane_stride(uint32_t plane) const;
32 	uint32_t get_plane_size(uint32_t plane) const;
33 	int32_t get_android_format() const;
34 	uint64_t get_android_usage() const;
35 
36 	/* The new reference count is returned by both these functions. */
37 	int32_t increase_refcount();
38 	int32_t decrease_refcount();
39 
40 	int32_t lock(const struct rectangle *rect, uint32_t map_flags,
41 		     uint8_t *addr[DRV_MAX_PLANES]);
42 	int32_t unlock();
43 	int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES],
44 			      uint64_t *format_modifier);
45 
46 	int32_t invalidate();
47 	int32_t flush();
48 
49 	int32_t get_reserved_region(void **reserved_region_addr,
50 				    uint64_t *reserved_region_size) const;
51 
52       private:
53 	cros_gralloc_buffer(struct bo *acquire_bo, struct cros_gralloc_handle *acquire_handle);
54 
55 	cros_gralloc_buffer(cros_gralloc_buffer const &);
56 	cros_gralloc_buffer operator=(cros_gralloc_buffer const &);
57 
58 	struct bo *bo_;
59 
60 	/* Note: this will be nullptr for imported/retained buffers. */
61 	struct cros_gralloc_handle *hnd_;
62 
63 	int32_t refcount_ = 1;
64 	int32_t lockcount_ = 0;
65 
66 	struct mapping *lock_data_[DRV_MAX_PLANES];
67 
68 	/* Optional additional shared memory region attached to some gralloc buffers. */
69 	mutable void *reserved_region_addr_ = nullptr;
70 };
71 
72 #endif
73