blob: 3bb5533b2f37a668ef145e06b27a23f8bd851801 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008, The Android Open Source Project
Duy Truong73d36df2013-02-09 20:33:23 -08003 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
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>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070026
27#include <linux/android_pmem.h>
28
29#include "gr.h"
30#include "gpu.h"
31#include "memalloc.h"
32#include "alloc_controller.h"
33
34using namespace gralloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070035
36int fb_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070037 hw_device_t** device);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070038
39static int gralloc_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070040 hw_device_t** device);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070041
42extern int gralloc_lock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070043 buffer_handle_t handle, int usage,
44 int l, int t, int w, int h,
45 void** vaddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070046
47extern int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070048 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070049
50extern int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070051 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070052
53extern int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070054 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055
56extern int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 int operation, ... );
Iliyan Malchev202a77d2012-06-11 14:41:12 -070058
59// HAL module methods
60static struct hw_module_methods_t gralloc_module_methods = {
Naseer Ahmed29a26812012-06-14 00:56:20 -070061open: gralloc_device_open
Iliyan Malchev202a77d2012-06-11 14:41:12 -070062};
63
64// HAL module initialize
65struct private_module_t HAL_MODULE_INFO_SYM = {
Naseer Ahmed29a26812012-06-14 00:56:20 -070066base: {
67 common: {
68 tag: HARDWARE_MODULE_TAG,
69 version_major: 1,
70 version_minor: 0,
71 id: GRALLOC_HARDWARE_MODULE_ID,
72 name: "Graphics Memory Allocator Module",
73 author: "The Android Open Source Project",
74 methods: &gralloc_module_methods,
75 dso: 0,
76 reserved: {0},
77 },
78 registerBuffer: gralloc_register_buffer,
79 unregisterBuffer: gralloc_unregister_buffer,
80 lock: gralloc_lock,
81 unlock: gralloc_unlock,
82 perform: gralloc_perform,
83 reserved_proc: {0},
84 },
85framebuffer: 0,
86fbFormat: 0,
87flags: 0,
88numBuffers: 0,
89bufferMask: 0,
90lock: PTHREAD_MUTEX_INITIALIZER,
91currentBuffer: 0,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070092};
93
94// Open Gralloc device
95int gralloc_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070096 hw_device_t** device)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070097{
98 int status = -EINVAL;
99 if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
100 const private_module_t* m = reinterpret_cast<const private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700102 gpu_context_t *dev;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700103 IAllocController* alloc_ctrl = IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700104 dev = new gpu_context_t(m, alloc_ctrl);
105 *device = &dev->common;
106 status = 0;
107 } else {
108 status = fb_device_open(module, name, device);
109 }
110 return status;
111}