mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
common: code refactoring
renamed the enum CompMethod -> CompositionMethod added FIXME comment also clean up internals for less code.
This commit is contained in:
parent
c6b3f78eca
commit
a200c6d4e2
10 changed files with 50 additions and 54 deletions
|
@ -56,7 +56,7 @@ enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
|
|||
enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt };
|
||||
enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
|
||||
enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
|
||||
enum class TVG_EXPORT CompMethod { None = 0, ClipPath };
|
||||
enum class TVG_EXPORT CompositeMethod { None = 0, ClipPath };
|
||||
enum class TVG_EXPORT CanvasEngine { Sw = (1 << 1), Gl = (1 << 2)};
|
||||
|
||||
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
Result bounds(float* x, float* y, float* w, float* h) const noexcept;
|
||||
Paint* duplicate() const noexcept;
|
||||
|
||||
Result composite(std::unique_ptr<Paint> target, CompMethod method) const noexcept;
|
||||
Result composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept;
|
||||
|
||||
_TVG_DECLARE_ACCESSOR();
|
||||
_TVG_DECLARE_PRIVATE(Paint);
|
||||
|
|
|
@ -46,7 +46,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
clipStar->fill(255, 255, 255, 255); // clip object must have alpha.
|
||||
clipStar->translate(10, 10);
|
||||
|
||||
star1->composite(move(clipStar), tvg::CompMethod::ClipPath);
|
||||
star1->composite(move(clipStar), tvg::CompositeMethod::ClipPath);
|
||||
|
||||
auto star2 = tvg::Shape::gen();
|
||||
tvgDrawStar(star2.get());
|
||||
|
@ -66,7 +66,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
scene->push(move(star2));
|
||||
|
||||
//Clipping scene to shape
|
||||
scene->composite(move(clip), tvg::CompMethod::ClipPath);
|
||||
scene->composite(move(clip), tvg::CompositeMethod::ClipPath);
|
||||
|
||||
canvas->push(move(scene));
|
||||
|
||||
|
@ -84,7 +84,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
clipRect->translate(20, 20);
|
||||
|
||||
//Clipping scene to rect(shape)
|
||||
star3->composite(move(clipRect), tvg::CompMethod::ClipPath);
|
||||
star3->composite(move(clipRect), tvg::CompositeMethod::ClipPath);
|
||||
|
||||
canvas->push(move(star3));
|
||||
|
||||
|
@ -105,7 +105,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
clipPath->translate(20, 20);
|
||||
|
||||
//Clipping picture to path
|
||||
picture->composite(move(clipPath), tvg::CompMethod::ClipPath);
|
||||
picture->composite(move(clipPath), tvg::CompositeMethod::ClipPath);
|
||||
|
||||
canvas->push(move(picture));
|
||||
}
|
||||
|
|
|
@ -85,10 +85,10 @@ struct SwTask : Task
|
|||
}
|
||||
}
|
||||
|
||||
//Composite clip-path
|
||||
//Composition
|
||||
for (auto comp : compList) {
|
||||
SwShape *compShape = &static_cast<SwTask*>(comp.edata)->shape;
|
||||
if (comp.method == CompMethod::ClipPath) {
|
||||
if (comp.method == CompositeMethod::ClipPath) {
|
||||
//Clip to fill(path) rle
|
||||
if (shape.rle && compShape->rect) rleClipRect(shape.rle, &compShape->bbox);
|
||||
else if (shape.rle && compShape->rle) rleClipPath(shape.rle, compShape->rle);
|
||||
|
@ -212,7 +212,9 @@ void* SwRenderer::prepare(const Shape& sdata, void* data, const RenderTransform*
|
|||
if (flags == RenderUpdateFlag::None || task->valid()) return task;
|
||||
|
||||
task->sdata = &sdata;
|
||||
|
||||
if (compList.size() > 0) {
|
||||
//Gurantee composition targets get ready.
|
||||
for (auto comp : compList) static_cast<SwTask*>(comp.edata)->get();
|
||||
task->compList.assign(compList.begin(), compList.end());
|
||||
}
|
||||
|
|
|
@ -78,15 +78,11 @@ struct Canvas::Impl
|
|||
|
||||
//Update single paint node
|
||||
if (paint) {
|
||||
if (!paint->pImpl->update(*renderer, nullptr, compList, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
|
||||
//Update retained all paint nodes
|
||||
} else {
|
||||
for (auto paint: paints) {
|
||||
if (!paint->pImpl->update(*renderer, nullptr, compList, nullptr, RenderUpdateFlag::None)) {
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
paint->pImpl->update(*renderer, nullptr, compList, RenderUpdateFlag::None);
|
||||
}
|
||||
}
|
||||
return Result::Success;
|
||||
|
|
|
@ -78,7 +78,7 @@ Paint* Paint::duplicate() const noexcept
|
|||
return pImpl->duplicate();
|
||||
}
|
||||
|
||||
Result Paint::composite(std::unique_ptr<Paint> target, CompMethod method) const noexcept
|
||||
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept
|
||||
{
|
||||
if (pImpl->composite(target.release(), method)) return Result::Success;
|
||||
return Result::InsufficientCondition;
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace tvg
|
|||
virtual ~StrategyMethod(){}
|
||||
|
||||
virtual bool dispose(RenderMethod& renderer) = 0;
|
||||
virtual bool update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, void** edata, RenderUpdateFlag pFlag) = 0;
|
||||
virtual void* update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, 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 Paint* duplicate() = 0;
|
||||
|
@ -46,7 +46,7 @@ namespace tvg
|
|||
uint32_t flag = RenderUpdateFlag::None;
|
||||
|
||||
Paint* compTarget = nullptr;
|
||||
CompMethod compMethod = CompMethod::None;
|
||||
CompositeMethod compMethod = CompositeMethod::None;
|
||||
|
||||
~Impl() {
|
||||
if (smethod) delete(smethod);
|
||||
|
@ -127,42 +127,38 @@ namespace tvg
|
|||
return smethod->dispose(renderer);
|
||||
}
|
||||
|
||||
bool update(RenderMethod& renderer, const RenderTransform* pTransform, vector<Composite>& compList, void **edata, uint32_t pFlag)
|
||||
void* update(RenderMethod& renderer, const RenderTransform* pTransform, vector<Composite>& compList, uint32_t pFlag)
|
||||
{
|
||||
if (flag & RenderUpdateFlag::Transform) {
|
||||
if (!rTransform) return false;
|
||||
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;
|
||||
bool updated = false;
|
||||
void *compEngineData = nullptr; //composite target paint's engine data.
|
||||
|
||||
if (this->compTarget && compMethod == CompMethod::ClipPath) {
|
||||
if (this->compTarget->pImpl->update(renderer, pTransform, compList, &compEngineData, static_cast<RenderUpdateFlag>(pFlag | flag))) {
|
||||
Composite comp;
|
||||
comp.edata = compEngineData;
|
||||
comp.method = this->compMethod;
|
||||
compList.push_back(comp);
|
||||
}
|
||||
}
|
||||
|
||||
if (rTransform && pTransform) {
|
||||
RenderTransform outTransform(pTransform, rTransform);
|
||||
updated = smethod->update(renderer, &outTransform, compList, edata, newFlag);
|
||||
edata = smethod->update(renderer, &outTransform, compList, newFlag);
|
||||
} else {
|
||||
auto outTransform = pTransform ? pTransform : rTransform;
|
||||
updated = smethod->update(renderer, outTransform, compList, edata, newFlag);
|
||||
edata = smethod->update(renderer, outTransform, compList, newFlag);
|
||||
}
|
||||
|
||||
if (compEngineData) {
|
||||
compList.pop_back();
|
||||
}
|
||||
return updated;
|
||||
if (compdata) compList.pop_back();
|
||||
|
||||
return edata;
|
||||
}
|
||||
|
||||
bool render(RenderMethod& renderer)
|
||||
|
@ -186,12 +182,12 @@ namespace tvg
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool composite(Paint* target, CompMethod compMethod)
|
||||
bool composite(Paint* target, CompositeMethod method)
|
||||
{
|
||||
this->compTarget = target;
|
||||
this->compMethod = compMethod;
|
||||
if (this->compTarget) return true;
|
||||
return false;
|
||||
if (!target && method != CompositeMethod::None) return false;
|
||||
compTarget = target;
|
||||
compMethod = method;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -214,9 +210,9 @@ namespace tvg
|
|||
return inst->dispose(renderer);
|
||||
}
|
||||
|
||||
bool update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, void** edata, RenderUpdateFlag flag) override
|
||||
void* update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite> compList, RenderUpdateFlag flag) override
|
||||
{
|
||||
return inst->update(renderer, transform, compList, edata, flag);
|
||||
return inst->update(renderer, transform, compList, flag);
|
||||
}
|
||||
|
||||
bool render(RenderMethod& renderer) override
|
||||
|
|
|
@ -57,13 +57,13 @@ struct Picture::Impl
|
|||
}
|
||||
|
||||
|
||||
bool update(RenderMethod &renderer, const RenderTransform* transform, vector<Composite>& compList, void** edata, RenderUpdateFlag flag)
|
||||
void* update(RenderMethod &renderer, const RenderTransform* transform, vector<Composite>& compList, RenderUpdateFlag flag)
|
||||
{
|
||||
reload();
|
||||
|
||||
if (!paint) return false;
|
||||
if (!paint) return nullptr;
|
||||
|
||||
return paint->pImpl->update(renderer, transform, compList, edata, flag);
|
||||
return paint->pImpl->update(renderer, transform, compList, flag);
|
||||
}
|
||||
|
||||
bool render(RenderMethod &renderer)
|
||||
|
|
|
@ -39,7 +39,7 @@ struct Surface
|
|||
|
||||
struct Composite {
|
||||
void* edata;
|
||||
CompMethod method;
|
||||
CompositeMethod method;
|
||||
};
|
||||
|
||||
enum RenderUpdateFlag {None = 0, Path = 1, Color = 2, Gradient = 4, Stroke = 8, Transform = 16, All = 32};
|
||||
|
|
|
@ -44,12 +44,16 @@ struct Scene::Impl
|
|||
return true;
|
||||
}
|
||||
|
||||
bool update(RenderMethod &renderer, const RenderTransform* transform, vector<Composite>& compList, void** edata, RenderUpdateFlag flag)
|
||||
void* update(RenderMethod &renderer, const RenderTransform* transform, vector<Composite>& compList, RenderUpdateFlag flag)
|
||||
{
|
||||
/* FXIME: it requires to return list of childr engine data
|
||||
This is necessary for scene composition */
|
||||
void* edata = nullptr;
|
||||
|
||||
for (auto paint: paints) {
|
||||
if (!paint->pImpl->update(renderer, transform, compList, edata, static_cast<uint32_t>(flag))) return false;
|
||||
edata = paint->pImpl->update(renderer, transform, compList, static_cast<uint32_t>(flag));
|
||||
}
|
||||
return true;
|
||||
return edata;
|
||||
}
|
||||
|
||||
bool render(RenderMethod &renderer)
|
||||
|
|
|
@ -221,13 +221,11 @@ struct Shape::Impl
|
|||
return renderer.render(*shape, edata);
|
||||
}
|
||||
|
||||
bool update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite>& compList, void** edata, RenderUpdateFlag pFlag)
|
||||
void* update(RenderMethod& renderer, const RenderTransform* transform, vector<Composite>& compList, RenderUpdateFlag pFlag)
|
||||
{
|
||||
this->edata = renderer.prepare(*shape, this->edata, transform, compList, static_cast<RenderUpdateFlag>(pFlag | flag));
|
||||
flag = RenderUpdateFlag::None;
|
||||
if (edata) *edata = this->edata;
|
||||
if (this->edata) return true;
|
||||
return false;
|
||||
return this->edata;
|
||||
}
|
||||
|
||||
bool bounds(float* x, float* y, float* w, float* h)
|
||||
|
|
Loading…
Add table
Reference in a new issue