android_external_minigbm/cros_gralloc/cros_gralloc_helpers.h
Gurchetan Singh 1b1d56ae40 minigbm: add clang-format and presubmit hooks
Running the presubmit.sh script will apply our rules to every file in
the repo. Exclude gbm.h from the formatting requirements since this file
was taken from other open-source projects, and diffing will be easier
without our formatting rules.

In addition, special case drivers where the order of includes matters.

BUG=none
TEST=Verified the following commands succeed:

emerge-cyan minigbm/arc-cros-gralloc
emerge-oak minigbm/arc-cros-gralloc
emerge-veyron_minnie-cheets minigbm/arc-cros-gralloc
emerge-peach_pi minigbm
emerge-nyan_big minigbm
emerge-jadeite minigbm

Change-Id: I6ce93fb1930da254d13d5017766c17341870ccc9
Reviewed-on: https://chromium-review.googlesource.com/447319
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2017-03-31 10:40:27 -07:00

87 lines
2.4 KiB
C++

/*
* Copyright 2016 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef CROS_GRALLOC_HELPERS_H
#define CROS_GRALLOC_HELPERS_H
#include "../drv.h"
#include "cros_gralloc_handle.h"
#include <hardware/gralloc.h>
#include <system/graphics.h>
/* Use these error codes derived from gralloc1 to make transition easier when
* it happens
*/
typedef enum {
CROS_GRALLOC_ERROR_NONE = 0,
CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1,
CROS_GRALLOC_ERROR_BAD_HANDLE = 2,
CROS_GRALLOC_ERROR_BAD_VALUE = 3,
CROS_GRALLOC_ERROR_NOT_SHARED = 4,
CROS_GRALLOC_ERROR_NO_RESOURCES = 5,
CROS_GRALLOC_ERROR_UNDEFINED = 6,
CROS_GRALLOC_ERROR_UNSUPPORTED = 7,
} cros_gralloc_error_t;
/* This enumeration must match the one in <gralloc_drm.h>.
* The functions supported by this gralloc's temporary private API are listed
* below. Use of these functions is highly discouraged and should only be
* reserved for cases where no alternative to get same information (such as
* querying ANativeWindow) exists.
*/
// clang-format off
enum {
GRALLOC_DRM_GET_STRIDE,
GRALLOC_DRM_GET_FORMAT,
GRALLOC_DRM_GET_DIMENSIONS,
GRALLOC_DRM_GET_BACKING_STORE,
};
// clang-format on
constexpr uint32_t cros_gralloc_magic(void)
{
return 0xABCDDCBA;
}
constexpr uint32_t num_ints_handle()
{
return ((sizeof(struct cros_gralloc_handle)) / sizeof(int));
}
constexpr uint32_t sw_access(void)
{
return GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
}
constexpr uint32_t sw_read(void)
{
return GRALLOC_USAGE_SW_READ_MASK;
}
constexpr uint32_t sw_write(void)
{
return GRALLOC_USAGE_SW_WRITE_MASK;
}
uint64_t cros_gralloc_convert_flags(int flags);
uint32_t cros_gralloc_convert_format(int format);
int32_t cros_gralloc_rendernode_open(struct driver **drv);
int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
/* Logging code adapted from bsdrm */
__attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file,
int line, const char *format, ...);
#define cros_gralloc_error(...) \
do { \
cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \
} while (0)
#endif