Skip to content

Commit

Permalink
feat(browser): introduce quadrant rendering (#120)
Browse files Browse the repository at this point in the history
Fixes #28
Fixes #55
Fixes #78
  • Loading branch information
fathyb committed Feb 14, 2023
1 parent 6b906b0 commit 6747498
Show file tree
Hide file tree
Showing 67 changed files with 3,318 additions and 1,284 deletions.
421 changes: 235 additions & 186 deletions .refloat/config.js

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,15 @@ RUN groupadd -r carbonyl && \
mkdir -p /carbonyl/data && \
chown -R carbonyl:carbonyl /carbonyl && \
apt-get update && \
apt-get install -y \
libasound2 libatk-bridge2.0-0 libatk1.0-0 libatomic1 libatspi2.0-0 \
libbrotli1 libc6 libcairo2 libcups2 libdbus-1-3 libdouble-conversion3 \
libdrm2 libevent-2.1-7 libexpat1 libflac8 libfontconfig1 libfreetype6 \
libgbm1 libgcc-s1 libglib2.0-0 libjpeg62-turbo libjsoncpp24 liblcms2-2 \
libminizip1 libnspr4 libnss3 libopenjp2-7 libopus0 libpango-1.0-0 \
libpng16-16 libpulse0 libre2-9 libsnappy1v5 libstdc++6 libwebp6 \
libwebpdemux2 libwebpmux3 libwoff1 libx11-6 libxcb1 libxcomposite1 \
libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxml2 libxnvctrl0 \
libxrandr2 libxslt1.1 zlib1g libgtk-3-0 && \
apt-get install -y libasound2 libexpat1 libfontconfig1 libnss3 && \
rm -rf /var/lib/apt/lists/*

USER carbonyl
VOLUME /carbonyl/data
ENV HOME=/carbonyl/data

COPY . /carbonyl

RUN /carbonyl/carbonyl --version

ENTRYPOINT ["/carbonyl/carbonyl", "--no-sandbox", "--disable-dev-shm-usage", "--user-data-dir=/carbonyl/data"]
5 changes: 1 addition & 4 deletions chromium/patches/chromium/0001-Add-Carbonyl-library.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0ed9a390f25d73492ce1170ce229b95772fd458d Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:20:50 +0100
Subject: [PATCH 1/9] Add Carbonyl library
Subject: [PATCH 01/14] Add Carbonyl library

---
carbonyl/build | 1 +
Expand Down Expand Up @@ -66,6 +66,3 @@ index bfae1e3290de0..8018111ed9898 100644

if (!headless_use_embedded_resources) {
data = [
--
2.38.1

5 changes: 1 addition & 4 deletions chromium/patches/chromium/0002-Add-Carbonyl-service.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 795b29828fd7ac95548c4dcab483cbc3b6c1d361 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:21:59 +0100
Subject: [PATCH 2/9] Add Carbonyl service
Subject: [PATCH 02/14] Add Carbonyl service

---
cc/trees/layer_tree_host.cc | 21 ++
Expand Down Expand Up @@ -637,6 +637,3 @@ index 089a11b156ade..dfdc79eacce3b 100644
ShapeResultBloberizer::FillGlyphsNG bloberizer(
GetFontDescription(), device_scale_factor > 1.0f, text_info.text,
text_info.from, text_info.to, text_info.shape_result,
--
2.38.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From eea9662f4ba08a655057143d320e4e692fd92469 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:24:29 +0100
Subject: [PATCH 3/9] Setup shared software rendering surface
Subject: [PATCH 03/14] Setup shared software rendering surface

---
components/viz/host/host_display_client.cc | 4 +++-
Expand Down Expand Up @@ -224,6 +224,3 @@ index 50cea82c6b477..f024e6013bfb9 100644
// The root of the Layer tree drawn by this compositor.
raw_ptr<Layer> root_layer_ = nullptr;

--
2.38.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From c960c9b1f7ef3f16b27e4eaa4896e3563c88ea91 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:27:27 +0100
Subject: [PATCH 4/9] Setup browser default settings
Subject: [PATCH 04/14] Setup browser default settings

---
headless/public/headless_browser.cc | 4 ++--
Expand Down Expand Up @@ -46,6 +46,3 @@ index 48efaa7d57ca2..afc0236147519 100644

// Whether or not BeginFrames will be issued over DevTools protocol
// (experimental).
--
2.38.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 481ff19118891fe65e80b8be0e1f4498874d3b56 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:28:35 +0100
Subject: [PATCH 5/9] Remove some debug assertions
Subject: [PATCH 05/14] Remove some debug assertions

---
.../browser/web_contents/web_contents_impl.cc | 1 -
Expand Down Expand Up @@ -124,6 +124,3 @@ index 2518b71275670..3a1b8e6646c43 100644
}

void GraphicsContext::CopyConfigFrom(GraphicsContext& other) {
--
2.38.1

67 changes: 46 additions & 21 deletions chromium/patches/chromium/0006-Setup-display-DPI.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
From 5693445bf736c51d3255c10115767ba8886d68da Mon Sep 17 00:00:00 2001
From cc9c37adb3ad2613a114bd37e1fde43f83951d88 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:29:34 +0100
Subject: [PATCH 6/9] Setup display DPI
Date: Sun, 12 Feb 2023 01:00:43 +0100
Subject: [PATCH 06/14] Setup display DPI

---
.../lib/browser/headless_browser_impl_aura.cc | 9 +---
headless/lib/browser/headless_screen.cc | 2 +-
ui/display/display.cc | 50 +++++++++----------
3 files changed, 28 insertions(+), 33 deletions(-)
.../lib/browser/headless_browser_impl_aura.cc | 11 ++--
headless/lib/browser/headless_screen.cc | 5 +-
ui/display/display.cc | 52 ++++++++++---------
3 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/headless/lib/browser/headless_browser_impl_aura.cc b/headless/lib/browser/headless_browser_impl_aura.cc
index 81261215c702f..b8eb5fc429a2a 100644
index 81261215c702f..508660db32151 100644
--- a/headless/lib/browser/headless_browser_impl_aura.cc
+++ b/headless/lib/browser/headless_browser_impl_aura.cc
@@ -57,13 +57,8 @@ void HeadlessBrowserImpl::PlatformSetWebContentsBounds(
@@ -19,6 +19,8 @@
#include "ui/events/devices/device_data_manager.h"
#include "ui/gfx/geometry/rect.h"

+#include "carbonyl/src/browser/bridge.h"
+
namespace headless {

void HeadlessBrowserImpl::PlatformInitialize() {
@@ -57,13 +59,8 @@ void HeadlessBrowserImpl::PlatformSetWebContentsBounds(
const gfx::Rect& bounds) {
// Browser's window bounds should contain all web contents, so that we're sure
// that we will actually produce visible damage when taking a screenshot.
Expand All @@ -24,29 +33,48 @@ index 81261215c702f..b8eb5fc429a2a 100644
- std::max(old_host_bounds.height(), bounds.y() + bounds.height()));
- web_contents->window_tree_host()->SetBoundsInPixels(new_host_bounds);
- web_contents->window_tree_host()->window()->SetBounds(new_host_bounds);
+ web_contents->window_tree_host()->SetBoundsInPixels(ScaleToEnclosedRect(bounds, 1.0 / 7.0));
+ web_contents->window_tree_host()->SetBoundsInPixels(ScaleToEnclosedRect(bounds, carbonyl::Renderer::GetDPI()));
+ web_contents->window_tree_host()->window()->SetBounds(bounds);

gfx::NativeView native_view = web_contents->web_contents()->GetNativeView();
native_view->SetBounds(bounds);
diff --git a/headless/lib/browser/headless_screen.cc b/headless/lib/browser/headless_screen.cc
index 28f1a65f6dce5..e595735be187b 100644
index 28f1a65f6dce5..8bf00ef5e036a 100644
--- a/headless/lib/browser/headless_screen.cc
+++ b/headless/lib/browser/headless_screen.cc
@@ -49,7 +49,7 @@ display::Display HeadlessScreen::GetDisplayNearestWindow(
@@ -13,6 +13,8 @@
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/native_widget_types.h"

+#include "carbonyl/src/browser/bridge.h"
+
namespace headless {

// static
@@ -49,7 +51,8 @@ display::Display HeadlessScreen::GetDisplayNearestWindow(
HeadlessScreen::HeadlessScreen(const gfx::Rect& screen_bounds) {
static int64_t synthesized_display_id = 2000;
display::Display display(synthesized_display_id++);
- display.SetScaleAndBounds(1.0f, screen_bounds);
+ display.SetScaleAndBounds(1.0f / 7.0, ScaleToEnclosedRect(screen_bounds, 1.0 / 7.0));
+ float dpi = carbonyl::Renderer::GetDPI();
+ display.SetScaleAndBounds(dpi, ScaleToEnclosedRect(screen_bounds, dpi));
ProcessDisplayChanged(display, true /* is_primary */);
}

