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 "shader_test.h"
17
18 namespace OHOS {
19 namespace Rosen {
20 namespace Drawing {
TestDrawShader(Canvas & canvas,uint32_t width,uint32_t height)21 void ShaderTest::TestDrawShader(Canvas& canvas, uint32_t width, uint32_t height)
22 {
23 LOGI("+++++++ TestDrawShader");
24
25 Brush brush;
26 brush.SetColor(Drawing::Color::COLOR_BLUE);
27 std::vector<ColorQuad> colors { Drawing::Color::COLOR_GREEN, Drawing::Color::COLOR_BLUE,
28 Drawing::Color::COLOR_RED };
29 std::vector<scalar> pos { 0.0, 0.5, 1.0 };
30 // The start and end points for the gradient: {1200, 700}, {1300, 800}.
31 auto e = ShaderEffect::CreateLinearGradient({ 1200, 700 }, { 1300, 800 }, colors, pos, TileMode::MIRROR);
32 brush.SetShaderEffect(e);
33
34 canvas.AttachBrush(brush);
35 canvas.DrawRect({ 1200, 700, 1500, 1000 }); // rect is set to (fLeft, fTop, fRight, fBottom)
36 LOGI("------- TestDrawShader");
37 }
38
ShaderTestCase()39 std::vector<ShaderTest::TestFunc> ShaderTest::ShaderTestCase()
40 {
41 std::vector<TestFunc> testFuncVec;
42 testFuncVec.push_back(TestDrawShader);
43 return testFuncVec;
44 }
45 } // namespace Drawing
46 } // namespace Rosen
47 } // namespace OHOS