File: draw_quad_matchers.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (157 lines) | stat: -rw-r--r-- 5,508 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/viz/test/draw_quad_matchers.h"

#include "components/viz/common/quads/compositor_render_pass_draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h"
#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "ui/gfx/overlay_layer_id.h"

namespace viz {
namespace {

const char* MaterialToString(DrawQuad::Material material) {
  switch (material) {
    case DrawQuad::Material::kInvalid:
      return "kInvalid";
    case DrawQuad::Material::kDebugBorder:
      return "kDebugBorder";
    case DrawQuad::Material::kPictureContent:
      return "kPictureContent";
    case DrawQuad::Material::kCompositorRenderPass:
      return "kCompositorRenderPass";
    case DrawQuad::Material::kAggregatedRenderPass:
      return "kAggregatedRenderPass";
    case DrawQuad::Material::kSolidColor:
      return "kSolidColor";
    case DrawQuad::Material::kSharedElement:
      return "kSharedElement";
    case DrawQuad::Material::kSurfaceContent:
      return "kSurfaceContent";
    case DrawQuad::Material::kTextureContent:
      return "kTextureContent";
    case DrawQuad::Material::kTiledContent:
      return "kTiledContent";
    case DrawQuad::Material::kVideoHole:
      return "kVideoHole";
  }
}

// Produces a matcher for a DrawQuad that matches on quad material.
testing::Matcher<const DrawQuad*> IsQuadType(
    DrawQuad::Material expected_material) {
  return testing::Field("material", &DrawQuad::material,
                        testing::Eq(expected_material));
}

}  // namespace

void PrintTo(DrawQuad::Material material, ::std::ostream* os) {
  *os << MaterialToString(material);
}

void PrintTo(const OffsetTag& offset_tag, ::std::ostream* os) {
  *os << offset_tag.ToString();
}

testing::Matcher<const DrawQuad*> IsSolidColorQuad() {
  return IsQuadType(DrawQuad::Material::kSolidColor);
}

testing::Matcher<const DrawQuad*> IsSolidColorQuad(SkColor4f expected_color) {
  return testing::AllOf(
      IsSolidColorQuad(),
      testing::Truly([expected_color](const DrawQuad* quad) {
        return SolidColorDrawQuad::MaterialCast(quad)->color == expected_color;
      }));
}

testing::Matcher<const DrawQuad*> IsTextureQuad() {
  return IsQuadType(DrawQuad::Material::kTextureContent);
}

testing::Matcher<const DrawQuad*> IsSurfaceQuad() {
  return IsQuadType(DrawQuad::Material::kSurfaceContent);
}

testing::Matcher<const DrawQuad*> IsCompositorRenderPassQuad(
    CompositorRenderPassId id) {
  return testing::AllOf(
      IsQuadType(DrawQuad::Material::kCompositorRenderPass),
      testing::Truly([id](const DrawQuad* quad) {
        return CompositorRenderPassDrawQuad::MaterialCast(quad)
                   ->render_pass_id == id;
      }));
}

testing::Matcher<const DrawQuad*> IsAggregatedRenderPassQuad() {
  return IsQuadType(DrawQuad::Material::kAggregatedRenderPass);
}

testing::Matcher<const DrawQuad*> HasRect(const gfx::Rect& rect) {
  return testing::Field("rect", &DrawQuad::rect, testing::Eq(rect));
}

testing::Matcher<const DrawQuad*> HasVisibleRect(
    const gfx::Rect& visible_rect) {
  return testing::Field("visible_rect", &DrawQuad::visible_rect,
                        testing::Eq(visible_rect));
}

testing::Matcher<const DrawQuad*> HasSharedQuadState(
    testing::Matcher<const SharedQuadState*> matcher) {
  return testing::Field("shared_quad_state", &DrawQuad::shared_quad_state,
                        matcher);
}

testing::Matcher<const DrawQuad*> HasTransform(
    const gfx::Transform& transform) {
  return HasSharedQuadState(testing::Field(
      "quad_to_target_transform", &SharedQuadState::quad_to_target_transform,
      testing::Eq(transform)));
}

testing::Matcher<const DrawQuad*> HasOpacity(float opacity) {
  return HasSharedQuadState(testing::Field("opacity", &SharedQuadState::opacity,
                                           testing::Eq(opacity)));
}

testing::Matcher<const DrawQuad*> AreContentsOpaque(bool opaque) {
  return HasSharedQuadState(testing::Field(
      "are_contents_opaque", &SharedQuadState::are_contents_opaque,
      testing::Eq(opaque)));
}

testing::Matcher<const DrawQuad*> HasClipRect(
    std::optional<gfx::Rect> clip_rect) {
  return HasSharedQuadState(testing::Field(
      "clip_rect", &SharedQuadState::clip_rect, testing::Eq(clip_rect)));
}

testing::Matcher<const DrawQuad*> HasOffsetTag(OffsetTag offset_tag) {
  return HasSharedQuadState(testing::Field(
      "offset_tag", &SharedQuadState::offset_tag, testing::Eq(offset_tag)));
}

testing::Matcher<const DrawQuad*> HasLayerId(uint32_t layer_id) {
  return HasSharedQuadState(testing::Field(
      "layer_id", &SharedQuadState::layer_id, testing::Eq(layer_id)));
}

testing::Matcher<const DrawQuad*> HasLayerNamespaceId(
    const gfx::OverlayLayerId::NamespaceId& layer_namespace_id) {
  return HasSharedQuadState(testing::Field("layer_namespace_id",
                                           &SharedQuadState::layer_namespace_id,
                                           testing::Eq(layer_namespace_id)));
}

testing::Matcher<const DrawQuad*> HasMaskFilterInfo(
    const gfx::MaskFilterInfo& mask_filter_info) {
  return HasSharedQuadState(testing::Field("mask_filter_info",
                                           &SharedQuadState::mask_filter_info,
                                           testing::Eq(mask_filter_info)));
}

}  // namespace viz