From: Hermet Park Date: Sat, 18 Apr 2020 14:21:22 +0000 (+0900) Subject: code refactoring. X-Git-Tag: accepted/tizen/unified/20200806.062539~187 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2de30ba48c83a4a97b8970f0dc8609f897c6463;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git code refactoring. separate Renderer interfaces to RenderCommon. Change-Id: I682b20db6cc8a058efee7dd4f519277d86306153 --- diff --git a/src/lib/meson.build b/src/lib/meson.build index b2243fe..ffecb2a 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -3,6 +3,7 @@ subdir('gl_engine') source_file = [ 'tvgCommon.h', + 'tvgRenderCommon.h', 'tvgEngine.cpp', 'tvgCanvasBase.h', 'tvgShapePath.h', diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 90e1b9f..1a4a0d0 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -22,82 +22,9 @@ #include #include #include "tizenvg.h" +#include "tvgRenderCommon.h" using namespace std; using namespace tvg; -namespace tvg -{ - -class RenderMethod -{ -public: - enum UpdateFlag { None = 0, Path = 1, Fill = 2, All = 3 }; - virtual ~RenderMethod() {} - virtual void* prepare(const ShapeNode& shape, void* data, UpdateFlag flags) = 0; - virtual void* dispose(const ShapeNode& shape, void *data) = 0; - virtual size_t ref() = 0; - virtual size_t unref() = 0; -}; - -struct RenderInitializer -{ - RenderMethod* pInst = nullptr; - size_t refCnt = 0; - bool initialized = false; - - static int init(RenderInitializer& renderInit, RenderMethod* engine) - { - assert(engine); - if (renderInit.pInst || renderInit.refCnt > 0) return -1; - renderInit.pInst = engine; - renderInit.refCnt = 0; - renderInit.initialized = true; - return 0; - } - - static int term(RenderInitializer& renderInit) - { - if (!renderInit.pInst || !renderInit.initialized) return -1; - - renderInit.initialized = false; - - //Still it's refered.... - if (renderInit.refCnt > 0) return 0; - delete(renderInit.pInst); - renderInit.pInst = nullptr; - - return 0; - } - - static size_t unref(RenderInitializer& renderInit) - { - assert(renderInit.refCnt > 0); - --renderInit.refCnt; - - //engine has been requested to termination - if (!renderInit.initialized && renderInit.refCnt == 0) { - if (renderInit.pInst) { - delete(renderInit.pInst); - renderInit.pInst = nullptr; - } - } - return renderInit.refCnt; - } - - static RenderMethod* inst(RenderInitializer& renderInit) - { - assert(renderInit.pInst); - return renderInit.pInst; - } - - static size_t ref(RenderInitializer& renderInit) - { - return ++renderInit.refCnt; - } - -}; - -} - #endif //_TVG_COMMON_H_ diff --git a/src/lib/tvgRenderCommon.h b/src/lib/tvgRenderCommon.h new file mode 100644 index 0000000..e06f1ac --- /dev/null +++ b/src/lib/tvgRenderCommon.h @@ -0,0 +1,94 @@ +/* + * 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_RENDER_COMMON_H_ +#define _TVG_RENDER_COMMON_H_ + +namespace tvg +{ + +class RenderMethod +{ +public: + enum UpdateFlag { None = 0, Path = 1, Fill = 2, All = 3 }; + virtual ~RenderMethod() {} + virtual void* prepare(const ShapeNode& shape, void* data, UpdateFlag flags) = 0; + virtual void* dispose(const ShapeNode& shape, void *data) = 0; + virtual size_t ref() = 0; + virtual size_t unref() = 0; +}; + +struct RenderInitializer +{ + RenderMethod* pInst = nullptr; + size_t refCnt = 0; + bool initialized = false; + + static int init(RenderInitializer& renderInit, RenderMethod* engine) + { + assert(engine); + if (renderInit.pInst || renderInit.refCnt > 0) return -1; + renderInit.pInst = engine; + renderInit.refCnt = 0; + renderInit.initialized = true; + return 0; + } + + static int term(RenderInitializer& renderInit) + { + if (!renderInit.pInst || !renderInit.initialized) return -1; + + renderInit.initialized = false; + + //Still it's refered.... + if (renderInit.refCnt > 0) return 0; + delete(renderInit.pInst); + renderInit.pInst = nullptr; + + return 0; + } + + static size_t unref(RenderInitializer& renderInit) + { + assert(renderInit.refCnt > 0); + --renderInit.refCnt; + + //engine has been requested to termination + if (!renderInit.initialized && renderInit.refCnt == 0) { + if (renderInit.pInst) { + delete(renderInit.pInst); + renderInit.pInst = nullptr; + } + } + return renderInit.refCnt; + } + + static RenderMethod* inst(RenderInitializer& renderInit) + { + assert(renderInit.pInst); + return renderInit.pInst; + } + + static size_t ref(RenderInitializer& renderInit) + { + return ++renderInit.refCnt; + } + +}; + +} + +#endif //_TVG_RENDER_COMMON_H_