blob: 026d92a6ed0bc3687cbfd55689193e08c02e4cf6 [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 */
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080036// clang-format off
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070037enum {
38 GRALLOC_DRM_GET_STRIDE,
39 GRALLOC_DRM_GET_FORMAT,
40 GRALLOC_DRM_GET_DIMENSIONS,
41 GRALLOC_DRM_GET_BACKING_STORE,
42};
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080043// clang-format on
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070044
Gurchetan Singhb7538e22017-03-20 14:45:39 -070045constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA;
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070046
Gurchetan Singhb7538e22017-03-20 14:45:39 -070047constexpr uint32_t num_ints_handle = ((sizeof(struct cros_gralloc_handle)) / sizeof(int));
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070048
Gurchetan Singhb7538e22017-03-20 14:45:39 -070049constexpr uint32_t sw_access = GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070050
51uint64_t cros_gralloc_convert_flags(int flags);
52
Gurchetan Singhf3b22da2016-11-21 10:46:38 -080053uint32_t cros_gralloc_convert_format(int format);
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070054
55int32_t cros_gralloc_rendernode_open(struct driver **drv);
56
57int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
58
59/* Logging code adapted from bsdrm */
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080060__attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file,
61 int line, const char *format, ...);
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070062
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080063#define cros_gralloc_error(...) \
64 do { \
65 cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \
Gurchetan Singh2e786ad2016-08-24 18:31:23 -070066 } while (0)
67
68#endif