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 #include <optional> 12 13 #include <aidl/android/hardware/graphics/common/BlendMode.h> 14 #include <aidl/android/hardware/graphics/common/Cta861_3.h> 15 #include <aidl/android/hardware/graphics/common/Dataspace.h> 16 #include <aidl/android/hardware/graphics/common/Smpte2086.h> 17 18 #include "cros_gralloc_helpers.h" 19 20 class cros_gralloc_buffer 21 { 22 public: 23 static std::unique_ptr<cros_gralloc_buffer> 24 create(struct bo *acquire_bo, const struct cros_gralloc_handle *borrowed_handle); 25 26 ~cros_gralloc_buffer(); 27 28 int32_t initialize_metadata(const struct cros_gralloc_buffer_descriptor *descriptor); 29 30 uint32_t get_id() const; 31 uint32_t get_width() const; 32 uint32_t get_pixel_stride() const; 33 uint32_t get_height() const; 34 uint32_t get_format() const; 35 uint64_t get_format_modifier() const; 36 uint64_t get_total_size() const; 37 uint32_t get_num_planes() const; 38 uint32_t get_plane_offset(uint32_t plane) const; 39 uint32_t get_plane_stride(uint32_t plane) const; 40 uint32_t get_plane_size(uint32_t plane) const; 41 int32_t get_android_format() const; 42 int64_t get_android_usage() const; 43 44 int32_t get_name(std::optional<std::string> *name) const; 45 46 int32_t get_blend_mode( 47 std::optional<aidl::android::hardware::graphics::common::BlendMode> *blend_mode) const; 48 int32_t set_blend_mode(aidl::android::hardware::graphics::common::BlendMode blend_mode); 49 50 int32_t get_dataspace( 51 std::optional<aidl::android::hardware::graphics::common::Dataspace> *dataspace) const; 52 int32_t set_dataspace(aidl::android::hardware::graphics::common::Dataspace dataspace); 53 54 int32_t 55 get_cta861_3(std::optional<aidl::android::hardware::graphics::common::Cta861_3> *cta) const; 56 int32_t 57 set_cta861_3(std::optional<aidl::android::hardware::graphics::common::Cta861_3> cta); 58 59 int32_t get_smpte2086( 60 std::optional<aidl::android::hardware::graphics::common::Smpte2086> *smpte) const; 61 int32_t 62 set_smpte2086(std::optional<aidl::android::hardware::graphics::common::Smpte2086> smpte); 63 64 /* The new reference count is returned by both these functions. */ 65 int32_t increase_refcount(); 66 int32_t decrease_refcount(); 67 68 int32_t lock(const struct rectangle *rect, uint32_t map_flags, 69 uint8_t *addr[DRV_MAX_PLANES]); 70 int32_t unlock(); 71 int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES], 72 uint64_t *format_modifier); 73 74 int32_t invalidate(); 75 int32_t flush(); 76 77 int32_t get_client_reserved_region(void **client_reserved_region_addr, 78 uint64_t *client_reserved_region_size) const; 79 80 private: 81 cros_gralloc_buffer(struct bo *acquire_bo, struct cros_gralloc_handle *acquire_handle); 82 83 cros_gralloc_buffer(cros_gralloc_buffer const &); 84 cros_gralloc_buffer operator=(cros_gralloc_buffer const &); 85 86 int32_t get_reserved_region(void **reserved_region_addr, 87 uint64_t *reserved_region_size) const; 88 89 int32_t get_metadata(struct cros_gralloc_buffer_metadata **metadata); 90 int32_t get_metadata(const struct cros_gralloc_buffer_metadata **metadata) const; 91 92 struct bo *bo_; 93 94 /* Note: this will be nullptr for imported/retained buffers. */ 95 struct cros_gralloc_handle *hnd_; 96 97 int32_t refcount_ = 1; 98 int32_t lockcount_ = 0; 99 100 struct mapping *lock_data_[DRV_MAX_PLANES]; 101 102 /* Optional additional shared memory region attached to some gralloc buffers. */ 103 mutable void *reserved_region_addr_ = nullptr; 104 }; 105 106 #endif 107