blob: b173c854d9c2a813dcd3be47033feeec59d8256e [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
Mathias Agopian3330b202009-10-05 17:07:12 -070017#define LOG_TAG "GraphicBufferMapper"
Mathias Agopian076b1cc2009-04-10 14:24:30 -070018
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
Mathias Agopian3330b202009-10-05 17:07:12 -070025#include <ui/GraphicBufferMapper.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026#include <ui/Rect.h>
27
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <hardware/gralloc.h>
29
Mathias Agopian8b765b72009-04-10 20:34:46 -070030
Mathias Agopian076b1cc2009-04-10 14:24:30 -070031namespace android {
32// ---------------------------------------------------------------------------
33
Mathias Agopian3330b202009-10-05 17:07:12 -070034ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
Mathias Agopian4243e662009-04-15 18:34:24 -070035
Mathias Agopian3330b202009-10-05 17:07:12 -070036GraphicBufferMapper::GraphicBufferMapper()
Mathias Agopian076b1cc2009-04-10 14:24:30 -070037 : mAllocMod(0)
38{
39 hw_module_t const* module;
40 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
Steve Blocke6f43dd2012-01-06 19:20:56 +000041 ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070042 if (err == 0) {
43 mAllocMod = (gralloc_module_t const *)module;
44 }
45}
46
Mathias Agopian3330b202009-10-05 17:07:12 -070047status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070048{
Mathias Agopianb26af232009-10-05 18:19:57 -070049 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080050
51 err = mAllocMod->registerBuffer(mAllocMod, handle);
52
Steve Block32397c12012-01-05 23:22:43 +000053 ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
Mathias Agopian0926f502009-05-04 14:17:04 -070054 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070055 return err;
56}
57
Mathias Agopian3330b202009-10-05 17:07:12 -070058status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070059{
Mathias Agopianb26af232009-10-05 18:19:57 -070060 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080061
62 err = mAllocMod->unregisterBuffer(mAllocMod, handle);
63
Steve Block32397c12012-01-05 23:22:43 +000064 ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
Mathias Agopian0926f502009-05-04 14:17:04 -070065 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 return err;
67}
68
Mathias Agopian3330b202009-10-05 17:07:12 -070069status_t GraphicBufferMapper::lock(buffer_handle_t handle,
Mathias Agopian0926f502009-05-04 14:17:04 -070070 int usage, const Rect& bounds, void** vaddr)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070071{
Mathias Agopianb26af232009-10-05 18:19:57 -070072 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080073
74 err = mAllocMod->lock(mAllocMod, handle, usage,
75 bounds.left, bounds.top, bounds.width(), bounds.height(),
76 vaddr);
77
Steve Block32397c12012-01-05 23:22:43 +000078 ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070079 return err;
80}
81
Mathias Agopian3330b202009-10-05 17:07:12 -070082status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070083{
Mathias Agopianb26af232009-10-05 18:19:57 -070084 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080085
86 err = mAllocMod->unlock(mAllocMod, handle);
87
Steve Block32397c12012-01-05 23:22:43 +000088 ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070089 return err;
90}
91
Mathias Agopian076b1cc2009-04-10 14:24:30 -070092// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -070093}; // namespace android