Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: services/ui/display/platform_screen_stub.cc

Issue 2434923002: Handle modified displays in mustash. (Closed)
Patch Set: Fix PlatformScreenStub for tests. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/display/platform_screen_stub.h ('k') | services/ui/display/viewport_metrics.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/service_manager/public/cpp/interface_registry.h" 13 #include "services/service_manager/public/cpp/interface_registry.h"
14 #include "ui/display/display.h" 14 #include "ui/display/display.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
17 17
18 namespace display { 18 namespace display {
19 namespace { 19 namespace {
20 20
21 const int64_t kDisplayId = 1; 21 // Build a ViewportMetric for a 1024x768 display.
22 constexpr gfx::Size kDisplaySize(1024, 768); 22 ViewportMetrics DefaultViewportMetrics() {
23 ViewportMetrics metrics;
24
25 metrics.device_scale_factor = 1.0f;
26 if (Display::HasForceDeviceScaleFactor())
27 metrics.device_scale_factor = Display::GetForcedDeviceScaleFactor();
28
29 metrics.pixel_size = gfx::Size(1024, 768);
30 gfx::Size scaled_size = gfx::ScaleToRoundedSize(
31 metrics.pixel_size, 1.0f / metrics.device_scale_factor);
32
33 metrics.bounds = gfx::Rect(scaled_size);
34 metrics.work_area = gfx::Rect(scaled_size);
35
36 return metrics;
37 }
23 38
24 } // namespace 39 } // namespace
25 40
26 // static 41 // static
27 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { 42 std::unique_ptr<PlatformScreen> PlatformScreen::Create() {
28 return base::MakeUnique<PlatformScreenStub>(); 43 return base::MakeUnique<PlatformScreenStub>();
29 } 44 }
30 45
31 PlatformScreenStub::PlatformScreenStub() : weak_ptr_factory_(this) {} 46 PlatformScreenStub::PlatformScreenStub()
47 : weak_ptr_factory_(this) {}
32 48
33 PlatformScreenStub::~PlatformScreenStub() {} 49 PlatformScreenStub::~PlatformScreenStub() {}
34 50
35 void PlatformScreenStub::FixedSizeScreenConfiguration() { 51 void PlatformScreenStub::FixedSizeScreenConfiguration() {
36 float device_scale_factor = 1.0f; 52 delegate_->OnDisplayAdded(display_id_, display_metrics_);
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);
44 } 53 }
45 54
46 void PlatformScreenStub::AddInterfaces( 55 void PlatformScreenStub::AddInterfaces(
47 service_manager::InterfaceRegistry* registry) {} 56 service_manager::InterfaceRegistry* registry) {}
48 57
49 void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) { 58 void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) {
50 DCHECK(delegate); 59 DCHECK(delegate);
51 delegate_ = delegate; 60 delegate_ = delegate;
61 display_metrics_ = DefaultViewportMetrics();
52 base::ThreadTaskRunnerHandle::Get()->PostTask( 62 base::ThreadTaskRunnerHandle::Get()->PostTask(
53 FROM_HERE, base::Bind(&PlatformScreenStub::FixedSizeScreenConfiguration, 63 FROM_HERE, base::Bind(&PlatformScreenStub::FixedSizeScreenConfiguration,
54 weak_ptr_factory_.GetWeakPtr())); 64 weak_ptr_factory_.GetWeakPtr()));
55 } 65 }
56 66
57 void PlatformScreenStub::RequestCloseDisplay(int64_t display_id) { 67 void PlatformScreenStub::RequestCloseDisplay(int64_t display_id) {
58 if (display_id == kDisplayId) { 68 if (display_id == display_id_) {
59 base::ThreadTaskRunnerHandle::Get()->PostTask( 69 base::ThreadTaskRunnerHandle::Get()->PostTask(
60 FROM_HERE, base::Bind(&PlatformScreenDelegate::OnDisplayRemoved, 70 FROM_HERE, base::Bind(&PlatformScreenDelegate::OnDisplayRemoved,
61 base::Unretained(delegate_), display_id)); 71 base::Unretained(delegate_), display_id));
62 } 72 }
63 } 73 }
64 74
65 int64_t PlatformScreenStub::GetPrimaryDisplayId() const { 75 int64_t PlatformScreenStub::GetPrimaryDisplayId() const {
66 return kDisplayId; 76 return display_id_;
67 } 77 }
68 78
69 } // namespace display 79 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/platform_screen_stub.h ('k') | services/ui/display/viewport_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698