1 /* 2 * Copyright 2016 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_HELPERS_H 8 #define CROS_GRALLOC_HELPERS_H 9 10 #include "../drv.h" 11 #include "cros_gralloc_handle.h" 12 13 #include <aidl/android/hardware/graphics/common/BlendMode.h> 14 #include <aidl/android/hardware/graphics/common/Dataspace.h> 15 #include <log/log.h> 16 #include <system/graphics.h> 17 #include <system/window.h> 18 19 #include <string> 20 21 // Reserve the GRALLOC_USAGE_PRIVATE_0 bit from hardware/gralloc.h for buffers 22 // used for front rendering. minigbm backend later decides to use 23 // BO_USE_FRONT_RENDERING or BO_USE_LINEAR upon buffer allocaton. 24 #define BUFFER_USAGE_FRONT_RENDERING (1U << 28) 25 26 // Adopt BufferUsage::FRONT_BUFFER from api level 33 27 #define BUFFER_USAGE_FRONT_RENDERING_MASK (BUFFER_USAGE_FRONT_RENDERING | (1ULL << 32)) 28 29 #define CROS_GRALLOC_BUFFER_METADATA_MAX_NAME_SIZE 1024 30 31 struct cros_gralloc_buffer_descriptor { 32 uint32_t width; 33 uint32_t height; 34 int32_t droid_format; 35 int64_t droid_usage; 36 uint32_t drm_format; 37 uint64_t use_flags; 38 // If true, allocate an additional shared memory region for buffer metadata. 39 bool enable_metadata_fd = false; 40 // If the additional shared memory region for buffer metadata is present, the 41 // additional amount of space reserved for client use. 42 uint64_t client_metadata_size = 0; 43 std::string name; 44 aidl::android::hardware::graphics::common::Dataspace dataspace = 45 aidl::android::hardware::graphics::common::Dataspace::UNKNOWN; 46 aidl::android::hardware::graphics::common::BlendMode blend = 47 aidl::android::hardware::graphics::common::BlendMode::INVALID; 48 }; 49 50 constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA; 51 constexpr uint32_t handle_data_size = 52 ((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int)); 53 54 uint32_t cros_gralloc_convert_format(int32_t format); 55 56 uint64_t cros_gralloc_convert_usage(uint64_t usage); 57 58 uint32_t cros_gralloc_convert_map_usage(uint64_t usage); 59 60 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle); 61 62 int32_t cros_gralloc_sync_wait(int32_t fence, bool close_fence); 63 64 std::string get_drm_format_string(uint32_t drm_format); 65 66 #endif 67