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
|
@ -164,9 +164,9 @@ struct TvgWgEngine : TvgEngineMethod
|
|||
{
|
||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||
wgpuSurfaceRelease(surface);
|
||||
#endif
|
||||
Initializer::term(tvg::CanvasEngine::Wg);
|
||||
retrieveFont();
|
||||
#endif
|
||||
}
|
||||
|
||||
Canvas* init(string& selector) override
|
||||
|
@ -180,18 +180,18 @@ struct TvgWgEngine : TvgEngineMethod
|
|||
WGPUSurfaceDescriptor surfaceDesc{};
|
||||
surfaceDesc.nextInChain = &canvasDesc.chain;
|
||||
surface = wgpuInstanceCreateSurface(instance, &surfaceDesc);
|
||||
#endif
|
||||
|
||||
Initializer::init(0, tvg::CanvasEngine::Wg);
|
||||
loadFont();
|
||||
return WgCanvas::gen();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void resize(Canvas* canvas, int w, int h) override
|
||||
{
|
||||
#ifdef THORVG_WG_RASTER_SUPPORT
|
||||
static_cast<WgCanvas*>(canvas)->target(device, instance, surface, w, h, ColorSpace::ABGR8888S);
|
||||
#endif
|
||||
if (canvas) static_cast<WgCanvas*>(canvas)->target(device, instance, surface, w, h, ColorSpace::ABGR8888S);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -206,8 +206,8 @@ struct TvgGLEngine : TvgEngineMethod
|
|||
emscripten_webgl_destroy_context(context);
|
||||
context = 0;
|
||||
}
|
||||
#endif
|
||||
retrieveFont();
|
||||
#endif
|
||||
}
|
||||
|
||||
Canvas* init(string& selector) override
|
||||
|
@ -227,19 +227,19 @@ struct TvgGLEngine : TvgEngineMethod
|
|||
if (context == 0) return nullptr;
|
||||
|
||||
emscripten_webgl_make_context_current(context);
|
||||
#endif
|
||||
|
||||
if (Initializer::init(0, tvg::CanvasEngine::Gl) != Result::Success) return nullptr;
|
||||
loadFont();
|
||||
|
||||
return GlCanvas::gen();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void resize(Canvas* canvas, int w, int h) override
|
||||
{
|
||||
#ifdef THORVG_GL_RASTER_SUPPORT
|
||||
static_cast<GlCanvas*>(canvas)->target((void*)context, 0, w, h, ColorSpace::ABGR8888S);
|
||||
#endif
|
||||
if (canvas) static_cast<GlCanvas*>(canvas)->target((void*)context, 0, w, h, ColorSpace::ABGR8888S);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue