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

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

Issue 2843373005: [Remoting Client] DesktopViewport Implementation (Closed)
Patch Set: Rename SimpleMatrix to ViewMatrix 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 | « remoting/client/BUILD.gn ('k') | remoting/client/desktop_viewport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Sets the viewport center to (x, y) on the desktop's coordinate.
52 void SetViewportCenter(float x, float y);
53
54 // 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
56 // will be called immedately with the transformation matrix.
57 void RegisterOnTransformationChangedCallback(
58 const TransformationCallback& callback,
59 bool run_immediately);
60
61 private:
62 struct Bounds {
63 float left;
64 float right;
65 float top;
66 float bottom;
67 };
68
69 // 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
71 // and the surface size are set.
72 void ResizeToFit();
73
74 // True if desktop size and surface size are set.
75 bool IsViewportReady() const;
76
77 // Adjusts the size and position of the viewport so that the constrains always
78 // hold, then feed the matrix to |on_transformation_changed_|.
79 void UpdateViewport();
80
81 // Gets a rectangle of all possible positions where the viewport's center can
82 // locate.
83 Bounds GetViewportCenterBounds() const;
84
85 // Returns the current center of the viewport on the desktop's coordinate.
86 ViewMatrix::Point GetViewportCenter() const;
87
88 // Translates the viewport on the desktop's reference frame by <dx, dy>,
89 // without calling UpdateViewport().
90 void MoveViewportCenterWithoutUpdate(float dx, float dy);
91
92 // Moves the point inside the bounds with minimum displacement if it is out of
93 // the bounds.
94 static ViewMatrix::Point ConstrainPointToBounds(
95 const Bounds& bounds,
96 const ViewMatrix::Point& point);
97
98 ViewMatrix::Vector2D desktop_size_;
99 ViewMatrix::Vector2D surface_size_;
100
101 bool desktop_size_ready_ = false;
102 bool surface_size_ready_ = false;
103
104 ViewMatrix desktop_to_surface_transform_;
105
106 TransformationCallback on_transformation_changed_;
107
108 // DesktopViewport is neither copyable nor movable.
109 DesktopViewport(const DesktopViewport&) = delete;
110 DesktopViewport& operator=(const DesktopViewport&) = delete;
111 };
112
113 } // namespace remoting
114 #endif // REMOTING_CLIENT_DESKTOP_VIEWPORT_H_
OLDNEW
« no previous file with comments | « remoting/client/BUILD.gn ('k') | remoting/client/desktop_viewport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698