gl_display_manager_unittest.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (c) 2022 The Chromium 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. #include "ui/gl/gl_display_manager.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace gl {
  7. class GLDisplayManagerEGLTest : public testing::Test {
  8. public:
  9. GLDisplayManagerEGLTest() = default;
  10. ~GLDisplayManagerEGLTest() override = default;
  11. protected:
  12. class ScopedGLDisplayManagerEGL {
  13. public:
  14. ScopedGLDisplayManagerEGL() = default;
  15. ScopedGLDisplayManagerEGL(const ScopedGLDisplayManagerEGL&) = delete;
  16. ScopedGLDisplayManagerEGL& operator=(const ScopedGLDisplayManagerEGL&) =
  17. delete;
  18. GLDisplayManagerEGL* operator->() { return &manager_; }
  19. private:
  20. GLDisplayManagerEGL manager_;
  21. };
  22. };
  23. TEST_F(GLDisplayManagerEGLTest, SingleGPU) {
  24. constexpr uint64_t kSingleGpu = 18;
  25. // Set up.
  26. ScopedGLDisplayManagerEGL manager;
  27. manager->SetGpuPreference(GpuPreference::kDefault, kSingleGpu);
  28. // Query the default display.
  29. GLDisplayEGL* display = manager->GetDisplay(GpuPreference::kDefault);
  30. EXPECT_NE(nullptr, display);
  31. EXPECT_EQ(kSingleGpu, display->system_device_id());
  32. // Query again should return the same display.
  33. GLDisplayEGL* display_2 = manager->GetDisplay(GpuPreference::kDefault);
  34. EXPECT_EQ(display, display_2);
  35. // Query with the system device id.
  36. display_2 = manager->GetDisplay(kSingleGpu);
  37. EXPECT_EQ(display, display_2);
  38. // Query the low power display. It should be the same as the default.
  39. GLDisplayEGL* display_low_power =
  40. manager->GetDisplay(GpuPreference::kLowPower);
  41. EXPECT_EQ(display, display_low_power);
  42. // Query the high performance display. It should be the same as the default.
  43. GLDisplayEGL* display_high_performance =
  44. manager->GetDisplay(GpuPreference::kHighPerformance);
  45. EXPECT_EQ(display, display_high_performance);
  46. }
  47. TEST_F(GLDisplayManagerEGLTest, DualGPUs) {
  48. constexpr uint64_t kIntegratedGpu = 18;
  49. constexpr uint64_t kDiscreteGpu = 76;
  50. constexpr uint64_t kDefaultGpu = kIntegratedGpu;
  51. // Set up.
  52. ScopedGLDisplayManagerEGL manager;
  53. manager->SetGpuPreference(GpuPreference::kDefault, kDefaultGpu);
  54. manager->SetGpuPreference(GpuPreference::kLowPower, kIntegratedGpu);
  55. manager->SetGpuPreference(GpuPreference::kHighPerformance, kDiscreteGpu);
  56. // Query the low power display.
  57. GLDisplayEGL* display_low_power =
  58. manager->GetDisplay(GpuPreference::kLowPower);
  59. EXPECT_NE(nullptr, display_low_power);
  60. EXPECT_EQ(kIntegratedGpu, display_low_power->system_device_id());
  61. // Query again should return the same display.
  62. GLDisplayEGL* display_low_power_2 =
  63. manager->GetDisplay(GpuPreference::kLowPower);
  64. EXPECT_EQ(display_low_power, display_low_power_2);
  65. // Query with the system device id.
  66. display_low_power_2 = manager->GetDisplay(kIntegratedGpu);
  67. EXPECT_EQ(display_low_power, display_low_power_2);
  68. // Query the high performance display.
  69. GLDisplayEGL* display_high_performance =
  70. manager->GetDisplay(GpuPreference::kHighPerformance);
  71. EXPECT_NE(nullptr, display_high_performance);
  72. EXPECT_EQ(kDiscreteGpu, display_high_performance->system_device_id());
  73. // Query with the system device id.
  74. GLDisplayEGL* display_high_performance_2 = manager->GetDisplay(kDiscreteGpu);
  75. EXPECT_EQ(display_high_performance, display_high_performance_2);
  76. // Query the default display.
  77. // Due to the set up, it should be the same as the low power display.
  78. GLDisplayEGL* display_default = manager->GetDisplay(GpuPreference::kDefault);
  79. EXPECT_EQ(display_low_power, display_default);
  80. }
  81. TEST_F(GLDisplayManagerEGLTest, NoSetUp) {
  82. // Verify that without setting up GPU preferences, it's still OK to call
  83. // GetDisplay().
  84. // This is to make sure tests that do not care about multi-gpus still work.
  85. ScopedGLDisplayManagerEGL manager;
  86. // Query the default display.
  87. GLDisplayEGL* display = manager->GetDisplay(GpuPreference::kDefault);
  88. EXPECT_NE(nullptr, display);
  89. EXPECT_EQ(0u, display->system_device_id());
  90. }
  91. } // namespace gl