2 * Copyright (c) 2020 - 2022 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"
30 enum ContextFlag {Invalid = 0, FastTrack = 1};
34 virtual ~Iterator() {}
35 virtual const Paint* next() = 0;
36 virtual uint32_t count() = 0;
37 virtual void begin() = 0;
42 virtual ~StrategyMethod() {}
44 virtual bool dispose(RenderMethod& renderer) = 0;
45 virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0; //Return engine data if it has.
46 virtual bool render(RenderMethod& renderer) = 0;
47 virtual bool bounds(float* x, float* y, float* w, float* h) = 0;
48 virtual RenderRegion bounds(RenderMethod& renderer) const = 0;
49 virtual Paint* duplicate() = 0;
50 virtual Iterator* iterator() = 0;
57 CompositeMethod method;
62 StrategyMethod* smethod = nullptr;
63 RenderTransform* rTransform = nullptr;
64 Composite* compData = nullptr;
65 uint32_t renderFlag = RenderUpdateFlag::None;
66 uint32_t ctxFlag = ContextFlag::Invalid;
68 uint8_t opacity = 255;
73 delete(compData->target);
76 if (smethod) delete(smethod);
77 if (rTransform) delete(rTransform);
80 void method(StrategyMethod* method)
85 bool transform(const Matrix& m)
88 rTransform = new RenderTransform();
89 if (!rTransform) return false;
91 rTransform->override(m);
92 renderFlag |= RenderUpdateFlag::Transform;
100 rTransform->update();
101 return &rTransform->m;
106 RenderRegion bounds(RenderMethod& renderer) const
108 return smethod->bounds(renderer);
111 bool dispose(RenderMethod& renderer)
113 if (compData) compData->target->pImpl->dispose(renderer);
114 return smethod->dispose(renderer);
119 return smethod->iterator();
122 bool composite(Paint* source, Paint* target, CompositeMethod method)
125 if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
128 delete(compData->target);
130 if (!target && method == CompositeMethod::None) {
136 if (!target && method == CompositeMethod::None) return true;
137 compData = static_cast<Composite*>(calloc(1, sizeof(Composite)));
139 compData->target = target;
140 compData->source = source;
141 compData->method = method;
145 bool rotate(float degree);
146 bool scale(float factor);
147 bool translate(float x, float y);
148 bool bounds(float* x, float* y, float* w, float* h, bool transformed);
149 void* update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, uint32_t pFlag);
150 bool render(RenderMethod& renderer);
156 struct PaintMethod : StrategyMethod
160 PaintMethod(T* _inst) : inst(_inst) {}
163 bool bounds(float* x, float* y, float* w, float* h) override
165 return inst->bounds(x, y, w, h);
168 RenderRegion bounds(RenderMethod& renderer) const override
170 return inst->bounds(renderer);
173 bool dispose(RenderMethod& renderer) override
175 return inst->dispose(renderer);
178 void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag renderFlag) override
180 return inst->update(renderer, transform, opacity, clips, renderFlag);
183 bool render(RenderMethod& renderer) override
185 return inst->render(renderer);
188 Paint* duplicate() override
190 return inst->duplicate();
193 Iterator* iterator() override
195 return inst->iterator();
200 #endif //_TVG_PAINT_H_