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 <log/log.h> 14 #include <system/graphics.h> 15 #include <system/window.h> 16 17 #include <string> 18 19 // Reserve the GRALLOC_USAGE_PRIVATE_0 bit from hardware/gralloc.h for buffers 20 // used for front rendering. minigbm backend later decides to use 21 // BO_USE_FRONT_RENDERING or BO_USE_LINEAR upon buffer allocaton. 22 #define BUFFER_USAGE_FRONT_RENDERING (1U << 28) 23 24 // Adopt BufferUsage::FRONT_BUFFER from api level 33 25 #define BUFFER_USAGE_FRONT_RENDERING_MASK (BUFFER_USAGE_FRONT_RENDERING | (1ULL << 32)) 26 27 struct cros_gralloc_buffer_descriptor { 28 uint32_t width; 29 uint32_t height; 30 int32_t droid_format; 31 int32_t droid_usage; 32 uint32_t drm_format; 33 uint64_t use_flags; 34 uint64_t reserved_region_size; 35 std::string name; 36 }; 37 38 constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA; 39 constexpr uint32_t handle_data_size = 40 ((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int)); 41 42 uint32_t cros_gralloc_convert_format(int32_t format); 43 44 uint64_t cros_gralloc_convert_usage(uint64_t usage); 45 46 uint32_t cros_gralloc_convert_map_usage(uint64_t usage); 47 48 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle); 49 50 int32_t cros_gralloc_sync_wait(int32_t fence, bool close_fence); 51 52 std::string get_drm_format_string(uint32_t drm_format); 53 54 #endif 55