Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 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 | |
Gurchetan Singh | c67f9e4 | 2016-11-28 15:25:26 -0800 | [diff] [blame] | 10 | #include "../drv.h" |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 11 | #include "cros_gralloc_handle.h" |
| 12 | |
| 13 | #include <hardware/gralloc.h> |
| 14 | #include <system/graphics.h> |
| 15 | |
| 16 | /* Use these error codes derived from gralloc1 to make transition easier when |
| 17 | * it happens |
| 18 | */ |
| 19 | typedef enum { |
| 20 | CROS_GRALLOC_ERROR_NONE = 0, |
| 21 | CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1, |
| 22 | CROS_GRALLOC_ERROR_BAD_HANDLE = 2, |
| 23 | CROS_GRALLOC_ERROR_BAD_VALUE = 3, |
| 24 | CROS_GRALLOC_ERROR_NOT_SHARED = 4, |
| 25 | CROS_GRALLOC_ERROR_NO_RESOURCES = 5, |
| 26 | CROS_GRALLOC_ERROR_UNDEFINED = 6, |
| 27 | CROS_GRALLOC_ERROR_UNSUPPORTED = 7, |
| 28 | } cros_gralloc_error_t; |
| 29 | |
| 30 | /* This enumeration must match the one in <gralloc_drm.h>. |
| 31 | * The functions supported by this gralloc's temporary private API are listed |
| 32 | * below. Use of these functions is highly discouraged and should only be |
| 33 | * reserved for cases where no alternative to get same information (such as |
| 34 | * querying ANativeWindow) exists. |
| 35 | */ |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 36 | // clang-format off |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 37 | enum { |
| 38 | GRALLOC_DRM_GET_STRIDE, |
| 39 | GRALLOC_DRM_GET_FORMAT, |
| 40 | GRALLOC_DRM_GET_DIMENSIONS, |
| 41 | GRALLOC_DRM_GET_BACKING_STORE, |
| 42 | }; |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 43 | // clang-format on |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 44 | |
Gurchetan Singh | b7538e2 | 2017-03-20 14:45:39 -0700 | [diff] [blame^] | 45 | constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA; |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 46 | |
Gurchetan Singh | b7538e2 | 2017-03-20 14:45:39 -0700 | [diff] [blame^] | 47 | constexpr uint32_t num_ints_handle = ((sizeof(struct cros_gralloc_handle)) / sizeof(int)); |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 48 | |
Gurchetan Singh | b7538e2 | 2017-03-20 14:45:39 -0700 | [diff] [blame^] | 49 | constexpr uint32_t sw_access = GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK; |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 50 | |
| 51 | uint64_t cros_gralloc_convert_flags(int flags); |
| 52 | |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 53 | uint32_t cros_gralloc_convert_format(int format); |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 54 | |
| 55 | int32_t cros_gralloc_rendernode_open(struct driver **drv); |
| 56 | |
| 57 | int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd); |
| 58 | |
| 59 | /* Logging code adapted from bsdrm */ |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 60 | __attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file, |
| 61 | int line, const char *format, ...); |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 62 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 63 | #define cros_gralloc_error(...) \ |
| 64 | do { \ |
| 65 | cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \ |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 66 | } while (0) |
| 67 | |
| 68 | #endif |