Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
6#include "flutter/impeller/aiks/aiks_unittests.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
14namespace impeller {
15namespace testing {
16
17using namespace flutter;
18
19TEST_P(AiksTest, DrawOpacityPeephole) {
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
35TEST_P(AiksTest, CanRenderGroupOpacity) {
37
38 DlPaint red;
40 DlPaint green;
41 green.setColor(DlColor::kGreen().modulateOpacity(0.5));
42 DlPaint blue;
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
57TEST_P(AiksTest, CanRenderGroupOpacityToSavelayer) {
59
60 DlPaint red;
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
DlPaint & setColor(DlColor color)
Definition: dl_paint.h:70
Optional< SkRect > bounds
Definition: SkRecords.h:189
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static constexpr DlColor kBlue()
Definition: dl_color.h:26
static constexpr DlColor kRed()
Definition: dl_color.h:24
static constexpr DlColor kGreen()
Definition: dl_color.h:25