2 * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include "tvgRender.h"
32 virtual ~StrategyMethod() {}
34 virtual bool dispose(RenderMethod& renderer) = 0;
35 virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0; //Return engine data if it has.
36 virtual bool render(RenderMethod& renderer) = 0;
37 virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
38 virtual RenderRegion bounds(RenderMethod& renderer) const = 0;
39 virtual Paint* duplicate() = 0;
44 StrategyMethod* smethod = nullptr;
45 RenderTransform *rTransform = nullptr;
46 uint32_t flag = RenderUpdateFlag::None;
47 Paint* cmpTarget = nullptr;
48 CompositeMethod cmpMethod = CompositeMethod::None;
49 uint8_t opacity = 255;
52 if (cmpTarget) delete(cmpTarget);
53 if (smethod) delete(smethod);
54 if (rTransform) delete(rTransform);
57 void method(StrategyMethod* method)
62 bool transform(const Matrix& m)
65 rTransform = new RenderTransform();
66 if (!rTransform) return false;
68 rTransform->override(m);
69 flag |= RenderUpdateFlag::Transform;
78 return &rTransform->m;
83 bool bounds(float* x, float* y, float* w, float* h) const
85 return smethod->bounds(x, y, w, h);
88 RenderRegion bounds(RenderMethod& renderer) const
90 return smethod->bounds(renderer);
93 bool dispose(RenderMethod& renderer)
95 if (cmpTarget) cmpTarget->pImpl->dispose(renderer);
96 return smethod->dispose(renderer);
99 bool composite(Paint* target, CompositeMethod method)
101 if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
102 if (cmpTarget) delete(cmpTarget);
108 bool rotate(float degree);
109 bool scale(float factor);
110 bool translate(float x, float y);
111 void* update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, uint32_t pFlag);
112 bool render(RenderMethod& renderer);
118 struct PaintMethod : StrategyMethod
122 PaintMethod(T* _inst) : inst(_inst) {}
125 bool bounds(float* x, float* y, float* w, float* h) const override
127 return inst->bounds(x, y, w, h);
130 RenderRegion bounds(RenderMethod& renderer) const override
132 return inst->bounds(renderer);
135 bool dispose(RenderMethod& renderer) override
137 return inst->dispose(renderer);
140 void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flag) override
142 return inst->update(renderer, transform, opacity, clips, flag);
145 bool render(RenderMethod& renderer) override
147 return inst->render(renderer);
150 Paint* duplicate() override
152 return inst->duplicate();
157 #endif //_TVG_PAINT_H_