| 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 "services/ui/display/platform_screen_stub.h" | 5 #include "services/ui/display/platform_screen_stub.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "services/shell/public/cpp/interface_registry.h" | 13 #include "services/shell/public/cpp/interface_registry.h" |
| 14 #include "ui/display/display.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/geometry/size.h" |
| 15 | 17 |
| 16 namespace display { | 18 namespace display { |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 const int64_t kDisplayId = 1; | 21 const int64_t kDisplayId = 1; |
| 22 constexpr gfx::Size kDisplaySize(1024, 768); |
| 20 | 23 |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 23 // static | 26 // static |
| 24 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { | 27 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { |
| 25 return base::MakeUnique<PlatformScreenStub>(); | 28 return base::MakeUnique<PlatformScreenStub>(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 PlatformScreenStub::PlatformScreenStub() : weak_ptr_factory_(this) {} | 31 PlatformScreenStub::PlatformScreenStub() : weak_ptr_factory_(this) {} |
| 29 | 32 |
| 30 PlatformScreenStub::~PlatformScreenStub() {} | 33 PlatformScreenStub::~PlatformScreenStub() {} |
| 31 | 34 |
| 32 void PlatformScreenStub::FixedSizeScreenConfiguration() { | 35 void PlatformScreenStub::FixedSizeScreenConfiguration() { |
| 33 delegate_->OnDisplayAdded(kDisplayId, gfx::Rect(1024, 768)); | 36 float device_scale_factor = 1.0f; |
| 37 if (Display::HasForceDeviceScaleFactor()) |
| 38 device_scale_factor = Display::GetForcedDeviceScaleFactor(); |
| 39 |
| 40 gfx::Size scaled_size = |
| 41 gfx::ScaleToRoundedSize(kDisplaySize, 1.0f / device_scale_factor); |
| 42 delegate_->OnDisplayAdded(kDisplayId, gfx::Rect(scaled_size), kDisplaySize, |
| 43 device_scale_factor); |
| 34 } | 44 } |
| 35 | 45 |
| 36 void PlatformScreenStub::AddInterfaces(shell::InterfaceRegistry* registry) {} | 46 void PlatformScreenStub::AddInterfaces(shell::InterfaceRegistry* registry) {} |
| 37 | 47 |
| 38 void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) { | 48 void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) { |
| 39 DCHECK(delegate); | 49 DCHECK(delegate); |
| 40 delegate_ = delegate; | 50 delegate_ = delegate; |
| 41 base::ThreadTaskRunnerHandle::Get()->PostTask( | 51 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 42 FROM_HERE, base::Bind(&PlatformScreenStub::FixedSizeScreenConfiguration, | 52 FROM_HERE, base::Bind(&PlatformScreenStub::FixedSizeScreenConfiguration, |
| 43 weak_ptr_factory_.GetWeakPtr())); | 53 weak_ptr_factory_.GetWeakPtr())); |
| 44 } | 54 } |
| 45 | 55 |
| 46 void PlatformScreenStub::RequestCloseDisplay(int64_t display_id) { | 56 void PlatformScreenStub::RequestCloseDisplay(int64_t display_id) { |
| 47 if (display_id == kDisplayId) { | 57 if (display_id == kDisplayId) { |
| 48 base::ThreadTaskRunnerHandle::Get()->PostTask( | 58 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 49 FROM_HERE, base::Bind(&PlatformScreenDelegate::OnDisplayRemoved, | 59 FROM_HERE, base::Bind(&PlatformScreenDelegate::OnDisplayRemoved, |
| 50 base::Unretained(delegate_), display_id)); | 60 base::Unretained(delegate_), display_id)); |
| 51 } | 61 } |
| 52 } | 62 } |
| 53 | 63 |
| 54 int64_t PlatformScreenStub::GetPrimaryDisplayId() const { | 64 int64_t PlatformScreenStub::GetPrimaryDisplayId() const { |
| 55 return kDisplayId; | 65 return kDisplayId; |
| 56 } | 66 } |
| 57 | 67 |
| 58 } // namespace display | 68 } // namespace display |
| OLD | NEW |