diff --git a/skia/imgui/imgui.h b/skia/imgui/imgui.h index a0e6e97..6837f48 100644 --- a/skia/imgui/imgui.h +++ b/skia/imgui/imgui.h @@ -311,7 +311,7 @@ namespace ImGui { #ifdef SKIA_DRAW_BACKEND extern SkFont skiaFont; - extern bool skiaActive; + extern bool useVectorCmd; extern float skiaFontDyFudge; extern std::shared_ptr paragraph; constexpr unsigned int skiaPasswordDefaultCharacter = U'*'; // TODO make this configurable or runtime selectable @@ -2966,10 +2966,10 @@ struct ImDrawList #ifdef SKIA_DRAW_BACKEND flatbuffers::FlatBufferBuilder *fbBuilder; std::vector> *_FbCmds; - int _FbProcessedDrawCmdIdx; uint32_t _FbProcessedDrawCmdIndexOffset; public: // public: ImFont needs to access this method, in spirit of the rest of imgui I do not use C++'s friend keyword void addVectorCmdFB(VectorCmdFB::VectorCmdArg arg_type, flatbuffers::Offset arg); + void addVerticesAsVectorCmd(); #ifdef SKIA_DRAW_BACKEND_PARAGRAPH_AS_PATH ImVector fPathVerbBuffer; ImVector fPathPointBuffer; @@ -3240,7 +3240,7 @@ struct ImFont IMGUI_API const ImFontGlyph*FindGlyphNoFallback(ImWchar c) const; #ifdef SKIA_DRAW_BACKEND float GetCharAdvance(ImWchar c) const { - if(!ImGui::skiaActive) { + if(!ImGui::useVectorCmd) { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; } diff --git a/skia/imgui/imgui_draw_fb.cpp b/skia/imgui/imgui_draw_fb.cpp index e422ff7..2ba2a22 100644 --- a/skia/imgui/imgui_draw_fb.cpp +++ b/skia/imgui/imgui_draw_fb.cpp @@ -171,7 +171,7 @@ using namespace IMGUI_STB_NAMESPACE; #ifdef SKIA_DRAW_BACKEND #include "tracy/Tracy.hpp" -#define SKIA_DRAW_BACKEND_BEGIN if(ImGui::skiaActive) { ZoneScoped; +#define SKIA_DRAW_BACKEND_BEGIN if(ImGui::useVectorCmd) { ZoneScoped; #define SKIA_DRAW_BACKEND_END } //----------------------------------------------------------------------------- // [SECTION] Skia @@ -183,7 +183,7 @@ using namespace IMGUI_STB_NAMESPACE; #include "vectorCmd_generated.h" namespace ImGui { SkFont skiaFont; - bool skiaActive = false; + bool useVectorCmd = false; float skiaFontDyFudge = 0.0f; std::shared_ptr paragraph = nullptr; } @@ -225,29 +225,31 @@ static inline void initHiddenPwBuffer(const ImFont &font) { #ifdef SKIA_DRAW_BACKEND #include "flatbufferHelpers.h" static constexpr bool enableVectorCmdFBVertexDraw = true; -void ImDrawList::addVectorCmdFB(VectorCmdFB::VectorCmdArg arg_type, flatbuffers::Offset arg) { - if(enableVectorCmdFBVertexDraw && ImGui::skiaActive) { - auto sz = CmdBuffer.Size; - if(sz >= 2) { - _TryMergeDrawCmds(); - } - IM_ASSERT(_FbProcessedDrawCmdIdx >= 0); - bool added = false; - for(int i=_FbProcessedDrawCmdIdx;ipush_back(VectorCmdFB::CreateSingleVectorCmdDto(*fbBuilder,VectorCmdFB::VectorCmdArg_CmdVertexDraw,cmd.Union())); - _FbProcessedDrawCmdIndexOffset += cur.ElemCount; - added = true; +void ImDrawList::addVerticesAsVectorCmd() { + auto sz = CmdBuffer.Size; + if(sz >= 2) { + _TryMergeDrawCmds(); + } + bool added = false; + for(int i=0;ipush_back(VectorCmdFB::CreateSingleVectorCmdDto(*fbBuilder,VectorCmdFB::VectorCmdArg_CmdVertexDraw,cmd.Union())); + _FbProcessedDrawCmdIndexOffset += cur.ElemCount; + added = true; + } + if(added) { CmdBuffer.clear(); AddDrawCmd(); - } + } +} +void ImDrawList::addVectorCmdFB(VectorCmdFB::VectorCmdArg arg_type, flatbuffers::Offset arg) { + if(enableVectorCmdFBVertexDraw && ImGui::useVectorCmd) { + addVerticesAsVectorCmd(); } _FbCmds->push_back(VectorCmdFB::CreateSingleVectorCmdDto(*fbBuilder,arg_type,arg)); } @@ -293,6 +295,11 @@ static flatbuffers::Offset createVectorCmdFBDrawList(ImDr return VectorCmdFB::CreateDrawList(fbBuilder,f,name,vertices,cmds); } void ImDrawList::serializeFB(const uint8_t *&out,size_t &size) { ZoneScoped; + if(!ImGui::useVectorCmd) { + // no native drawing commands, add all vertices as command (this will emulate the standard ImGui backend implementation) + addVerticesAsVectorCmd(); + } + auto dlFb = createVectorCmdFBDrawList(*this,false,*_FbCmds,*fbBuilder); fbBuilder->Finish(dlFb,nullptr); size = fbBuilder->GetSize(); @@ -534,8 +541,7 @@ void ImDrawList::_ResetForNewFrame() _Splitter.Merge(this); CmdBuffer.resize(0); -SKIA_DRAW_BACKEND_BEGIN - _FbProcessedDrawCmdIdx = 0; +#ifdef SKIA_DRAW_BACKEND _FbProcessedDrawCmdIndexOffset = 0; if(fbBuilder == nullptr) { fbBuilder = new flatbuffers::FlatBufferBuilder(); @@ -547,7 +553,7 @@ SKIA_DRAW_BACKEND_BEGIN } else { _FbCmds->resize(0); } -SKIA_DRAW_BACKEND_END +#endif IdxBuffer.resize(0); VtxBuffer.resize(0); Flags = _Data->InitialFlags; @@ -568,7 +574,7 @@ void ImDrawList::_ClearFreeMemory() CmdBuffer.clear(); IdxBuffer.clear(); VtxBuffer.clear(); -SKIA_DRAW_BACKEND_BEGIN +#ifdef SKIA_DRAW_BACKEND if(fbBuilder != nullptr) { fbBuilder->Reset(); delete fbBuilder; @@ -584,7 +590,7 @@ SKIA_DRAW_BACKEND_BEGIN fPathPointBuffer.clear(); fPathWeightBuffer.clear(); #endif -SKIA_DRAW_BACKEND_END +#endif Flags = ImDrawListFlags_None; _VtxCurrentIdx = 0; _VtxWritePtr = NULL; @@ -2419,7 +2425,7 @@ void ImDrawData::Clear() void ImGui::AddDrawListToDrawDataEx(ImDrawData* draw_data, ImVector* out_list, ImDrawList* draw_list) { ZoneScoped; #ifdef SKIA_DRAW_BACKEND - if(ImGui::skiaActive) { + if(ImGui::useVectorCmd) { if(draw_list->_FbCmds->size() == 0) { // skip empty drawlist return; @@ -4419,14 +4425,15 @@ SKIA_DRAW_BACKEND_BEGIN if(!found) { break; } - //draw_list->AddRect(ImVec2(pos.x+ SkScalarToFloat(bounds.top()), pos.y+SkScalarToFloat(bounds.left())), - // ImVec2(pos.x+SkScalarToFloat(bounds.right()), pos.y+SkScalarToFloat(bounds.bottom())), - // 0xaa1199ff,0.0f,0,2.0f); if(!bounds.intersect(clipRectSkiaTrans)) { // clipped continue; } + //draw_list->AddRect(ImVec2(pos.x+ SkScalarToFloat(bounds.top()), pos.y+SkScalarToFloat(bounds.left())), + // ImVec2(pos.x+SkScalarToFloat(bounds.right()), pos.y+SkScalarToFloat(bounds.bottom())), + // 0xaa1199ff,0.0f,0,2.0f); + SkPath p; auto unrenderedGlyphs = ImGui::paragraph->getPath(lineNumber,p); /* diff --git a/skia/imgui/vectorCmd_generated.h b/skia/imgui/vectorCmd_generated.h index 69504f2..ea3967d 100644 --- a/skia/imgui/vectorCmd_generated.h +++ b/skia/imgui/vectorCmd_generated.h @@ -3743,7 +3743,8 @@ struct CmdSvgPathSubset FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_SVG = 4, VT_COL = 6, - VT_FILL = 8 + VT_STROKE = 8, + VT_FILL = 10 }; const ::flatbuffers::String *svg() const { return GetPointer(VT_SVG); @@ -3751,6 +3752,9 @@ struct CmdSvgPathSubset FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { uint32_t col() const { return GetField(VT_COL, 0); } + bool stroke() const { + return GetField(VT_STROKE, 0) != 0; + } bool fill() const { return GetField(VT_FILL, 0) != 0; } @@ -3759,6 +3763,7 @@ struct CmdSvgPathSubset FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { VerifyOffset(verifier, VT_SVG) && verifier.VerifyString(svg()) && VerifyField(verifier, VT_COL, 4) && + VerifyField(verifier, VT_STROKE, 1) && VerifyField(verifier, VT_FILL, 1) && verifier.EndTable(); } @@ -3774,6 +3779,9 @@ struct CmdSvgPathSubsetBuilder { void add_col(uint32_t col) { fbb_.AddElement(CmdSvgPathSubset::VT_COL, col, 0); } + void add_stroke(bool stroke) { + fbb_.AddElement(CmdSvgPathSubset::VT_STROKE, static_cast(stroke), 0); + } void add_fill(bool fill) { fbb_.AddElement(CmdSvgPathSubset::VT_FILL, static_cast(fill), 0); } @@ -3792,11 +3800,13 @@ inline ::flatbuffers::Offset CreateCmdSvgPathSubset( ::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::String> svg = 0, uint32_t col = 0, + bool stroke = false, bool fill = false) { CmdSvgPathSubsetBuilder builder_(_fbb); builder_.add_col(col); builder_.add_svg(svg); builder_.add_fill(fill); + builder_.add_stroke(stroke); return builder_.Finish(); } @@ -3804,33 +3814,47 @@ inline ::flatbuffers::Offset CreateCmdSvgPathSubsetDirect( ::flatbuffers::FlatBufferBuilder &_fbb, const char *svg = nullptr, uint32_t col = 0, + bool stroke = false, bool fill = false) { auto svg__ = svg ? _fbb.CreateString(svg) : 0; return VectorCmdFB::CreateCmdSvgPathSubset( _fbb, svg__, col, + stroke, fill); } struct CmdPath FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { typedef CmdPathBuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_VERBS = 4, - VT_POINTS_XY = 6, - VT_COL = 8, - VT_FILL = 10, - VT_FILLTYPE = 12 + VT_OFFSET = 4, + VT_VERBS = 6, + VT_POINTS_XY = 8, + VT_CONIC_WEIGHTS = 10, + VT_COL = 12, + VT_STROKE = 14, + VT_FILL = 16, + VT_FILLTYPE = 18 }; + const VectorCmdFB::SingleVec2 *offset() const { + return GetStruct(VT_OFFSET); + } const ::flatbuffers::Vector *verbs() const { return GetPointer *>(VT_VERBS); } const ::flatbuffers::Vector *points_xy() const { return GetPointer *>(VT_POINTS_XY); } + const ::flatbuffers::Vector *conic_weights() const { + return GetPointer *>(VT_CONIC_WEIGHTS); + } uint32_t col() const { return GetField(VT_COL, 0); } + bool stroke() const { + return GetField(VT_STROKE, 0) != 0; + } bool fill() const { return GetField(VT_FILL, 0) != 0; } @@ -3839,11 +3863,15 @@ struct CmdPath FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { } bool Verify(::flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && + VerifyField(verifier, VT_OFFSET, 4) && VerifyOffset(verifier, VT_VERBS) && verifier.VerifyVector(verbs()) && VerifyOffset(verifier, VT_POINTS_XY) && verifier.VerifyVector(points_xy()) && + VerifyOffset(verifier, VT_CONIC_WEIGHTS) && + verifier.VerifyVector(conic_weights()) && VerifyField(verifier, VT_COL, 4) && + VerifyField(verifier, VT_STROKE, 1) && VerifyField(verifier, VT_FILL, 1) && VerifyField(verifier, VT_FILLTYPE, 1) && verifier.EndTable(); @@ -3854,15 +3882,24 @@ struct CmdPathBuilder { typedef CmdPath Table; ::flatbuffers::FlatBufferBuilder &fbb_; ::flatbuffers::uoffset_t start_; + void add_offset(const VectorCmdFB::SingleVec2 *offset) { + fbb_.AddStruct(CmdPath::VT_OFFSET, offset); + } void add_verbs(::flatbuffers::Offset<::flatbuffers::Vector> verbs) { fbb_.AddOffset(CmdPath::VT_VERBS, verbs); } void add_points_xy(::flatbuffers::Offset<::flatbuffers::Vector> points_xy) { fbb_.AddOffset(CmdPath::VT_POINTS_XY, points_xy); } + void add_conic_weights(::flatbuffers::Offset<::flatbuffers::Vector> conic_weights) { + fbb_.AddOffset(CmdPath::VT_CONIC_WEIGHTS, conic_weights); + } void add_col(uint32_t col) { fbb_.AddElement(CmdPath::VT_COL, col, 0); } + void add_stroke(bool stroke) { + fbb_.AddElement(CmdPath::VT_STROKE, static_cast(stroke), 0); + } void add_fill(bool fill) { fbb_.AddElement(CmdPath::VT_FILL, static_cast(fill), 0); } @@ -3882,34 +3919,47 @@ struct CmdPathBuilder { inline ::flatbuffers::Offset CreateCmdPath( ::flatbuffers::FlatBufferBuilder &_fbb, + const VectorCmdFB::SingleVec2 *offset = nullptr, ::flatbuffers::Offset<::flatbuffers::Vector> verbs = 0, ::flatbuffers::Offset<::flatbuffers::Vector> points_xy = 0, + ::flatbuffers::Offset<::flatbuffers::Vector> conic_weights = 0, uint32_t col = 0, + bool stroke = false, bool fill = false, VectorCmdFB::PathFillType fillType = VectorCmdFB::PathFillType_winding) { CmdPathBuilder builder_(_fbb); builder_.add_col(col); + builder_.add_conic_weights(conic_weights); builder_.add_points_xy(points_xy); builder_.add_verbs(verbs); + builder_.add_offset(offset); builder_.add_fillType(fillType); builder_.add_fill(fill); + builder_.add_stroke(stroke); return builder_.Finish(); } inline ::flatbuffers::Offset CreateCmdPathDirect( ::flatbuffers::FlatBufferBuilder &_fbb, + const VectorCmdFB::SingleVec2 *offset = nullptr, const std::vector *verbs = nullptr, const std::vector *points_xy = nullptr, + const std::vector *conic_weights = nullptr, uint32_t col = 0, + bool stroke = false, bool fill = false, VectorCmdFB::PathFillType fillType = VectorCmdFB::PathFillType_winding) { auto verbs__ = verbs ? _fbb.CreateVector(*verbs) : 0; auto points_xy__ = points_xy ? _fbb.CreateVector(*points_xy) : 0; + auto conic_weights__ = conic_weights ? _fbb.CreateVector(*conic_weights) : 0; return VectorCmdFB::CreateCmdPath( _fbb, + offset, verbs__, points_xy__, + conic_weights__, col, + stroke, fill, fillType); } diff --git a/skia/skia/cliOptions.cpp b/skia/skia/cliOptions.cpp index 7c53173..58f88e9 100644 --- a/skia/skia/cliOptions.cpp +++ b/skia/skia/cliOptions.cpp @@ -55,11 +55,12 @@ void CliOptions::usage(const char *name, FILE *file) const { fprintf(file," bool flags:\n"); fprintf(file," -fffiInterpreter [bool:%s]\n",fffiInterpreter ? "on" : "off"); fprintf(file," -vsync [bool:%s]\n",vsync ? "on" : "off"); - fprintf(file, " -backdropFilter [bool:%s]\n", backdropFilter ? "on" : "off"); - fprintf(file, " -sketchFilter [bool:%s]\n", sketchFilter ? "on" : "off"); - fprintf(file, " -imguiNavKeyboard [bool:%s]\n", imguiNavKeyboard ? "on" : "off"); - fprintf(file, " -imguiNavGamepad [bool:%s]\n", imguiNavGamepad ? "on" : "off"); - fprintf(file, " -imguiDocking [bool:%s]\n", imguiDocking ? "on" : "off"); + fprintf(file," -backdropFilter [bool:%s]\n", backdropFilter ? "on" : "off"); + fprintf(file," -sketchFilter [bool:%s]\n", sketchFilter ? "on" : "off"); + fprintf(file," -imguiNavKeyboard [bool:%s]\n", imguiNavKeyboard ? "on" : "off"); + fprintf(file," -imguiNavGamepad [bool:%s]\n", imguiNavGamepad ? "on" : "off"); + fprintf(file," -imguiDocking [bool:%s]\n", imguiDocking ? "on" : "off"); + fprintf(file," -vectorCmd [bool:%s] on: intercept ImGui DrawList draw commands and replay them on client (e.g. skia)\n", vectorCmd ? "on" : "off"); } void CliOptions::parse(int argc,char **argv,FILE *logChannel) { if(argc > 1) { @@ -94,6 +95,7 @@ void CliOptions::parse(int argc,char **argv,FILE *logChannel) { imguiNavKeyboard = getBoolFlagValue(logChannel,u, argc, argv, "-imguiNavKeyboard",imguiNavKeyboard); imguiNavGamepad = getBoolFlagValue(logChannel,u, argc, argv, "-imguiNavGamepad",imguiNavGamepad); imguiDocking = getBoolFlagValue(logChannel,u, argc, argv, "-imguiDocking",imguiDocking); + vectorCmd = getBoolFlagValue(logChannel,u, argc, argv, "-vectorCmd",vectorCmd); if(std::popcount(u) != (argc-1)) { for(int i=1;ifffiInterpreter), fTotalVectorCmdSerializedSize(0) { +ImGuiLayer::ImGuiLayer(const CliOptions *opts) : fWindow(nullptr), fSvgBytesWritten(0), fSkpBytesWritten(0), fPngBytesWritten(0), ffffiInterpreter(opts->fffiInterpreter), fTotalVectorCmdSerializedSize(0), fBackground(SK_ColorTRANSPARENT), fUseVectorCmd(true) { // ImGui initialization: IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -73,6 +73,8 @@ ImGuiLayer::ImGuiLayer(const CliOptions *opts) : fWindow(nullptr), fSvgBytesWrit fBackground = SkColorSetARGB(a,r,g,b); } + fUseVectorCmd = opts->vectorCmd; + // Keymap... io.KeyMap[ImGuiKey_Tab] = (int)skui::Key::kTab; io.KeyMap[ImGuiKey_LeftArrow] = (int)skui::Key::kLeft; @@ -111,8 +113,6 @@ ImGuiLayer::ImGuiLayer(const CliOptions *opts) : fWindow(nullptr), fSvgBytesWrit mode |= RenderModeE_Sketch; } fVectorCmdSkiaRenderer.changeRenderMode(mode); - - fSkiaBackendActive = true; } ImGuiLayer::~ImGuiLayer() { @@ -181,12 +181,6 @@ bool ImGuiLayer::onMouseWheel(float delta, int, int, skui::ModifierKey modifiers return io.WantCaptureMouse; } -void ImGuiLayer::skiaWidget(const ImVec2& size, SkiaWidgetFunc func) { - intptr_t funcIndex = fSkiaWidgetFuncs.size(); - fSkiaWidgetFuncs.push_back(func); - ImGui::Image((ImTextureID)funcIndex, size); -} - void ImGuiLayer::onPrePaint() { // Update ImGui input ImGuiIO& io = ImGui::GetIO(); @@ -214,76 +208,6 @@ void ImGuiLayer::onPrePaint() { ImGui::NewFrame(); } -void ImGuiLayer::drawImDrawData(SkCanvas &canvas) { - // Then we fetch the most recent data, and convert it so we can render with Skia - const ImDrawData* drawData = ImGui::GetDrawData(); - SkTDArray pos; - SkTDArray uv; - SkTDArray color; - - for (int i = 0; i < drawData->CmdListsCount; ++i) { - const ImDrawList* drawList = drawData->CmdLists[i]; - - // De-interleave all vertex data (sigh), convert to Skia types - pos.clear(); uv.clear(); color.clear(); - for (int j = 0; j < drawList->VtxBuffer.size(); ++j) { - const ImDrawVert& vert = drawList->VtxBuffer[j]; - pos.push_back(SkPoint::Make(vert.pos.x, vert.pos.y)); - uv.push_back(SkPoint::Make(vert.uv.x, vert.uv.y)); - color.push_back(vert.col); - } - // ImGui colors are RGBA -#ifndef IMGUI_USE_BGRA_PACKED_COLOR - SkSwapRB(color.begin(), color.begin(), color.size()); -#endif - - int indexOffset = 0; - - // Draw everything with canvas.drawVertices... - for (int j = 0; j < drawList->CmdBuffer.size(); ++j) { - const ImDrawCmd* drawCmd = &drawList->CmdBuffer[j]; - - SkAutoCanvasRestore acr(&canvas, true); - - // TODO: Find min/max index for each draw, so we know how many vertices (sigh) - if (drawCmd->UserCallback) { - drawCmd->UserCallback(drawList, drawCmd); - } else { - auto idIndex = reinterpret_cast(drawCmd->TextureId); - if (idIndex < fSkiaWidgetFuncs.size()) { - // Small image IDs are actually indices into a list of callbacks. We directly - // examing the vertex data to deduce the image rectangle, then reconfigure the - // canvas to be clipped and translated so that the callback code gets to use - // Skia to render a widget in the middle of an ImGui panel. - ImDrawIdx rectIndex = drawList->IdxBuffer[indexOffset]; - SkPoint tl = pos[rectIndex], br = pos[rectIndex + 2]; - canvas.clipRect(SkRect::MakeLTRB(tl.fX, tl.fY, br.fX, br.fY)); - canvas.translate(tl.fX, tl.fY); - fSkiaWidgetFuncs[static_cast(idIndex)](&canvas); - } else { - auto paint = static_cast(drawCmd->TextureId); - SkASSERT(paint); - - canvas.clipRect(SkRect::MakeLTRB(drawCmd->ClipRect.x, drawCmd->ClipRect.y, - drawCmd->ClipRect.z, drawCmd->ClipRect.w)); - auto vtxOffset = drawCmd->VtxOffset; - auto vertices = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, - static_cast(drawList->VtxBuffer.size() - vtxOffset), - pos.begin() + vtxOffset, - uv.begin() + vtxOffset, - color.begin() + vtxOffset, - static_cast(drawCmd->ElemCount), - drawList->IdxBuffer.begin() + indexOffset); - canvas.drawVertices(vertices, SkBlendMode::kModulate, *paint); - } - indexOffset += static_cast(drawCmd->ElemCount); - } - } - } - - fSkiaWidgetFuncs.clear(); -} - void ImGuiLayer::drawImGuiVectorCmdsFB(SkCanvas &canvas) { const ImDrawData* drawData = ImGui::GetDrawData(); fTotalVectorCmdSerializedSize = 0; @@ -299,8 +223,7 @@ void ImGuiLayer::drawImGuiVectorCmdsFB(SkCanvas &canvas) { } void ImGuiLayer::onPaint(SkSurface* surface) { ZoneScoped; - - ImGui::skiaActive = fSkiaBackendActive; + ImGui::useVectorCmd = fUseVectorCmd; auto renderMode = fVectorCmdSkiaRenderer.getRenderMode(); resetReceiveStat(); resetSendStat(); @@ -312,10 +235,9 @@ void ImGuiLayer::onPaint(SkSurface* surface) { ZoneScoped; SaveFormatE saveFormat = SaveFormatE_None; if(ImGui::Begin("ImZeroSkia Settings")) { ZoneScoped; - ImGui::Text("gitCommit=\"%s\",dirty=%s",buildinfo::gitCommit,buildinfo::gitDirty ? "yes" : "no"); - fImZeroSkiaSetupUi.render(saveFormat, fVectorCmdSkiaRenderer, fSkiaBackendActive, + fImZeroSkiaSetupUi.render(saveFormat, fVectorCmdSkiaRenderer, fUseVectorCmd, fTotalVectorCmdSerializedSize, totalSentBytes+totalReceivedBytes, - fSkpBytesWritten,fSvgBytesWritten, fPngBytesWritten, + fSkpBytesWritten, fSvgBytesWritten, fPngBytesWritten, fWindow->width(), fWindow->height() ); } @@ -414,17 +336,13 @@ void ImGuiLayer::onPaint(SkSurface* surface) { ZoneScoped; break; } } - } else if(fSkiaBackendActive) { ZoneScoped; + } else { ZoneScoped; auto skiaCanvas = surface->getCanvas(); - skiaCanvas->clear(fBackground); skiaCanvas->save(); drawImGuiVectorCmdsFB(*skiaCanvas); - //renderImDrawData(*skiaCanvas); skiaCanvas->restore(); - } else { ZoneScoped; - drawImDrawData(*surface->getCanvas()); } FrameMark; diff --git a/skia/skia/modified/ImGuiLayer.h b/skia/skia/modified/ImGuiLayer.h index 566f172..407e0f2 100644 --- a/skia/skia/modified/ImGuiLayer.h +++ b/skia/skia/modified/ImGuiLayer.h @@ -46,7 +46,6 @@ class ImGuiLayer : public sk_app::Window::Layer { void setScaleFactor(float scaleFactor); typedef std::function SkiaWidgetFunc; - void skiaWidget(const ImVec2& size, SkiaWidgetFunc func); void onAttach(sk_app::Window* window) override; void onPrePaint() override; @@ -59,7 +58,6 @@ class ImGuiLayer : public sk_app::Window::Layer { private: sk_app::Window* fWindow; SkPaint fFontPaint; - skia_private::TArray fSkiaWidgetFuncs; VectorCmdSkiaRenderer fVectorCmdSkiaRenderer; size_t fTotalVectorCmdSerializedSize{}; @@ -70,9 +68,8 @@ class ImGuiLayer : public sk_app::Window::Layer { bool ffffiInterpreter; SkColor fBackground; - void drawImDrawData(SkCanvas &canvas); void drawImGuiVectorCmdsFB(SkCanvas &canvas); - bool fSkiaBackendActive; + bool fUseVectorCmd; }; #endif diff --git a/skia/skia/setupUI.cpp b/skia/skia/setupUI.cpp index 6e1447c..482a577 100644 --- a/skia/skia/setupUI.cpp +++ b/skia/skia/setupUI.cpp @@ -7,6 +7,7 @@ #include "tools/trace/ChromeTracingTracer.h" #include "skiaTracyTracer.h" #include "implot.h" +#include "buildinfo.gen.h" ImZeroSkiaSetupUI::ImZeroSkiaSetupUI() { fontMetricsText[0] = 'H'; @@ -44,13 +45,15 @@ static void helpMarker(const char* desc) ImGui::EndTooltip(); } } -void ImZeroSkiaSetupUI::render(SaveFormatE &saveFormat, VectorCmdSkiaRenderer &vectorCmdSkiaRenderer, bool &skiaBackendActive, +void ImZeroSkiaSetupUI::render(SaveFormatE &saveFormat, VectorCmdSkiaRenderer &vectorCmdSkiaRenderer, bool &useVectorCmd, size_t totalVectorCmdSerializedSz, size_t totalFffiSz, size_t skpBytes, size_t svgBytes, size_t pngBytes, int windowW, int windowH ) { ZoneScoped; + ImGui::Text("gitCommit=\"%s\",dirty=%s",buildinfo::gitCommit,buildinfo::gitDirty ? "yes" : "no"); + if(ImGui::CollapsingHeader("Skia Backend")) { auto renderMode = vectorCmdSkiaRenderer.getRenderMode(); - ImGui::Checkbox("Render##Skia",&skiaBackendActive); + ImGui::Checkbox("Use vector commands##Skia",&useVectorCmd); #ifdef RENDER_MODE_SKETCH_ENABLED if(ImGui::CheckboxFlags("Sketch",&renderMode,RenderModeE_Sketch)) { @@ -400,7 +403,8 @@ void ImZeroSkiaSetupUI::render(SaveFormatE &saveFormat, VectorCmdSkiaRenderer &v } } if(ImGui::CollapsingHeader("Paragraph")) { - ImGui::TextUnformatted("this is a multiline\ntext with many words that will\nhopefully form a paragraph."); + //ImGui::TextUnformatted("this is a multiline\ntext with many words that will\nhopefully form a paragraph."); + ImGui::TextUnformatted("this is a multiline\ntext with many words that will\nšŸ« šŸ‘©šŸ¼ā€šŸ¤ā€šŸ‘©šŸ»\nhopefully form a paragraph."); } if(ImGui::CollapsingHeader("Paragraph Cache")) { diff --git a/skia/skia/setupUI.h b/skia/skia/setupUI.h index 131c9c3..52fdf89 100644 --- a/skia/skia/setupUI.h +++ b/skia/skia/setupUI.h @@ -18,7 +18,7 @@ class ImZeroSkiaSetupUI { ImZeroSkiaSetupUI(); ~ImZeroSkiaSetupUI(); - void render(SaveFormatE &saveFormat, VectorCmdSkiaRenderer &vectorCmdSkiaRenderer,bool &skiaBackendActive, + void render(SaveFormatE &saveFormat, VectorCmdSkiaRenderer &vectorCmdSkiaRenderer,bool &useVectorCmd, size_t totalVectorCmdSerializedSize, size_t fTotalFffiSz, size_t skpBytes, size_t svgBytes, size_t pngBytes, int windowW, int windowH);