blob: 4da740f70bd4830c97495a4e27006476363ce6f2 [file] [log] [blame]
Cody Schuffelen134ff032019-11-22 00:25:32 -08001#pragma once
2/*
3 * Copyright (C) 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "common/vsoc/shm/base.h"
19#include "common/vsoc/shm/graphics.h"
20#include "common/vsoc/shm/lock.h"
21
22// Memory layout for the gralloc manager region.
23
24namespace vsoc {
25namespace layout {
26
27namespace gralloc {
28
29struct BufferEntry {
30 static constexpr size_t layout_size =
31 7 * 4 + PixelFormatRegister::layout_size;
32
33 uint32_t owned_by;
34 uint32_t buffer_begin;
35 uint32_t buffer_end;
36
37 PixelFormatRegister pixel_format;
38 uint32_t stride;
39 uint32_t width;
40 uint32_t height;
41
42 // A size of 28 is causing different layouts when GrallocManagerLayout is
43 // compiled in host and guest sides
44 uint32_t padding;
45
46 uint32_t buffer_size() {
47 return buffer_end - buffer_begin;
48 }
49};
50ASSERT_SHM_COMPATIBLE(BufferEntry);
51
52struct GrallocBufferLayout : public RegionLayout {
53 static constexpr size_t layout_size = 1;
54 static const char* region_name;
55};
56ASSERT_SHM_COMPATIBLE(GrallocBufferLayout);
57
58struct GrallocManagerLayout : public RegionLayout {
59 static constexpr size_t layout_size =
60 8 + GuestLock::layout_size + BufferEntry::layout_size;
61 static const char* region_name;
62 typedef GrallocBufferLayout ManagedRegion;
63
64 uint32_t allocated_buffer_memory;
65 uint32_t buffer_count;
66 // Make sure this isn't the first field
67 GuestLock new_buffer_lock;
68 // Needs to be last field
69 BufferEntry buffers_table[1];
70};
71ASSERT_SHM_COMPATIBLE(GrallocManagerLayout);
72
73} // namespace gralloc
74} // namespace layout
75} // namespace vsoc