mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
wasm: refine the logic for clarity
1. return null canvas when engine is not avaiable. 2. remove the ifdef for unnecessary taret calls.
This commit is contained in:
parent
583fb6503c
commit
ce96024e99
1 changed files with 23 additions and 23 deletions
|
@ -156,42 +156,42 @@ struct TvgSwEngine : TvgEngineMethod
|
||||||
|
|
||||||
struct TvgWgEngine : TvgEngineMethod
|
struct TvgWgEngine : TvgEngineMethod
|
||||||
{
|
{
|
||||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||||
WGPUSurface surface{};
|
WGPUSurface surface{};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~TvgWgEngine()
|
~TvgWgEngine()
|
||||||
{
|
{
|
||||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||||
wgpuSurfaceRelease(surface);
|
wgpuSurfaceRelease(surface);
|
||||||
#endif
|
|
||||||
Initializer::term(tvg::CanvasEngine::Wg);
|
Initializer::term(tvg::CanvasEngine::Wg);
|
||||||
retrieveFont();
|
retrieveFont();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas* init(string& selector) override
|
Canvas* init(string& selector) override
|
||||||
{
|
{
|
||||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||||
WGPUSurfaceDescriptorFromCanvasHTMLSelector canvasDesc{};
|
WGPUSurfaceDescriptorFromCanvasHTMLSelector canvasDesc{};
|
||||||
canvasDesc.chain.next = nullptr;
|
canvasDesc.chain.next = nullptr;
|
||||||
canvasDesc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
canvasDesc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
||||||
canvasDesc.selector = selector.c_str();
|
canvasDesc.selector = selector.c_str();
|
||||||
|
|
||||||
WGPUSurfaceDescriptor surfaceDesc{};
|
WGPUSurfaceDescriptor surfaceDesc{};
|
||||||
surfaceDesc.nextInChain = &canvasDesc.chain;
|
surfaceDesc.nextInChain = &canvasDesc.chain;
|
||||||
surface = wgpuInstanceCreateSurface(instance, &surfaceDesc);
|
surface = wgpuInstanceCreateSurface(instance, &surfaceDesc);
|
||||||
#endif
|
|
||||||
|
|
||||||
Initializer::init(0, tvg::CanvasEngine::Wg);
|
Initializer::init(0, tvg::CanvasEngine::Wg);
|
||||||
loadFont();
|
loadFont();
|
||||||
return WgCanvas::gen();
|
return WgCanvas::gen();
|
||||||
|
#else
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(Canvas* canvas, int w, int h) override
|
void resize(Canvas* canvas, int w, int h) override
|
||||||
{
|
{
|
||||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
if (canvas) static_cast<WgCanvas*>(canvas)->target(device, instance, surface, w, h, ColorSpace::ABGR8888S);
|
||||||
static_cast<WgCanvas*>(canvas)->target(device, instance, surface, w, h, ColorSpace::ABGR8888S);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,8 +206,8 @@ struct TvgGLEngine : TvgEngineMethod
|
||||||
emscripten_webgl_destroy_context(context);
|
emscripten_webgl_destroy_context(context);
|
||||||
context = 0;
|
context = 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
retrieveFont();
|
retrieveFont();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Canvas* init(string& selector) override
|
Canvas* init(string& selector) override
|
||||||
|
@ -227,19 +227,19 @@ struct TvgGLEngine : TvgEngineMethod
|
||||||
if (context == 0) return nullptr;
|
if (context == 0) return nullptr;
|
||||||
|
|
||||||
emscripten_webgl_make_context_current(context);
|
emscripten_webgl_make_context_current(context);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (Initializer::init(0, tvg::CanvasEngine::Gl) != Result::Success) return nullptr;
|
if (Initializer::init(0, tvg::CanvasEngine::Gl) != Result::Success) return nullptr;
|
||||||
loadFont();
|
loadFont();
|
||||||
|
|
||||||
return GlCanvas::gen();
|
return GlCanvas::gen();
|
||||||
|
#else
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(Canvas* canvas, int w, int h) override
|
void resize(Canvas* canvas, int w, int h) override
|
||||||
{
|
{
|
||||||
#ifdef THORVG_GL_RASTER_SUPPORT
|
if (canvas) static_cast<GlCanvas*>(canvas)->target((void*)context, 0, w, h, ColorSpace::ABGR8888S);
|
||||||
static_cast<GlCanvas*>(canvas)->target((void*)context, 0, w, h, ColorSpace::ABGR8888S);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue