Skip to content

Commit

Permalink
cleanp: moving stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
stergiotis committed Oct 5, 2024
1 parent 9acd9b7 commit 2fc1aec
Show file tree
Hide file tree
Showing 37 changed files with 62 additions and 1,318 deletions.
24 changes: 3 additions & 21 deletions dhall/sourceTreeParts.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,16 @@ let skiaShared =
, nonSourceObjs = [] : List Text
}
let mainSkiaSdl3 =
let dir = "./skia/sdl3"
let dir = "./main/sdl3"
in sourceTreePart::{
, name = "mainSkiaSdl3"
, dir = dir
, sources = [
, "${dir}/imgui_impl_sdl3.cpp"
, "${dir}/../../imgui/imgui_impl_sdl3.cpp"
, "${dir}/main.cpp"
, "${dir}/app.cpp"
, "${dir}/bmpEncoder.cpp"

, "${dir}/../bmpEncoder.cpp"
, "${dir}/../paragraph.cpp"
, "${dir}/../cliOptions.cpp"
, "${dir}/../setupUI.cpp"
Expand Down Expand Up @@ -491,23 +491,6 @@ let mainSkiaSdl3 =
}
, nonSourceObjs = [ ] : List Text
}
let mainSkiaSdl3Video =
let dir = "./skia/video"
in mainSkiaSdl3 // {
, name = "mainSkiaSdl3Video"
, dir = dir
, sources = [
, "${dir}/app.cpp"
, "${dir}/bmpEncoder.cpp"
, "${dir}/main.cpp"

, "${dir}/../paragraph.cpp"
, "${dir}/../cliOptions.cpp"
, "${dir}/../setupUI.cpp"
, "${dir}/../vectorCmdSkiaRenderer.cpp"
, "${dir}/../skiaTracyTracer.cpp"
]
}
let mainVideoPlayerSdl3Mpv =
let dir = "./sdl3_mpv"
in sourceTreePart::{
Expand Down Expand Up @@ -613,7 +596,6 @@ in
, imguiTextedit
, binding
, mainSkiaSdl3
, mainSkiaSdl3Video
, tracyEnabled
, tracyDisabled
, sdl3Shared
Expand Down
20 changes: 10 additions & 10 deletions skia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ target_compile_options(imguiTextedit PUBLIC -Wno-unused-variable)
# skiaShared

# mainSkiaSdl3
add_library(mainSkiaSdl3 OBJECT "${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/imgui_impl_sdl3.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/main.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/app.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/bmpEncoder.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/../paragraph.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/../cliOptions.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/../setupUI.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/../vectorCmdSkiaRenderer.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3/../skiaTracyTracer.cpp")
add_library(mainSkiaSdl3 OBJECT "${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../../imgui/imgui_impl_sdl3.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/main.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/app.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../bmpEncoder.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../paragraph.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../cliOptions.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../setupUI.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../vectorCmdSkiaRenderer.cpp"
"${CMAKE_CURRENT_LIST_DIR}/./main/sdl3/../skiaTracyTracer.cpp")
target_compile_options(mainSkiaSdl3 PUBLIC -Wno-unused-parameter)
target_include_directories(mainSkiaSdl3 PUBLIC "${CMAKE_CURRENT_LIST_DIR}/./skia/sdl3"
target_include_directories(mainSkiaSdl3 PUBLIC "${CMAKE_CURRENT_LIST_DIR}/./main/sdl3"
"${CMAKE_CURRENT_LIST_DIR}/./imgui"
"${CMAKE_CURRENT_LIST_DIR}/./src/widgets/imgui_implot"
"${CMAKE_CURRENT_LIST_DIR}/./src")
Expand Down
10 changes: 3 additions & 7 deletions skia/build_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ set -ev
here=$(dirname "$(readlink -f "$BASH_SOURCE")")
cd "$here"
flatc="../../contrib/flatbuffers/flatc"
"$flatc" -o skia --cpp ../spec/ImZeroFB.fbs --reflect-types --reflect-names --filename-suffix .out
xxd -i ../spec/ImZeroFB.fbs skia/ImZeroFB.fbs.gen.h
"$flatc" -o main --cpp ../spec/ImZeroFB.fbs --reflect-types --reflect-names --filename-suffix .out
xxd -i ../spec/ImZeroFB.fbs main/ImZeroFB.fbs.gen.h

if [[ -z "${IMZERO_BUILD_VIDEO}" ]]; then
./cmakelists.dhall
else
./cmakelists_video.dhall
fi
./cmakelists.dhall

generate_buildinfo() {
echo -en "#pragma once\nnamespace buildinfo {\n static const char *gitCommit=\""
Expand Down
3 changes: 1 addition & 2 deletions skia/cmakelists.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ let prelude = ../dhall/prelude.dhall
let lib = ../dhall/lib.dhall
let cmake = ../dhall/cmakelists.dhall
let sourceTreePartsRepo = ../dhall/sourceTreeParts.dhall
let c = ./common.dhall
let common = c False
let common = ./common.dhall
in
cmake.cmakelistsToText cmake.cmakelists::{
, cxx = common.cxx
Expand Down
18 changes: 0 additions & 18 deletions skia/cmakelists_video.dhall

This file was deleted.

4 changes: 2 additions & 2 deletions skia/common.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let common = \(video : Bool) ->
let common =
let lib = ../dhall/lib.dhall
let debug = False
let asan = False
Expand All @@ -20,7 +20,7 @@ let common = \(video : Bool) ->
, sourceTreePartsRepo.binding
, sourceTreePartsRepo.sdl3Shared
, sourceTreePartsRepo.skiaShared
, if video then sourceTreePartsRepo.mainSkiaSdl3Video else sourceTreePartsRepo.mainSkiaSdl3
, sourceTreePartsRepo.mainSkiaSdl3
]
# (if debug then [ , sourceTreePartsRepo.tracyEnabled ] else [ ,sourceTreePartsRepo.tracyDisabled ] : List lib.sourceTreePart.Type )
let cxx = "clang++"
Expand Down
4 changes: 2 additions & 2 deletions skia/generate_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ link ../common/contrib/sdl3 contrib/sdl3
link ../common/contrib/qoi contrib/qoi
link ../common/contrib/tracy contrib/tracy
link ../common/contrib/flatbuffers/include contrib/flatbuffers
link ../common/contrib/imgui/backends/imgui_impl_sdl3.cpp ./skia/sdl3/imgui_impl_sdl3.cpp
link ../common/contrib/imgui/backends/imgui_impl_sdl3.h ./skia/sdl3/imgui_impl_sdl3.h
link ../common/contrib/imgui/backends/imgui_impl_sdl3.cpp ./imgui/imgui_impl_sdl3.cpp
link ../common/contrib/imgui/backends/imgui_impl_sdl3.h ./imgui/imgui_impl_sdl3.h
File renamed without changes.
1 change: 1 addition & 0 deletions skia/imgui/imgui_impl_sdl3.cpp
1 change: 1 addition & 0 deletions skia/imgui/imgui_impl_sdl3.h
6 changes: 3 additions & 3 deletions skia/imgui/imzero_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "include/core/SkSurface.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkFont.h"
#include "../skia/ImZeroFB.out.h"
#include "../skia/paragraph.h"
#include "../skia/imzero_assert.h"
#include "../main/ImZeroFB.out.h"
#include "../main/paragraph.h"
#include "../main/imzero_assert.h"


// NOTE: part of ImDrawChannel as std::vector and FlatBufferBuilder are not trivially default constructible
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions skia/skia/imzero_assert.h → skia/main/imzero_assert.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once
#ifdef IMZERO_DEBUG_BUILD
static void imzeroAssert(const char *func,const char *file,int line) {
const char *basePath = std::getenv("IMZERO_ASSERT_BASE_PATH");
fprintf(stderr,",------------------------[ ASSERTION ]-----------------------\n");
Expand All @@ -19,3 +21,4 @@ static void imzeroAssert(const char *func,const char *file,int line) {
fflush(stderr);
assert(false && "imzeroAssert");
}
#endif
File renamed without changes.
File renamed without changes.
64 changes: 27 additions & 37 deletions skia/skia/sdl3/app.cpp → skia/main/sdl3/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "include/encode/SkPngEncoder.h"
#include "include/encode/SkJpegEncoder.h"
#include "include/encode/SkWebpEncoder.h"
#include "bmpEncoder.h"
#include "../bmpEncoder.h"
#if defined(__linux__)
#include "include/gpu/gl/glx/GrGLMakeGLXInterface.h"
#endif
Expand Down Expand Up @@ -81,7 +81,7 @@ static inline void applyFlag(int &flag,T val,bool v) {
constexpr int msaaSampleCount = 0; //4;
constexpr int stencilBits = 8; // Skia needs 8 stencil bits

void App::DrawImGuiVectorCmdsFB(SkCanvas &canvas) { ZoneScoped;
void App::drawImGuiVectorCmdsFB(SkCanvas &canvas) { ZoneScoped;
const ImDrawData* drawData = ImGui::GetDrawData();
fTotalVectorCmdSerializedSize = 0;
for (int i = 0; i < drawData->CmdListsCount; ++i) {
Expand All @@ -95,7 +95,7 @@ void App::DrawImGuiVectorCmdsFB(SkCanvas &canvas) { ZoneScoped;
}
}

void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;
void App::paint(SkSurface* surface, int width, int height) { ZoneScoped;
ImGui::useVectorCmd = fUseVectorCmd && surface != nullptr;
auto renderMode = fVectorCmdSkiaRenderer.getRenderMode();
resetReceiveStat();
Expand Down Expand Up @@ -133,7 +133,7 @@ void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;

skiaCanvas->clear(fBackgroundColor);
skiaCanvas->save();
DrawImGuiVectorCmdsFB(*skiaCanvas);
drawImGuiVectorCmdsFB(*skiaCanvas);
skiaCanvas->restore();

sk_sp<SkPicture> picture = skiaRecorder.finishRecordingAsPicture();
Expand All @@ -155,7 +155,7 @@ void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;
SkFILEWStream svgStream(path1);
{ // svg canvas may buffer commands, extra scope to ensure flush by RAII
auto skiaCanvas = SkSVGCanvas::Make(bounds, &svgStream, flags1);
DrawImGuiVectorCmdsFB(*skiaCanvas);
drawImGuiVectorCmdsFB(*skiaCanvas);
}
fSvgBytesWritten = svgStream.bytesWritten();
}
Expand All @@ -167,7 +167,7 @@ void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;
SkFILEWStream svgStream(path);
{ // svg canvas may buffer commands, extra scope to ensure flush by RAII
auto skiaCanvas = SkSVGCanvas::Make(bounds, &svgStream, flags);
DrawImGuiVectorCmdsFB(*skiaCanvas);
drawImGuiVectorCmdsFB(*skiaCanvas);
}
fSvgBytesWritten = svgStream.bytesWritten();
}
Expand All @@ -185,7 +185,7 @@ void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;
const auto c = SkColorInfo(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
sk_sp<SkSurface> rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(s, c));
SkCanvas *rasterCanvas = rasterSurface->getCanvas();
DrawImGuiVectorCmdsFB(*rasterCanvas);
drawImGuiVectorCmdsFB(*rasterCanvas);
sk_sp<SkImage> img(rasterSurface->makeImageSnapshot());
SkFILEWStream pngStream(path);
SkPixmap pixmap;
Expand Down Expand Up @@ -218,7 +218,7 @@ void App::Paint(SkSurface* surface, int width, int height) { ZoneScoped;
skiaCanvas->clear(fBackgroundColor);

skiaCanvas->save();
DrawImGuiVectorCmdsFB(*skiaCanvas);
drawImGuiVectorCmdsFB(*skiaCanvas);
skiaCanvas->restore();
}

Expand Down Expand Up @@ -1072,11 +1072,7 @@ void App::loopWebp(const CliOptions &opts) {
const int h = static_cast<int>(opts.videoResolutionHeight);
SkWebpEncoder::Options webPOptions;

SkColorType colorType = kRGBA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
const auto rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
auto const rasterSurface = getSurfaceRaster(w,h);
auto canvas = rasterSurface->getCanvas();

if(fOutputFormat == kRawFrameOutputFormat_WebP_Lossy) {
Expand Down Expand Up @@ -1114,11 +1110,7 @@ void App::loopJpeg(const CliOptions &opts) {
const int h = static_cast<int>(opts.videoResolutionHeight);
SkJpegEncoder::Options jpegOptions;

SkColorType colorType = kRGBA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
const auto rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
auto const rasterSurface = getSurfaceRaster(w,h);
auto canvas = rasterSurface->getCanvas();

jpegOptions.fQuality = 80;
Expand Down Expand Up @@ -1150,11 +1142,7 @@ void App::loopPng(const CliOptions &opts) {
const int h = static_cast<int>(opts.videoResolutionHeight);
SkPngEncoder::Options pngOptions;

SkColorType colorType = kRGBA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
const auto rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
auto const rasterSurface = getSurfaceRaster(w,h);
auto canvas = rasterSurface->getCanvas();

pngOptions.fZLibLevel = 6;
Expand Down Expand Up @@ -1191,11 +1179,7 @@ void App::loopQoi(const CliOptions &opts) {
QOI_SRGB
};

SkColorType colorType = kRGBA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
const auto rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
auto const rasterSurface = getSurfaceRaster(w,h);
auto canvas = rasterSurface->getCanvas();
auto stream = SkFILEWStream(opts.videoRawFramesFile);
uint64_t maxFrame = opts.videoExitAfterNFrames;
Expand Down Expand Up @@ -1225,11 +1209,7 @@ void App::loopBmp(const CliOptions &opts) {
const int h = static_cast<int>(opts.videoResolutionHeight);
const auto bmpEncoder = BmpBGRA8888Encoder(w,h);

SkColorType colorType = kBGRA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
const auto rasterSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
auto const rasterSurface = getSurfaceRaster(w,h);
auto canvas = rasterSurface->getCanvas();

uint64_t maxFrame = opts.videoExitAfterNFrames;
Expand Down Expand Up @@ -1420,7 +1400,7 @@ void App::videoPaint(SkCanvas* canvas, int width, int height) { ZoneScoped;
canvas->clear(fBackgroundColor);

canvas->save();
DrawImGuiVectorCmdsFB(*canvas);
drawImGuiVectorCmdsFB(*canvas);
canvas->restore();
}

Expand Down Expand Up @@ -1884,7 +1864,7 @@ int App::mainLoopInteractive(CliOptions &opts,SDL_GLContext glContext,ImVec4 con
continue;
}

auto const surface = getSurface();
auto const surface = getSurfaceGL();

// Start the Dear ImGui frame
ImGui_ImplSDL3_NewFrame();
Expand All @@ -1893,7 +1873,7 @@ int App::mainLoopInteractive(CliOptions &opts,SDL_GLContext glContext,ImVec4 con
{

ImGui::ShowMetricsWindow();
Paint(surface.get(),width,height); // will call ImGui::Render();
paint(surface.get(),width,height); // will call ImGui::Render();
fContext->flush();

// Update and Render additional Platform Windows
Expand Down Expand Up @@ -1961,7 +1941,17 @@ void App::createContext(ImVec4 const &clearColor,int width,int height) {
exit(1);
}
}
sk_sp<SkSurface> App::getSurface() {
sk_sp<SkSurface> App::getSurfaceRaster(int w, int h) {
if(fSurface == nullptr) {
SkColorType colorType = kRGBA_8888_SkColorType;
SkAlphaType alphaType = kPremul_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
const auto c = SkColorInfo(colorType, alphaType, colorSpace);
fSurface = SkSurfaces::Raster(SkImageInfo::Make(SkISize::Make(w,h), c));
}
return fSurface;
}
sk_sp<SkSurface> App::getSurfaceGL() {
if(fSurface == nullptr && fContext != nullptr && fWindow != nullptr && fNativeInterface != nullptr) {
// Wrap the frame buffer object attached to the screen in a Skia render target so Skia can render to it
GrGLint buffer = 0;
Expand Down
7 changes: 4 additions & 3 deletions skia/skia/sdl3/app.h → skia/main/sdl3/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class App {
~App();
int Run(CliOptions &opts);
private:
void Paint(SkSurface* surface, int width, int height);
void DrawImGuiVectorCmdsFB(SkCanvas &canvas);
void paint(SkSurface* surface, int width, int height);
void drawImGuiVectorCmdsFB(SkCanvas &canvas);
void createContext(ImVec4 const &clearColor, int width, int height);
void destroyContext();
sk_sp<SkSurface> getSurface();
sk_sp<SkSurface> getSurfaceGL();
sk_sp<SkSurface> getSurfaceRaster(int w, int h);

sk_sp<SkFontMgr> fFontMgr = nullptr;
SkPaint fFontPaint;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions skia/run_pipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ font="./SauceCodeProNerdFontMono-Regular.ttf"
VSYNC="${VSYNC:-on}"
./main_go --logFormat console demo --mainFontTTF "$font" --mainFontSizeInPixels 13 "$@" < transfer | \
./imgui_exe -ttfFilePath "$font" -fffiInterpreter on -skiaBackendType gl -vsync $VSYNC -backdropFilter off \
-vectorCmd on \
-fontManager fontconfig -imguiNavKeyboard on > transfer
rm -f transfer
1 change: 0 additions & 1 deletion skia/skia/sdl3/imgui_impl_sdl3.cpp

This file was deleted.

1 change: 0 additions & 1 deletion skia/skia/sdl3/imgui_impl_sdl3.h

This file was deleted.

Loading

0 comments on commit 2fc1aec

Please sign in to comment.