• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <hardware/hardware.h>
20 
21 #include <cutils/native_handle.h>
22 
23 #define GRALLOC_MODULE_API_VERSION_1_0 HARDWARE_MAKE_API_VERSION(1, 0)
24 
25 #define GRALLOC_HARDWARE_MODULE_ID "gralloc"
26 
27 enum {
28     GRALLOC1_ERROR_NONE = 0,
29     GRALLOC1_ERROR_BAD_HANDLE = 2,
30     GRALLOC1_ERROR_BAD_VALUE = 3,
31     GRALLOC1_ERROR_UNDEFINED = 6,
32 };
33 
34 enum {
35     GRALLOC1_FUNCTION_LOCK = 18,
36     GRALLOC1_FUNCTION_UNLOCK = 20,
37 };
38 
39 enum {
40     GRALLOC1_CONSUMER_USAGE_CPU_READ = 1ULL << 1,
41     GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN = 1ULL << 2 | GRALLOC1_CONSUMER_USAGE_CPU_READ,
42     GRALLOC1_CONSUMER_USAGE_CPU_WRITE = 1ULL << 5,
43     GRALLOC1_CONSUMER_USAGE_CPU_WRITE_OFTEN = 1ULL << 6 | GRALLOC1_CONSUMER_USAGE_CPU_WRITE,
44     GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE = 1ULL << 8,
45 };
46 
47 enum {
48     GRALLOC1_PRODUCER_USAGE_CPU_READ = 1ULL << 1,
49     GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN = 1ULL << 2 | GRALLOC1_PRODUCER_USAGE_CPU_READ,
50     GRALLOC1_PRODUCER_USAGE_CPU_WRITE = 1ULL << 5,
51     GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN = 1ULL << 6 | GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
52     GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET = 1ULL << 9,
53 };
54 
55 typedef void (*gralloc1_function_pointer_t)();
56 
57 struct gralloc1_rect_t {
58     int32_t left;
59     int32_t top;
60     int32_t width;
61     int32_t height;
62 };
63 
64 struct gralloc1_device_t {
65     hw_device_t common;
66     void (*getCapabilities)(gralloc1_device_t*, uint32_t*, int32_t*);
67     gralloc1_function_pointer_t (*getFunction)(gralloc1_device_t*, int32_t);
68 };
69 
70 typedef int32_t (*GRALLOC1_PFN_LOCK)(gralloc1_device_t*, buffer_handle_t, uint64_t, uint64_t,
71                                      const gralloc1_rect_t*, void**, int32_t);
72 typedef int32_t (*GRALLOC1_PFN_UNLOCK)(gralloc1_device_t*, buffer_handle_t, int32_t*);
73 
gralloc1_open(const hw_module_t * module,gralloc1_device_t ** device)74 static inline int gralloc1_open(const hw_module_t* module, gralloc1_device_t** device) {
75     return module->methods->open(module, GRALLOC_HARDWARE_MODULE_ID,
76                                  reinterpret_cast<hw_device_t**>(device));
77 }
78