Flutter Impeller
aiks_dl_opacity_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "display_list/dl_blend_mode.h"
7 
8 #include "flutter/display_list/dl_builder.h"
9 #include "flutter/display_list/dl_color.h"
10 #include "flutter/display_list/dl_paint.h"
11 #include "flutter/testing/testing.h"
12 #include "include/core/SkRect.h"
13 
14 namespace impeller {
15 namespace testing {
16 
17 using namespace flutter;
18 
19 TEST_P(AiksTest, DrawOpacityPeephole) {
20  DisplayListBuilder builder;
21 
22  DlPaint green;
23  green.setColor(DlColor::kGreen().modulateOpacity(0.5));
24 
25  DlPaint alpha;
26  alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
27 
28  builder.SaveLayer(nullptr, &alpha);
29  builder.DrawRect(SkRect::MakeXYWH(0, 0, 100, 100), green);
30  builder.Restore();
31 
32  ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
33 }
34 
35 TEST_P(AiksTest, CanRenderGroupOpacity) {
36  DisplayListBuilder builder;
37 
38  DlPaint red;
39  red.setColor(DlColor::kRed());
40  DlPaint green;
41  green.setColor(DlColor::kGreen().modulateOpacity(0.5));
42  DlPaint blue;
43  blue.setColor(DlColor::kBlue());
44 
45  DlPaint alpha;
46  alpha.setColor(DlColor::kRed().modulateOpacity(0.5));
47 
48  builder.SaveLayer(nullptr, &alpha);
49  builder.DrawRect(SkRect::MakeXYWH(0, 0, 100, 100), red);
50  builder.DrawRect(SkRect::MakeXYWH(200, 200, 100, 100), green);
51  builder.DrawRect(SkRect::MakeXYWH(400, 400, 100, 100), blue);
52  builder.Restore();
53 
54  ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
55 }
56 
57 TEST_P(AiksTest, CanRenderGroupOpacityToSavelayer) {
58  DisplayListBuilder builder;
59 
60  DlPaint red;
61  red.setColor(DlColor::kRed());
62 
63  DlPaint alpha;
64  alpha.setColor(DlColor::kRed().modulateOpacity(0.7));
65 
66  // Create a saveLayer that will forward its opacity to another
67  // saveLayer, to verify that we correctly distribute opacity.
68  SkRect bounds = SkRect::MakeLTRB(0, 0, 500, 500);
69  builder.SaveLayer(&bounds, &alpha);
70  builder.SaveLayer(&bounds, &alpha);
71  builder.DrawRect(SkRect::MakeXYWH(0, 0, 400, 400), red);
72  builder.DrawRect(SkRect::MakeXYWH(0, 0, 450, 450), red);
73  builder.Restore();
74  builder.Restore();
75 
76  ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
77 }
78 
79 } // namespace testing
80 } // namespace impeller
impeller::AiksPlayground
Definition: aiks_playground.h:16
aiks_unittests.h
flutter
Definition: dl_golden_blur_unittests.cc:15
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:78
impeller
Definition: allocation.cc:12