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