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_height() const; 25 uint32_t get_format() const; 26 uint64_t get_format_modifier() const; 27 uint64_t get_total_size() const; 28 uint32_t get_num_planes() const; 29 uint32_t get_plane_offset(uint32_t plane) const; 30 uint32_t get_plane_stride(uint32_t plane) const; 31 uint32_t get_plane_size(uint32_t plane) const; 32 int32_t get_android_format() const; 33 uint64_t get_android_usage() const; 34 35 /* The new reference count is returned by both these functions. */ 36 int32_t increase_refcount(); 37 int32_t decrease_refcount(); 38 39 int32_t lock(const struct rectangle *rect, uint32_t map_flags, 40 uint8_t *addr[DRV_MAX_PLANES]); 41 int32_t unlock(); 42 int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES], 43 uint64_t *format_modifier); 44 45 int32_t invalidate(); 46 int32_t flush(); 47 48 int32_t get_reserved_region(void **reserved_region_addr, 49 uint64_t *reserved_region_size) const; 50 51 private: 52 cros_gralloc_buffer(struct bo *acquire_bo, struct cros_gralloc_handle *acquire_handle); 53 54 cros_gralloc_buffer(cros_gralloc_buffer const &); 55 cros_gralloc_buffer operator=(cros_gralloc_buffer const &); 56 57 struct bo *bo_; 58 59 /* Note: this will be nullptr for imported/retained buffers. */ 60 struct cros_gralloc_handle *hnd_; 61 62 int32_t refcount_ = 1; 63 int32_t lockcount_ = 0; 64 65 struct mapping *lock_data_[DRV_MAX_PLANES]; 66 67 /* Optional additional shared memory region attached to some gralloc buffers. */ 68 mutable void *reserved_region_addr_ = nullptr; 69 }; 70 71 #endif 72