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