Skip to content

Commit ef6429d

Browse files
committed
feat: better true color detection
1 parent b7d3b74 commit ef6429d

29 files changed

+1270
-1093
lines changed

.cargo/config.toml

-3
This file was deleted.

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/build
2+
!/build/browser
3+
/chromium

Dockerfile

+19-60
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,22 @@
1-
FROM debian:11 AS build-env
2-
3-
ARG WORKDIR
4-
WORKDIR ${WORKDIR}
5-
6-
ENV PATH="${PATH}:/depot_tools"
7-
ENV CCACHE_DIR="${WORKDIR}/.ccache"
8-
ENV GIT_CACHE_PATH="${WORKDIR}/.git_cache"
9-
ENV DEBIAN_FRONTEND=noninteractive
10-
ENV CHROMIUM_BUILDTOOLS_PATH="${WORKDIR}/electron/src/buildtools"
11-
ENV CCACHE_DIR="${WORKDIR}/.ccache"
12-
ENV CCACHE_CPP2=yes
13-
ENV CCACHE_SLOPPINESS=time_macros
14-
RUN apt-get update && \
15-
apt-get install -y git sudo curl ccache python3 bzip2 xz-utils \
16-
binutils binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf binutils-mips64el-linux-gnuabi64 binutils-mipsel-linux-gnu bison bzip2 cdbs curl dbus-x11 devscripts dpkg-dev elfutils fakeroot flex git-core gperf libasound2 libasound2-dev libatk1.0-0 libatspi2.0-0 libatspi2.0-dev libbluetooth-dev libbrlapi-dev libbrlapi0.8 libbz2-1.0 libbz2-dev libc6 libc6-dev libcairo2 libcairo2-dev libcap-dev libcap2 libcups2 libcups2-dev libcurl4-gnutls-dev libdrm-dev libdrm2 libegl1 libelf-dev libevdev-dev libevdev2 libexpat1 libffi-dev libffi7 libfontconfig1 libfreetype6 libgbm-dev libgbm1 libgl1 libglib2.0-0 libglib2.0-dev libglu1-mesa-dev libgtk-3-0 libgtk-3-dev libinput-dev libinput10 libjpeg-dev libkrb5-dev libnspr4 libnspr4-dev libnss3 libnss3-dev libpam0g libpam0g-dev libpango-1.0-0 libpangocairo-1.0-0 libpci-dev libpci3 libpcre3 libpixman-1-0 libpng16-16 libpulse-dev libpulse0 libsctp-dev libspeechd-dev libspeechd2 libsqlite3-0 libsqlite3-dev libssl-dev libstdc++6 libudev-dev libudev1 libuuid1 libva-dev libvulkan-dev libvulkan1 libwayland-egl1 libwayland-egl1-mesa libwww-perl libx11-6 libx11-xcb1 libxau6 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxinerama1 libxkbcommon-dev libxrandr2 libxrender1 libxshmfence-dev libxslt1-dev libxss-dev libxt-dev libxtst-dev libxtst6 locales mesa-common-dev openbox p7zip patch perl pkg-config rpm ruby subversion uuid-dev wdiff x11-utils xcompmgr xz-utils zip zlib1g zstd && \
17-
curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
18-
apt-get install -y nodejs && \
19-
git clone --depth 1 --single-branch https://chromium.googlesource.com/chromium/tools/depot_tools.git /depot_tools && \
20-
ccache --max-size=256G
21-
22-
# Release binaries
23-
# ================
24-
FROM --platform=$BUILDPLATFORM debian:11 AS carbonyl-binaries
25-
26-
RUN apt-get update && apt-get install -y unzip
1+
FROM debian:bullseye-slim
2+
3+
RUN groupadd -r carbonyl && useradd -r -g carbonyl carbonyl && \
4+
apt-get update && \
5+
apt-get install -y \
6+
libasound2 libatk-bridge2.0-0 libatk1.0-0 libatomic1 libatspi2.0-0 \
7+
libbrotli1 libc6 libcairo2 libcups2 libdbus-1-3 libdouble-conversion3 \
8+
libdrm2 libevent-2.1-7 libexpat1 libflac8 libfontconfig1 libfreetype6 \
9+
libgbm1 libgcc-s1 libglib2.0-0 libjpeg62-turbo libjsoncpp24 liblcms2-2 \
10+
libminizip1 libnspr4 libnss3 libopenjp2-7 libopus0 libpango-1.0-0 \
11+
libpng16-16 libpulse0 libre2-9 libsnappy1v5 libstdc++6 libwebp6 \
12+
libwebpdemux2 libwebpmux3 libwoff1 libx11-6 libxcb1 libxcomposite1 \
13+
libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxml2 libxnvctrl0 \
14+
libxrandr2 libxslt1.1 zlib1g libgtk-3-0 && \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
USER carbonyl
2718

