mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
common canvas: hide engine() interface
this engine() is not necessary by users, we can hide this by moving out CanvasImpl class. Change-Id: Iaf47dbd3c523e96d6af0bd1fd4caa11a7fd3778a
This commit is contained in:
parent
211dafdaed
commit
4ff97a6a40
6 changed files with 119 additions and 107 deletions
|
@ -36,7 +36,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _TIZENVG_DECLARE_PRIVATE(A) \
|
#define _TIZENVG_DECLARE_PRIVATE(A) \
|
||||||
private: \
|
protected: \
|
||||||
struct Impl; \
|
struct Impl; \
|
||||||
std::unique_ptr<Impl> pImpl; \
|
std::unique_ptr<Impl> pImpl; \
|
||||||
A(const A&) = delete; \
|
A(const A&) = delete; \
|
||||||
|
@ -107,8 +107,6 @@ public:
|
||||||
virtual int draw(bool async = true) noexcept;
|
virtual int draw(bool async = true) noexcept;
|
||||||
virtual int sync() = 0;
|
virtual int sync() = 0;
|
||||||
|
|
||||||
RenderMethod* engine() noexcept;
|
|
||||||
|
|
||||||
_TIZENVG_DECLARE_PRIVATE(Canvas);
|
_TIZENVG_DECLARE_PRIVATE(Canvas);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ source_file = [
|
||||||
'tvgRenderCommon.h',
|
'tvgRenderCommon.h',
|
||||||
'tvgShapePath.h',
|
'tvgShapePath.h',
|
||||||
'tvgShapeImpl.h',
|
'tvgShapeImpl.h',
|
||||||
|
'tvgCanvasImpl.h',
|
||||||
'tvgEngine.cpp',
|
'tvgEngine.cpp',
|
||||||
'tvgCanvas.cpp',
|
'tvgCanvas.cpp',
|
||||||
'tvgSwCanvas.cpp',
|
'tvgSwCanvas.cpp',
|
||||||
|
|
|
@ -18,109 +18,7 @@
|
||||||
#define _TVG_CANVAS_CPP_
|
#define _TVG_CANVAS_CPP_
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgShapeImpl.h"
|
#include "tvgCanvasImpl.h"
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* Internal Class Implementation */
|
|
||||||
/************************************************************************/
|
|
||||||
|
|
||||||
struct Canvas::Impl
|
|
||||||
{
|
|
||||||
vector<Paint*> paints;
|
|
||||||
RenderMethod* renderer;
|
|
||||||
|
|
||||||
Impl(RenderMethod* pRenderer):renderer(pRenderer)
|
|
||||||
{
|
|
||||||
renderer->ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
~Impl()
|
|
||||||
{
|
|
||||||
clear();
|
|
||||||
renderer->unref();
|
|
||||||
}
|
|
||||||
|
|
||||||
int push(unique_ptr<Paint> paint)
|
|
||||||
{
|
|
||||||
Paint* pPaint = paint.release();
|
|
||||||
assert(pPaint);
|
|
||||||
paints.push_back(pPaint);
|
|
||||||
|
|
||||||
return update(pPaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
int clear()
|
|
||||||
{
|
|
||||||
assert(renderer);
|
|
||||||
|
|
||||||
for (auto paint : paints) {
|
|
||||||
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
|
||||||
cout << "TODO: " << scene << endl;
|
|
||||||
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
|
||||||
auto p = shape->pImpl.get();
|
|
||||||
assert(p);
|
|
||||||
if (!p->dispose(*shape, *renderer)) return -1;
|
|
||||||
}
|
|
||||||
delete(paint);
|
|
||||||
}
|
|
||||||
paints.clear();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int update()
|
|
||||||
{
|
|
||||||
assert(renderer);
|
|
||||||
|
|
||||||
for(auto paint: paints) {
|
|
||||||
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
|
||||||
cout << "TODO: " << scene << endl;
|
|
||||||
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
|
||||||
auto p = shape->pImpl.get();
|
|
||||||
assert(p);
|
|
||||||
if (!p->update(*shape, *renderer)) return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int update(Paint* paint)
|
|
||||||
{
|
|
||||||
assert(renderer);
|
|
||||||
|
|
||||||
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
|
||||||
cout << "TODO: " << scene << endl;
|
|
||||||
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
|
||||||
auto p = shape->pImpl.get();
|
|
||||||
assert(p);
|
|
||||||
if (!p->update(*shape, *renderer)) return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int draw()
|
|
||||||
{
|
|
||||||
assert(renderer);
|
|
||||||
|
|
||||||
//Clear render target before drawing
|
|
||||||
if (!renderer->clear()) return -1;
|
|
||||||
|
|
||||||
for(auto paint: paints) {
|
|
||||||
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
|
||||||
cout << "TODO: " << scene << endl;
|
|
||||||
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
|
||||||
auto p = shape->pImpl.get();
|
|
||||||
assert(p);
|
|
||||||
if(!p->render(*shape, *renderer)) return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* External Class Implementation */
|
/* External Class Implementation */
|
||||||
|
|
113
src/lib/tvgCanvasImpl.h
Normal file
113
src/lib/tvgCanvasImpl.h
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef _TVG_CANVAS_IMPL_H_
|
||||||
|
#define _TVG_CANVAS_IMPL_H_
|
||||||
|
|
||||||
|
#include "tvgCommon.h"
|
||||||
|
#include "tvgShapeImpl.h"
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* Internal Class Implementation */
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
struct Canvas::Impl
|
||||||
|
{
|
||||||
|
vector<Paint*> paints;
|
||||||
|
RenderMethod* renderer;
|
||||||
|
|
||||||
|
Impl(RenderMethod* pRenderer):renderer(pRenderer)
|
||||||
|
{
|
||||||
|
renderer->ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
~Impl()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
renderer->unref();
|
||||||
|
}
|
||||||
|
|
||||||
|
int push(unique_ptr<Paint> paint)
|
||||||
|
{
|
||||||
|
auto p = paint.release();
|
||||||
|
assert(p);
|
||||||
|
paints.push_back(p);
|
||||||
|
|
||||||
|
return update(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
int clear()
|
||||||
|
{
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
|
for (auto paint : paints) {
|
||||||
|
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
||||||
|
cout << "TODO: " << scene << endl;
|
||||||
|
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
||||||
|
if (!shape->pImpl.get()->dispose(*shape, *renderer)) return -1;
|
||||||
|
}
|
||||||
|
delete(paint);
|
||||||
|
}
|
||||||
|
paints.clear();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int update()
|
||||||
|
{
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
|
for(auto paint: paints) {
|
||||||
|
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
||||||
|
cout << "TODO: " << scene << endl;
|
||||||
|
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
||||||
|
if (!shape->pImpl.get()->update(*shape, *renderer)) return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int update(Paint* paint)
|
||||||
|
{
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
|
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
||||||
|
cout << "TODO: " << scene << endl;
|
||||||
|
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
||||||
|
if (!shape->pImpl.get()->update(*shape, *renderer)) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int draw()
|
||||||
|
{
|
||||||
|
assert(renderer);
|
||||||
|
|
||||||
|
//Clear render target before drawing
|
||||||
|
if (!renderer->clear()) return -1;
|
||||||
|
|
||||||
|
for(auto paint: paints) {
|
||||||
|
if (auto scene = dynamic_cast<Scene*>(paint)) {
|
||||||
|
cout << "TODO: " << scene << endl;
|
||||||
|
} else if (auto shape = dynamic_cast<Shape*>(paint)) {
|
||||||
|
if(!shape->pImpl.get()->render(*shape, *renderer)) return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _TVG_CANVAS_IMPL_H_ */
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgGlRenderer.h"
|
#include "tvgGlRenderer.h"
|
||||||
|
#include "tvgCanvasImpl.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgSwRenderer.h"
|
#include "tvgSwRenderer.h"
|
||||||
|
#include "tvgCanvasImpl.h"
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -46,7 +47,7 @@ SwCanvas::~SwCanvas()
|
||||||
|
|
||||||
int SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
|
int SwCanvas::target(uint32_t* buffer, size_t stride, size_t w, size_t h) noexcept
|
||||||
{
|
{
|
||||||
auto renderer = dynamic_cast<SwRenderer*>(engine());
|
auto renderer = dynamic_cast<SwRenderer*>(Canvas::pImpl.get()->renderer);
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
|
||||||
if (!renderer->target(buffer, stride, w, h)) return -1;
|
if (!renderer->target(buffer, stride, w, h)) return -1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue