blob: 9b5ab045628da9d88125a90fe200bc8334260ca5 [file] [log] [blame]
Chia-I Wu79d13ff2017-03-31 12:48:11 -07001/*
2 * Copyright 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
17#ifndef ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_GRALLOCBUFFERDESCRIPTOR_H
18#define ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_GRALLOCBUFFERDESCRIPTOR_H
19
20#include <android/hardware/graphics/mapper/2.0/IMapper.h>
21
22namespace android {
23namespace hardware {
24namespace graphics {
25namespace mapper {
26namespace V2_0 {
27namespace implementation {
28
29using android::hardware::graphics::common::V1_0::PixelFormat;
30
31/**
32 * BufferDescriptor is created by IMapper and consumed by IAllocator. It is
33 * versioned so that IMapper and IAllocator can be updated independently.
34 */
35constexpr uint32_t grallocBufferDescriptorSize = 7;
36constexpr uint32_t grallocBufferDescriptorMagicVersion = ((0x9487 << 16) | 0);
37
38inline BufferDescriptor grallocEncodeBufferDescriptor(
39 const IMapper::BufferDescriptorInfo& descriptorInfo) {
40 BufferDescriptor descriptor;
41 descriptor.resize(grallocBufferDescriptorSize);
42 descriptor[0] = grallocBufferDescriptorMagicVersion;
43 descriptor[1] = descriptorInfo.width;
44 descriptor[2] = descriptorInfo.height;
45 descriptor[3] = descriptorInfo.layerCount;
46 descriptor[4] = static_cast<uint32_t>(descriptorInfo.format);
47 descriptor[5] = static_cast<uint32_t>(descriptorInfo.usage);
48 descriptor[6] = static_cast<uint32_t>(descriptorInfo.usage >> 32);
49
50 return descriptor;
51}
52
53inline bool grallocDecodeBufferDescriptor(
54 const BufferDescriptor& descriptor,
55 IMapper::BufferDescriptorInfo* outDescriptorInfo) {
56 if (descriptor.size() != grallocBufferDescriptorSize ||
57 descriptor[0] != grallocBufferDescriptorMagicVersion) {
58 return false;
59 }
60
61 *outDescriptorInfo = IMapper::BufferDescriptorInfo{
62 descriptor[1],
63 descriptor[2],
64 descriptor[3],
65 static_cast<PixelFormat>(descriptor[4]),
66 (static_cast<uint64_t>(descriptor[6]) << 32) | descriptor[5],
67 };
68
69 return true;
70}
71
72} // namespace implementation
73} // namespace V2_0
74} // namespace mapper
75} // namespace graphics
76} // namespace hardware
77} // namespace android
78
79#endif // ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_GRALLOCBUFFERDESCRIPTOR_H