2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "GraphicBufferMapper"
18 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
23 #include <utils/Errors.h>
24 #include <utils/Log.h>
25 #include <utils/Trace.h>
27 #include <ui/GraphicBufferMapper.h>
30 #include <hardware/gralloc.h>
34 // ---------------------------------------------------------------------------
36 ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
38 GraphicBufferMapper::GraphicBufferMapper()
41 hw_module_t const* module;
42 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
43 ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
45 mAllocMod = (gralloc_module_t const *)module;
49 status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle)
54 err = mAllocMod->registerBuffer(mAllocMod, handle);
56 ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
57 handle, err, strerror(-err));
61 status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
66 err = mAllocMod->unregisterBuffer(mAllocMod, handle);
68 ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
69 handle, err, strerror(-err));
73 status_t GraphicBufferMapper::lock(buffer_handle_t handle,
74 int usage, const Rect& bounds, void** vaddr)
79 err = mAllocMod->lock(mAllocMod, handle, usage,
80 bounds.left, bounds.top, bounds.width(), bounds.height(),
83 ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
87 status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle,
88 int usage, const Rect& bounds, android_ycbcr *ycbcr)
93 err = mAllocMod->lock_ycbcr(mAllocMod, handle, usage,
94 bounds.left, bounds.top, bounds.width(), bounds.height(),
97 ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
101 status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
106 err = mAllocMod->unlock(mAllocMod, handle);
108 ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
112 // ---------------------------------------------------------------------------
113 }; // namespace android