2819
ARG TARGETARCH
29-
COPY electron/src/out/release-$TARGETARCH/dist.zip /runtime.zip
30-
RUN unzip /runtime.zip -d /runtime
31-
32-
# TypeScript build
33-
# ================
34-
FROM --platform=$BUILDPLATFORM node:18 AS carbonyl-js
35-
36-
WORKDIR /app
37-
COPY package.json yarn.lock /app/
38-
RUN yarn
39-
40-
COPY tsconfig.json /app/
41-
COPY src /app/src
42-
RUN yarn tsc -b
43-
44-
# Main image
45-
# ==========
46-
FROM node:18
47-
48-
RUN apt-get update && \
49-
apt-get install --yes \
50-
libglib2.0-0 libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libgtk-3-0 libgbm1 libasound2 \
51-
xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps \
52-
fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho fonts-ipafont-gothic fonts-unfonts-core fonts-noto-core
53-
54-
WORKDIR /app
55-
COPY package.json yarn.lock /app/
56-
RUN yarn --production
57-
58-
COPY --from=carbonyl-js /app/build /app/build
59-
COPY --from=carbonyl-binaries /runtime /app/build/runtime
60-
COPY /scripts/docker-entrypoint.sh /app/scripts/docker-entrypoint.sh
61-
62-
ENTRYPOINT ["/app/scripts/docker-entrypoint.sh"]
20+
COPY build/browser/${TARGETARCH:-amd64} /carbonyl
6321

22+
ENTRYPOINT ["/carbonyl/carbonyl", "--no-sandbox", "--disable-dev-shm-usage"]

chromium/.gclient

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
solutions = [
22
{
33
"name": "src",
4-
"url": "https://chromium.googlesource.com/chromium/src.git@111.0.5539.1",
4+
"url": "https://chromium.googlesource.com/chromium/src.git@111.0.5511.1",
55
"managed": False,
66
"custom_deps": {},
77
"custom_vars": {
88
"use_rust": True,
9+
"checkout_pgo_profiles": True,
910
}
1011
},
1112
]
File renamed without changes.

src/browser/bridge.cc

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "carbonyl/src/browser/bridge.h"
2+
3+
#include <memory>
4+
#include <iostream>
5+
#include <stdio.h>
6+
7+
#include "third_party/skia/include/core/SkColor.h"
8+
9+
extern "C" {
10+
11+
void* carbonyl_renderer_create();
12+
void carbonyl_renderer_clear_text(void* renderer);
13+
void carbonyl_input_listen(void* renderer, void* delegate);
14+
void carbonyl_renderer_draw_text(
15+
void* renderer,
16+
const char* utf8,
17+
const struct carbonyl_bridge_rect* rect,
18+
const struct carbonyl_bridge_color* color
19+
);
20+
void carbonyl_renderer_draw_background(
21+
void* renderer,
22+
const unsigned char* pixels,
23+
size_t pixels_size,
24+
const struct carbonyl_bridge_rect* rect
25+
);
26+
27+
}
28+
29+
namespace carbonyl {
30+
31+
namespace {
32+
static std::unique_ptr<Renderer> globalInstance;
33+
}
34+
35+
Renderer::Renderer(void* ptr): ptr_(ptr) {}
36+
37+
Renderer* Renderer::Main() {
38+
if (!globalInstance) {
39+
globalInstance = std::make_unique<Renderer>(
40+
carbonyl_renderer_create()
41+
);
42+
}
43+
44+
return globalInstance.get();
45+
}
46+
void Renderer::Listen(void* delegate) {
47+
carbonyl_input_listen(ptr_, delegate);
48+
}
49+
50+
void Renderer::ClearText() {
51+
carbonyl_renderer_clear_text(ptr_);
52+
}
53+
54+
void Renderer::DrawText(const std::string& text, const gfx::RectF& bounds, uint32_t sk_color) {
55+
struct carbonyl_bridge_rect rect;
56+
struct carbonyl_bridge_color color;
57+
58+
rect.origin.x = bounds.x();
59+
rect.origin.y = bounds.y();
60+
rect.size.width = bounds.width();
61+
rect.size.height = bounds.height();
62+
63+
color.r = SkColorGetR(sk_color);
64+
color.g = SkColorGetG(sk_color);
65+
color.b = SkColorGetB(sk_color);
66+
67+
carbonyl_renderer_draw_text(ptr_, text.c_str(), &rect, &color);
68+
}
69+
70+
void Renderer::DrawBackgrond(const unsigned char* pixels, size_t pixels_size, const gfx::Rect& bounds) {
71+
struct carbonyl_bridge_rect rect;
72+
73+
rect.origin.x = bounds.x();
74+
rect.origin.y = bounds.y();
75+
rect.size.width = bounds.width();
76+
rect.size.height = bounds.height();
77+
78+
carbonyl_renderer_draw_background(ptr_, pixels, pixels_size, &rect);
79+
}
80+
81+
}

src/browser/bridge.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef CARBONYL_SRC_BROWSER_BRIDGE_H_
2+
#define CARBONYL_SRC_BROWSER_BRIDGE_H_
3+
4+
#include <cstdint>
5+
6+
#include "ui/gfx/geometry/rect_f.h"
7+
8+
extern "C" {
9+
10+
struct carbonyl_bridge_size {
11+
unsigned int width;
12+
unsigned int height;
13+
};
14+
struct carbonyl_bridge_point {
15+
unsigned int x;
16+
unsigned int y;
17+
};
18+
struct carbonyl_bridge_rect {
19+
struct carbonyl_bridge_point origin;
20+
struct carbonyl_bridge_size size;
21+
};
22+
struct carbonyl_bridge_color {
23+
uint8_t r;
24+
uint8_t g;
25+
uint8_t b;
26+
};
27+
struct carbonyl_bridge_browser_delegate {
28+
void (*shutdown) ();
29+
void (*scroll) (int);
30+
void (*key_press) (char);
31+
void (*mouse_up) (unsigned int, unsigned int);
32+
void (*mouse_down) (unsigned int, unsigned int);
33+
void (*mouse_move) (unsigned int, unsigned int);
34+
};
35+
36+
void carbonyl_shell_main();
37+
void carbonyl_output_get_size(struct carbonyl_bridge_size* size);
38+
39+
} /* end extern "C" */
40+
41+
namespace carbonyl {
42+
43+
class Renderer {
44+
public:
45+
Renderer(void* ptr);
46+
47+
static Renderer* Main();
48+
49+
void Listen(void* delegate);
50+
void ClearText();
51+
void DrawText(const std::string& text, const gfx::RectF& bounds, uint32_t color);
52+
void DrawBackgrond(const unsigned char* pixels, size_t pixels_size, const gfx::Rect& bounds);
53+
54+
private:
55+
void* ptr_;
56+
};
57+
58+
}
59+
60+
#endif // CARBONYL_SRC_BROWSER_BRIDGE_H_
File renamed without changes.

0 commit comments

Comments
 (0)