Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include("${BLEND2D_DIR}/CMakeLists.txt")
# Dependencies - Probe
# ====================

pkg_check_modules(CTX ctx)
pkg_check_modules(CAIRO cairo)
find_package(unofficial-skia CONFIG)
find_package(Qt6 COMPONENTS Core Gui Widgets)
Expand Down Expand Up @@ -201,6 +202,13 @@ if(CAIRO_FOUND)
set(DEPENDENCY_CAIRO_DEFINITIONS BLEND2D_APPS_ENABLE_CAIRO)
endif()

if(CTX_FOUND)
message("-- [blend2d-apps] adding support for ctx")
set(DEPENDENCY_CTX_LIBRARIES ${CTX_LIBRARIES})
set(DEPENDENCY_CTX_INCLUDE_DIRS ${CTX_INCLUDE_DIRS})
set(DEPENDENCY_CTX_DEFINITIONS BLEND2D_APPS_ENABLE_CTX)
endif()

# Dependencies - SKIA (Optional)
# ==============================

Expand Down Expand Up @@ -234,6 +242,8 @@ set(BLEND2D_BENCH_SRC
bl_bench/module_blend2d.h
bl_bench/module_cairo.cpp
bl_bench/module_cairo.h
bl_bench/module_ctx.cpp
bl_bench/module_ctx.h
bl_bench/module_qt.cpp
bl_bench/module_qt.h
bl_bench/module_skia.cpp
Expand All @@ -245,9 +255,9 @@ set(BLEND2D_BENCH_SRC
add_executable(bl_bench ${BLEND2D_BENCH_SRC} ${ANTIGRAIN_SRC})
target_compile_features(bl_bench PUBLIC cxx_std_11)
set_property(TARGET bl_bench PROPERTY CXX_VISIBILITY_PRESET hidden)
target_include_directories(bl_bench PRIVATE ${DEPENDENCY_AGG_INCLUDE_DIRS} ${DEPENDENCY_CAIRO_INCLUDE_DIRS})
target_compile_definitions(bl_bench PRIVATE ${DEPENDENCY_AGG_DEFINITIONS} ${DEPENDENCY_CAIRO_DEFINITIONS} ${DEPENDENCY_QT_DEFINITIONS} ${DEPENDENCY_SKIA_DEFINITIONS})
target_link_libraries(bl_bench blend2d::blend2d ${DEPENDENCY_AGG_LIBRARUES} ${DEPENDENCY_CAIRO_LIBRARIES} ${DEPENDENCY_QT_LIBRARIES} ${DEPENDENCY_SKIA_LIBRARIES})
target_include_directories(bl_bench PRIVATE ${DEPENDENCY_AGG_INCLUDE_DIRS} ${DEPENDENCY_CAIRO_INCLUDE_DIRS} ${DEPENDENCY_CTX_INCLUDE_DITS})
target_compile_definitions(bl_bench PRIVATE ${DEPENDENCY_AGG_DEFINITIONS} ${DEPENDENCY_CAIRO_DEFINITIONS} ${DEPENDENCY_QT_DEFINITIONS} ${DEPENDENCY_SKIA_DEFINITIONS} ${DEPENDENCY_CTX_DEFINITIONS})
target_link_libraries(bl_bench blend2d::blend2d ${DEPENDENCY_AGG_LIBRARUES} ${DEPENDENCY_CAIRO_LIBRARIES} ${DEPENDENCY_QT_LIBRARIES} ${DEPENDENCY_SKIA_LIBRARIES} ${DEPENDENCY_CTX_LIBRARIES})
target_link_directories(bl_bench PRIVATE ${DEPENDENCY_CAIRO_LIBRARY_DIRS})

# Blend2D-Apps - Qt Demos
Expand Down
22 changes: 20 additions & 2 deletions bl_bench/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <type_traits>

#include "./app.h"
Expand All @@ -27,6 +29,10 @@
#include "./module_skia.h"
#endif // BLEND2D_APPS_ENABLE_SKIA

#if defined(BLEND2D_APPS_ENABLE_CTX)
#include "./module_ctx.h"
#endif // BLEND2D_APPS_ENABLE_CTX

#define ARRAY_SIZE(X) uint32_t(sizeof(X) / sizeof(X[0]))

namespace blbench {
Expand All @@ -50,6 +56,7 @@ static const char* benchIdNameList[] = {
"StrokeRectRot",
"StrokeRoundU",
"StrokeRoundRot",
"StrokeLine",
"StrokeTriangle",
"StrokePoly10",
"StrokePoly20",
Expand Down Expand Up @@ -245,8 +252,8 @@ void BenchApp::info() {
" --quantity=N [%d] Override the default quantity of each operation\n"
" --comp-op=X [%s] Benchmark a specific composition operator\n"
"\n",
no_yes[_deepBench],
no_yes[_saveImages],
no_yes[_deepBench],
no_yes[_isolated],
_repeat,
_quantity,
Expand Down Expand Up @@ -310,6 +317,8 @@ int BenchApp::run() {
else {
BenchModule* mod;



mod = createBlend2DModule(0);
runModule(*mod, params);
delete mod;
Expand All @@ -321,6 +330,12 @@ int BenchApp::run() {
mod = createBlend2DModule(4);
runModule(*mod, params);

#if defined(BLEND2D_APPS_ENABLE_CTX)
mod = createCtxModule();
runModule(*mod, params);
delete mod;
#endif

#if defined(BLEND2D_APPS_ENABLE_AGG)
mod = createAggModule();
runModule(*mod, params);
Expand Down Expand Up @@ -394,7 +409,10 @@ int BenchApp::runModule(BenchModule& mod, BenchParams& params) {
params.shapeSize = benchShapeSizeList[sizeId];

uint64_t duration = std::numeric_limits<uint64_t>::max();
for (uint32_t attempt = 0; attempt < _repeat; attempt++) {
int repeats = _repeat;
if (testId <= 5)
repeats *= 4;
for (uint32_t attempt = 0; attempt < repeats; attempt++) {
mod.run(*this, params);

if (duration > mod._duration)
Expand Down
1 change: 1 addition & 0 deletions bl_bench/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void BenchModule::run(const BenchApp& app, const BenchParams& params) {
case kBenchIdStrokeRotatedRect : onDoRectRotated(true); break;
case kBenchIdStrokeSmoothRound : onDoRoundSmooth(true); break;
case kBenchIdStrokeRotatedRound: onDoRoundRotated(true); break;
case kBenchIdStrokeLine : onDoPolygon(2, 2); break;
case kBenchIdStrokeTriangle : onDoPolygon(2, 3); break;
case kBenchIdStrokePolygon10 : onDoPolygon(2, 10); break;
case kBenchIdStrokePolygon20 : onDoPolygon(2, 20); break;
Expand Down
1 change: 1 addition & 0 deletions bl_bench/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum BenchId : uint32_t {
kBenchIdStrokeRotatedRect,
kBenchIdStrokeSmoothRound,
kBenchIdStrokeRotatedRound,
kBenchIdStrokeLine,
kBenchIdStrokeTriangle,
kBenchIdStrokePolygon10,
kBenchIdStrokePolygon20,
Expand Down
8 changes: 4 additions & 4 deletions bl_bench/module_blend2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void Blend2DModule::onDoRectAligned(bool stroke) {
BLRgba32 color(_rndColor.nextRgba32());

if (opType == BL_CONTEXT_STYLE_SLOT_STROKE)
_context.strokeRect(BLRect(rect.x + 0.5, rect.y + 0.5, rect.w, rect.h), color);
_context.strokeRect(BLRect(rect.x, rect.y, rect.w, rect.h), color);
else
_context.fillRect(rect, color);
}
Expand All @@ -235,7 +235,7 @@ void Blend2DModule::onDoRectAligned(bool stroke) {
_context.setStyle(opType, gradient);

if (opType == BL_CONTEXT_STYLE_SLOT_STROKE)
_context.strokeRect(BLRect(rect.x + 0.5, rect.y + 0.5, rect.w, rect.h));
_context.strokeRect(BLRect(rect.x, rect.y, rect.w, rect.h));
else
_context.fillRect(rect);

Expand All @@ -252,10 +252,10 @@ void Blend2DModule::onDoRectAligned(bool stroke) {
BLRectI rect(_rndCoord.nextRectI(bounds, wh, wh));

if (opType == BL_CONTEXT_STYLE_SLOT_STROKE) {
pattern.create(_sprites[nextSpriteId()], BL_EXTEND_MODE_REPEAT, BLMatrix2D::makeTranslation(rect.x + 0.5, rect.y + 0.5));
pattern.create(_sprites[nextSpriteId()], BL_EXTEND_MODE_REPEAT, BLMatrix2D::makeTranslation(rect.x, rect.y));
_context.save();
_context.setStrokeStyle(pattern);
_context.strokeRect(BLRect(rect.x + 0.5, rect.y + 0.5, rect.w, rect.h));
_context.strokeRect(BLRect(rect.x, rect.y, rect.w, rect.h));
_context.restore();
}
else {
Expand Down
9 changes: 3 additions & 6 deletions bl_bench/module_cairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,11 @@ void CairoModule::onDoRectAligned(bool stroke) {
BLRectI rect(_rndCoord.nextRectI(bounds, wh, wh));
setupStyle<BLRectI>(style, rect);

if (stroke) {
cairo_rectangle(_cairoContext, rect.x + 0.5, rect.y + 0.5, rect.w, rect.h);
cairo_rectangle(_cairoContext, rect.x, rect.y, rect.w, rect.h);
if (stroke)
cairo_stroke(_cairoContext);
}
else {
cairo_rectangle(_cairoContext, rect.x, rect.y, rect.w, rect.h);
else
cairo_fill(_cairoContext);
}
}
}

Expand Down
Loading