Commit f49fe7bc authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/wayland: Use new shmen API when loading keymap

Modify WaylandKeyboard keymap handling method to use the brand new
SharedMemory API rather than raw mmap/munmap calls. This does not
implies in any behavioral change.

Bug: 578890, 795291
Change-Id: I7e5a0495b96af84a114414ce34268410d2cee57b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637627Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#665210}
parent 85670e9f
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include "ui/ozone/platform/wayland/host/wayland_keyboard.h" #include "ui/ozone/platform/wayland/host/wayland_keyboard.h"
#include <sys/mman.h>
#include <utility> #include <utility>
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/unguessable_token.h"
#include "ui/base/buildflags.h" #include "ui/base/buildflags.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -58,25 +59,26 @@ WaylandKeyboard::~WaylandKeyboard() {} ...@@ -58,25 +59,26 @@ WaylandKeyboard::~WaylandKeyboard() {}
void WaylandKeyboard::Keymap(void* data, void WaylandKeyboard::Keymap(void* data,
wl_keyboard* obj, wl_keyboard* obj,
uint32_t format, uint32_t format,
int32_t raw_fd, int32_t keymap_fd,
uint32_t size) { uint32_t size) {
WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data); WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
DCHECK(keyboard); DCHECK(keyboard);
base::ScopedFD fd(raw_fd); base::ScopedFD fd(keymap_fd);
if (!data || format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) auto length = size - 1;
return; auto shmen = base::subtle::PlatformSharedMemoryRegion::Take(
std::move(fd), base::subtle::PlatformSharedMemoryRegion::Mode::kUnsafe,
length, base::UnguessableToken::Create());
auto mapped_memory =
base::UnsafeSharedMemoryRegion::Deserialize(std::move(shmen)).Map();
const char* keymap = mapped_memory.GetMemoryAs<char>();
char* keymap_str = reinterpret_cast<char*>( if (!keymap || format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)
mmap(nullptr, size, PROT_READ, MAP_SHARED, fd.get(), 0));
if (keymap_str == MAP_FAILED)
return; return;
auto length = strnlen(keymap_str, size); bool success = keyboard->layout_engine_->SetCurrentLayoutFromBuffer(
bool success = keymap, mapped_memory.size());
keyboard->layout_engine_->SetCurrentLayoutFromBuffer(keymap_str, length);
DCHECK(success) << "Failed to set the XKB keyboard mapping."; DCHECK(success) << "Failed to set the XKB keyboard mapping.";
munmap(keymap_str, size);
} }
void WaylandKeyboard::Enter(void* data, void WaylandKeyboard::Enter(void* data,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment