mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
WindowServer: Create the VirtualScreenBackend
This screen backend is just memory-backed and doesn't connect to any screen hardware. That way, we can boot Serenity without video hardware but in full graphical mode :^) To create a virtual screen, put something like this in your WindowServer.ini. There's no way yet to do this through Display Settings, though an existing virtual screen's settings can be changed there. ```ini [Screen0] Mode=Virtual Left=1024 Top=0 Width=1920 Height=1080 ScaleFactor=1 ```
This commit is contained in:
parent
be98ce0f9f
commit
935f401714
4 changed files with 140 additions and 4 deletions
|
@ -26,6 +26,7 @@ set(SOURCES
|
||||||
Overlays.cpp
|
Overlays.cpp
|
||||||
Screen.cpp
|
Screen.cpp
|
||||||
HardwareScreenBackend.cpp
|
HardwareScreenBackend.cpp
|
||||||
|
VirtualScreenBackend.cpp
|
||||||
ScreenLayout.cpp
|
ScreenLayout.cpp
|
||||||
Window.cpp
|
Window.cpp
|
||||||
WindowFrame.cpp
|
WindowFrame.cpp
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "EventLoop.h"
|
#include "EventLoop.h"
|
||||||
#include "ScreenBackend.h"
|
#include "ScreenBackend.h"
|
||||||
|
#include "VirtualScreenBackend.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
@ -228,8 +229,8 @@ bool Screen::open_device()
|
||||||
close_device();
|
close_device();
|
||||||
auto& info = screen_layout_info();
|
auto& info = screen_layout_info();
|
||||||
|
|
||||||
// TODO: Support other backends
|
switch (info.mode) {
|
||||||
if (info.mode == ScreenLayout::Screen::Mode::Device) {
|
case ScreenLayout::Screen::Mode::Device: {
|
||||||
m_backend = make<HardwareScreenBackend>(info.device.value());
|
m_backend = make<HardwareScreenBackend>(info.device.value());
|
||||||
auto return_value = m_backend->open();
|
auto return_value = m_backend->open();
|
||||||
if (return_value.is_error()) {
|
if (return_value.is_error()) {
|
||||||
|
@ -240,10 +241,19 @@ bool Screen::open_device()
|
||||||
set_resolution(true);
|
set_resolution(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case ScreenLayout::Screen::Mode::Virtual: {
|
||||||
|
m_backend = make<VirtualScreenBackend>();
|
||||||
|
// Virtual device open should never fail.
|
||||||
|
MUST(m_backend->open());
|
||||||
|
|
||||||
|
set_resolution(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
dbgln("Unsupported screen type {}", ScreenLayout::Screen::mode_to_string(info.mode));
|
dbgln("Unsupported screen type {}", ScreenLayout::Screen::mode_to_string(info.mode));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Screen::close_device()
|
void Screen::close_device()
|
||||||
{
|
{
|
||||||
|
|
81
Userland/Services/WindowServer/VirtualScreenBackend.cpp
Normal file
81
Userland/Services/WindowServer/VirtualScreenBackend.cpp
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020, the SerenityOS developers.
|
||||||
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "VirtualScreenBackend.h"
|
||||||
|
#include "ScreenBackend.h"
|
||||||
|
#include <AK/Try.h>
|
||||||
|
#include <AK/kmalloc.h>
|
||||||
|
#include <LibGfx/Color.h>
|
||||||
|
|
||||||
|
namespace WindowServer {
|
||||||
|
|
||||||
|
VirtualScreenBackend::~VirtualScreenBackend()
|
||||||
|
{
|
||||||
|
MUST(unmap_framebuffer());
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> VirtualScreenBackend::open()
|
||||||
|
{
|
||||||
|
m_can_device_flush_buffers = true;
|
||||||
|
m_can_set_head_buffer = true;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void VirtualScreenBackend::set_head_buffer(int index)
|
||||||
|
{
|
||||||
|
VERIFY(index <= 1 && index >= 0);
|
||||||
|
m_first_buffer_active = index == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> VirtualScreenBackend::set_head_resolution(FBHeadResolution resolution)
|
||||||
|
{
|
||||||
|
if (resolution.head_index != 0)
|
||||||
|
return Error::from_string_literal("Only head index 0 is supported."sv);
|
||||||
|
m_height = resolution.height;
|
||||||
|
|
||||||
|
if (resolution.pitch == 0)
|
||||||
|
resolution.pitch = static_cast<int>(resolution.width * sizeof(Gfx::ARGB32));
|
||||||
|
m_pitch = resolution.pitch;
|
||||||
|
if (static_cast<int>(resolution.width * sizeof(Gfx::ARGB32)) != resolution.pitch)
|
||||||
|
return Error::from_string_literal("Unsupported pitch"sv);
|
||||||
|
|
||||||
|
m_width = resolution.width;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<FBHeadProperties> VirtualScreenBackend::get_head_properties()
|
||||||
|
{
|
||||||
|
return FBHeadProperties {
|
||||||
|
.head_index = 0,
|
||||||
|
.pitch = static_cast<unsigned>(m_pitch),
|
||||||
|
.width = static_cast<unsigned>(m_width),
|
||||||
|
.height = static_cast<unsigned>(m_height),
|
||||||
|
.offset = static_cast<unsigned>(m_first_buffer_active ? 0 : m_back_buffer_offset),
|
||||||
|
.buffer_length = static_cast<unsigned>(m_size_in_bytes),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> VirtualScreenBackend::map_framebuffer()
|
||||||
|
{
|
||||||
|
m_size_in_bytes = static_cast<unsigned long>(m_pitch) * m_height * 2;
|
||||||
|
m_framebuffer = new Gfx::ARGB32[static_cast<unsigned long>(m_width) * m_height * 2];
|
||||||
|
if (m_framebuffer == nullptr)
|
||||||
|
return Error::from_errno(ENOMEM);
|
||||||
|
|
||||||
|
m_back_buffer_offset = m_size_in_bytes / 2;
|
||||||
|
m_first_buffer_active = true;
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> VirtualScreenBackend::unmap_framebuffer()
|
||||||
|
{
|
||||||
|
delete[] m_framebuffer;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
Userland/Services/WindowServer/VirtualScreenBackend.h
Normal file
44
Userland/Services/WindowServer/VirtualScreenBackend.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ScreenBackend.h"
|
||||||
|
#include "ScreenLayout.h"
|
||||||
|
#include <AK/Error.h>
|
||||||
|
#include <AK/Span.h>
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <sys/ioctl_numbers.h>
|
||||||
|
|
||||||
|
namespace WindowServer {
|
||||||
|
|
||||||
|
class VirtualScreenBackend : public ScreenBackend {
|
||||||
|
public:
|
||||||
|
virtual ~VirtualScreenBackend();
|
||||||
|
|
||||||
|
VirtualScreenBackend() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Screen;
|
||||||
|
|
||||||
|
virtual ErrorOr<void> open() override;
|
||||||
|
|
||||||
|
virtual void set_head_buffer(int index) override;
|
||||||
|
|
||||||
|
virtual ErrorOr<void> flush_framebuffer_rects(int, Span<FBRect const>) override { return {}; }
|
||||||
|
|
||||||
|
virtual ErrorOr<void> unmap_framebuffer() override;
|
||||||
|
virtual ErrorOr<void> map_framebuffer() override;
|
||||||
|
|
||||||
|
virtual ErrorOr<void> set_head_resolution(FBHeadResolution) override;
|
||||||
|
virtual ErrorOr<FBHeadProperties> get_head_properties() override;
|
||||||
|
|
||||||
|
int m_height { 0 };
|
||||||
|
int m_width { 0 };
|
||||||
|
bool m_first_buffer_active { true };
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue