Skip to content

Commit

Permalink
Test Ladybird
Browse files Browse the repository at this point in the history
  • Loading branch information
shlyakpavel committed Nov 13, 2024
1 parent d8e0643 commit 58bd010
Show file tree
Hide file tree
Showing 12 changed files with 1,964 additions and 1,876 deletions.
3,360 changes: 1,680 additions & 1,680 deletions results.csv

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tools/vdiff/src/exportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ExportDialog::ExportDialog(const QList<Backend> &backends, QWidget *parent)
ui->chBoxBInkscape->setEnabled(backends.contains(Backend::Inkscape));
ui->chBoxBLibrsvg->setEnabled(backends.contains(Backend::Librsvg));
ui->chBoxBQtSvg->setEnabled(backends.contains(Backend::QtSvg));
ui->chBoxBLadybird->setEnabled(backends.contains(Backend::Ladybird));

ui->chBoxBResvg->setChecked(backends.contains(Backend::Resvg));
ui->chBoxBChrome->setChecked(backends.contains(Backend::Chrome));
Expand All @@ -27,6 +28,7 @@ ExportDialog::ExportDialog(const QList<Backend> &backends, QWidget *parent)
ui->chBoxBInkscape->setChecked(backends.contains(Backend::Inkscape));
ui->chBoxBLibrsvg->setChecked(backends.contains(Backend::Librsvg));
ui->chBoxBQtSvg->setChecked(backends.contains(Backend::QtSvg));
ui->chBoxBLadybird->setChecked(backends.contains(Backend::Ladybird));

ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Export");

Expand Down Expand Up @@ -54,6 +56,8 @@ ExportDialog::Options ExportDialog::options() const
if (ui->chBoxBInkscape->isChecked()) { opt.backends << Backend::Inkscape; }
if (ui->chBoxBLibrsvg->isChecked()) { opt.backends << Backend::Librsvg; }
if (ui->chBoxBQtSvg->isChecked()) { opt.backends << Backend::QtSvg; }
if (ui->chBoxBLadybird->isChecked()) { opt.backends << Backend::Ladybird; }


return opt;
}
15 changes: 11 additions & 4 deletions tools/vdiff/src/exportdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chBoxBLadybird">
<property name="text">
<string>Ladybird</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -135,7 +142,7 @@
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -152,10 +159,10 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down
4 changes: 4 additions & 0 deletions tools/vdiff/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ void MainWindow::prepareBackends()
backends << Backend::QtSvg;
}

if (m_settings.useLadybird) {
backends << Backend::Ladybird;
}


for (const Backend backend : backends) {
auto w = new BackendWidget(backend);
Expand Down
44 changes: 42 additions & 2 deletions tools/vdiff/src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QXmlStreamReader>
#include <QtConcurrent/QtConcurrentMap>
#include <QtConcurrent/QtConcurrentRun>
#include <QDir>

#include <cmath>

Expand Down Expand Up @@ -307,6 +308,40 @@ QImage Render::renderViaQtSvg(const RenderData &data)
return loadImage(outImg);
}

QImage Render::renderViaLadybird(const RenderData& data)
{
// Define the default output image path
const auto defaultOutImg = Paths::workDir() + "/output.png"; // Ladybird default output file

// Construct the command and arguments with fixed 500x500 viewport
QString command = "/Users/Pavel/Develop/ladybird/Build/release/bin/Ladybird.app/Contents/MacOS/headless-browser";
QStringList arguments = {
"--screenshot=1", // Take screenshot after 1 second
"--width=500", // Set viewport width to 500 pixels
"--height=500", // Set viewport height to 500 pixels
data.imgPath // Path to the SVG file to render
};

// Change working directory to ensure the output goes where expected
QDir::setCurrent(Paths::workDir());

// Execute the command
const QString out = Process::run(command, arguments, true);

if (!out.isEmpty()) {
qDebug().noquote() << "Ladybird output:" << out;
}

// Check if the default output file was created
QFile file(defaultOutImg);
if (!file.exists()) {
throw QString("Failed to generate output image: %1").arg(defaultOutImg);
}

return loadImage(defaultOutImg);
}


void Render::renderImages()
{
const auto ts = m_settings->testSuite;
Expand Down Expand Up @@ -372,6 +407,10 @@ void Render::renderImages()
list.append({ Backend::QtSvg, m_viewSize, imageSize, m_imgPath, QString(), ts });
}

if (m_settings->useLadybird) {
renderCached(Backend::Ladybird, m_imgPath);
}

const auto future = QtConcurrent::mapped(list, &Render::renderImage);
m_watcher1.setFuture(future);
}
Expand Down Expand Up @@ -402,6 +441,7 @@ RenderResult Render::renderImage(const RenderData &data)
case Backend::Inkscape : img = renderViaInkscape(data); break;
case Backend::Librsvg : img = renderViaRsvg(data); break;
case Backend::QtSvg : img = renderViaQtSvg(data); break;
case Backend::Ladybird : img = renderViaLadybird(data); break;
}

return { data.type, img };
Expand Down Expand Up @@ -525,7 +565,7 @@ void Render::onImagesRendered()
}
};

for (int t = (int)Backend::Firefox; t <= (int)Backend::QtSvg; ++t) {
for (int t = (int)Backend::Firefox; t <= (int)Backend::Ladybird; ++t) {
append((Backend)t);
}

Expand All @@ -541,7 +581,7 @@ void Render::onImagesRendered()
}
};

for (int t = (int)Backend::Chrome; t <= (int)Backend::QtSvg; ++t) {
for (int t = (int)Backend::Chrome; t <= (int)Backend::Ladybird; ++t) {
append((Backend)t);
}

Expand Down
1 change: 1 addition & 0 deletions tools/vdiff/src/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Render : public QObject
static QImage renderViaInkscape(const RenderData &data);
static QImage renderViaRsvg(const RenderData &data);
static QImage renderViaQtSvg(const RenderData &data);
static QImage renderViaLadybird(const RenderData &data);
static RenderResult renderImage(const RenderData &data);
static DiffOutput diffImage(const DiffData &data);

Expand Down
3 changes: 3 additions & 0 deletions tools/vdiff/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Key {
static const QString UseSvgNet = "UseSvgNet";
static const QString UseLibrsvg = "UseLibrsvg";
static const QString UseQtSvg = "UseQtSvg";
static const QString UseLadybird = "UseLadybird";
static const QString ViewSize = "ViewSize";
}

Expand Down Expand Up @@ -72,6 +73,7 @@ void Settings::load() noexcept
this->useLibrsvg = appSettings.value(Key::UseLibrsvg).toBool();
this->useSvgNet = appSettings.value(Key::UseSvgNet).toBool();
this->useQtSvg = appSettings.value(Key::UseQtSvg).toBool();
this->useLadybird = appSettings.value(Key::UseLadybird).toBool();

this->resvgDir = appSettings.value(Key::ResvgDir).toString();
this->firefoxPath = appSettings.value(Key::FirefoxPath).toString();
Expand All @@ -95,6 +97,7 @@ void Settings::save() const noexcept
appSettings.setValue(Key::UseLibrsvg, this->useLibrsvg);
appSettings.setValue(Key::UseSvgNet, this->useSvgNet);
appSettings.setValue(Key::UseQtSvg, this->useQtSvg);
appSettings.setValue(Key::UseLadybird, this->useLadybird);
appSettings.setValue(Key::ResvgDir, this->resvgDir);
appSettings.setValue(Key::FirefoxPath, this->firefoxPath);
appSettings.setValue(Key::BatikPath, this->batikPath);
Expand Down
1 change: 1 addition & 0 deletions tools/vdiff/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Settings
bool useLibrsvg = true;
bool useSvgNet = true;
bool useQtSvg = true;
bool useLadybird = true;
QString resvgDir; // it's a dir, not a path
QString firefoxPath;
QString batikPath;
Expand Down
3 changes: 3 additions & 0 deletions tools/vdiff/src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void SettingsDialog::loadSettings()

ui->chBoxUseQtSvg->setChecked(m_settings->useQtSvg);

ui->chBoxUseLadybird->setChecked(m_settings->useLadybird);

prepareTestsPathWidgets();
}

Expand Down Expand Up @@ -95,6 +97,7 @@ void SettingsDialog::on_buttonBox_accepted()
m_settings->useLibrsvg = ui->chBoxUseLibrsvg->isChecked();
m_settings->useSvgNet = ui->chBoxUseSvgNet->isChecked();
m_settings->useQtSvg = ui->chBoxUseQtSvg->isChecked();
m_settings->useLadybird = ui->chBoxUseLadybird->isChecked();

m_settings->resvgDir = ui->lineEditResvg->text();
m_settings->firefoxPath = ui->lineEditFirefox->text();
Expand Down
Loading

0 comments on commit 58bd010

Please sign in to comment.