blob: 7ba3a9a7033da905361068c178f2dab5ddaa1ea7 [file] [log] [blame]
Gurchetan Singh2e786ad2016-08-24 18:31:23 -07001/*
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 Singhc67f9e42016-11-28 15:25:26 -080010#include "../drv.h"
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070011#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 */
19typedef 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 */
36enum {
37 GRALLOC_DRM_GET_STRIDE,
38 GRALLOC_DRM_GET_FORMAT,
39 GRALLOC_DRM_GET_DIMENSIONS,
40 GRALLOC_DRM_GET_BACKING_STORE,
41};
42
43constexpr uint32_t cros_gralloc_magic(void)
44{
45 return 0xABCDDCBA;
46}
47
Gurchetan Singhc67f9e42016-11-28 15:25:26 -080048constexpr uint32_t num_ints_handle()
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070049{
Gurchetan Singhc67f9e42016-11-28 15:25:26 -080050 return ((sizeof(struct cros_gralloc_handle)) / sizeof(int));
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070051}
52
53constexpr uint32_t sw_access(void)
54{
55 return GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
56}
57
58constexpr uint32_t sw_read(void)
59{
60 return GRALLOC_USAGE_SW_READ_MASK;
61}
62
63constexpr uint32_t sw_write(void)
64{
65 return GRALLOC_USAGE_SW_WRITE_MASK;
66}
67
68uint64_t cros_gralloc_convert_flags(int flags);
69
Gurchetan Singhf3b22da2016-11-21 10:46:38 -080070uint32_t cros_gralloc_convert_format(int format);
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070071
72int32_t cros_gralloc_rendernode_open(struct driver **drv);
73
74int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
75
76/* Logging code adapted from bsdrm */
77__attribute__((format(printf, 4, 5)))
78void cros_gralloc_log(const char *prefix, const char *file, int line,
79 const char *format, ...);
80
81#define cros_gralloc_error(...) \
82 do { \
Gurchetan Singh54150e82016-12-02 18:28:38 -080083 cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, \
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070084 __LINE__, __VA_ARGS__); \
85 } while (0)
86
87#endif