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" 18cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian#define ATRACE_TAG ATRACE_TAG_GRAPHICS 19076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 20076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <stdint.h> 21076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <errno.h> 22076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 23076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/Errors.h> 24076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/Log.h> 25cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian#include <utils/Trace.h> 26076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 273330b203039dea366d4981db1408a460134b2d2cMathias Agopian#include <ui/GraphicBufferMapper.h> 28076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <ui/Rect.h> 29076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 30076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <hardware/gralloc.h> 31076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 328b765b7f5ea7f56963ea0e3141d043d20944dbccMathias Agopian 33076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiannamespace android { 34076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian// --------------------------------------------------------------------------- 35076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 363330b203039dea366d4981db1408a460134b2d2cMathias AgopianANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) 374243e666213029a293935987c979831093fb0779Mathias Agopian 383330b203039dea366d4981db1408a460134b2d2cMathias AgopianGraphicBufferMapper::GraphicBufferMapper() 39076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian : mAllocMod(0) 40076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 41076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian hw_module_t const* module; 42076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); 43e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID); 44076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian if (err == 0) { 45076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian mAllocMod = (gralloc_module_t const *)module; 46076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian } 47076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 48076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 493330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle) 50076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 51cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian ATRACE_CALL(); 52b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian status_t err; 530a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 540a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian err = mAllocMod->registerBuffer(mAllocMod, handle); 550a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 5632397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)", 570926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian handle, err, strerror(-err)); 58076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 59076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 60076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 613330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle) 62076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 63cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian ATRACE_CALL(); 64b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian status_t err; 650a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 660a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian err = mAllocMod->unregisterBuffer(mAllocMod, handle); 670a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 6832397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)", 690926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian handle, err, strerror(-err)); 70076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 71076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 72076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 733330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::lock(buffer_handle_t handle, 740926f50664c739eaee60341f8e8c694dc9a4f3ebMathias Agopian int usage, const Rect& bounds, void** vaddr) 75076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 76cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian ATRACE_CALL(); 77b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian status_t err; 780a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 790a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian err = mAllocMod->lock(mAllocMod, handle, usage, 800a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian bounds.left, bounds.top, bounds.width(), bounds.height(), 810a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian vaddr); 820a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian 8332397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err)); 84076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian return err; 85076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian} 86076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian 873330b203039dea366d4981db1408a460134b2d2cMathias Agopianstatus_t GraphicBufferMapper::unlock(buffer_handle_t handle) 88076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian{ 89cf56319d4deb2215e5274f321f7fee71caa1ada1Mathias Agopian ATRACE_CALL(); 90b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian status_t err; 91b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian 920a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian err = mAllocMod->unlock(mAllocMod, handle); 93b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian 9432397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err)); 950a757814f3e4ca4db772144e85b687fe89a7fba5Mathias Agopian return err; 96b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian} 97b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian 98b26af23744fa73e8bc142b1eb98772fde5970c10Mathias Agopian// --------------------------------------------------------------------------- 99076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian}; // namespace android 100