e4ca0ebdd674d8de671c37c7cc0d0be6bf029a5d
[platform/core/uifw/lottie-player.git] / src / vector / vpainter.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the LGPL License, Version 2.1 (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
7  *
8  *     https://www.gnu.org/licenses/
9  *
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.
15  */
16
17 #include "vpainter.h"
18 #include "vdrawhelper.h"
19
20 V_BEGIN_NAMESPACE
21
22 class VPainterImpl {
23 public:
24     void drawRle(const VPoint &pos, const VRle &rle);
25     void drawRle(const VRle &rle, const VRle &clip);
26
27 public:
28     VRasterBuffer mBuffer;
29     VSpanData     mSpanData;
30 };
31
32 void VPainterImpl::drawRle(const VPoint &pos, const VRle &rle)
33 {
34     if (rle.empty()) return;
35     // mSpanData.updateSpanFunc();
36
37     if (!mSpanData.mUnclippedBlendFunc) return;
38
39     mSpanData.setPos(pos);
40
41     // do draw after applying clip.
42     rle.intersect(mSpanData.clipRect(), mSpanData.mUnclippedBlendFunc,
43                   &mSpanData);
44 }
45
46 void VPainterImpl::drawRle(const VRle &rle, const VRle &clip)
47 {
48     if (rle.empty() || clip.empty()) return;
49
50     if (!mSpanData.mUnclippedBlendFunc) return;
51
52     rle.intersect(clip, mSpanData.mUnclippedBlendFunc,
53                   &mSpanData);
54 }
55
56
57 VPainter::~VPainter()
58 {
59     delete mImpl;
60 }
61
62 VPainter::VPainter()
63 {
64     mImpl = new VPainterImpl;
65 }
66
67 VPainter::VPainter(VBitmap *buffer)
68 {
69     mImpl = new VPainterImpl;
70     begin(buffer);
71 }
72 bool VPainter::begin(VBitmap *buffer)
73 {
74     mImpl->mBuffer.prepare(buffer);
75     mImpl->mSpanData.init(&mImpl->mBuffer);
76     // TODO find a better api to clear the surface
77     mImpl->mBuffer.clear();
78     return true;
79 }
80 void VPainter::end() {}
81
82 void VPainter::setBrush(const VBrush &brush)
83 {
84     mImpl->mSpanData.setup(brush);
85 }
86
87 void VPainter::drawRle(const VPoint &pos, const VRle &rle)
88 {
89     mImpl->drawRle(pos, rle);
90 }
91
92 void VPainter::drawRle(const VRle &rle, const VRle &clip)
93 {
94     mImpl->drawRle(rle, clip);
95 }
96
97
98 VRect VPainter::clipBoundingRect() const
99 {
100     return mImpl->mSpanData.mSystemClip;
101 }
102
103 V_END_NAMESPACE