Truly independent web browser
/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <AK/Weakable.h>
#include <AK/kmalloc.h>
#include <Compositor/PresentableSurface.h>
#include <Compositor/RemoteLayer.h>
#include <LibGfx/Size.h>
namespace Compositor {
// The window server, as this process reaches it for the views of one presentation.
class WindowServer
: public RefCounted<WindowServer>
, public Weakable<WindowServer> {
AK_MAKE_NONCOPYABLE(WindowServer);
AK_MAKE_NONMOVABLE(WindowServer);
public:
AK_ALLOC_WITH_KMALLOC;
// None where frames reach the screen only through the presentation.
static RefPtr<WindowServer> try_create_for_presentation();
virtual ~WindowServer() = default;
virtual OwnPtr<RemoteLayer> try_create_remote_layer(u64 remote_layer_id) = 0;
virtual ErrorOr<NonnullRefPtr<PresentableSurface>> try_create_presentable_surface(Gfx::IntSize, RefPtr<Gfx::SkiaBackendContext> const&) = 0;
// None where no window server shows surfaces above the frames.
static ErrorOr<RefPtr<PresentableSurface>> try_create_presentable_surface_for_sublayers(Gfx::IntSize, Gfx::SkiaBackendContext&);
// Whether a remote layer of this window server shows each tile of a painted layer as a sublayer of its own, in a
// group that places and clips the tiles of the layer, so that it can show every layer of a frame by itself.
virtual bool shows_tiles_of_painted_layers() const { return false; }
// Whether no window server shows tiles, as asked by the environment, which lets a frame composited by the window
// server be told apart from one composited into a store.
static bool showing_tiles_of_painted_layers_is_switched_off();
// Whether a remote layer of this window server runs what it shows below a sublayer through a blur and color
// matrices, as a backdrop filter does.
virtual bool filters_what_is_below_layers() const { return false; }
enum class FrameHandOff : u8 {
OnceGpuWorkIsScheduled,
OnceGpuWorkIsFinished,
};
virtual FrameHandOff frame_hand_off() const = 0;
static FrameHandOff frame_hand_off_through_presentation();
// While held, what every remote layer of this window server shows changes nowhere on screen, and changes all at once
// when released.
virtual void hold_changes_on_screen() = 0;
virtual void release_changes_held_off_screen() = 0;
protected:
WindowServer() = default;
};
}