1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "filter_test.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 namespace Drawing {
TestDrawFilter(Canvas & canvas,uint32_t width,uint32_t height)21 void FilterTest::TestDrawFilter(Canvas& canvas, uint32_t width, uint32_t height)
22 {
23     LOGI("+++++++ TestDrawFilter");
24 
25     Pen pen;
26     pen.SetAntiAlias(true);
27     pen.SetColor(Drawing::Color::COLOR_BLUE);
28     pen.SetColor(pen.GetColor4f(), ColorSpace::CreateSRGBLinear());
29     pen.SetAlpha(0x44); // alpha value is 0x44
30     pen.SetWidth(10);   // The thickness of the pen is 10
31     Filter filter;
32     filter.SetColorFilter(ColorFilter::CreateBlendModeColorFilter(Drawing::Color::COLOR_RED, BlendMode::SRC_ATOP));
33     // Radius of the Gaussian blur to apply is 10.
34     filter.SetMaskFilter(MaskFilter::CreateBlurMaskFilter(BlurType::NORMAL, 10));
35     pen.SetFilter(filter);
36     canvas.AttachPen(pen);
37 
38     Brush brush;
39     brush.SetColor(Drawing::Color::COLOR_BLUE);
40     brush.SetColor(brush.GetColor4f(), ColorSpace::CreateSRGBLinear());
41     brush.SetAlpha(0x44); // alpha value is 0x44
42     brush.SetBlendMode(BlendMode::SRC_ATOP);
43     brush.SetFilter(filter);
44     canvas.AttachBrush(brush);
45     canvas.DrawRect({ 1200, 300, 1500, 600 }); // rect is set to (fLeft, fTop, fRight, fBottom)
46 
47     canvas.DetachPen();
48     canvas.DrawRect({ 1200, 700, 1500, 1000 }); // rect is set to (fLeft, fTop, fRight, fBottom)
49     LOGI("------- TestDrawFilter");
50 }
51 
FilterTestCase()52 std::vector<FilterTest::TestFunc> FilterTest::FilterTestCase()
53 {
54     std::vector<TestFunc> testFuncVec;
55     testFuncVec.push_back(TestDrawFilter);
56     return testFuncVec;
57 }
58 } // namespace Drawing
59 } // namespace Rosen
60 } // namespace OHOS