updated licenses info.
[platform/core/uifw/lottie-player.git] / src / vector / vdrawable.cpp
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "vdrawable.h"
20 #include "vdasher.h"
21 #include "vraster.h"
22
23 void VDrawable::preprocess(const VRect &clip)
24 {
25     if (mFlag & (DirtyState::Path)) {
26
27         if (!mRleFuture) mRleFuture = std::make_shared<VSharedState<VRle>>();
28
29         mRleFuture->reuse();
30
31         if (mStroke.enable) {
32             if (mStroke.mDash.size()) {
33                 VDasher dasher(mStroke.mDash.data(), mStroke.mDash.size());
34                 mPath = dasher.dashed(mPath);
35             }
36             VRaster::generateStrokeInfo(mRleFuture,
37                 std::move(mPath), std::move(mRle), mStroke.cap, mStroke.join,
38                 mStroke.width, mStroke.meterLimit, clip);
39         } else {
40             VRaster::generateFillInfo(mRleFuture,
41                 std::move(mPath), std::move(mRle), mFillRule, clip);
42         }
43         mRle = VRle();
44         mFlag &= ~DirtyFlag(DirtyState::Path);
45     }
46 }
47
48 VRle VDrawable::rle()
49 {
50     if (mRleFuture && mRleFuture->valid()) {
51         mRle = mRleFuture->get();
52     }
53     return mRle;
54 }
55
56 void VDrawable::setStrokeInfo(CapStyle cap, JoinStyle join, float meterLimit,
57                               float strokeWidth)
58 {
59     if ((mStroke.cap == cap) && (mStroke.join == join) &&
60         vCompare(mStroke.meterLimit, meterLimit) &&
61         vCompare(mStroke.width, strokeWidth))
62         return;
63
64     mStroke.enable = true;
65     mStroke.cap = cap;
66     mStroke.join = join;
67     mStroke.meterLimit = meterLimit;
68     mStroke.width = strokeWidth;
69     mFlag |= DirtyState::Path;
70 }
71
72 void VDrawable::setDashInfo(float *array, uint size)
73 {
74     bool hasChanged = false;
75
76     if (mStroke.mDash.size() == size) {
77         for (uint i = 0; i < size; i++) {
78             if (!vCompare(mStroke.mDash[i], array[i])) {
79                 hasChanged = true;
80                 break;
81             }
82         }
83     } else {
84         hasChanged = true;
85     }
86
87     if (!hasChanged) return;
88
89     mStroke.mDash.clear();
90
91     for (uint i = 0; i < size; i++) {
92         mStroke.mDash.push_back(array[i]);
93     }
94     mFlag |= DirtyState::Path;
95 }
96
97 void VDrawable::setPath(const VPath &path)
98 {
99     mPath = path;
100     mFlag |= DirtyState::Path;
101 }