Hash :
3d8dff0a
Author :
Date :
2025-08-26T20:23:21
Suppress unsafe buffers on a file-by-file basis in util/ Bug: b/436880895 Change-Id: I299247e38853bb16afd466e3f6521342c0a2b0f8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6891980 Auto-Submit: Tom Sepez <tsepez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// WaylandWindow.cpp: Implementation of OSWindow for Wayland
#ifdef UNSAFE_BUFFERS_BUILD
# pragma allow_unsafe_buffers
#endif
#include "util/linux/wayland/WaylandWindow.h"
#include <cerrno>
#include <cstring>
WaylandWindow::WaylandWindow()
: mDisplay{nullptr}, mCompositor{nullptr}, mSurface{nullptr}, mWindow{nullptr}
{}
WaylandWindow::~WaylandWindow()
{
destroy();
}
void WaylandWindow::RegistryHandleGlobal(void *data,
struct wl_registry *registry,
uint32_t name,
const char *interface,
uint32_t version)
{
WaylandWindow *vc = reinterpret_cast<WaylandWindow *>(data);
if (strcmp(interface, "wl_compositor") == 0)
{
void *compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
vc->mCompositor = reinterpret_cast<wl_compositor *>(compositor);
}
}
void WaylandWindow::RegistryHandleGlobalRemove(void *data,
struct wl_registry *registry,
uint32_t name)
{}
const struct wl_registry_listener WaylandWindow::registryListener = {
WaylandWindow::RegistryHandleGlobal, WaylandWindow::RegistryHandleGlobalRemove};
bool WaylandWindow::initializeImpl(const std::string &name, int width, int height)
{
destroy();
if (!mDisplay)
{
mDisplay = wl_display_connect(nullptr);
if (!mDisplay)
{
return false;
}
}
// Not get a window
struct wl_registry *registry = wl_display_get_registry(mDisplay);
wl_registry_add_listener(registry, ®istryListener, this);
// Round-trip to get globals
wl_display_roundtrip(mDisplay);
if (!mCompositor)
{
return false;
}
// We don't need this anymore
wl_registry_destroy(registry);
mSurface = wl_compositor_create_surface(mCompositor);
if (!mSurface)
{
return false;
}
mWindow = wl_egl_window_create(mSurface, width, height);
if (!mWindow)
{
return false;
}
fds[0] = {wl_display_get_fd(mDisplay), POLLIN, 0};
mY = 0;
mX = 0;
mWidth = width;
mHeight = height;
return true;
}
void WaylandWindow::disableErrorMessageDialog() {}
void WaylandWindow::destroy()
{
if (mWindow)
{
wl_egl_window_destroy(mWindow);
mWindow = nullptr;
}
if (mSurface)
{
wl_surface_destroy(mSurface);
mSurface = nullptr;
}
if (mCompositor)
{
wl_compositor_destroy(mCompositor);
mCompositor = nullptr;
}
}
void WaylandWindow::resetNativeWindow() {}
void WaylandWindow::setNativeDisplay(EGLNativeDisplayType display)
{
mDisplay = reinterpret_cast<wl_display *>(display);
}
EGLNativeWindowType WaylandWindow::getNativeWindow() const
{
return reinterpret_cast<EGLNativeWindowType>(mWindow);
}
EGLNativeDisplayType WaylandWindow::getNativeDisplay() const
{
return reinterpret_cast<EGLNativeDisplayType>(mDisplay);
}
void WaylandWindow::messageLoop()
{
while (wl_display_prepare_read(mDisplay) != 0)
wl_display_dispatch_pending(mDisplay);
if (wl_display_flush(mDisplay) < 0 && errno != EAGAIN)
{
wl_display_cancel_read(mDisplay);
return;
}
if (poll(fds, 1, 0) > 0)
{
wl_display_read_events(mDisplay);
wl_display_dispatch_pending(mDisplay);
}
else
{
wl_display_cancel_read(mDisplay);
}
}
void WaylandWindow::setMousePosition(int x, int y) {}
bool WaylandWindow::setOrientation(int width, int height)
{
return true;
}
bool WaylandWindow::setPosition(int x, int y)
{
return true;
}
bool WaylandWindow::resize(int width, int height)
{
wl_egl_window_resize(mWindow, width, height, 0, 0);
mWidth = width;
mHeight = height;
return true;
}
void WaylandWindow::setVisible(bool isVisible) {}
void WaylandWindow::signalTestEvent() {}
bool IsWaylandWindowAvailable()
{
wl_display *display = wl_display_connect(nullptr);
if (!display)
{
return false;
}
wl_display_disconnect(display);
return true;
}