| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ | 5 #ifndef UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ |
| 6 #define UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ | 6 #define UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "ui/display/display_export.h" | 15 #include "ui/display/display_export.h" |
| 16 #include "ui/display/types/display_constants.h" | 16 #include "ui/display/types/display_constants.h" |
| 17 #include "ui/display/types/display_mode.h" | 17 #include "ui/display/types/display_mode.h" |
| 18 #include "ui/display/types/display_snapshot.h" | 18 #include "ui/display/types/display_snapshot.h" |
| 19 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 20 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 21 | 21 |
| 22 namespace display { | 22 namespace display { |
| 23 | 23 |
| 24 // A display snapshot that doesn't correspond to a physical display, used when | 24 // A display snapshot that doesn't correspond to a physical display, used when |
| 25 // running off device. | 25 // running off device. |
| 26 class DISPLAY_EXPORT FakeDisplaySnapshot : public ui::DisplaySnapshot { | 26 class DISPLAY_EXPORT FakeDisplaySnapshot : public DisplaySnapshot { |
| 27 public: | 27 public: |
| 28 class Builder { | 28 class Builder { |
| 29 public: | 29 public: |
| 30 Builder(); | 30 Builder(); |
| 31 ~Builder(); | 31 ~Builder(); |
| 32 | 32 |
| 33 // Builds new FakeDisplaySnapshot. At the very minimum you must set id and | 33 // Builds new FakeDisplaySnapshot. At the very minimum you must set id and |
| 34 // native display mode before building or it will fail. | 34 // native display mode before building or it will fail. |
| 35 std::unique_ptr<FakeDisplaySnapshot> Build(); | 35 std::unique_ptr<FakeDisplaySnapshot> Build(); |
| 36 | 36 |
| 37 Builder& SetId(int64_t id); | 37 Builder& SetId(int64_t id); |
| 38 // Adds display mode with |size| and set as native mode. If a display mode | 38 // Adds display mode with |size| and set as native mode. If a display mode |
| 39 // with |size| already exists then it will be reused. | 39 // with |size| already exists then it will be reused. |
| 40 Builder& SetNativeMode(const gfx::Size& size); | 40 Builder& SetNativeMode(const gfx::Size& size); |
| 41 // Adds display mode and set as native mode. If an existing display mode is | 41 // Adds display mode and set as native mode. If an existing display mode is |
| 42 // equivalent to |mode| it will be set as native mode instead. | 42 // equivalent to |mode| it will be set as native mode instead. |
| 43 Builder& SetNativeMode(std::unique_ptr<ui::DisplayMode> mode); | 43 Builder& SetNativeMode(std::unique_ptr<DisplayMode> mode); |
| 44 // Adds display mode with |size| and set as current mode. If a display mode | 44 // Adds display mode with |size| and set as current mode. If a display mode |
| 45 // with |size| already exists then it will be reused. | 45 // with |size| already exists then it will be reused. |
| 46 Builder& SetCurrentMode(const gfx::Size& size); | 46 Builder& SetCurrentMode(const gfx::Size& size); |
| 47 // Adds display mode and set as current mode. If an existing display mode is | 47 // Adds display mode and set as current mode. If an existing display mode is |
| 48 // equivalent to |mode| it will be set as current mode instead. | 48 // equivalent to |mode| it will be set as current mode instead. |
| 49 Builder& SetCurrentMode(std::unique_ptr<ui::DisplayMode> mode); | 49 Builder& SetCurrentMode(std::unique_ptr<DisplayMode> mode); |
| 50 // Adds display mode with |size| if necessary. If a display mode with |size| | 50 // Adds display mode with |size| if necessary. If a display mode with |size| |
| 51 // already exists then it will be reused. | 51 // already exists then it will be reused. |
| 52 Builder& AddMode(const gfx::Size& size); | 52 Builder& AddMode(const gfx::Size& size); |
| 53 // Adds |mode| if necessary. If an existing display mode is equivalent to | 53 // Adds |mode| if necessary. If an existing display mode is equivalent to |
| 54 // |mode| it will not be added. | 54 // |mode| it will not be added. |
| 55 Builder& AddMode(std::unique_ptr<ui::DisplayMode> mode); | 55 Builder& AddMode(std::unique_ptr<DisplayMode> mode); |
| 56 Builder& SetOrigin(const gfx::Point& origin); | 56 Builder& SetOrigin(const gfx::Point& origin); |
| 57 Builder& SetType(ui::DisplayConnectionType type); | 57 Builder& SetType(DisplayConnectionType type); |
| 58 Builder& SetIsAspectPerservingScaling(bool is_aspect_preserving_scaling); | 58 Builder& SetIsAspectPerservingScaling(bool is_aspect_preserving_scaling); |
| 59 Builder& SetHasOverscan(bool has_overscan); | 59 Builder& SetHasOverscan(bool has_overscan); |
| 60 Builder& SetHasColorCorrectionMatrix(bool val); | 60 Builder& SetHasColorCorrectionMatrix(bool val); |
| 61 Builder& SetName(const std::string& name); | 61 Builder& SetName(const std::string& name); |
| 62 Builder& SetProductId(int64_t product_id); | 62 Builder& SetProductId(int64_t product_id); |
| 63 // Sets physical_size so that the screen has the specified DPI using the | 63 // Sets physical_size so that the screen has the specified DPI using the |
| 64 // native resolution. | 64 // native resolution. |
| 65 Builder& SetDPI(int dpi); | 65 Builder& SetDPI(int dpi); |
| 66 // Sets physical_size for low DPI display. | 66 // Sets physical_size for low DPI display. |
| 67 Builder& SetLowDPI(); | 67 Builder& SetLowDPI(); |
| 68 // Sets physical_size for high DPI display. | 68 // Sets physical_size for high DPI display. |
| 69 Builder& SetHighDPI(); | 69 Builder& SetHighDPI(); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 // Returns a display mode with |size|. If there is no existing mode, insert | 72 // Returns a display mode with |size|. If there is no existing mode, insert |
| 73 // a display mode with |size| first. | 73 // a display mode with |size| first. |
| 74 const ui::DisplayMode* AddOrFindDisplayMode(const gfx::Size& size); | 74 const DisplayMode* AddOrFindDisplayMode(const gfx::Size& size); |
| 75 // Returns a display mode equivalent to |mode|. If there is no equivalent | 75 // Returns a display mode equivalent to |mode|. If there is no equivalent |
| 76 // display mode, insert |mode| first. | 76 // display mode, insert |mode| first. |
| 77 const ui::DisplayMode* AddOrFindDisplayMode( | 77 const DisplayMode* AddOrFindDisplayMode(std::unique_ptr<DisplayMode> mode); |
| 78 std::unique_ptr<ui::DisplayMode> mode); | |
| 79 | 78 |
| 80 int64_t id_ = kInvalidDisplayId; | 79 int64_t id_ = kInvalidDisplayId; |
| 81 gfx::Point origin_; | 80 gfx::Point origin_; |
| 82 float dpi_ = 96.0; | 81 float dpi_ = 96.0; |
| 83 ui::DisplayConnectionType type_ = ui::DISPLAY_CONNECTION_TYPE_UNKNOWN; | 82 DisplayConnectionType type_ = DISPLAY_CONNECTION_TYPE_UNKNOWN; |
| 84 bool is_aspect_preserving_scaling_ = false; | 83 bool is_aspect_preserving_scaling_ = false; |
| 85 bool has_overscan_ = false; | 84 bool has_overscan_ = false; |
| 86 bool has_color_correction_matrix_ = false; | 85 bool has_color_correction_matrix_ = false; |
| 87 std::string name_; | 86 std::string name_; |
| 88 int64_t product_id_ = DisplaySnapshot::kInvalidProductID; | 87 int64_t product_id_ = DisplaySnapshot::kInvalidProductID; |
| 89 DisplayModeList modes_; | 88 DisplayModeList modes_; |
| 90 const ui::DisplayMode* current_mode_ = nullptr; | 89 const DisplayMode* current_mode_ = nullptr; |
| 91 const ui::DisplayMode* native_mode_ = nullptr; | 90 const DisplayMode* native_mode_ = nullptr; |
| 92 | 91 |
| 93 DISALLOW_COPY_AND_ASSIGN(Builder); | 92 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 FakeDisplaySnapshot(int64_t display_id, | 95 FakeDisplaySnapshot(int64_t display_id, |
| 97 const gfx::Point& origin, | 96 const gfx::Point& origin, |
| 98 const gfx::Size& physical_size, | 97 const gfx::Size& physical_size, |
| 99 ui::DisplayConnectionType type, | 98 DisplayConnectionType type, |
| 100 bool is_aspect_preserving_scaling, | 99 bool is_aspect_preserving_scaling, |
| 101 bool has_overscan, | 100 bool has_overscan, |
| 102 bool has_color_correction_matrix, | 101 bool has_color_correction_matrix, |
| 103 std::string display_name, | 102 std::string display_name, |
| 104 int64_t product_id, | 103 int64_t product_id, |
| 105 DisplayModeList modes, | 104 DisplayModeList modes, |
| 106 const ui::DisplayMode* current_mode, | 105 const DisplayMode* current_mode, |
| 107 const ui::DisplayMode* native_mode); | 106 const DisplayMode* native_mode); |
| 108 ~FakeDisplaySnapshot() override; | 107 ~FakeDisplaySnapshot() override; |
| 109 | 108 |
| 110 // Creates a display snapshot from the provided |spec| string. Returns null if | 109 // Creates a display snapshot from the provided |spec| string. Returns null if |
| 111 // |spec| is invalid. See fake_display_delegate.h for |spec| format | 110 // |spec| is invalid. See fake_display_delegate.h for |spec| format |
| 112 // description. | 111 // description. |
| 113 static std::unique_ptr<ui::DisplaySnapshot> CreateFromSpec( | 112 static std::unique_ptr<DisplaySnapshot> CreateFromSpec( |
| 114 int64_t id, | 113 int64_t id, |
| 115 const std::string& spec); | 114 const std::string& spec); |
| 116 | 115 |
| 117 // DisplaySnapshot: | 116 // DisplaySnapshot: |
| 118 std::string ToString() const override; | 117 std::string ToString() const override; |
| 119 | 118 |
| 120 private: | 119 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(FakeDisplaySnapshot); | 120 DISALLOW_COPY_AND_ASSIGN(FakeDisplaySnapshot); |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 } // namespace display | 123 } // namespace display |
| 125 | 124 |
| 126 #endif // UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ | 125 #endif // UI_DISPLAY_FAKE_DISPLAY_SNAPSHOT_H_ |
| OLD | NEW |