/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
#ifndef _TVG_PAINT_H_
#define _TVG_PAINT_H_
-#include <float.h>
-#include <math.h>
#include "tvgRender.h"
+
namespace tvg
{
+ enum ContextFlag {Invalid = 0, FastTrack = 1};
+
+ struct Iterator
+ {
+ virtual ~Iterator() {}
+ virtual const Paint* next() = 0;
+ virtual uint32_t count() = 0;
+ virtual void begin() = 0;
+ };
+
struct StrategyMethod
{
- virtual ~StrategyMethod(){}
+ virtual ~StrategyMethod() {}
virtual bool dispose(RenderMethod& renderer) = 0;
- virtual void* update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, 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) = 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) = 0;
+ virtual RenderRegion bounds(RenderMethod& renderer) const = 0;
virtual Paint* duplicate() = 0;
+ virtual Iterator* iterator() = 0;
};
struct Paint::Impl
{
StrategyMethod* smethod = nullptr;
- RenderTransform *rTransform = nullptr;
- uint32_t flag = RenderUpdateFlag::None;
-
- Paint* compTarget = nullptr;
- CompositeMethod compMethod = CompositeMethod::None;
+ RenderTransform* rTransform = nullptr;
+ uint32_t renderFlag = RenderUpdateFlag::None;
+ Paint* cmpTarget = nullptr;
+ CompositeMethod cmpMethod = CompositeMethod::None;
+ uint32_t ctxFlag = ContextFlag::Invalid;
+ uint32_t id;
+ uint8_t opacity = 255;
~Impl() {
+ if (cmpTarget) delete(cmpTarget);
if (smethod) delete(smethod);
if (rTransform) delete(rTransform);
}
smethod = method;
}
- bool rotate(float degree)
- {
- if (rTransform) {
- if (fabsf(degree - rTransform->degree) <= FLT_EPSILON) return true;
- } else {
- if (fabsf(degree) <= FLT_EPSILON) return true;
- rTransform = new RenderTransform();
- if (!rTransform) return false;
- }
- rTransform->degree = degree;
- if (!rTransform->overriding) flag |= RenderUpdateFlag::Transform;
-
- return true;
- }
-
- bool scale(float factor)
+ bool transform(const Matrix& m)
{
- if (rTransform) {
- if (fabsf(factor - rTransform->scale) <= FLT_EPSILON) return true;
- } else {
- if (fabsf(factor) <= FLT_EPSILON) return true;
+ if (!rTransform) {
rTransform = new RenderTransform();
if (!rTransform) return false;
}
- rTransform->scale = factor;
- if (!rTransform->overriding) flag |= RenderUpdateFlag::Transform;
+ rTransform->override(m);
+ renderFlag |= RenderUpdateFlag::Transform;
return true;
}
- bool translate(float x, float y)
+ Matrix* transform()
{
if (rTransform) {
- if (fabsf(x - rTransform->x) <= FLT_EPSILON && fabsf(y - rTransform->y) <= FLT_EPSILON) return true;
- } else {
- if (fabsf(x) <= FLT_EPSILON && fabsf(y) <= FLT_EPSILON) return true;
- rTransform = new RenderTransform();
- if (!rTransform) return false;
- }
- rTransform->x = x;
- rTransform->y = y;
- if (!rTransform->overriding) flag |= RenderUpdateFlag::Transform;
-
- return true;
- }
-
- bool transform(const Matrix& m)
- {
- if (!rTransform) {
- rTransform = new RenderTransform();
- if (!rTransform) return false;
+ rTransform->update();
+ return &rTransform->m;
}
- rTransform->override(m);
- flag |= RenderUpdateFlag::Transform;
-
- return true;
+ return nullptr;
}
- bool bounds(float* x, float* y, float* w, float* h) const
+ RenderRegion bounds(RenderMethod& renderer) const
{
- return smethod->bounds(x, y, w, h);
+ return smethod->bounds(renderer);
}
bool dispose(RenderMethod& renderer)
{
- if (this->compTarget) this->compTarget->pImpl->dispose(renderer);
+ if (cmpTarget) cmpTarget->pImpl->dispose(renderer);
return smethod->dispose(renderer);
}
- void* update(RenderMethod& renderer, const RenderTransform* pTransform, vector<Composite>& compList, uint32_t pFlag)
+ Iterator* iterator()
{
- if (flag & RenderUpdateFlag::Transform) {
- if (!rTransform) return nullptr;
- if (!rTransform->update()) {
- delete(rTransform);
- rTransform = nullptr;
- }
- }
-
- void *compdata = nullptr;
-
- if (compTarget && compMethod == CompositeMethod::ClipPath) {
- compdata = compTarget->pImpl->update(renderer, pTransform, compList, pFlag);
- if (compdata) compList.push_back({compdata, compMethod});
- }
-
- void *edata = nullptr;
- auto newFlag = static_cast<RenderUpdateFlag>(pFlag | flag);
- flag = RenderUpdateFlag::None;
-
- if (rTransform && pTransform) {
- RenderTransform outTransform(pTransform, rTransform);
- edata = smethod->update(renderer, &outTransform, compList, newFlag);
- } else {
- auto outTransform = pTransform ? pTransform : rTransform;
- edata = smethod->update(renderer, outTransform, compList, newFlag);
- }
-
- if (compdata) compList.pop_back();
-
- return edata;
- }
-
- bool render(RenderMethod& renderer)
- {
- return smethod->render(renderer);
- }
-
- Paint* duplicate()
- {
- auto ret = smethod->duplicate();
-
- //duplicate Transform
- if (ret && rTransform) {
- ret->pImpl->rTransform = new RenderTransform();
- if (ret->pImpl->rTransform) {
- *ret->pImpl->rTransform = *rTransform;
- ret->pImpl->flag |= RenderUpdateFlag::Transform;
- }
- }
-
- return ret;
+ return smethod->iterator();
}
bool composite(Paint* target, CompositeMethod method)
{
- if (!target && method != CompositeMethod::None) return false;
- compTarget = target;
- compMethod = method;
+ if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
+ if (cmpTarget) delete(cmpTarget);
+ cmpTarget = target;
+ cmpMethod = method;
return true;
}
+
+ bool rotate(float degree);
+ bool scale(float factor);
+ bool translate(float x, float y);
+ bool bounds(float* x, float* y, float* w, float* h, bool transformed);
+ void* update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, uint32_t pFlag);
+ bool render(RenderMethod& renderer);
+ Paint* duplicate();
};
T* inst = nullptr;
PaintMethod(T* _inst) : inst(_inst) {}
- ~PaintMethod(){}
+ ~PaintMethod() {}
- bool bounds(float* x, float* y, float* w, float* h) const override
+ bool bounds(float* x, float* y, float* w, float* h) override
{
return inst->bounds(x, y, w, h);
}
+ RenderRegion bounds(RenderMethod& renderer) const override
+ {
+ return inst->bounds(renderer);
+ }
+
bool dispose(RenderMethod& renderer) override
{
return inst->dispose(renderer);
}
- void* update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, RenderUpdateFlag flag) override
+ void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag renderFlag) override
{
- return inst->update(renderer, transform, compList, flag);
+ return inst->update(renderer, transform, opacity, clips, renderFlag);
}
bool render(RenderMethod& renderer) override
{
return inst->duplicate();
}
+
+ Iterator* iterator() override
+ {
+ return inst->iterator();
+ }
};
}