Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
djowel committed Mar 25, 2024
2 parents e7007e3 + 8a2c432 commit a37196d
Show file tree
Hide file tree
Showing 14 changed files with 1,731 additions and 73 deletions.
12 changes: 9 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ function(add_example name)
print_elapsed.cpp
)

set_property(TARGET ${name} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_property(TARGET ${name} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
else()
set_property(TARGET ${name} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreadedDebug"
)
endif()

target_link_options(${name} PRIVATE
/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup shcore.lib
Expand Down
52 changes: 40 additions & 12 deletions examples/host/linux/skia_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "GrDirectContext.h"
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
#include "SkImage.h"
#include "SkColorSpace.h"
#include "SkCanvas.h"
Expand Down Expand Up @@ -43,15 +44,30 @@ namespace

void realize(GtkGLArea* area, gpointer user_data)
{
gtk_gl_area_make_current (area);
if (gtk_gl_area_get_error (area) != NULL)
return;
auto error = [](char const* msg) { throw std::runtime_error(msg); };

gtk_gl_area_make_current(area);
if (gtk_gl_area_get_error(area) != nullptr)
error("Error. gtk_gl_area_get_error failed");

view_state& state = *reinterpret_cast<view_state*>(user_data);
glClearColor(state._bkd.red, state._bkd.green, state._bkd.blue, state._bkd.alpha);
glClear(GL_COLOR_BUFFER_BIT);
state._xface = GrGLMakeNativeInterface();
state._ctx = GrDirectContext::MakeGL(state._xface);
if (state._xface = GrGLMakeNativeInterface(); state._xface == nullptr)
{
//backup plan. see https://gist.github.com/ad8e/dd150b775ae6aa4d5cf1a092e4713add?permalink_comment_id=4680136#gistcomment-4680136
state._xface = GrGLMakeAssembledInterface(
nullptr, (GrGLGetProc) *
[](void*, const char* p) -> void*
{
return (void*)glXGetProcAddress((const GLubyte*)p);
}
);
if (state._xface == nullptr)
error("Error. GLMakeNativeInterface failed");
}
if (state._ctx = GrDirectContext::MakeGL(state._xface); state._ctx == nullptr)
error("Error. GrDirectContext::MakeGL failed");
}

gboolean render(GtkGLArea* area, GdkGLContext* context, gpointer user_data)
Expand Down Expand Up @@ -89,8 +105,8 @@ namespace

SkCanvas* gpu_canvas = state._surface->getCanvas();
gpu_canvas->save();
gpu_canvas->scale(state._scale, state._scale);
auto cnv = canvas{gpu_canvas};
cnv.pre_scale(state._scale);

draw(cnv);

Expand Down Expand Up @@ -127,8 +143,10 @@ namespace

g_signal_connect(window, "destroy", G_CALLBACK(close_window), user_data);

GtkWidget* widget = nullptr;
// create a GtkGLArea instance
auto* gl_area = gtk_gl_area_new();
GtkWidget* gl_area = gtk_gl_area_new();
widget = gl_area;
gtk_container_add(GTK_CONTAINER(window), gl_area);

g_signal_connect(gl_area, "render", G_CALLBACK(render), user_data);
Expand All @@ -140,8 +158,8 @@ namespace
auto w = gtk_widget_get_window(GTK_WIDGET(window));
state._scale = gdk_window_get_scale_factor(w);

if (state._animate)
state._timer_id = g_timeout_add(1000 / 60, animate, gl_area);
if (widget && state._animate)
state._timer_id = g_timeout_add(1000 / 60, animate, widget);
}
}

Expand Down Expand Up @@ -175,12 +193,22 @@ int run_app(
state._bkd = background_color;

auto* app = gtk_application_new("org.gtk-skia.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), &state);
int status = g_application_run(G_APPLICATION(app), argc, const_cast<char**>(argv));
int status = 0;

try
{
g_signal_connect(app, "activate", G_CALLBACK(activate), &state);
int status = g_application_run(G_APPLICATION(app), argc, const_cast<char**>(argv));
}
catch (std::runtime_error const& e)
{
// GPU rendering not available
g_printerr(e.what());
int status = 1;
}
g_object_unref(app);

return status;
}



2 changes: 1 addition & 1 deletion examples/host/macos/skia_app.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ - (void) drawRect : (NSRect) dirty
{
SkCanvas* gpu_canvas = surface->getCanvas();
gpu_canvas->save();
gpu_canvas->scale(_scale, _scale);
auto cnv = canvas{gpu_canvas};
cnv.pre_scale(_scale);

draw(cnv);

Expand Down
2 changes: 1 addition & 1 deletion examples/host/windows/skia_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ void window::render()
{
SkCanvas* gpu_canvas = surface->getCanvas();
gpu_canvas->save();
gpu_canvas->scale(_scale, _scale);
auto cnv = canvas{gpu_canvas};
cnv.pre_scale(_scale);

draw(cnv);

Expand Down
47 changes: 37 additions & 10 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ if (WIN32)
NOMINMAX
_UNICODE
)
set_property(TARGET libunibreak PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_property(TARGET libunibreak PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreadedDebug"
)
else()
set_property(TARGET libunibreak PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
endif()
endif()

if (ARTIST_SKIA)
Expand Down Expand Up @@ -91,10 +97,19 @@ if (ARTIST_SKIA)

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(ARTIST_BINARIES ${CMAKE_CURRENT_BINARY_DIR}/windows/msvc/x86_64/src/prebuilt_binaries)
set(ARTIST_BINARIES_URL https://github.com/cycfi/artist/raw/prebuilt_binaries_0.90/windows/skia/msvc/x86_64/x86_64.zip)
set(ARTIST_BINARIES_MD5 93b0a532f87c1068bc2adabf19da086d)
set(ARTIST_BINARIES_PREFIX windows/msvc/x86_64)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(ARTIST_BINARIES_URL https://github.com/cycfi/artist/raw/prebuilt_binaries_0.90/windows/skia/msvc/x86_64/x86_64.zip)
set(ARTIST_BINARIES_MD5 93b0a532f87c1068bc2adabf19da086d)
set(ARTIST_BINARIES_PREFIX windows/msvc/x86_64)
else()
set(ARTIST_BINARIES_URL https://github.com/cycfi/artist/raw/prebuilt_binaries_0.90/windows/skia/msvc/x86_64-dbg/x86_64-dbg.zip)
set(ARTIST_BINARIES_MD5 b2e5f3927c3b6b3f41ca1c51c8b6a55f)
set(ARTIST_BINARIES_PREFIX windows/msvc/x86_64)
endif()
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "Warning: There are no precompiled binaries built using MTd for Clang. Use MT.")
endif()
set(ARTIST_BINARIES ${CMAKE_CURRENT_BINARY_DIR}/windows/clang/x86_64/src/prebuilt_binaries)
set(ARTIST_BINARIES_URL https://github.com/cycfi/artist/raw/prebuilt_binaries_0.90/windows/skia/clang/x86_64/x86_64.zip)
set(ARTIST_BINARIES_MD5 b2bc06c19cd61f93505b7e37eaf489db)
Expand Down Expand Up @@ -227,13 +242,15 @@ if (ARTIST_SKIA)
if (APPLE)
set(ARTIST_SKIA_PLATFORM_WINDOW_CONTEXT
external/skia/tools/sk_app/mac/GLWindowContext_mac.mm
external/skia/tools/sk_app/mac/RasterWindowContext_mac.mm
)
set_source_files_properties(${ARTIST_SKIA_PLATFORM_WINDOW_CONTEXT}
PROPERTIES COMPILE_FLAGS -fno-objc-arc
)
elseif (MSVC)
set(ARTIST_SKIA_PLATFORM_WINDOW_CONTEXT
external/skia/tools/sk_app/win/GLWindowContext_win.cpp
external/skia/tools/sk_app/win/RasterWindowContext_win.cpp
)
endif()

Expand All @@ -246,6 +263,8 @@ if (ARTIST_SKIA)
impl/skia/detail/harfbuzz.cpp
external/skia/tools/sk_app/GLWindowContext.cpp
external/skia/tools/sk_app/WindowContext.cpp
external/skia/tools/ToolUtils.cpp
external/skia/tools/SkMetaData.cpp
${ARTIST_SKIA_PLATFORM_WINDOW_CONTEXT}
)
endif()
Expand Down Expand Up @@ -280,7 +299,7 @@ endif()
add_dependencies(artist libunibreak)

if (ARTIST_SKIA)
add_dependencies(artist prebuilt_binaries)
add_dependencies(artist prebuilt_binaries)
endif()

target_sources(artist
Expand Down Expand Up @@ -376,9 +395,17 @@ elseif (WIN32)
NOMINMAX
_UNICODE
)
set_property(TARGET artist PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_property(TARGET artist PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded"
)
else()
set_property(TARGET artist PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreadedDebug"
)
endif()


endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
Loading

0 comments on commit a37196d

Please sign in to comment.