blob: cf57fee70d6082e3e2a564b91acbec5e3eb9e754 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008, The Android Open Source Project
Naseer Ahmed29a26812012-06-14 00:56:20 -07003 * Copyright (c) 2011-2012, Code Aurora Forum. 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>
26#include <utils/RefBase.h>
27
28#include <linux/android_pmem.h>
29
30#include "gr.h"
31#include "gpu.h"
32#include "memalloc.h"
33#include "alloc_controller.h"
34
35using namespace gralloc;
36using android::sp;
37
38int fb_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070039 hw_device_t** device);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070040
41static int gralloc_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070042 hw_device_t** device);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070043
44extern int gralloc_lock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070045 buffer_handle_t handle, int usage,
46 int l, int t, int w, int h,
47 void** vaddr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070048
49extern int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070050 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051
52extern int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070054
55extern int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070056 buffer_handle_t handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070057
58extern int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070059 int operation, ... );
Iliyan Malchev202a77d2012-06-11 14:41:12 -070060
61// HAL module methods
62static struct hw_module_methods_t gralloc_module_methods = {
Naseer Ahmed29a26812012-06-14 00:56:20 -070063open: gralloc_device_open
Iliyan Malchev202a77d2012-06-11 14:41:12 -070064};
65
66// HAL module initialize
67struct private_module_t HAL_MODULE_INFO_SYM = {
Naseer Ahmed29a26812012-06-14 00:56:20 -070068base: {
69 common: {
70 tag: HARDWARE_MODULE_TAG,
71 version_major: 1,
72 version_minor: 0,
73 id: GRALLOC_HARDWARE_MODULE_ID,
74 name: "Graphics Memory Allocator Module",
75 author: "The Android Open Source Project",
76 methods: &gralloc_module_methods,
77 dso: 0,
78 reserved: {0},
79 },
80 registerBuffer: gralloc_register_buffer,
81 unregisterBuffer: gralloc_unregister_buffer,
82 lock: gralloc_lock,
83 unlock: gralloc_unlock,
84 perform: gralloc_perform,
85 reserved_proc: {0},
86 },
87framebuffer: 0,
88fbFormat: 0,
89flags: 0,
90numBuffers: 0,
91bufferMask: 0,
92lock: PTHREAD_MUTEX_INITIALIZER,
93currentBuffer: 0,
Iliyan Malchev202a77d2012-06-11 14:41:12 -070094};
95
96// Open Gralloc device
97int gralloc_device_open(const hw_module_t* module, const char* name,
Naseer Ahmed29a26812012-06-14 00:56:20 -070098 hw_device_t** device)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070099{
100 int status = -EINVAL;
101 if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
102 const private_module_t* m = reinterpret_cast<const private_module_t*>(
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103 module);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700104 gpu_context_t *dev;
105 sp<IAllocController> alloc_ctrl = IAllocController::getInstance(true);
106 dev = new gpu_context_t(m, alloc_ctrl);
107 *device = &dev->common;
108 status = 0;
109 } else {
110 status = fb_device_open(module, name, device);
111 }
112 return status;
113}