mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 06:34:01 +00:00
common sw_engine: polished code
--OOM handling ++exception handling ++log info
This commit is contained in:
parent
56d18f37c3
commit
1302c18f28
3 changed files with 6 additions and 16 deletions
|
@ -154,12 +154,12 @@ static uint32_t _interpDownScaler(const uint32_t *img, uint32_t stride, uint32_t
|
|||
|
||||
static bool _rasterMaskedRect(SwSurface* surface, const SwBBox& region, uint32_t color, uint32_t (*blendMethod)(uint32_t))
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Masked Rect");
|
||||
|
||||
auto buffer = surface->buffer + (region.min.y * surface->stride) + region.min.x;
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
|
||||
TVGLOG("SW_ENGINE", "Masked Rect [Region: %lu %lu %u %u]", region.min.x, region.min.y, w, h);
|
||||
|
||||
auto cbuffer = surface->compositor->image.data + (region.min.y * surface->compositor->image.stride) + region.min.x; //compositor buffer
|
||||
|
||||
for (uint32_t y = 0; y < h; ++y) {
|
||||
|
|
|
@ -581,7 +581,7 @@ Compositor* SwRenderer::target(const RenderRegion& region)
|
|||
auto sh = static_cast<int32_t>(surface->h);
|
||||
|
||||
//Out of boundary
|
||||
if (x > sw || y > sh) return nullptr;
|
||||
if (x >= sw || y >= sh || x + w < 0 || y + h < 0) return nullptr;
|
||||
|
||||
SwSurface* cmp = nullptr;
|
||||
|
||||
|
@ -596,17 +596,14 @@ Compositor* SwRenderer::target(const RenderRegion& region)
|
|||
//New Composition
|
||||
if (!cmp) {
|
||||
cmp = new SwSurface;
|
||||
if (!cmp) goto err;
|
||||
|
||||
//Inherits attributes from main surface
|
||||
*cmp = *surface;
|
||||
|
||||
cmp->compositor = new SwCompositor;
|
||||
if (!cmp->compositor) goto err;
|
||||
|
||||
//SwImage, Optimize Me: Surface size from MainSurface(WxH) to Parameter W x H
|
||||
cmp->compositor->image.data = (uint32_t*) malloc(sizeof(uint32_t) * surface->stride * surface->h);
|
||||
if (!cmp->compositor->image.data) goto err;
|
||||
compositors.push(cmp);
|
||||
}
|
||||
|
||||
|
@ -644,14 +641,6 @@ Compositor* SwRenderer::target(const RenderRegion& region)
|
|||
surface = cmp;
|
||||
|
||||
return cmp->compositor;
|
||||
|
||||
err:
|
||||
if (cmp) {
|
||||
if (cmp->compositor) delete(cmp->compositor);
|
||||
delete(cmp);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -168,8 +168,9 @@ bool Paint::Impl::render(RenderMethod& renderer)
|
|||
auto region = smethod->bounds(renderer);
|
||||
if (region.w == 0 || region.h == 0) return true;
|
||||
cmp = renderer.target(region);
|
||||
renderer.beginComposite(cmp, CompositeMethod::None, 255);
|
||||
compData->target->pImpl->render(renderer);
|
||||
if (renderer.beginComposite(cmp, CompositeMethod::None, 255)) {
|
||||
compData->target->pImpl->render(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (cmp) renderer.beginComposite(cmp, compData->method, compData->target->pImpl->opacity);
|
||||
|
|
Loading…
Add table
Reference in a new issue