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 | |
| 10 | #include "cros_gralloc_handle.h" |
| 11 | |
| 12 | #include <hardware/gralloc.h> |
| 13 | #include <system/graphics.h> |
| 14 | |
| 15 | /* Use these error codes derived from gralloc1 to make transition easier when |
| 16 | * it happens |
| 17 | */ |
| 18 | typedef enum { |
| 19 | CROS_GRALLOC_ERROR_NONE = 0, |
| 20 | CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1, |
| 21 | CROS_GRALLOC_ERROR_BAD_HANDLE = 2, |
| 22 | CROS_GRALLOC_ERROR_BAD_VALUE = 3, |
| 23 | CROS_GRALLOC_ERROR_NOT_SHARED = 4, |
| 24 | CROS_GRALLOC_ERROR_NO_RESOURCES = 5, |
| 25 | CROS_GRALLOC_ERROR_UNDEFINED = 6, |
| 26 | CROS_GRALLOC_ERROR_UNSUPPORTED = 7, |
| 27 | } cros_gralloc_error_t; |
| 28 | |
| 29 | /* This enumeration must match the one in <gralloc_drm.h>. |
| 30 | * The functions supported by this gralloc's temporary private API are listed |
| 31 | * below. Use of these functions is highly discouraged and should only be |
| 32 | * reserved for cases where no alternative to get same information (such as |
| 33 | * querying ANativeWindow) exists. |
| 34 | */ |
| 35 | enum { |
| 36 | GRALLOC_DRM_GET_STRIDE, |
| 37 | GRALLOC_DRM_GET_FORMAT, |
| 38 | GRALLOC_DRM_GET_DIMENSIONS, |
| 39 | GRALLOC_DRM_GET_BACKING_STORE, |
| 40 | }; |
| 41 | |
| 42 | constexpr uint32_t cros_gralloc_magic(void) |
| 43 | { |
| 44 | return 0xABCDDCBA; |
| 45 | } |
| 46 | |
| 47 | constexpr uint32_t num_ints(void) |
| 48 | { |
| 49 | /* |
| 50 | * numFds in our case is one. Subtract that from our numInts |
| 51 | * calculation. |
| 52 | */ |
| 53 | return ((sizeof(struct cros_gralloc_handle) |
| 54 | - offsetof(cros_gralloc_handle, data)) / sizeof(int)) - 1; |
| 55 | } |
| 56 | |
| 57 | constexpr uint32_t sw_access(void) |
| 58 | { |
| 59 | return GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK; |
| 60 | } |
| 61 | |
| 62 | constexpr uint32_t sw_read(void) |
| 63 | { |
| 64 | return GRALLOC_USAGE_SW_READ_MASK; |
| 65 | } |
| 66 | |
| 67 | constexpr uint32_t sw_write(void) |
| 68 | { |
| 69 | return GRALLOC_USAGE_SW_WRITE_MASK; |
| 70 | } |
| 71 | |
| 72 | uint64_t cros_gralloc_convert_flags(int flags); |
| 73 | |
| 74 | drv_format_t cros_gralloc_convert_format(int format); |
| 75 | |
| 76 | int32_t cros_gralloc_rendernode_open(struct driver **drv); |
| 77 | |
| 78 | int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd); |
| 79 | |
| 80 | /* Logging code adapted from bsdrm */ |
| 81 | __attribute__((format(printf, 4, 5))) |
| 82 | void cros_gralloc_log(const char *prefix, const char *file, int line, |
| 83 | const char *format, ...); |
| 84 | |
| 85 | #define cros_gralloc_error(...) \ |
| 86 | do { \ |
| 87 | cros_gralloc_log("cros_gralloc_error", __FILE__, \ |
| 88 | __LINE__, __VA_ARGS__); \ |
| 89 | } while (0) |
| 90 | |
| 91 | #endif |