Android-cuttlefish cvd tool
protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 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#pragma once
18
19#include <stddef.h>
20#include <stdint.h>
21
22#include <type_traits>
23
25
26// Messages exchanged between cvd_display_server and its clients.
27// This is a cuttlefish specific protocol, not based on an existing one.
28
29inline constexpr uint32_t kFrameSlotsPerDisplay = 4;
30
31// Frame info stored in a shared memory.
32struct FrameInfo {
33 uint32_t width;
34 uint32_t height;
35 uint32_t fourcc_format;
36 uint32_t stride_bytes;
37};
38
39// Start of each display's shared memory object. It is followed by
40// kFrameSlotsPerDisplay frame data slots of `slot_size` bytes each.
41struct alignas(64) ShmHeader {
42 uint64_t slot_size;
44};
45static_assert(std::is_trivially_copyable_v<ShmHeader>);
46static_assert(std::is_standard_layout_v<ShmHeader>);
47
48// Byte offset of a slot's pixels in the shared memory object.
49inline constexpr size_t SlotOffset(uint64_t slot_size, uint32_t slot) {
50 return sizeof(ShmHeader) + slot * slot_size;
51}
52
53enum class MsgType : uint32_t {
54 // A display was added. Payload is DisplayCreatedMsg.
56 // A display was removed. Payload is DisplayDestroyedMsg.
58 // Shared memory info for a display. Payload is DisplayShmMsg.
59 kDisplayShm = 3,
60 // A new frame is available. Payload is FrameMsg.
61 kFrame = 4,
62};
63
66 uint32_t width;
67 uint32_t height;
68};
69
72};
73
76 // Name of the shared memory object holding the display's frame slots.
77 char shm_name[64];
78};
79
80// The frame geometry is in the shared memory header.
81struct FrameMsg {
83 // Slot number of the frame in the shared memory.
84 uint32_t slot;
85};
86
87// Sent by the server to the client.
88struct Message {
90 union {
95 };
96};
97static_assert(std::is_trivially_copyable_v<Message>);
98static_assert(std::is_standard_layout_v<Message>);
99
100inline constexpr size_t kMaxMsgSize = 256;
101static_assert(sizeof(Message) <= kMaxMsgSize);
102
103inline constexpr size_t kMsgAlignment = 8;
104static_assert(alignof(Message) <= kMsgAlignment);
105
106} // namespace cuttlefish::display_server
Definition: display_server_frame_source.cpp:48
constexpr size_t SlotOffset(uint64_t slot_size, uint32_t slot)
Definition: protocol.h:49
constexpr uint32_t kFrameSlotsPerDisplay
Definition: protocol.h:29
MsgType
Definition: protocol.h:53
constexpr size_t kMsgAlignment
Definition: protocol.h:103
constexpr size_t kMaxMsgSize
Definition: protocol.h:100
uint32_t display_number
Definition: protocol.h:65
uint32_t width
Definition: protocol.h:66
uint32_t height
Definition: protocol.h:67
uint32_t display_number
Definition: protocol.h:71
char shm_name[64]
Definition: protocol.h:77
uint32_t display_number
Definition: protocol.h:75
Definition: protocol.h:32
uint32_t fourcc_format
Definition: protocol.h:35
uint32_t stride_bytes
Definition: protocol.h:36
uint32_t width
Definition: protocol.h:33
uint32_t height
Definition: protocol.h:34
Definition: protocol.h:81
uint32_t slot
Definition: protocol.h:84
uint32_t display_number
Definition: protocol.h:82
Definition: protocol.h:88
DisplayDestroyedMsg destroyed
Definition: protocol.h:92
DisplayShmMsg shm
Definition: protocol.h:93
DisplayCreatedMsg created
Definition: protocol.h:91
FrameMsg frame
Definition: protocol.h:94
MsgType type
Definition: protocol.h:89
Definition: protocol.h:41
uint64_t slot_size
Definition: protocol.h:42
FrameInfo frame
Definition: protocol.h:43