Skip to content

Truly independent web browser

11.6 KB
Raw Blame
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <LibCompositing/DisplayList/Canvas2DCommandStreamSegment.h>
#include <LibCompositing/DisplayList/DisplayListResources.h>
#include <LibCompositing/Forward.h>
#include <LibCompositing/Types.h>
#include <LibCompositing/Video/VideoFramePresentationPage.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibGfx/ColorSpace.h>
#include <LibGfx/DecodedImageFrame.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibGfx/Size.h>
#include <LibIPC/TransportHandle.h>
#include <LibMedia/VideoSinkHandle.h>
#include <LibWebCommon/Page/InputEvent.h>
#include <LibWebCommon/Page/InputTrace.h>

endpoint CompositorWebContentServer
{
    add_video_sink(Media::VideoSinkHandle video_sink_handle, NonnullRefPtr<Compositing::VideoFramePresentationPage> presentation_page) =|
    remove_video_sink(Media::VideoSinkHandle video_sink_handle) =|
    release_video_frame_hold(Media::VideoSinkHandle video_sink_handle, u64 generation) =|
    // Answered with video_sink_is_up_to_date() once the sink's frame follows its clock, which waits for it to tick.
    bring_video_sink_up_to_date(Media::VideoSinkHandle video_sink_handle, u64 token) =|

    // A channel to the image decoder of this WebContent, which the frames of its animated images come through.
    connect_to_image_decoder(IPC::TransportHandle handle) =|
    // The image frame with the id shows the frames of the image decoder's session, once the image is started.
    add_animated_image(u64 frame_id, i64 session_id, Gfx::IntSize size, Gfx::ColorSpace color_space, Vector<u32> frame_durations_in_milliseconds, u32 loop_count) =|
    remove_animated_image(u64 frame_id) =|
    start_animated_image(u64 frame_id) =|
    stop_animated_image(u64 frame_id) =|
    animated_image_state_for_testing(u64 frame_id) => (bool is_animating, u32 frame_index, u32 shown_frame_index, u32 loops_completed)

    set_parent_context(Web::CompositorContextId context_id, Optional<Web::CompositorContextId> parent_context_id) =|
    stop_presenting_to_client(Web::CompositorContextId context_id) =|
    destroy_context(Web::CompositorContextId context_id) =|

    // A font names its typeface by the id the typeface was registered under, until the typeface is unregistered.
    register_typeface(Compositing::TypefaceRegistration registration) =|
    unregister_typeface(u64 typeface_id) =|

    // A display list, a visual context tree, a canvas 2D stream and a staged rasterization draw the image frames
    // that are registered under the ids they name. An image frame registered under an id that names another one
    // takes its place.
    register_image_frames(Vector<Compositing::DisplayListImageFrameResource> image_frames) =|
    unregister_image_frame(Compositing::ImageFrameResourceId image_frame_id) =|

    // The fonts that a display list draws go ahead of it, in describe_display_list_fonts. The context keeps the fonts
    // and the image frames that its display list and its visual context tree draw. Only Rust sends and receives the
    // display lists, the visual context trees, the scroll state snapshots and the plans of layers. A display list or a
    // tree without a plan leaves the context without one; a scroll state without one keeps the plan the context has.
    [RustReceiver, RustSender] update_display_list(Web::CompositorContextId context_id, Compositing::DisplayList display_list, Compositing::VisualContextTree visual_context_tree, Compositing::ScrollStateSnapshot scroll_state, Optional<Compositing::LayerPlan> layer_plan) =|
    describe_display_list_fonts(Web::CompositorContextId context_id, Vector<Compositing::DisplayListFontDescription> fonts) =|
    [RustReceiver, RustSender] update_visual_context_tree(Web::CompositorContextId context_id, Compositing::VisualContextTree visual_context_tree, Compositing::ScrollStateSnapshot scroll_state, Compositing::KeyboardScrollState keyboard_scroll_state, Optional<Compositing::LayerPlan> layer_plan) =|
    [RustReceiver, RustSender] update_scroll_state(Web::CompositorContextId context_id, Compositing::ScrollStateSnapshot scroll_state, Compositing::KeyboardScrollState keyboard_scroll_state, Optional<Compositing::LayerPlan> layer_plan) =|

    // Hands WebContent a range of canvas IDs it may name its own 2D contexts with, so creating one needs no round trip.
    [RustReceiver, RustSender] reserve_canvas_ids() => (Compositing::CanvasId first_canvas_id, u64 count)
    // The pixels of the context, and the colors of its commands, are in the color space.
    [RustReceiver, RustSender] create_canvas_2d_context(Compositing::CanvasId canvas_id, Gfx::IntSize size, bool alpha, bool will_read_frequently, Web::Bindings::PredefinedColorSpace color_space) =|
    // The fonts are those that the segments of the canvas 2D stream that follow draw. The fonts described before that
    // are not among them are released.
    describe_canvas_2d_fonts(Vector<Compositing::DisplayListFontDescription> fonts) =|
    [RustReceiver, RustSender] update_canvas_2d_stream(Vector<Compositing::Canvas2DCommandStreamSegment> segments) =|
    [RustReceiver, RustSender] destroy_canvas_2d_context(Compositing::CanvasId canvas_id) =|
    // The pixels come back in the color space.
    // Unpremultiplied pixels are RGBA8888 and premultiplied ones BGRA8888, as rows of the size answered.
    [RustReceiver, RustSender] read_back_canvas_2d_pixels(Compositing::CanvasId canvas_id, Gfx::IntRect rect, Gfx::AlphaType alpha_type, Web::Bindings::PredefinedColorSpace color_space, Core::AnonymousBuffer pixels) => (Gfx::IntSize size)

    allocate_placeholder_canvas() => (Compositing::CanvasId canvas_id, u64 secret)
    release_placeholder_canvas(Compositing::CanvasId canvas_id) =|
    commit_placeholder_canvas(Compositing::CanvasId canvas_id, u64 secret, Optional<Compositing::CanvasId> source_canvas_id, Gfx::IntSize size, bool origin_clean) =|
    get_placeholder_canvas_pixels(Compositing::CanvasId canvas_id, Gfx::IntRect rect) => (Gfx::ShareableBitmap pixels, bool origin_clean)

    // A display list is rasterized into the target bitmap with the fonts and the registered image frames staged for
    // it under a token that the next rasterize_display_list names.
    stage_rasterization(u64 token, Vector<Compositing::DisplayListFontDescription> fonts, Vector<Compositing::ImageFrameResourceId> image_frame_ids, Gfx::ShareableBitmap target_bitmap) =|
    [RustReceiver, RustSender] rasterize_display_list(u64 token, Compositing::DisplayList display_list, Compositing::VisualContextTree visual_context_tree) => (bool success)

    // Only Rust sends and receives the messages of WebGL contexts. The commands of a context name the images that they
    // upload by their position among the image sources sent with them.
    [RustReceiver, RustSender] create_webgl_context(Compositing::WebGL::WebGLVersion webgl_version, Gfx::IntSize size, bool depth, bool stencil, bool antialias) => (bool success, Compositing::CanvasId canvas_id, Vector<String> supported_extensions)
    [RustReceiver, RustSender] destroy_webgl_context(Compositing::CanvasId canvas_id) =|
    [RustReceiver, RustSender] webgl_set_command_buffer(Compositing::CanvasId canvas_id, Core::AnonymousBuffer command_buffer) =|
    [RustReceiver, RustSender] webgl_commands_from_shared_buffer(Compositing::CanvasId canvas_id, u64 offset, u64 size_in_bytes, u64 flush_sequence_number, Vector<Compositing::WebGL::ImageSource> image_sources) =|
    [RustReceiver, RustSender] webgl_drain_command_buffer(Compositing::CanvasId canvas_id) => ()
    [RustReceiver, RustSender] webgl_commands(Compositing::CanvasId canvas_id, Core::AnonymousBuffer commands, u64 size_in_bytes, Vector<Compositing::WebGL::ImageSource> image_sources) =|
    [RustReceiver, RustSender] webgl_present_canvas(Compositing::CanvasId canvas_id, bool preserve_drawing_buffer) =|
    [RustReceiver, RustSender] webgl_clear_drawing_buffer(Compositing::CanvasId canvas_id) =|
    [RustReceiver, RustSender] webgl_sync_call(Compositing::CanvasId canvas_id, ByteBuffer request) => (ByteBuffer reply)
    [RustReceiver, RustSender] webgl_read_pixels(Compositing::CanvasId canvas_id, i32 x, i32 y, i32 width, i32 height, u32 format, u32 type, i32 buf_size, Core::AnonymousBuffer pixels) => (i32 length, i32 columns, i32 rows)
    [RustReceiver, RustSender] webgl_read_buffer_sub_data(Compositing::CanvasId canvas_id, u32 target, i64 offset, i64 size, Core::AnonymousBuffer data) => (bool success)
    // The pixels of the drawing buffer that the rect covers, as premultiplied BGRA8888 rows of the size answered.
    [RustReceiver, RustSender] webgl_read_back_drawing_buffer(Compositing::CanvasId canvas_id, Gfx::IntRect rect, Core::AnonymousBuffer pixels) => (Gfx::IntSize size)

    [RustReceiver] invalidate_wheel_event_listener_state(Web::CompositorContextId context_id, u64 generation) =|
    [RustReceiver] invalidate_keyboard_scroll_state(Web::CompositorContextId context_id, u64 generation) => ()
    [RustReceiver] take_wheel_event_from_main_thread(Web::CompositorContextId context_id, Web::MouseEvent event, Compositing::AsyncScrollOperationTracking operation_tracking, Compositing::WheelEventRouting routing) => (Compositing::WheelEventAnswer answer)
    [RustReceiver] wheel_event_let_through(Web::CompositorContextId context_id, Compositing::WheelStepLetThrough step, Compositing::AsyncScrollOperationTracking operation_tracking) => (Compositing::WheelEventAnswer answer)
    [RustReceiver] wheel_event_canceled(Web::CompositorContextId context_id, u64 wheel_gesture_id) =|
    [RustReceiver, RustSender] apply_scroll_requests(Web::CompositorContextId context_id, Vector<Compositing::ScrollRequest> scroll_requests) =|
    [RustReceiver] scroll_state_for_testing(Web::CompositorContextId context_id, Web::AsyncScrollNodeStableID stretched_scroller) => (String scroll_state)
    // Returns once the compositor has handled every message WebContent sent before it.
    synchronize_for_testing() => ()
    [RustReceiver] route_first_wheel_step_for_testing(Web::CompositorContextId context_id, Gfx::FloatPoint position, Gfx::FloatPoint delta_in_css_pixels) => (Optional<Web::InputRoutingDecision> decision, Optional<Web::AsyncScrollNodeStableID> scroller, Optional<Web::UniqueNodeID> document_id)
    [RustReceiver] begin_input_trace_for_testing(Web::CompositorContextId context_id) => ()
    [RustReceiver] clear_per_test_input_state_for_testing(Web::CompositorContextId context_id) => ()
    [RustReceiver] take_input_trace_for_testing(Web::CompositorContextId context_id) => (Vector<Web::InputTraceRecord> records)

    [RustReceiver] take_pending_async_scroll_updates(Web::CompositorContextId context_id) => (Compositing::PendingAsyncScrollUpdates updates)
    viewport_size_updated(Web::CompositorContextId context_id, Gfx::IntSize viewport_size, double device_pixel_ratio, Compositing::WindowResizingInProgress window_resize_in_progress) =|
    request_rendering_opportunity(Web::CompositorContextId context_id, double maximum_frames_per_second) =|
    hurry_rendering_opportunity(Web::CompositorContextId context_id) =|
    [RustSender] present_frame(Web::CompositorContextId context_id, Gfx::IntRect viewport_rect) =|
    request_screenshot(Web::CompositorContextId context_id, Compositing::ScreenshotRequestId request_id, Gfx::ShareableBitmap target_bitmap) =|
    // Has the processes that own the context's descendants in other processes paint them, and answers with
    // remote_descendants_prepared_for_screenshot() once the compositor has their frames.
    prepare_remote_descendants_for_screenshot(Web::CompositorContextId context_id, u64 request_id) =|
    // Answers paint_contexts_for_screenshot() once this process has handed the compositor the contexts' frames.
    did_paint_contexts_for_screenshot(u64 preparation_id) =|
}