/* * 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" /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ struct Canvas::Impl { vector paints; RenderMethod* renderer; Impl(RenderMethod* pRenderer):renderer(pRenderer) { renderer->ref(); } ~Impl() { clear(); renderer->unref(); } Result push(unique_ptr paint) { auto p = paint.release(); if (!p) return Result::MemoryCorruption; paints.push_back(p); return update(p); } Result clear() { if (!renderer) return Result::InsufficientCondition; //Clear render target before drawing if (!renderer->clear()) return Result::InsufficientCondition; for (auto paint : paints) { paint->IMPL->method->dispose(*renderer); delete(paint); } paints.clear(); return Result::Success; } Result update(Paint* paint) { if (!renderer) return Result::InsufficientCondition; //Update single paint node if (paint) { if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } //Update retained all paint nodes } else { for(auto paint: paints) { if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } } } return Result::Success; } Result draw() { if (!renderer) return Result::InsufficientCondition; if (!renderer->preRender()) return Result::InsufficientCondition; for(auto paint: paints) { if(!paint->IMPL->method->render(*renderer)) return Result::InsufficientCondition; } if (!renderer->postRender()) return Result::InsufficientCondition; return Result::Success; } }; #endif /* _TVG_CANVAS_IMPL_H_ */