Android-cuttlefish cvd tool
wayland_surface.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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
18#pragma once
19
20#include <stdint.h>
21#include <mutex>
22#include <optional>
23
24#include <wayland-server-core.h>
25
26namespace wayland {
27
28class Surfaces;
29
30// Tracks the buffer associated with a Wayland surface.
31class Surface {
32 public:
33 Surface(Surfaces& surfaces);
34 virtual ~Surface();
35
36 Surface(const Surface& rhs) = delete;
37 Surface& operator=(const Surface& rhs) = delete;
38
39 Surface(Surface&& rhs) = delete;
40 Surface& operator=(Surface&& rhs) = delete;
41
42 struct Region {
43 int32_t x;
44 int32_t y;
45 int32_t w;
46 int32_t h;
47 };
48
49 void SetRegion(const Region& region);
50
51 // Sets the buffer of the pending frame.
52 void Attach(struct wl_resource* buffer);
53
54 // Commits the pending frame state.
55 void Commit();
56
57 void SetVirtioGpuScanoutId(uint32_t scanout);
58
59 private:
61
63 std::optional<uint32_t> scanout_id;
64 };
65
66 struct State {
68
69 // The buffer for the current committed frame.
70 struct wl_resource* current_buffer = nullptr;
71
72 // The buffer for the next frame.
73 struct wl_resource* pending_buffer = nullptr;
74
75 // The buffers expected dimensions.
77
79
81 };
82
83 std::mutex state_mutex_;
85};
86
87} // namespace wayland
Definition: wayland_surface.h:31
Surface(const Surface &rhs)=delete
std::mutex state_mutex_
Definition: wayland_surface.h:83
Surfaces & surfaces_
Definition: wayland_surface.h:60
Surface & operator=(Surface &&rhs)=delete
virtual ~Surface()
Definition: wayland_surface.cpp:43
Surface(Surface &&rhs)=delete
void SetVirtioGpuScanoutId(uint32_t scanout)
Definition: wayland_surface.cpp:107
void SetRegion(const Region &region)
Definition: wayland_surface.cpp:50
void Commit()
Definition: wayland_surface.cpp:60
Surface & operator=(const Surface &rhs)=delete
State state_
Definition: wayland_surface.h:84
void Attach(struct wl_resource *buffer)
Definition: wayland_surface.cpp:55
Surface(Surfaces &surfaces)
Definition: wayland_surface.cpp:41
Definition: wayland_surfaces.h:33
Definition: wayland_compositor.cpp:27
Definition: wayland_surface.h:42
int32_t x
Definition: wayland_surface.h:43
int32_t w
Definition: wayland_surface.h:45
int32_t y
Definition: wayland_surface.h:44
int32_t h
Definition: wayland_surface.h:46
Definition: wayland_surface.h:66
struct wl_resource * pending_buffer
Definition: wayland_surface.h:73
bool has_notified_surface_create
Definition: wayland_surface.h:80
uint32_t current_frame_number
Definition: wayland_surface.h:67
VirtioGpuMetadata virtio_gpu_metadata_
Definition: wayland_surface.h:78
struct wl_resource * current_buffer
Definition: wayland_surface.h:70
Region region
Definition: wayland_surface.h:76
Definition: wayland_surface.h:62
std::optional< uint32_t > scanout_id
Definition: wayland_surface.h:63