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

Side by Side Diff: remoting/client/desktop_viewport.cc

Issue 2866843002: [Remoting Client] Always ResizeToFit when desktop/surface size is changed (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | remoting/client/view_matrix.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "remoting/client/desktop_viewport.h" 5 #include "remoting/client/desktop_viewport.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace remoting { 11 namespace remoting {
12 12
13 namespace { 13 namespace {
14 14
15 float MAX_ZOOM_LEVEL = 100.f; 15 float MAX_ZOOM_LEVEL = 100.f;
16 16
17 } // namespace 17 } // namespace
18 18
19 DesktopViewport::DesktopViewport() : desktop_to_surface_transform_() {} 19 DesktopViewport::DesktopViewport() : desktop_to_surface_transform_() {}
20 20
21 DesktopViewport::~DesktopViewport() {} 21 DesktopViewport::~DesktopViewport() {}
22 22
23 void DesktopViewport::SetDesktopSize(int desktop_width, int desktop_height) { 23 void DesktopViewport::SetDesktopSize(int desktop_width, int desktop_height) {
24 bool need_resize_to_fit = !desktop_size_ready_ && surface_size_ready_;
25 desktop_size_.x = desktop_width; 24 desktop_size_.x = desktop_width;
26 desktop_size_.y = desktop_height; 25 desktop_size_.y = desktop_height;
27 desktop_size_ready_ = true; 26 desktop_size_ready_ = true;
28 if (need_resize_to_fit) { 27 ResizeToFit();
29 ResizeToFit();
30 } else if (IsViewportReady()) {
31 UpdateViewport();
32 }
33 } 28 }
34 29
35 void DesktopViewport::SetSurfaceSize(int surface_width, int surface_height) { 30 void DesktopViewport::SetSurfaceSize(int surface_width, int surface_height) {
36 bool need_resize_to_fit = desktop_size_ready_ && !surface_size_ready_;
37 surface_size_.x = surface_width; 31 surface_size_.x = surface_width;
38 surface_size_.y = surface_height; 32 surface_size_.y = surface_height;
39 surface_size_ready_ = true; 33 surface_size_ready_ = true;
40 if (need_resize_to_fit) { 34 ResizeToFit();
41 ResizeToFit();
42 } else if (IsViewportReady()) {
43 UpdateViewport();
44 }
45 } 35 }
46 36
47 void DesktopViewport::MoveDesktop(float dx, float dy) { 37 void DesktopViewport::MoveDesktop(float dx, float dy) {
48 desktop_to_surface_transform_.PostTranslate({dx, dy}); 38 desktop_to_surface_transform_.PostTranslate({dx, dy});
49 UpdateViewport(); 39 UpdateViewport();
50 } 40 }
51 41
52 void DesktopViewport::ScaleDesktop(float px, float py, float scale) { 42 void DesktopViewport::ScaleDesktop(float px, float py, float scale) {
53 desktop_to_surface_transform_.PostScale({px, py}, scale); 43 desktop_to_surface_transform_.PostScale({px, py}, scale);
54 UpdateViewport(); 44 UpdateViewport();
55 } 45 }
56 46
57 void DesktopViewport::SetViewportCenter(float x, float y) { 47 void DesktopViewport::SetViewportCenter(float x, float y) {
58 ViewMatrix::Point old_center = GetViewportCenter(); 48 ViewMatrix::Point old_center = GetViewportCenter();
59 MoveViewportCenterWithoutUpdate(x - old_center.x, y - old_center.y); 49 MoveViewportCenterWithoutUpdate(x - old_center.x, y - old_center.y);
60 UpdateViewport(); 50 UpdateViewport();
61 } 51 }
62 52
63 void DesktopViewport::RegisterOnTransformationChangedCallback( 53 void DesktopViewport::RegisterOnTransformationChangedCallback(
64 const TransformationCallback& callback, 54 const TransformationCallback& callback,
65 bool run_immediately) { 55 bool run_immediately) {
66 on_transformation_changed_ = callback; 56 on_transformation_changed_ = callback;
67 if (IsViewportReady() && run_immediately) { 57 if (IsViewportReady() && run_immediately) {
68 callback.Run(desktop_to_surface_transform_); 58 callback.Run(desktop_to_surface_transform_);
69 } 59 }
70 } 60 }
71 61
72 void DesktopViewport::ResizeToFit() { 62 void DesktopViewport::ResizeToFit() {
73 DCHECK(IsViewportReady()); 63 if (!IsViewportReady()) {
64 return;
65 }
74 66
75 // <---Desktop Width----> 67 // <---Desktop Width---->
76 // +==========+---------+ 68 // +==========+---------+
77 // | | | 69 // | | |
78 // | Viewport | Desktop | 70 // | Viewport | Desktop |
79 // | | | 71 // | | |
80 // +==========+---------+ 72 // +==========+---------+
81 // 73 //
82 // +==========+ ^ 74 // +==========+ ^
83 // | | | 75 // | | |
84 // | Viewport | | 76 // | Viewport | |
85 // | | | 77 // | | |
86 // +==========+ | Desktop 78 // +==========+ | Desktop
87 // | | | Height 79 // | | | Height
88 // | Desktop | | 80 // | Desktop | |
89 // | | | 81 // | | |
90 // +----------+ v 82 // +----------+ v
91 // resize the desktop such that it fits the viewport in one dimension. 83 // resize the desktop such that it fits the viewport in one dimension.
92 84
93 float scale = std::max(surface_size_.x / desktop_size_.x, 85 float scale = std::max(surface_size_.x / desktop_size_.x,
94 surface_size_.y / desktop_size_.y); 86 surface_size_.y / desktop_size_.y);
95 desktop_to_surface_transform_.SetScale(scale); 87 desktop_to_surface_transform_.SetScale(scale);
88 desktop_to_surface_transform_.SetOffset({0.f, 0.f});
96 UpdateViewport(); 89 UpdateViewport();
97 } 90 }
98 91
99 bool DesktopViewport::IsViewportReady() const { 92 bool DesktopViewport::IsViewportReady() const {
100 return desktop_size_ready_ && surface_size_ready_; 93 return desktop_size_ready_ && surface_size_ready_;
joedow 2017/05/05 21:53:20 Per discussion, I think removing these member vars
Yuwei 2017/05/05 22:04:48 Done.
101 } 94 }
102 95
103 void DesktopViewport::UpdateViewport() { 96 void DesktopViewport::UpdateViewport() {
104 if (!IsViewportReady()) { 97 if (!IsViewportReady()) {
105 // User may attempt to zoom and pan before the desktop image is received. 98 // User may attempt to zoom and pan before the desktop image is received.
106 // This should be fine since the viewport will be reset once the image 99 // This should be fine since the viewport will be reset once the image
107 // dimension is set. 100 // dimension is set.
108 VLOG(1) << "Viewport is not ready yet."; 101 VLOG(1) << "Viewport is not ready yet.";
109 return; 102 return;
110 } 103 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 222
230 if (new_point.y < bounds.top) { 223 if (new_point.y < bounds.top) {
231 new_point.y = bounds.top; 224 new_point.y = bounds.top;
232 } else if (new_point.y > bounds.bottom) { 225 } else if (new_point.y > bounds.bottom) {
233 new_point.y = bounds.bottom; 226 new_point.y = bounds.bottom;
234 } 227 }
235 return new_point; 228 return new_point;
236 } 229 }
237 230
238 } // namespace remoting 231 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/client/view_matrix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698