diff --git a/ui/display/display.cc b/ui/display/display.cc
index 466ef1fd1fe6e..cb503dc5cda0f 100644
index 466ef1fd1fe6e..1d71f3b4c9857 100644
--- a/ui/display/display.cc
+++ b/ui/display/display.cc
@@ -39,22 +39,22 @@ float g_forced_device_scale_factor = -1.0;
@@ -21,6 +21,8 @@
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/icc_profile.h"

+#include "carbonyl/src/browser/bridge.h"
+
namespace display {
namespace {

@@ -39,22 +41,22 @@ float g_forced_device_scale_factor = -1.0;
constexpr float kDisplaySizeAllowanceEpsilon = 0.01f;

bool HasForceDeviceScaleFactorImpl() {
Expand Down Expand Up @@ -78,11 +106,11 @@ index 466ef1fd1fe6e..cb503dc5cda0f 100644
+ // scale_in_double = 1.0;
+ // }
+ // }
+ return 1.0 / 7.0;
+ return carbonyl::Bridge::GetCurrent()->GetDPI();
}

const char* ToRotationString(display::Display::Rotation rotation) {
@@ -97,11 +97,11 @@ void Display::ResetForceDeviceScaleFactorForTesting() {
@@ -97,11 +99,11 @@ void Display::ResetForceDeviceScaleFactorForTesting() {
// static
void Display::SetForceDeviceScaleFactor(double dsf) {
// Reset any previously set values and unset the flag.
Expand All @@ -98,7 +126,7 @@ index 466ef1fd1fe6e..cb503dc5cda0f 100644
}

// static
@@ -273,15 +273,15 @@ void Display::SetScaleAndBounds(float device_scale_factor,
@@ -273,15 +275,15 @@ void Display::SetScaleAndBounds(float device_scale_factor,
}

void Display::SetScale(float device_scale_factor) {
Expand All @@ -122,6 +150,3 @@ index 466ef1fd1fe6e..cb503dc5cda0f 100644
}

void Display::SetSize(const gfx::Size& size_in_pixel) {
--
2.38.1

7 changes: 2 additions & 5 deletions chromium/patches/chromium/0007-Disable-text-effects.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 5557ea65c9769fd0f99bd1f8eb58b05634f9faa2 Mon Sep 17 00:00:00 2001
From 022ed4d808369659eab4e83cd677eb974215c58c Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:31:17 +0100
Subject: [PATCH 7/9] Disable text effects
Subject: [PATCH 07/14] Disable text effects

---
.../core/paint/ng/ng_text_painter_base.cc | 30 ++++++++--------
Expand Down Expand Up @@ -108,6 +108,3 @@ index 67fbf128ea158..a645ba61c8597 100644
}

StyleIterator::StyleIterator(const BreakList<SkColor>* colors,
--
2.38.1

7 changes: 2 additions & 5 deletions chromium/patches/chromium/0008-Fix-text-layout.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1820cd34967c756d2459f4a2894492662edbf58b Mon Sep 17 00:00:00 2001
From 7b1f72900f704ffecc48c66da7ccd6de205b88f7 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:32:14 +0100
Subject: [PATCH 8/9] Fix text layout
Subject: [PATCH 08/14] Fix text layout

---
.../core/css/resolver/style_resolver.cc | 17 ++++++++++++++++-
Expand Down Expand Up @@ -42,6 +42,3 @@ index 6207b72d17cb9..79cb8c85b697f 100644
state.LoadPendingResources();

// Now return the style.
--
2.38.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0697c3ab8f52592b0a0d4241e2938b8e622a01f6 Mon Sep 17 00:00:00 2001
From 792e123bb57b1b379b0367b2568302e2cb0dc3c9 Mon Sep 17 00:00:00 2001
From: Fathy Boundjadj <hey@fathy.fr>
Date: Thu, 9 Feb 2023 03:32:30 +0100
Subject: [PATCH 9/9] Bridge browser into Carbonyl library
Subject: [PATCH 09/14] Bridge browser into Carbonyl library

---
headless/app/headless_shell.cc | 33 +-
Expand Down Expand Up @@ -645,6 +645,3 @@ index b80147fd06be8..09773596aa5ce 100644

content::WebContents* web_contents() const;
bool OpenURL(const GURL& url);
--
2.38.1

Loading

0 comments on commit 6747498

Please sign in to comment.