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 | */ |
| 36 | enum { |
| 37 | GRALLOC_DRM_GET_STRIDE, |
| 38 | GRALLOC_DRM_GET_FORMAT, |
| 39 | GRALLOC_DRM_GET_DIMENSIONS, |
| 40 | GRALLOC_DRM_GET_BACKING_STORE, |
| 41 | }; |
| 42 | |
| 43 | constexpr uint32_t cros_gralloc_magic(void) |
| 44 | { |
| 45 | return 0xABCDDCBA; |
| 46 | } |
| 47 | |
Gurchetan Singh | c67f9e4 | 2016-11-28 15:25:26 -0800 | [diff] [blame^] | 48 | constexpr uint32_t num_ints_handle() |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 49 | { |
Gurchetan Singh | c67f9e4 | 2016-11-28 15:25:26 -0800 | [diff] [blame^] | 50 | return ((sizeof(struct cros_gralloc_handle)) / sizeof(int)); |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | constexpr uint32_t sw_access(void) |
| 54 | { |
| 55 | return GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK; |
| 56 | } |
| 57 | |
| 58 | constexpr uint32_t sw_read(void) |
| 59 | { |
| 60 | return GRALLOC_USAGE_SW_READ_MASK; |
| 61 | } |
| 62 | |
| 63 | constexpr uint32_t sw_write(void) |
| 64 | { |
| 65 | return GRALLOC_USAGE_SW_WRITE_MASK; |
| 66 | } |
| 67 | |
| 68 | uint64_t cros_gralloc_convert_flags(int flags); |
| 69 | |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 70 | uint32_t cros_gralloc_convert_format(int format); |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 71 | |
| 72 | int32_t cros_gralloc_rendernode_open(struct driver **drv); |
| 73 | |
| 74 | int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd); |
| 75 | |
| 76 | /* Logging code adapted from bsdrm */ |
| 77 | __attribute__((format(printf, 4, 5))) |
| 78 | void cros_gralloc_log(const char *prefix, const char *file, int line, |
| 79 | const char *format, ...); |
| 80 | |
| 81 | #define cros_gralloc_error(...) \ |
| 82 | do { \ |
| 83 | cros_gralloc_log("cros_gralloc_error", __FILE__, \ |
| 84 | __LINE__, __VA_ARGS__); \ |
| 85 | } while (0) |
| 86 | |
| 87 | #endif |