2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _TVG_SW_RENDERER_CPP_
18 #define _TVG_SW_RENDERER_CPP_
20 #include "tvgSwCommon.h"
21 #include "tvgSwRenderer.h"
23 /************************************************************************/
24 /* Internal Class Implementation */
25 /************************************************************************/
27 static RenderInitializer renderInit;
29 static inline size_t COLOR(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
31 return (a << 24 | r << 16 | g << 8 | b);
34 /************************************************************************/
35 /* External Class Implementation */
36 /************************************************************************/
38 bool SwRenderer::target(uint32_t* buffer, size_t stride, size_t height)
40 assert(buffer && stride > 0 && height > 0);
42 surface.buffer = buffer;
43 surface.stride = stride;
44 surface.height = height;
50 bool SwRenderer::render(const ShapeNode& shape, void *data)
52 SwShape* sdata = static_cast<SwShape*>(data);
53 if (!sdata) return false;
57 shape.fill(&r, &g, &b, &a);
58 if (a == 0) return true;
61 return rasterShape(surface, *sdata, COLOR(r, g, b, a));
65 bool SwRenderer::dispose(const ShapeNode& shape, void *data)
67 SwShape* sdata = static_cast<SwShape*>(data);
68 if (!sdata) return false;
74 void* SwRenderer::prepare(const ShapeNode& shape, void* data, UpdateFlag flags)
77 SwShape* sdata = static_cast<SwShape*>(data);
79 sdata = static_cast<SwShape*>(calloc(1, sizeof(SwShape)));
83 if (flags == UpdateFlag::None) return nullptr;
87 shape.fill(nullptr, nullptr, nullptr, &alpha);
88 if (alpha == 0) return sdata;
91 if (flags & UpdateFlag::Path) {
93 if (!shapeGenOutline(shape, *sdata)) return sdata;
94 if (!shapeTransformOutline(shape, *sdata)) return sdata;
95 if (!shapeGenRle(shape, *sdata)) return sdata;
102 int SwRenderer::init()
104 return RenderInitializer::init(renderInit, new SwRenderer);
108 int SwRenderer::term()
110 return RenderInitializer::term(renderInit);
114 size_t SwRenderer::unref()
116 return RenderInitializer::unref(renderInit);
120 size_t SwRenderer::ref()
122 return RenderInitializer::ref(renderInit);
126 SwRenderer* SwRenderer::inst()
128 return dynamic_cast<SwRenderer*>(RenderInitializer::inst(renderInit));
132 #endif /* _TVG_SW_RENDERER_CPP_ */