| OLD | NEW |
| 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void DesktopViewport::MoveDesktop(float dx, float dy) { | 47 void DesktopViewport::MoveDesktop(float dx, float dy) { |
| 48 desktop_to_surface_transform_.PostTranslate({dx, dy}); | 48 desktop_to_surface_transform_.PostTranslate({dx, dy}); |
| 49 UpdateViewport(); | 49 UpdateViewport(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void DesktopViewport::ScaleDesktop(float px, float py, float scale) { | 52 void DesktopViewport::ScaleDesktop(float px, float py, float scale) { |
| 53 desktop_to_surface_transform_.PostScale({px, py}, scale); | 53 desktop_to_surface_transform_.PostScale({px, py}, scale); |
| 54 UpdateViewport(); | 54 UpdateViewport(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void DesktopViewport::MoveViewport(float dx, float dy) { |
| 58 MoveViewportWithoutUpdate(dx, dy); |
| 59 UpdateViewport(); |
| 60 } |
| 61 |
| 57 void DesktopViewport::SetViewportCenter(float x, float y) { | 62 void DesktopViewport::SetViewportCenter(float x, float y) { |
| 58 ViewMatrix::Point old_center = GetViewportCenter(); | 63 ViewMatrix::Point old_center = GetViewportCenter(); |
| 59 MoveViewportCenterWithoutUpdate(x - old_center.x, y - old_center.y); | 64 MoveViewport(x - old_center.x, y - old_center.y); |
| 60 UpdateViewport(); | |
| 61 } | 65 } |
| 62 | 66 |
| 63 void DesktopViewport::RegisterOnTransformationChangedCallback( | 67 void DesktopViewport::RegisterOnTransformationChangedCallback( |
| 64 const TransformationCallback& callback, | 68 const TransformationCallback& callback, |
| 65 bool run_immediately) { | 69 bool run_immediately) { |
| 66 on_transformation_changed_ = callback; | 70 on_transformation_changed_ = callback; |
| 67 if (IsViewportReady() && run_immediately) { | 71 if (IsViewportReady() && run_immediately) { |
| 68 callback.Run(desktop_to_surface_transform_); | 72 callback.Run(desktop_to_surface_transform_); |
| 69 } | 73 } |
| 70 } | 74 } |
| 71 | 75 |
| 76 const ViewMatrix& DesktopViewport::GetTransformation() const { |
| 77 return desktop_to_surface_transform_; |
| 78 } |
| 79 |
| 72 void DesktopViewport::ResizeToFit() { | 80 void DesktopViewport::ResizeToFit() { |
| 73 DCHECK(IsViewportReady()); | 81 DCHECK(IsViewportReady()); |
| 74 | 82 |
| 75 // <---Desktop Width----> | 83 // <---Desktop Width----> |
| 76 // +==========+---------+ | 84 // +==========+---------+ |
| 77 // | | | | 85 // | | | |
| 78 // | Viewport | Desktop | | 86 // | Viewport | Desktop | |
| 79 // | | | | 87 // | | | |
| 80 // +==========+---------+ | 88 // +==========+---------+ |
| 81 // | 89 // |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // share the same center as the desktop. | 165 // share the same center as the desktop. |
| 158 // | 166 // |
| 159 // +==========+------+==+ +======+------+======+ | 167 // +==========+------+==+ +======+------+======+ |
| 160 // | VP | DP | | ==> | VP | DP | | | 168 // | VP | DP | | ==> | VP | DP | | |
| 161 // +==========+------+==+ +======+------+======+ | 169 // +==========+------+==+ +======+------+======+ |
| 162 // | 170 // |
| 163 // This is done on the desktop's reference frame to simplify things a bit. | 171 // This is done on the desktop's reference frame to simplify things a bit. |
| 164 ViewMatrix::Point old_center = GetViewportCenter(); | 172 ViewMatrix::Point old_center = GetViewportCenter(); |
| 165 ViewMatrix::Point new_center = | 173 ViewMatrix::Point new_center = |
| 166 ConstrainPointToBounds(GetViewportCenterBounds(), old_center); | 174 ConstrainPointToBounds(GetViewportCenterBounds(), old_center); |
| 167 MoveViewportCenterWithoutUpdate(new_center.x - old_center.x, | 175 MoveViewportWithoutUpdate(new_center.x - old_center.x, |
| 168 new_center.y - old_center.y); | 176 new_center.y - old_center.y); |
| 169 | 177 |
| 170 if (on_transformation_changed_) { | 178 if (on_transformation_changed_) { |
| 171 on_transformation_changed_.Run(desktop_to_surface_transform_); | 179 on_transformation_changed_.Run(desktop_to_surface_transform_); |
| 172 } | 180 } |
| 173 } | 181 } |
| 174 | 182 |
| 175 DesktopViewport::Bounds DesktopViewport::GetViewportCenterBounds() const { | 183 DesktopViewport::Bounds DesktopViewport::GetViewportCenterBounds() const { |
| 176 Bounds bounds; | 184 Bounds bounds; |
| 177 | 185 |
| 178 // Viewport size on the desktop space. | 186 // Viewport size on the desktop space. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 202 } | 210 } |
| 203 | 211 |
| 204 return bounds; | 212 return bounds; |
| 205 } | 213 } |
| 206 | 214 |
| 207 ViewMatrix::Point DesktopViewport::GetViewportCenter() const { | 215 ViewMatrix::Point DesktopViewport::GetViewportCenter() const { |
| 208 return desktop_to_surface_transform_.Invert().MapPoint( | 216 return desktop_to_surface_transform_.Invert().MapPoint( |
| 209 {surface_size_.x / 2.f, surface_size_.y / 2.f}); | 217 {surface_size_.x / 2.f, surface_size_.y / 2.f}); |
| 210 } | 218 } |
| 211 | 219 |
| 212 void DesktopViewport::MoveViewportCenterWithoutUpdate(float dx, float dy) { | 220 void DesktopViewport::MoveViewportWithoutUpdate(float dx, float dy) { |
| 213 // <dx, dy> is defined on desktop's reference frame. Translation must be | 221 // <dx, dy> is defined on desktop's reference frame. Translation must be |
| 214 // flipped and scaled. | 222 // flipped and scaled. |
| 215 desktop_to_surface_transform_.PostTranslate( | 223 desktop_to_surface_transform_.PostTranslate( |
| 216 desktop_to_surface_transform_.MapVector({-dx, -dy})); | 224 desktop_to_surface_transform_.MapVector({-dx, -dy})); |
| 217 } | 225 } |
| 218 | 226 |
| 219 // static | 227 // static |
| 220 ViewMatrix::Point DesktopViewport::ConstrainPointToBounds( | 228 ViewMatrix::Point DesktopViewport::ConstrainPointToBounds( |
| 221 const Bounds& bounds, | 229 const Bounds& bounds, |
| 222 const ViewMatrix::Point& point) { | 230 const ViewMatrix::Point& point) { |
| 223 ViewMatrix::Point new_point = point; | 231 ViewMatrix::Point new_point = point; |
| 224 if (new_point.x < bounds.left) { | 232 if (new_point.x < bounds.left) { |
| 225 new_point.x = bounds.left; | 233 new_point.x = bounds.left; |
| 226 } else if (new_point.x > bounds.right) { | 234 } else if (new_point.x > bounds.right) { |
| 227 new_point.x = bounds.right; | 235 new_point.x = bounds.right; |
| 228 } | 236 } |
| 229 | 237 |
| 230 if (new_point.y < bounds.top) { | 238 if (new_point.y < bounds.top) { |
| 231 new_point.y = bounds.top; | 239 new_point.y = bounds.top; |
| 232 } else if (new_point.y > bounds.bottom) { | 240 } else if (new_point.y > bounds.bottom) { |
| 233 new_point.y = bounds.bottom; | 241 new_point.y = bounds.bottom; |
| 234 } | 242 } |
| 235 return new_point; | 243 return new_point; |
| 236 } | 244 } |
| 237 | 245 |
| 238 } // namespace remoting | 246 } // namespace remoting |
| OLD | NEW |