| 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 #ifndef REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | 5 #ifndef REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ |
| 6 #define REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | 6 #define REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "remoting/client/view_matrix.h" | 9 #include "remoting/client/view_matrix.h" |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // Sets the |surface_size_| and initializes the viewport when necessary. | 41 // Sets the |surface_size_| and initializes the viewport when necessary. |
| 42 void SetSurfaceSize(int surface_width, int surface_height); | 42 void SetSurfaceSize(int surface_width, int surface_height); |
| 43 | 43 |
| 44 // Translates the desktop on the surface's reference frame by <dx, dy>. | 44 // Translates the desktop on the surface's reference frame by <dx, dy>. |
| 45 void MoveDesktop(float dx, float dy); | 45 void MoveDesktop(float dx, float dy); |
| 46 | 46 |
| 47 // Scales the desktop on the surface's reference frame at pivot point (px, py) | 47 // Scales the desktop on the surface's reference frame at pivot point (px, py) |
| 48 // by |scale|. | 48 // by |scale|. |
| 49 void ScaleDesktop(float px, float py, float scale); | 49 void ScaleDesktop(float px, float py, float scale); |
| 50 | 50 |
| 51 // Moves the viewport center by <x, y> on the desktop's coordinate. |
| 52 void MoveViewport(float dx, float dy); |
| 53 |
| 51 // Sets the viewport center to (x, y) on the desktop's coordinate. | 54 // Sets the viewport center to (x, y) on the desktop's coordinate. |
| 52 void SetViewportCenter(float x, float y); | 55 void SetViewportCenter(float x, float y); |
| 53 | 56 |
| 54 // Registers the callback to be called once the transformation has changed. | 57 // Registers the callback to be called once the transformation has changed. |
| 55 // run_immediately: If true and the viewport is ready to be used, the callback | 58 // run_immediately: If true and the viewport is ready to be used, the callback |
| 56 // will be called immedately with the transformation matrix. | 59 // will be called immedately with the transformation matrix. |
| 57 void RegisterOnTransformationChangedCallback( | 60 void RegisterOnTransformationChangedCallback( |
| 58 const TransformationCallback& callback, | 61 const TransformationCallback& callback, |
| 59 bool run_immediately); | 62 bool run_immediately); |
| 60 | 63 |
| 64 // Returns the reference to the desktop-to-surface transformation. |
| 65 const ViewMatrix& GetTransformation() const; |
| 66 |
| 61 private: | 67 private: |
| 62 struct Bounds { | 68 struct Bounds { |
| 63 float left; | 69 float left; |
| 64 float right; | 70 float right; |
| 65 float top; | 71 float top; |
| 66 float bottom; | 72 float bottom; |
| 67 }; | 73 }; |
| 68 | 74 |
| 69 // Resizes the desktop such that the image is displayed without borders in | 75 // Resizes the desktop such that the image is displayed without borders in |
| 70 // minimum possible zoom-level. This will be called once both the desktop | 76 // minimum possible zoom-level. This will be called once both the desktop |
| 71 // and the surface size are set. | 77 // and the surface size are set. |
| 72 void ResizeToFit(); | 78 void ResizeToFit(); |
| 73 | 79 |
| 74 // True if desktop size and surface size are set. | 80 // True if desktop size and surface size are set. |
| 75 bool IsViewportReady() const; | 81 bool IsViewportReady() const; |
| 76 | 82 |
| 77 // Adjusts the size and position of the viewport so that the constrains always | 83 // Adjusts the size and position of the viewport so that the constrains always |
| 78 // hold, then feed the matrix to |on_transformation_changed_|. | 84 // hold, then feed the matrix to |on_transformation_changed_|. |
| 79 void UpdateViewport(); | 85 void UpdateViewport(); |
| 80 | 86 |
| 81 // Gets a rectangle of all possible positions where the viewport's center can | 87 // Gets a rectangle of all possible positions where the viewport's center can |
| 82 // locate. | 88 // locate. |
| 83 Bounds GetViewportCenterBounds() const; | 89 Bounds GetViewportCenterBounds() const; |
| 84 | 90 |
| 85 // Returns the current center of the viewport on the desktop's coordinate. | 91 // Returns the current center of the viewport on the desktop's coordinate. |
| 86 ViewMatrix::Point GetViewportCenter() const; | 92 ViewMatrix::Point GetViewportCenter() const; |
| 87 | 93 |
| 88 // Translates the viewport on the desktop's reference frame by <dx, dy>, | 94 // Translates the viewport on the desktop's reference frame by <dx, dy>, |
| 89 // without calling UpdateViewport(). | 95 // without calling UpdateViewport(). |
| 90 void MoveViewportCenterWithoutUpdate(float dx, float dy); | 96 void MoveViewportWithoutUpdate(float dx, float dy); |
| 91 | 97 |
| 92 // Moves the point inside the bounds with minimum displacement if it is out of | 98 // Moves the point inside the bounds with minimum displacement if it is out of |
| 93 // the bounds. | 99 // the bounds. |
| 94 static ViewMatrix::Point ConstrainPointToBounds( | 100 static ViewMatrix::Point ConstrainPointToBounds( |
| 95 const Bounds& bounds, | 101 const Bounds& bounds, |
| 96 const ViewMatrix::Point& point); | 102 const ViewMatrix::Point& point); |
| 97 | 103 |
| 98 ViewMatrix::Vector2D desktop_size_; | 104 ViewMatrix::Vector2D desktop_size_; |
| 99 ViewMatrix::Vector2D surface_size_; | 105 ViewMatrix::Vector2D surface_size_; |
| 100 | 106 |
| 101 bool desktop_size_ready_ = false; | 107 bool desktop_size_ready_ = false; |
| 102 bool surface_size_ready_ = false; | 108 bool surface_size_ready_ = false; |
| 103 | 109 |
| 104 ViewMatrix desktop_to_surface_transform_; | 110 ViewMatrix desktop_to_surface_transform_; |
| 105 | 111 |
| 106 TransformationCallback on_transformation_changed_; | 112 TransformationCallback on_transformation_changed_; |
| 107 | 113 |
| 108 // DesktopViewport is neither copyable nor movable. | 114 // DesktopViewport is neither copyable nor movable. |
| 109 DesktopViewport(const DesktopViewport&) = delete; | 115 DesktopViewport(const DesktopViewport&) = delete; |
| 110 DesktopViewport& operator=(const DesktopViewport&) = delete; | 116 DesktopViewport& operator=(const DesktopViewport&) = delete; |
| 111 }; | 117 }; |
| 112 | 118 |
| 113 } // namespace remoting | 119 } // namespace remoting |
| 114 #endif // REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | 120 #endif // REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ |
| OLD | NEW |