Debian Codegraph @

thirdparty/thorvg/src/renderer/tvgSwCanvas.cpp

raw symbols SCIP
1 /*
2 * Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved.
3
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:
10
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13
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
20 * SOFTWARE.
21 */
22
23 #include "tvgCanvas.h"
24 #include "tvgLoadModule.h"
25
26 #ifdef THORVG_SW_RASTER_SUPPORT
27 #include "tvgSwRenderer.h"
28 #else
29 class SwRenderer : public RenderMethod
30 {
31 //Non Supported. Dummy Class */
32 };
33 #endif
34
35 /************************************************************************/
36 /* Internal Class Implementation */
37 /************************************************************************/
38
39 struct SwCanvas::Impl
40 {
41 };
42
43
44 /************************************************************************/
45 /* External Class Implementation */
46 /************************************************************************/
47
48 #ifdef THORVG_SW_RASTER_SUPPORT
49 SwCanvas::SwCanvas() : Canvas(SwRenderer::gen()), pImpl(nullptr)
50 #else
51 SwCanvas::SwCanvas() : Canvas(nullptr), pImpl(nullptr)
52 #endif
53 {
54 }
55
56
57 SwCanvas::~SwCanvas()
58 {
59 delete(pImpl);
60 }
61
62
63 Result SwCanvas::mempool(MempoolPolicy policy) noexcept
64 {
65 #ifdef THORVG_SW_RASTER_SUPPORT
66 //We know renderer type, avoid dynamic_cast for performance.
67 auto renderer = static_cast<SwRenderer*>(Canvas::pImpl->renderer);
68 if (!renderer) return Result::MemoryCorruption;
69
70 //It can't change the policy during the running.
71 if (!Canvas::pImpl->paints.empty()) return Result::InsufficientCondition;
72
73 if (policy == MempoolPolicy::Individual) renderer->mempool(false);
74 else renderer->mempool(true);
75
76 return Result::Success;
77 #endif
78 return Result::NonSupport;
79 }
80
81
82 Result SwCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept
83 {
84 #ifdef THORVG_SW_RASTER_SUPPORT
85 if (Canvas::pImpl->status != Status::Damaged && Canvas::pImpl->status != Status::Synced) {
86 return Result::InsufficientCondition;
87 }
88
89 //We know renderer type, avoid dynamic_cast for performance.
90 auto renderer = static_cast<SwRenderer*>(Canvas::pImpl->renderer);
91 if (!renderer) return Result::MemoryCorruption;
92
93 if (!renderer->target(buffer, stride, w, h, static_cast<ColorSpace>(cs))) return Result::InvalidArguments;
94 Canvas::pImpl->vport = {0, 0, (int32_t)w, (int32_t)h};
95 renderer->viewport(Canvas::pImpl->vport);
96
97 //FIXME: The value must be associated with an individual canvas instance.
98 ImageLoader::cs = static_cast<ColorSpace>(cs);
99
100 //Paints must be updated again with this new target.
101 Canvas::pImpl->status = Status::Damaged;
102
103 return Result::Success;
104 #endif
105 return Result::NonSupport;
106 }
107
108
109 unique_ptr<SwCanvas> SwCanvas::gen() noexcept
110 {
111 #ifdef THORVG_SW_RASTER_SUPPORT
112 if (SwRenderer::init() <= 0) return nullptr;
113 return unique_ptr<SwCanvas>(new SwCanvas);
114 #endif
115 return nullptr;
116 }