File: fake_display_snapshot.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (162 lines) | stat: -rw-r--r-- 7,046 bytes parent folder | download | duplicates (6)
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
158
159
160
161
162
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_DISPLAY_MANAGER_TEST_FAKE_DISPLAY_SNAPSHOT_H_
#define UI_DISPLAY_MANAGER_TEST_FAKE_DISPLAY_SNAPSHOT_H_

#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "ui/display/types/display_constants.h"
#include "ui/display/types/display_mode.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"

namespace display {

// A display snapshot that doesn't correspond to a physical display, used when
// running off device.
class FakeDisplaySnapshot : public DisplaySnapshot {
 public:
  class Builder {
   public:
    Builder();

    Builder(const Builder&) = delete;
    Builder& operator=(const Builder&) = delete;

    ~Builder();

    // Builds new FakeDisplaySnapshot. At the very minimum you must set id and
    // native display mode before building or it will fail.
    std::unique_ptr<FakeDisplaySnapshot> Build();

    Builder& SetId(int64_t id);
    Builder& SetPortDisplayId(int64_t id);
    Builder& SetEdidDisplayId(int64_t id);
    Builder& SetConnectorIndex(uint16_t index);
    // Adds display mode with |size| and set as native mode. If a display mode
    // with |size| already exists then it will be reused.
    Builder& SetNativeMode(const gfx::Size& size);
    // Adds display mode and set as native mode. If an existing display mode is
    // equivalent to |mode| it will be set as native mode instead.
    Builder& SetNativeMode(std::unique_ptr<DisplayMode> mode);
    // Adds display mode with |size| and set as current mode. If a display mode
    // with |size| already exists then it will be reused.
    Builder& SetCurrentMode(const gfx::Size& size);
    // Adds display mode and set as current mode. If an existing display mode is
    // equivalent to |mode| it will be set as current mode instead.
    Builder& SetCurrentMode(std::unique_ptr<DisplayMode> mode);
    // Adds display mode with |size| if necessary. If a display mode with |size|
    // already exists then it will be reused.
    Builder& AddMode(const gfx::Size& size);
    // Adds |mode| if necessary. If an existing display mode is equivalent to
    // |mode| it will not be added.
    Builder& AddMode(std::unique_ptr<DisplayMode> mode);
    Builder& SetOrigin(const gfx::Point& origin);
    Builder& SetType(DisplayConnectionType type);
    Builder& SetBaseConnectorId(uint64_t base_connector_id);
    Builder& SetPathTopology(const std::vector<uint64_t>& path_topology);
    Builder& SetIsAspectPreservingScaling(bool is_aspect_preserving_scaling);
    Builder& SetHasOverscan(bool has_overscan);
    Builder& SetHasColorCorrectionMatrix(bool val);
    Builder& SetName(const std::string& name);
    Builder& SetSysPath(const base::FilePath& sys_path);
    Builder& SetProductCode(int64_t product_code);
    Builder& SetMaximumCursorSize(const gfx::Size& maximum_cursor_size);
    // Sets physical_size so that the screen has the specified DPI using the
    // native resolution.
    Builder& SetDPI(int dpi);
    // Sets physical_size for low DPI display.
    Builder& SetLowDPI();
    // Sets physical_size for high DPI display.
    Builder& SetHighDPI();
    Builder& SetPrivacyScreen(PrivacyScreenState state);
    Builder& SetHasContentProtectionKey(bool has_content_protection_key);
    Builder& SetColorSpace(const gfx::ColorSpace& color_space);
    Builder& SetBitsPerChannel(uint32_t bits_per_channel);
    Builder& SetHDRStaticMetadata(
        const gfx::HDRStaticMetadata& hdr_static_metadata);
    Builder& SetVariableRefreshRateState(
        VariableRefreshRateState variable_refresh_rate_state);

   private:
    // Returns a display mode with |size|. If there is no existing mode, insert
    // a display mode with |size| first.
    const DisplayMode* AddOrFindDisplayMode(const gfx::Size& size);
    // Returns a display mode equivalent to |mode|. If there is no equivalent
    // display mode, insert |mode| first.
    const DisplayMode* AddOrFindDisplayMode(std::unique_ptr<DisplayMode> mode);

    int64_t id_ = kInvalidDisplayId;
    int64_t port_display_id_ = kInvalidDisplayId;
    int64_t edid_display_id_ = kInvalidDisplayId;
    uint16_t connector_index_ = 0u;
    gfx::Point origin_;
    float dpi_ = 96.0;
    DisplayConnectionType type_ = DISPLAY_CONNECTION_TYPE_UNKNOWN;
    uint64_t base_connector_id_ = 1u;
    std::vector<uint64_t> path_topology_ = {};
    bool is_aspect_preserving_scaling_ = false;
    bool has_overscan_ = false;
    PrivacyScreenState privacy_screen_state_ = kNotSupported;
    bool has_content_protection_key_ = false;
    std::string name_;
    base::FilePath sys_path_;
    int64_t product_code_ = DisplaySnapshot::kInvalidProductCode;
    gfx::Size maximum_cursor_size_ = gfx::Size(64, 64);
    DisplayModeList modes_;
    raw_ptr<const DisplayMode> current_mode_ = nullptr;
    raw_ptr<const DisplayMode> native_mode_ = nullptr;
    DisplaySnapshot::ColorInfo color_info_;
    VariableRefreshRateState variable_refresh_rate_state_ =
        VariableRefreshRateState::kVrrNotCapable;
  };

  FakeDisplaySnapshot(int64_t display_id,
                      int64_t port_display_id,
                      int64_t edid_display_id,
                      uint16_t connector_index,
                      const gfx::Point& origin,
                      const gfx::Size& physical_size,
                      DisplayConnectionType type,
                      uint64_t base_connector_id,
                      const std::vector<uint64_t>& path_topology,
                      bool is_aspect_preserving_scaling,
                      bool has_overscan,
                      PrivacyScreenState privacy_screen_state,
                      bool has_content_protection_key_,
                      std::string display_name,
                      const base::FilePath& sys_path,
                      DisplayModeList modes,
                      const DisplayMode* current_mode,
                      const DisplayMode* native_mode,
                      int64_t product_code,
                      const gfx::Size& maximum_cursor_size,
                      const DisplaySnapshot::ColorInfo& color_info,
                      VariableRefreshRateState variable_refresh_rate_state,
                      const DrmFormatsAndModifiers& drm_formats_and_modifiers);

  FakeDisplaySnapshot(const FakeDisplaySnapshot&) = delete;
  FakeDisplaySnapshot& operator=(const FakeDisplaySnapshot&) = delete;

  ~FakeDisplaySnapshot() override;

  // Creates a display snapshot from the provided |spec| string. Returns null if
  // |spec| is invalid. See fake_display_delegate.h for |spec| format
  // description.
  static std::unique_ptr<DisplaySnapshot> CreateFromSpec(
      int64_t id,
      const std::string& spec);
};

}  // namespace display

#endif  // UI_DISPLAY_MANAGER_TEST_FAKE_DISPLAY_SNAPSHOT_H_