• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008, The Android Open Source Project
3  * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <unistd.h>
19 #include <fcntl.h>
20 
21 #include <sys/mman.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <sys/ioctl.h>
25 #include <cutils/properties.h>
26 
27 #include <gralloc1-adapter.h>
28 
29 #include "gr.h"
30 #include "gpu.h"
31 #include "memalloc.h"
32 #include "alloc_controller.h"
33 
34 using namespace gralloc;
35 
36 int fb_device_open(const hw_module_t* module, const char* name,
37                    hw_device_t** device);
38 
39 static int gralloc_device_open(const hw_module_t* module, const char* name,
40                                hw_device_t** device);
41 
42 extern int gralloc_lock(gralloc_module_t const* module,
43                         buffer_handle_t handle, int usage,
44                         int l, int t, int w, int h,
45                         void** vaddr);
46 
47 extern int gralloc_lock_ycbcr(gralloc_module_t const* module,
48                         buffer_handle_t handle, int usage,
49                         int l, int t, int w, int h,
50                         struct android_ycbcr *ycbcr);
51 
52 extern int gralloc_unlock(gralloc_module_t const* module,
53                           buffer_handle_t handle);
54 
55 extern int gralloc_register_buffer(gralloc_module_t const* module,
56                                    buffer_handle_t handle);
57 
58 extern int gralloc_unregister_buffer(gralloc_module_t const* module,
59                                      buffer_handle_t handle);
60 
61 extern int gralloc_perform(struct gralloc_module_t const* module,
62                            int operation, ... );
63 
64 // HAL module methods
65 static struct hw_module_methods_t gralloc_module_methods = {
66     open: gralloc_device_open
67 };
68 
69 // HAL module initialize
70 struct private_module_t HAL_MODULE_INFO_SYM = {
71     base: {
72         common: {
73             tag: HARDWARE_MODULE_TAG,
74 #ifdef ADVERTISE_GRALLOC1
75             module_api_version: GRALLOC1_ADAPTER_MODULE_API_VERSION_1_0,
76 #else
77             module_api_version: 1,
78 #endif
79             version_minor: 0,
80             id: GRALLOC_HARDWARE_MODULE_ID,
81             name: "Graphics Memory Allocator Module",
82             author: "The Android Open Source Project",
83             methods: &gralloc_module_methods,
84             dso: 0,
85             reserved: {0},
86         },
87         registerBuffer: gralloc_register_buffer,
88         unregisterBuffer: gralloc_unregister_buffer,
89         lock: gralloc_lock,
90         unlock: gralloc_unlock,
91         perform: gralloc_perform,
92         lock_ycbcr: gralloc_lock_ycbcr,
93         validateBufferSize: NULL,
94         getTransportSize: NULL,
95     },
96     framebuffer: 0,
97     fbFormat: 0,
98     flags: 0,
99     numBuffers: 0,
100     bufferMask: 0,
101     lock: PTHREAD_MUTEX_INITIALIZER,
102 };
103 
104 // Open Gralloc device
gralloc_device_open(const hw_module_t * module,const char * name,hw_device_t ** device)105 int gralloc_device_open(const hw_module_t* module, const char* name,
106                         hw_device_t** device)
107 {
108     int status = -EINVAL;
109 
110 #ifdef ADVERTISE_GRALLOC1
111     if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
112         return gralloc1_adapter_device_open(module, name, device);
113     }
114 #endif
115 
116     if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
117         const private_module_t* m = reinterpret_cast<const private_module_t*>(
118             module);
119         gpu_context_t *dev;
120         IAllocController* alloc_ctrl = IAllocController::getInstance();
121         dev = new gpu_context_t(m, alloc_ctrl);
122         if(!dev)
123             return status;
124 
125         *device = &dev->common;
126         status = 0;
127     } else {
128         status = fb_device_open(module, name, device);
129     }
130     return status;
131 }
132