blob: 972b7b576f81a871b47805d8d1d8eb6708f44224 [file] [log] [blame]
Howard Chen4904f962017-12-08 18:11:05 +08001/*
2 * Copyright (C) 2016 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#ifndef ANDROID_HARDWARE_CACHE_MAPPING_H
17#define ANDROID_HARDWARE_CACHE_MAPPING_H
18
19#include <android/hidl/memory/1.0/IMemory.h>
20#include <android/hidl/memory/block/1.0/types.h>
21#include <android/hidl/memory/token/1.0/IMemoryToken.h>
22
23namespace android {
24namespace hardware {
25
26/**
27 * Returns the IMemory instance corresponding to a MemoryBlock. The heap that
28 * a MemoryBlock belongs to is stored in an internal cache to reduce the number
29 * of invocations to the mapMemory(hidl_memory)
30 *
31 * Note, a cache entry is maintained by reference count and may be flushed when
32 * the count decrease to zero. Performance critical part that does not want its
33 * caches to be flushed can use HidlMemoryCacheLock.
34 */
35sp<::android::hidl::memory::V1_0::IMemory> mapMemory(
36 const ::android::hidl::memory::block::V1_0::MemoryBlock& block);
37
38/**
39 * Internally, there's a cache pool to keep IMemory instances for heap regions
40 * that are referred by the MemoryBlock. During development, this
41 * lockMemoryCache(...) method helps to diagnosis whether the cache is effective
42 * for a specific key. It returns a RAII object used to lock an IMemory instance
43 * referred by the key and keep it alive even if the instance is not referred by
44 * any MemoryBlock. If the cache in interest is already effective. It won't differ
45 * much in performance w/ wo/ the lockMemoryCache()
46 *
47 * @note An IMemory instance that is returned from the mapMemory() is
48 * initialized in an unlocked state.
49 */
50sp<RefBase> lockMemoryCache(const sp<::android::hidl::memory::token::V1_0::IMemoryToken> key);
51
52} // namespace hardware
53} // namespace android
54#endif