1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _TVG_PAINT_H_
#define _TVG_PAINT_H_
#include "tvgRender.h"
namespace tvg
{
enum ContextFlag {Invalid = 0, FastTrack = 1};
struct Iterator
{
virtual ~Iterator() {}
virtual const Paint* next() = 0;
virtual uint32_t count() = 0;
virtual void begin() = 0;
};
struct StrategyMethod
{
virtual ~StrategyMethod() {}
virtual bool dispose(RenderMethod& renderer) = 0;
virtual void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag) = 0; //Return engine data if it has.
virtual bool render(RenderMethod& renderer) = 0;
virtual bool bounds(float* x, float* y, float* w, float* h) = 0;
virtual RenderRegion bounds(RenderMethod& renderer) const = 0;
virtual Paint* duplicate() = 0;
virtual Iterator* iterator() = 0;
};
struct Composite
{
Paint* target;
Paint* source;
CompositeMethod method;
};
struct Paint::Impl
{
StrategyMethod* smethod = nullptr;
RenderTransform* rTransform = nullptr;
Composite* compData = nullptr;
Paint* compSource = nullptr;
uint32_t renderFlag = RenderUpdateFlag::None;
uint32_t ctxFlag = ContextFlag::Invalid;
uint32_t id;
uint8_t opacity = 255;
~Impl()
{
if (compData) {
delete(compData->target);
free(compData);
}
if (smethod) delete(smethod);
if (rTransform) delete(rTransform);
}
void method(StrategyMethod* method)
{
smethod = method;
}
bool transform(const Matrix& m)
{
if (!rTransform) {
rTransform = new RenderTransform();
if (!rTransform) return false;
}
rTransform->override(m);
renderFlag |= RenderUpdateFlag::Transform;
return true;
}
Matrix* transform()
{
if (rTransform) {
rTransform->update();
return &rTransform->m;
}
return nullptr;
}
RenderRegion bounds(RenderMethod& renderer) const
{
return smethod->bounds(renderer);
}
bool dispose(RenderMethod& renderer)
{
if (compData) compData->target->pImpl->dispose(renderer);
return smethod->dispose(renderer);
}
Iterator* iterator()
{
return smethod->iterator();
}
bool composite(Paint* source, Paint* target, CompositeMethod method)
{
//Invalid case
if ((!target && method != CompositeMethod::None) || (target && method == CompositeMethod::None)) return false;
if (compData) {
delete(compData->target);
//Reset scenario
if (!target && method == CompositeMethod::None) {
free(compData);
compData = nullptr;
return true;
}
} else {
if (!target && method == CompositeMethod::None) return true;
compData = static_cast<Composite*>(calloc(1, sizeof(Composite)));
}
target->pImpl->compSource = source;
compData->target = target;
compData->source = source;
compData->method = method;
return true;
}
bool rotate(float degree);
bool scale(float factor);
bool translate(float x, float y);
bool bounds(float* x, float* y, float* w, float* h, bool transformed);
void* update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, uint32_t pFlag);
bool render(RenderMethod& renderer);
Paint* duplicate();
};
template<class T>
struct PaintMethod : StrategyMethod
{
T* inst = nullptr;
PaintMethod(T* _inst) : inst(_inst) {}
~PaintMethod() {}
bool bounds(float* x, float* y, float* w, float* h) override
{
return inst->bounds(x, y, w, h);
}
RenderRegion bounds(RenderMethod& renderer) const override
{
return inst->bounds(renderer);
}
bool dispose(RenderMethod& renderer) override
{
return inst->dispose(renderer);
}
void* update(RenderMethod& renderer, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag renderFlag) override
{
return inst->update(renderer, transform, opacity, clips, renderFlag);
}
bool render(RenderMethod& renderer) override
{
return inst->render(renderer);
}
Paint* duplicate() override
{
return inst->duplicate();
}
Iterator* iterator() override
{
return inst->iterator();
}
};
}
#endif //_TVG_PAINT_H_
|