2 * Copyright (c) 2021 - 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
29 TEST_CASE("Memory Reservation", "[tvgSwCanvasBase]")
31 REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
33 auto canvas = SwCanvas::gen();
36 //Check Growth / Reduction
37 REQUIRE(canvas->reserve(10) == Result::Success);
38 REQUIRE(canvas->reserve(1000) == Result::Success);
39 REQUIRE(canvas->reserve(100) == Result::Success);
40 REQUIRE(canvas->reserve(0) == Result::Success);
42 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
45 TEST_CASE("Pushing Paints", "[tvgSwCanvasBase]")
47 REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
49 auto canvas = SwCanvas::gen();
52 uint32_t buffer[100*100];
53 REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
55 //Try all types of paints.
56 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
57 REQUIRE(canvas->push(move(Picture::gen())) == Result::Success);
58 REQUIRE(canvas->push(move(Scene::gen())) == Result::Success);
61 REQUIRE(canvas->update() == Result::Success);
63 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
64 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
66 REQUIRE(canvas->clear() == Result::Success);
68 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
71 REQUIRE(canvas->push(nullptr) == Result::MemoryCorruption);
74 std::unique_ptr<Shape> shape6 = nullptr;
75 REQUIRE(canvas->push(move(shape6)) == Result::MemoryCorruption);
78 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
79 REQUIRE(canvas->draw() == Result::Success);
80 REQUIRE(canvas->push(move(Shape::gen())) == Result::InsufficientCondition);
82 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
85 TEST_CASE("Clear", "[tvgSwCanvasBase]")
87 REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
89 auto canvas = SwCanvas::gen();
91 auto canvas2 = SwCanvas::gen();
95 REQUIRE(canvas->clear() == Result::Success);
96 REQUIRE(canvas->clear(false) == Result::Success);
97 REQUIRE(canvas->clear() == Result::Success);
99 REQUIRE(canvas2->clear(false) == Result::Success);
100 REQUIRE(canvas2->clear() == Result::Success);
101 REQUIRE(canvas2->clear(false) == Result::Success);
105 //Try 1: Push -> Clear
106 for (int i = 0; i < 5; ++i) {
107 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
109 auto shape2 = Shape::gen();
111 ptrs[i] = shape2.get();
113 REQUIRE(canvas2->push(move(shape2)) == Result::Success);
116 REQUIRE(canvas->clear() == Result::Success);
117 REQUIRE(canvas->clear(false) == Result::Success);
119 REQUIRE(canvas2->clear(false) == Result::Success);
120 REQUIRE(canvas2->clear() == Result::Success);
122 for (int i = 0; i < 5; ++i) delete(ptrs[i]);
124 //Try 2: Push -> Update -> Clear
125 for (int i = 0; i < 5; ++i) {
126 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
128 auto shape2 = Shape::gen();
130 ptrs[i] = shape2.get();
132 REQUIRE(canvas2->push(move(shape2)) == Result::Success);
135 REQUIRE(canvas->update() == Result::Success);
136 REQUIRE(canvas->clear() == Result::Success);
137 REQUIRE(canvas->clear(false) == Result::Success);
139 REQUIRE(canvas2->update() == Result::Success);
140 REQUIRE(canvas2->clear(false) == Result::Success);
141 REQUIRE(canvas2->clear() == Result::Success);
143 for (int i = 0; i < 5; ++i) delete(ptrs[i]);
145 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
148 TEST_CASE("Update", "[tvgSwCanvasBase]")
150 REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
152 auto canvas = SwCanvas::gen();
155 uint32_t buffer[100*100];
156 REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
158 REQUIRE(canvas->update() == Result::InsufficientCondition);
160 REQUIRE(canvas->push(move(Shape::gen())) == Result::Success);
163 auto shape = Shape::gen();
164 REQUIRE(canvas->update(shape.get()) == Result::InvalidArguments);
167 auto ptr = shape.get();
168 REQUIRE(canvas->push(move(shape)) == Result::Success);
169 REQUIRE(canvas->update(ptr) == Result::Success);
170 REQUIRE(canvas->update() == Result::Success);
171 REQUIRE(canvas->draw() == Result::Success);
172 REQUIRE(canvas->update() == Result::InsufficientCondition);
174 REQUIRE(canvas->clear() == Result::Success);
177 REQUIRE(canvas->update(ptr) == Result::InsufficientCondition);
179 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
182 TEST_CASE("Synchronized Drawing", "[tvgSwCanvasBase]")
184 REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
186 auto canvas = SwCanvas::gen();
189 REQUIRE(canvas->sync() == Result::InsufficientCondition);
190 REQUIRE(canvas->draw() == Result::InsufficientCondition);
192 uint32_t buffer[100*100];
193 REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
195 REQUIRE(canvas->draw() == Result::InsufficientCondition);
196 REQUIRE(canvas->sync() == Result::InsufficientCondition);
199 auto shape = Shape::gen();
201 REQUIRE(canvas->push(move(shape)) == Result::Success);
203 REQUIRE(canvas->draw() == Result::Success);
204 REQUIRE(canvas->sync() == Result::Success);
205 REQUIRE(canvas->clear() == Result::Success);
207 auto shape2 = Shape::gen();
209 REQUIRE(shape2->appendRect(0, 0, 100, 100, 0, 0) == Result::Success);
210 REQUIRE(shape2->fill(255, 255, 255, 255) == Result::Success);
212 REQUIRE(canvas->push(move(shape2)) == Result::Success);
213 REQUIRE(canvas->draw() == Result::Success);
214 REQUIRE(canvas->sync() == Result::Success);
216 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
219 TEST_CASE("Asynchronized Drawing", "[tvgSwCanvasBase]")
221 //Use multi-threading
222 REQUIRE(Initializer::init(CanvasEngine::Sw, 2) == Result::Success);
224 auto canvas = SwCanvas::gen();
227 uint32_t buffer[100*100];
228 REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ARGB8888) == Result::Success);
230 for (int i = 0; i < 3; ++i) {
231 auto shape = Shape::gen();
233 REQUIRE(shape->appendRect(0, 0, 100, 100, 0, 0) == Result::Success);
234 REQUIRE(shape->fill(255, 255, 255, 255) == Result::Success);
236 REQUIRE(canvas->push(move(shape)) == Result::Success);
239 REQUIRE(canvas->draw() == Result::Success);
240 REQUIRE(canvas->sync() == Result::Success);
242 REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);