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:
Hermet Park 2021-02-25 12:38:39 +09:00 committed by GitHub
parent a576c8f4cd
commit b60a773d12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 3 deletions

View file

@ -102,4 +102,4 @@ Result Paint::opacity(uint8_t o) noexcept
uint8_t Paint::opacity() const noexcept
{
return pImpl->opacity;
}
}

View file

@ -26,9 +26,10 @@
#include <math.h>
#include "tvgRender.h"
namespace tvg
{
enum class PaintType { Shape = 0, Scene, Picture };
struct StrategyMethod
{
virtual ~StrategyMethod() {}
@ -52,6 +53,8 @@ namespace tvg
uint8_t opacity = 255;
PaintType type;
~Impl() {
if (cmpTarget) delete(cmpTarget);
if (smethod) delete(smethod);

View file

@ -28,6 +28,7 @@
Picture::Picture() : pImpl(new Impl(this))
{
Paint::pImpl->type = PaintType::Picture;
Paint::pImpl->method(new PaintMethod<Picture::Impl>(pImpl));
}

View file

@ -27,6 +27,7 @@
Scene::Scene() : pImpl(new Impl())
{
Paint::pImpl->type = PaintType::Scene;
Paint::pImpl->method(new PaintMethod<Scene::Impl>(pImpl));
}

View file

@ -64,8 +64,14 @@ struct Scene::Impl
{
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.
if ((opacity < 255 && opacity > 0) && (paints.count > 0)) {
if ((opacity < 255 && opacity > 0) && condition) {
uint32_t x, y, w, h;
if (!bounds(renderer, &x, &y, &w, &h)) return false;
cmp = renderer.target(x, y, w, h);

View file

@ -33,6 +33,7 @@ constexpr auto PATH_KAPPA = 0.552284f;
Shape :: Shape() : pImpl(new Impl(this))
{
Paint::pImpl->type = PaintType::Shape;
Paint::pImpl->method(new PaintMethod<Shape::Impl>(pImpl));
}