GraphicBufferMapper.cpp revision 3330b203039dea366d4981db1408a460134b2d2c
1076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/* 2076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * Copyright (C) 2007 The Android Open Source Project 3076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * 4076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * you may not use this file except in compliance with the License. 6076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * You may obtain a copy of the License at 7076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * 8076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * 10076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * Unless required by applicable law or agreed to in writing, software 11076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * See the License for the specific language governing permissions and 14076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian * limitations under the License. 15076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian */ 16076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 173330b203039dea366d4981db1408a460134b2d2cMathias Agopian#define LOG_TAG "GraphicBufferMapper" 18076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 19076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <stdint.h> 20076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <errno.h> 21076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 22076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/Errors.h> 23076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/Log.h> 24076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 253330b203039dea366d4981db1408a460134b2d2cMathias Agopian#include <ui/GraphicBufferMapper.h> 26076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <ui/Rect.h> 27076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 28076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <hardware/gralloc.h> 29076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 308b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian 31076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiannamespace android { 32076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian// --------------------------------------------------------------------------- 33076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 343330b203039dea366d4981db1408a460134b2d2cMathias AgopianANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) 354243e666213029a293935987c979831093fb0779Mathias Agopian 363330b203039dea366d4981db1408a460134b2d2cMathias AgopianGraphicBufferMapper::GraphicBufferMapper() 37076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian : mAllocMod(0) 38076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 39076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian hw_module_t const* module; 40076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); 41076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian LOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); 42076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian if (err == 0) { 43076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian mAllocMod = (gralloc_module_t const *)module; 44076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian } 45076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 46076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 473330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle) 48076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 490926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian status_t err = mAllocMod->registerBuffer(mAllocMod, handle); 500926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian LOGW_IF(err, "registerBuffer(%p) failed %d (%s)", 510926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian handle, err, strerror(-err)); 52076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 53076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 54076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 553330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle) 56076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 570926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian status_t err = mAllocMod->unregisterBuffer(mAllocMod, handle); 580926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian LOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)", 590926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian handle, err, strerror(-err)); 60076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 61076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 62076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 633330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::lock(buffer_handle_t handle, 640926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian int usage, const Rect& bounds, void** vaddr) 65076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 66076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian status_t err = mAllocMod->lock(mAllocMod, handle, usage, 670926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian bounds.left, bounds.top, bounds.width(), bounds.height(), vaddr); 6869bdcb9b7b5089984bf474f30029fa024f519e47Mathias Agopian LOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err)); 69076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 70076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 71076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 723330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::unlock(buffer_handle_t handle) 73076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 74076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian status_t err = mAllocMod->unlock(mAllocMod, handle); 75076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian LOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); 76076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 77076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 78076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 79076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian// --------------------------------------------------------------------------- 80076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}; // namespace android 81