| 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 #include "ui/display/fake_display_delegate.h" | 5 #include "ui/display/fake_display_delegate.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/hash.h" | 13 #include "base/hash.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/display_switches.h" | 19 #include "ui/display/display_switches.h" |
| 20 #include "ui/display/types/display_constants.h" |
| 20 #include "ui/display/types/native_display_observer.h" | 21 #include "ui/display/types/native_display_observer.h" |
| 21 #include "ui/display/util/display_util.h" | 22 #include "ui/display/util/display_util.h" |
| 22 | 23 |
| 23 namespace display { | 24 namespace display { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // The EDID specification marks the top bit of the manufacturer id as reserved. | 28 // The EDID specification marks the top bit of the manufacturer id as reserved. |
| 28 const uint16_t kReservedManufacturerID = 1 << 15; | 29 const uint16_t kReservedManufacturerID = 1 << 15; |
| 29 | 30 |
| 30 // A random product name hash. | 31 // A random product name hash. |
| 31 const uint32_t kProductCodeHash = base::Hash("Very Generic Display"); | 32 const uint32_t kProductCodeHash = base::Hash("Very Generic Display"); |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 FakeDisplayDelegate::FakeDisplayDelegate() {} | 36 FakeDisplayDelegate::FakeDisplayDelegate() {} |
| 36 | 37 |
| 37 FakeDisplayDelegate::~FakeDisplayDelegate() {} | 38 FakeDisplayDelegate::~FakeDisplayDelegate() {} |
| 38 | 39 |
| 39 int64_t FakeDisplayDelegate::AddDisplay(const gfx::Size& display_size) { | 40 int64_t FakeDisplayDelegate::AddDisplay(const gfx::Size& display_size) { |
| 40 DCHECK(!display_size.IsEmpty()); | 41 DCHECK(!display_size.IsEmpty()); |
| 41 | 42 |
| 42 if (next_display_id_ == 0xFF) { | 43 if (next_display_id_ == 0xFF) { |
| 43 LOG(ERROR) << "Exceeded display id limit"; | 44 LOG(ERROR) << "Exceeded display id limit"; |
| 44 return Display::kInvalidDisplayID; | 45 return kInvalidDisplayId; |
| 45 } | 46 } |
| 46 | 47 |
| 47 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, | 48 int64_t id = GenerateDisplayID(kReservedManufacturerID, kProductCodeHash, |
| 48 ++next_display_id_); | 49 ++next_display_id_); |
| 49 | 50 |
| 50 FakeDisplaySnapshot::Builder builder; | 51 FakeDisplaySnapshot::Builder builder; |
| 51 builder.SetId(id).SetNativeMode(display_size); | 52 builder.SetId(id).SetNativeMode(display_size); |
| 52 builder.SetName(base::StringPrintf("Fake Display %" PRId64, id)); | 53 builder.SetName(base::StringPrintf("Fake Display %" PRId64, id)); |
| 53 | 54 |
| 54 return AddDisplay(builder.Build()) ? id : Display::kInvalidDisplayID; | 55 return AddDisplay(builder.Build()) ? id : kInvalidDisplayId; |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool FakeDisplayDelegate::AddDisplay( | 58 bool FakeDisplayDelegate::AddDisplay( |
| 58 std::unique_ptr<ui::DisplaySnapshot> display) { | 59 std::unique_ptr<ui::DisplaySnapshot> display) { |
| 59 DCHECK(display); | 60 DCHECK(display); |
| 60 | 61 |
| 61 int64_t display_id = display->display_id(); | 62 int64_t display_id = display->display_id(); |
| 62 // Check there is no existing display with the same id. | 63 // Check there is no existing display with the same id. |
| 63 for (auto& existing_display : displays_) { | 64 for (auto& existing_display : displays_) { |
| 64 if (existing_display->display_id() == display_id) { | 65 if (existing_display->display_id() == display_id) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 226 |
| 226 void FakeDisplayDelegate::OnConfigurationChanged() { | 227 void FakeDisplayDelegate::OnConfigurationChanged() { |
| 227 if (!initialized_) | 228 if (!initialized_) |
| 228 return; | 229 return; |
| 229 | 230 |
| 230 for (ui::NativeDisplayObserver& observer : observers_) | 231 for (ui::NativeDisplayObserver& observer : observers_) |
| 231 observer.OnConfigurationChanged(); | 232 observer.OnConfigurationChanged(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace display | 235 } // namespace display |
| OLD | NEW |