• 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 "../drv.h"
11 #include "cros_gralloc_helpers.h"
12 
13 class cros_gralloc_buffer
14 {
15       public:
16 	cros_gralloc_buffer(uint32_t id, struct bo *acquire_bo,
17 			    struct cros_gralloc_handle *acquire_handle, int32_t reserved_region_fd,
18 			    uint64_t reserved_region_size);
19 	~cros_gralloc_buffer();
20 
21 	uint32_t get_id() const;
22 
23 	/* The new reference count is returned by both these functions. */
24 	int32_t increase_refcount();
25 	int32_t decrease_refcount();
26 
27 	int32_t lock(const struct rectangle *rect, uint32_t map_flags,
28 		     uint8_t *addr[DRV_MAX_PLANES]);
29 	int32_t unlock();
30 	int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES],
31 			      uint64_t *format_modifier);
32 
33 	int32_t invalidate();
34 	int32_t flush();
35 
36 	int32_t get_reserved_region(void **reserved_region_addr, uint64_t *reserved_region_size);
37 
38       private:
39 	cros_gralloc_buffer(cros_gralloc_buffer const &);
40 	cros_gralloc_buffer operator=(cros_gralloc_buffer const &);
41 
42 	uint32_t id_;
43 	struct bo *bo_;
44 
45 	/* Note: this will be nullptr for imported/retained buffers. */
46 	struct cros_gralloc_handle *hnd_;
47 
48 	int32_t refcount_;
49 	int32_t lockcount_;
50 	uint32_t num_planes_;
51 
52 	struct mapping *lock_data_[DRV_MAX_PLANES];
53 
54 	/* Optional additional shared memory region attached to some gralloc buffers. */
55 	int32_t reserved_region_fd_;
56 	uint64_t reserved_region_size_;
57 	void *reserved_region_addr_;
58 };
59 
60 #endif
61