blob: 1a75c5d9acdfa939da4f4516f03471d38c7550f5 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
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 "BufferMapper"
18
19#include <stdint.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070020#include <errno.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070021
22#include <utils/Errors.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070023#include <utils/Log.h>
24
25#include <ui/BufferMapper.h>
26#include <ui/Rect.h>
27
28#include <EGL/android_natives.h>
29
30#include <hardware/gralloc.h>
31
Mathias Agopian8b765b72009-04-10 20:34:46 -070032
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033namespace android {
34// ---------------------------------------------------------------------------
35
Mathias Agopian9f88afb2009-04-17 14:15:18 -070036ANDROID_SINGLETON_STATIC_INSTANCE( BufferMapper )
Mathias Agopian4243e662009-04-15 18:34:24 -070037
Mathias Agopian076b1cc2009-04-10 14:24:30 -070038BufferMapper::BufferMapper()
39 : mAllocMod(0)
40{
41 hw_module_t const* module;
42 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
43 LOGE_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
Mathias Agopian0926f502009-05-04 14:17:04 -070049status_t BufferMapper::registerBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070050{
Mathias Agopian0926f502009-05-04 14:17:04 -070051 status_t err = mAllocMod->registerBuffer(mAllocMod, handle);
52 LOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
53 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070054 return err;
55}
56
Mathias Agopian0926f502009-05-04 14:17:04 -070057status_t BufferMapper::unregisterBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070058{
Mathias Agopian0926f502009-05-04 14:17:04 -070059 status_t err = mAllocMod->unregisterBuffer(mAllocMod, handle);
60 LOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
61 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070062 return err;
63}
64
Mathias Agopian0926f502009-05-04 14:17:04 -070065status_t BufferMapper::lock(buffer_handle_t handle,
66 int usage, const Rect& bounds, void** vaddr)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070067{
68 status_t err = mAllocMod->lock(mAllocMod, handle, usage,
Mathias Agopian0926f502009-05-04 14:17:04 -070069 bounds.left, bounds.top, bounds.width(), bounds.height(), vaddr);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070070 LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
71 return err;
72}
73
74status_t BufferMapper::unlock(buffer_handle_t handle)
75{
76 status_t err = mAllocMod->unlock(mAllocMod, handle);
77 LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
78 return err;
79}
80
Mathias Agopian076b1cc2009-04-10 14:24:30 -070081// ---------------------------------------------------------------------------
82}; // namespace android