mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 14:13:43 +00:00
common: optimize scene composition
Scene could avoid composition if its children is only child (non scene) This patch bring it conditionally check so as to avoid unnecesary expensive job. @Issues: 254
This commit is contained in:
parent
a576c8f4cd
commit
b60a773d12
6 changed files with 15 additions and 3 deletions
|
@ -26,9 +26,10 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "tvgRender.h"
|
#include "tvgRender.h"
|
||||||
|
|
||||||
|
|
||||||
namespace tvg
|
namespace tvg
|
||||||
{
|
{
|
||||||
|
enum class PaintType { Shape = 0, Scene, Picture };
|
||||||
|
|
||||||
struct StrategyMethod
|
struct StrategyMethod
|
||||||
{
|
{
|
||||||
virtual ~StrategyMethod() {}
|
virtual ~StrategyMethod() {}
|
||||||
|
@ -52,6 +53,8 @@ namespace tvg
|
||||||
|
|
||||||
uint8_t opacity = 255;
|
uint8_t opacity = 255;
|
||||||
|
|
||||||
|
PaintType type;
|
||||||
|
|
||||||
~Impl() {
|
~Impl() {
|
||||||
if (cmpTarget) delete(cmpTarget);
|
if (cmpTarget) delete(cmpTarget);
|
||||||
if (smethod) delete(smethod);
|
if (smethod) delete(smethod);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
Picture::Picture() : pImpl(new Impl(this))
|
Picture::Picture() : pImpl(new Impl(this))
|
||||||
{
|
{
|
||||||
|
Paint::pImpl->type = PaintType::Picture;
|
||||||
Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
|
Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
Scene::Scene() : pImpl(new Impl())
|
Scene::Scene() : pImpl(new Impl())
|
||||||
{
|
{
|
||||||
|
Paint::pImpl->type = PaintType::Scene;
|
||||||
Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));
|
Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,14 @@ struct Scene::Impl
|
||||||
{
|
{
|
||||||
Compositor* cmp = nullptr;
|
Compositor* cmp = nullptr;
|
||||||
|
|
||||||
|
//If scene has several children or only scene, it may require composition.
|
||||||
|
auto condition = false;
|
||||||
|
if ((paints.count > 1) || (paints.count == 1 && (*paints.data)->pImpl->type == PaintType::Scene)) {
|
||||||
|
condition = true;
|
||||||
|
}
|
||||||
|
|
||||||
//Half translucent. This condition requires intermediate composition.
|
//Half translucent. This condition requires intermediate composition.
|
||||||
if ((opacity < 255 && opacity > 0) && (paints.count > 0)) {
|
if ((opacity < 255 && opacity > 0) && condition) {
|
||||||
uint32_t x, y, w, h;
|
uint32_t x, y, w, h;
|
||||||
if (!bounds(renderer, &x, &y, &w, &h)) return false;
|
if (!bounds(renderer, &x, &y, &w, &h)) return false;
|
||||||
cmp = renderer.target(x, y, w, h);
|
cmp = renderer.target(x, y, w, h);
|
||||||
|
|
|
@ -33,6 +33,7 @@ constexpr auto PATH_KAPPA = 0.552284f;
|
||||||
|
|
||||||
Shape :: Shape() : pImpl(new Impl(this))
|
Shape :: Shape() : pImpl(new Impl(this))
|
||||||
{
|
{
|
||||||
|
Paint::pImpl->type = PaintType::Shape;
|
||||||
Paint::pImpl->method(new PaintMethod<Shape::Impl>(pImpl));
|
Paint::pImpl->method(new PaintMethod<Shape::Impl>(pImpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue