blob: 967da986c861e1815d55a8f0e134fa4fb260b704 [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 Agopiancf563192012-02-29 20:43:29 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Mathias Agopian076b1cc2009-04-10 14:24:30 -070019
20#include <stdint.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070021#include <errno.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070022
23#include <utils/Errors.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070024#include <utils/Log.h>
Mathias Agopiancf563192012-02-29 20:43:29 -080025#include <utils/Trace.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026
Mathias Agopian3330b202009-10-05 17:07:12 -070027#include <ui/GraphicBufferMapper.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <ui/Rect.h>
29
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030#include <hardware/gralloc.h>
31
Mathias Agopian8b765b72009-04-10 20:34:46 -070032
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033namespace android {
34// ---------------------------------------------------------------------------
35
Mathias Agopian3330b202009-10-05 17:07:12 -070036ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
Mathias Agopian4243e662009-04-15 18:34:24 -070037
Mathias Agopian3330b202009-10-05 17:07:12 -070038GraphicBufferMapper::GraphicBufferMapper()
Mathias Agopian076b1cc2009-04-10 14:24:30 -070039 : mAllocMod(0)
40{
41 hw_module_t const* module;
42 int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
Steve Blocke6f43dd2012-01-06 19:20:56 +000043 ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070044 if (err == 0) {
45 mAllocMod = (gralloc_module_t const *)module;
46 }
47}
48
Mathias Agopian3330b202009-10-05 17:07:12 -070049status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070050{
Mathias Agopiancf563192012-02-29 20:43:29 -080051 ATRACE_CALL();
Mathias Agopianb26af232009-10-05 18:19:57 -070052 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080053
54 err = mAllocMod->registerBuffer(mAllocMod, handle);
55
Steve Block32397c12012-01-05 23:22:43 +000056 ALOGW_IF(err, "registerBuffer(%p) failed %d (%s)",
Mathias Agopian0926f502009-05-04 14:17:04 -070057 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070058 return err;
59}
60
Mathias Agopian3330b202009-10-05 17:07:12 -070061status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070062{
Mathias Agopiancf563192012-02-29 20:43:29 -080063 ATRACE_CALL();
Mathias Agopianb26af232009-10-05 18:19:57 -070064 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080065
66 err = mAllocMod->unregisterBuffer(mAllocMod, handle);
67
Steve Block32397c12012-01-05 23:22:43 +000068 ALOGW_IF(err, "unregisterBuffer(%p) failed %d (%s)",
Mathias Agopian0926f502009-05-04 14:17:04 -070069 handle, err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070070 return err;
71}
72
Mathias Agopian3330b202009-10-05 17:07:12 -070073status_t GraphicBufferMapper::lock(buffer_handle_t handle,
Mathias Agopian0926f502009-05-04 14:17:04 -070074 int usage, const Rect& bounds, void** vaddr)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070075{
Mathias Agopiancf563192012-02-29 20:43:29 -080076 ATRACE_CALL();
Mathias Agopianb26af232009-10-05 18:19:57 -070077 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080078
79 err = mAllocMod->lock(mAllocMod, handle, usage,
80 bounds.left, bounds.top, bounds.width(), bounds.height(),
81 vaddr);
82
Steve Block32397c12012-01-05 23:22:43 +000083 ALOGW_IF(err, "lock(...) failed %d (%s)", err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070084 return err;
85}
86
Mathias Agopian3330b202009-10-05 17:07:12 -070087status_t GraphicBufferMapper::unlock(buffer_handle_t handle)
Mathias Agopian076b1cc2009-04-10 14:24:30 -070088{
Mathias Agopiancf563192012-02-29 20:43:29 -080089 ATRACE_CALL();
Mathias Agopianb26af232009-10-05 18:19:57 -070090 status_t err;
Mathias Agopian0a757812010-12-08 16:40:01 -080091
92 err = mAllocMod->unlock(mAllocMod, handle);
93
Steve Block32397c12012-01-05 23:22:43 +000094 ALOGW_IF(err, "unlock(...) failed %d (%s)", err, strerror(-err));
Mathias Agopian076b1cc2009-04-10 14:24:30 -070095 return err;
96}
97
Mathias Agopian076b1cc2009-04-10 14:24:30 -070098// ---------------------------------------------------------------------------
Mathias Agopian076b1cc2009-04-10 14:24:30 -070099}; // namespace android