| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | |
| 6 #define REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "remoting/client/view_matrix.h" | |
| 10 | |
| 11 namespace remoting { | |
| 12 | |
| 13 // The viewport is a sliding window on the desktop image. This class defines | |
| 14 // the viewport's position and size, provides methods to manipulate it, and | |
| 15 // outputs a desktop space -> surface space transformation matrix for drawing | |
| 16 // the desktop onto the client's view surface on the screen. | |
| 17 // | |
| 18 // Desktop space: Coordinates to locate a point on the host's desktop image in | |
| 19 // pixels, similar to the mouse's cursor position. | |
| 20 // Surface space: Coordinates to locate a point on the client device's view | |
| 21 // surface (e.g. GLKView/SurfaceView) for rendering the desktop, this is | |
| 22 // often the coordinate system to locate a point on the user's phone | |
| 23 // screen (if the surface expands to the whole screen). | |
| 24 // | |
| 25 // Viewport: Projection of the user surface view on the desktop space. | |
| 26 // Desktop: Projection of the host's desktop on the surface space. | |
| 27 // | |
| 28 // You may either manipulate the desktop on the surface coordinate or manipulate | |
| 29 // the viewport on the desktop coordinate, depending on your choice of the | |
| 30 // reference frame. | |
| 31 class DesktopViewport { | |
| 32 public: | |
| 33 using TransformationCallback = base::Callback<void(const ViewMatrix&)>; | |
| 34 | |
| 35 DesktopViewport(); | |
| 36 ~DesktopViewport(); | |
| 37 | |
| 38 // Sets the |desktop_size_| and initializes the viewport when necessary. | |
| 39 void SetDesktopSize(int desktop_width, int desktop_height); | |
| 40 | |
| 41 // Sets the |surface_size_| and initializes the viewport when necessary. | |
| 42 void SetSurfaceSize(int surface_width, int surface_height); | |
| 43 | |
| 44 // Translates the desktop on the surface's reference frame by <dx, dy>. | |
| 45 void MoveDesktop(float dx, float dy); | |
| 46 | |
| 47 // Scales the desktop on the surface's reference frame at pivot point (px, py) | |
| 48 // by |scale|. | |
| 49 void ScaleDesktop(float px, float py, float scale); | |
| 50 | |
| 51 // Moves the viewport center by <x, y> on the desktop's coordinate. | |
| 52 void MoveViewport(float dx, float dy); | |
| 53 | |
| 54 // Sets the viewport center to (x, y) on the desktop's coordinate. | |
| 55 void SetViewportCenter(float x, float y); | |
| 56 | |
| 57 // Registers the callback to be called once the transformation has changed. | |
| 58 // run_immediately: If true and the viewport is ready to be used, the callback | |
| 59 // will be called immedately with the transformation matrix. | |
| 60 void RegisterOnTransformationChangedCallback( | |
| 61 const TransformationCallback& callback, | |
| 62 bool run_immediately); | |
| 63 | |
| 64 // Returns the reference to the desktop-to-surface transformation. | |
| 65 const ViewMatrix& GetTransformation() const; | |
| 66 | |
| 67 private: | |
| 68 struct Bounds { | |
| 69 float left; | |
| 70 float right; | |
| 71 float top; | |
| 72 float bottom; | |
| 73 }; | |
| 74 | |
| 75 // Resizes the desktop such that the image is displayed without borders in | |
| 76 // minimum possible zoom-level. This will be called once both the desktop | |
| 77 // and the surface size are set. | |
| 78 void ResizeToFit(); | |
| 79 | |
| 80 // True if desktop size and surface size are set. | |
| 81 bool IsViewportReady() const; | |
| 82 | |
| 83 // Adjusts the size and position of the viewport so that the constrains always | |
| 84 // hold, then feed the matrix to |on_transformation_changed_|. | |
| 85 void UpdateViewport(); | |
| 86 | |
| 87 // Gets a rectangle of all possible positions where the viewport's center can | |
| 88 // locate. | |
| 89 Bounds GetViewportCenterBounds() const; | |
| 90 | |
| 91 // Returns the current center of the viewport on the desktop's coordinate. | |
| 92 ViewMatrix::Point GetViewportCenter() const; | |
| 93 | |
| 94 // Translates the viewport on the desktop's reference frame by <dx, dy>, | |
| 95 // without calling UpdateViewport(). | |
| 96 void MoveViewportWithoutUpdate(float dx, float dy); | |
| 97 | |
| 98 // Moves the point inside the bounds with minimum displacement if it is out of | |
| 99 // the bounds. | |
| 100 static ViewMatrix::Point ConstrainPointToBounds( | |
| 101 const Bounds& bounds, | |
| 102 const ViewMatrix::Point& point); | |
| 103 | |
| 104 ViewMatrix::Vector2D desktop_size_{0.f, 0.f}; | |
| 105 ViewMatrix::Vector2D surface_size_{0.f, 0.f}; | |
| 106 | |
| 107 ViewMatrix desktop_to_surface_transform_; | |
| 108 | |
| 109 TransformationCallback on_transformation_changed_; | |
| 110 | |
| 111 // DesktopViewport is neither copyable nor movable. | |
| 112 DesktopViewport(const DesktopViewport&) = delete; | |
| 113 DesktopViewport& operator=(const DesktopViewport&) = delete; | |
| 114 }; | |
| 115 | |
| 116 } // namespace remoting | |
| 117 #endif // REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | |
| OLD | NEW |