mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
common paint: code refactoring.
remove the opacity argument in the render method. Considered again, this opacity value is not commonly used yet. we can introduce it when it's necessary.
This commit is contained in:
parent
0e9115cd00
commit
dc70920b40
5 changed files with 14 additions and 12 deletions
|
@ -97,7 +97,7 @@ struct Canvas::Impl
|
||||||
if (!renderer->preRender()) return Result::InsufficientCondition;
|
if (!renderer->preRender()) return Result::InsufficientCondition;
|
||||||
|
|
||||||
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
||||||
if (!(*paint)->pImpl->render(*renderer, 255)) return Result::InsufficientCondition;
|
if (!(*paint)->pImpl->render(*renderer)) return Result::InsufficientCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!renderer->postRender()) return Result::InsufficientCondition;
|
if (!renderer->postRender()) return Result::InsufficientCondition;
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace tvg
|
||||||
|
|
||||||
virtual bool dispose(RenderMethod& renderer) = 0;
|
virtual bool dispose(RenderMethod& renderer) = 0;
|
||||||
virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0; //Return engine data if it has.
|
virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0; //Return engine data if it has.
|
||||||
virtual bool render(RenderMethod& renderer, uint32_t opacity) = 0;
|
virtual bool render(RenderMethod& renderer) = 0;
|
||||||
virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
|
virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
|
||||||
virtual bool bounds(RenderMethod& renderer, uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) const = 0;
|
virtual bool bounds(RenderMethod& renderer, uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h) const = 0;
|
||||||
virtual Paint* duplicate() = 0;
|
virtual Paint* duplicate() = 0;
|
||||||
|
@ -172,7 +172,7 @@ namespace tvg
|
||||||
return edata;
|
return edata;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool render(RenderMethod& renderer, uint32_t opacity)
|
bool render(RenderMethod& renderer)
|
||||||
{
|
{
|
||||||
Compositor* cmp = nullptr;
|
Compositor* cmp = nullptr;
|
||||||
|
|
||||||
|
@ -183,12 +183,12 @@ namespace tvg
|
||||||
if (!cmpTarget->pImpl->bounds(renderer, &x, &y, &w, &h)) return false;
|
if (!cmpTarget->pImpl->bounds(renderer, &x, &y, &w, &h)) return false;
|
||||||
cmp = renderer.target(x, y, w, h);
|
cmp = renderer.target(x, y, w, h);
|
||||||
renderer.beginComposite(cmp, CompositeMethod::None, 255);
|
renderer.beginComposite(cmp, CompositeMethod::None, 255);
|
||||||
cmpTarget->pImpl->render(renderer, 255);
|
cmpTarget->pImpl->render(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmp) renderer.beginComposite(cmp, CompositeMethod::AlphaMask, cmpTarget->pImpl->opacity);
|
if (cmp) renderer.beginComposite(cmp, CompositeMethod::AlphaMask, cmpTarget->pImpl->opacity);
|
||||||
|
|
||||||
auto ret = smethod->render(renderer, ((opacity * this->opacity) / 255));
|
auto ret = smethod->render(renderer);
|
||||||
|
|
||||||
if (cmp) renderer.endComposite(cmp);
|
if (cmp) renderer.endComposite(cmp);
|
||||||
|
|
||||||
|
@ -252,9 +252,9 @@ namespace tvg
|
||||||
return inst->update(renderer, transform, opacity, clips, flag);
|
return inst->update(renderer, transform, opacity, clips, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool render(RenderMethod& renderer, uint32_t opacity) override
|
bool render(RenderMethod& renderer) override
|
||||||
{
|
{
|
||||||
return inst->render(renderer, opacity);
|
return inst->render(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Paint* duplicate() override
|
Paint* duplicate() override
|
||||||
|
|
|
@ -122,10 +122,10 @@ struct Picture::Impl
|
||||||
return rdata;
|
return rdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool render(RenderMethod &renderer, uint32_t opacity)
|
bool render(RenderMethod &renderer)
|
||||||
{
|
{
|
||||||
if (pixels) return renderer.renderImage(rdata);
|
if (pixels) return renderer.renderImage(rdata);
|
||||||
else if (paint) return paint->pImpl->render(renderer, opacity);
|
else if (paint) return paint->pImpl->render(renderer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
struct Scene::Impl
|
struct Scene::Impl
|
||||||
{
|
{
|
||||||
Array<Paint*> paints;
|
Array<Paint*> paints;
|
||||||
|
uint8_t opacity; //for composition
|
||||||
|
|
||||||
bool dispose(RenderMethod& renderer)
|
bool dispose(RenderMethod& renderer)
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,7 @@ struct Scene::Impl
|
||||||
{
|
{
|
||||||
/* Overriding opacity value. If this scene is half-translucent,
|
/* Overriding opacity value. If this scene is half-translucent,
|
||||||
It must do intermeidate composition with that opacity value. */
|
It must do intermeidate composition with that opacity value. */
|
||||||
|
this->opacity = static_cast<uint8_t>(opacity);
|
||||||
if (opacity > 0) opacity = 255;
|
if (opacity > 0) opacity = 255;
|
||||||
|
|
||||||
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
||||||
|
@ -58,7 +60,7 @@ struct Scene::Impl
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool render(RenderMethod& renderer, uint32_t opacity)
|
bool render(RenderMethod& renderer)
|
||||||
{
|
{
|
||||||
Compositor* cmp = nullptr;
|
Compositor* cmp = nullptr;
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ struct Scene::Impl
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
for (auto paint = paints.data; paint < (paints.data + paints.count); ++paint) {
|
||||||
if (!(*paint)->pImpl->render(renderer, opacity)) return false;
|
if (!(*paint)->pImpl->render(renderer)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmp) renderer.endComposite(cmp);
|
if (cmp) renderer.endComposite(cmp);
|
||||||
|
|
|
@ -218,7 +218,7 @@ struct Shape::Impl
|
||||||
return renderer.dispose(rdata);
|
return renderer.dispose(rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool render(RenderMethod& renderer, TVG_UNUSED uint32_t opacity)
|
bool render(RenderMethod& renderer)
|
||||||
{
|
{
|
||||||
return renderer.renderShape(rdata);
|
return renderer.renderShape(rdata);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue