1 /*
2 * Copyright (C) 2007 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 #define LOG_TAG "GraphicBufferMapper"
18 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
19
20 #include <stdint.h>
21 #include <errno.h>
22
23 #include <utils/Errors.h>
24 #include <utils/Log.h>
25 #include <utils/Trace.h>
26
27 #include <ui/GraphicBufferMapper.h>
28 #include <ui/Rect.h>
29
30 #include <hardware/gralloc.h>
31
32
33 namespace android {
34 // ---------------------------------------------------------------------------
35
ANDROID_SINGLETON_STATIC_INSTANCE(GraphicBufferMapper)36 ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
37
38 GraphicBufferMapper::GraphicBufferMapper()
39 : mAllocMod(0)
40 {
41 hw_module_t const* module;
42 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
43 ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
44 if (err == 0) {
45 mAllocMod = (gralloc_module_t const *)module;
46 }
47 }
48
registerBuffer(buffer_handle_t handle)49 status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle)
50 {
51 ATRACE_CALL();
52 status_t err;
53
54 err = mAllocMod->registerBuffer(mAllocMod, handle);
55
56 ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
57 handle, err, strerror(-err));
58 return err;
59 }
60
unregisterBuffer(buffer_handle_t handle)61 status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
62 {
63 ATRACE_CALL();
64 status_t err;
65
66 err = mAllocMod->unregisterBuffer(mAllocMod, handle);
67
68 ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
69 handle, err, strerror(-err));
70 return err;
71 }
72
lock(buffer_handle_t handle,int usage,const Rect & bounds,void ** vaddr)73 status_t GraphicBufferMapper::lock(buffer_handle_t handle,
74 int usage, const Rect& bounds, void** vaddr)
75 {
76 ATRACE_CALL();
77 status_t err;
78
79 err = mAllocMod->lock(mAllocMod, handle, usage,
80 bounds.left, bounds.top, bounds.width(), bounds.height(),
81 vaddr);
82
83 ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
84 return err;
85 }
86
unlock(buffer_handle_t handle)87 status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
88 {
89 ATRACE_CALL();
90 status_t err;
91
92 err = mAllocMod->unlock(mAllocMod, handle);
93
94 ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
95 return err;
96 }
97
98 // ---------------------------------------------------------------------------
99 }; // namespace android
100