Chromium Code Reviews| 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 <array> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "remoting/client/simple_matrix.h" | |
| 12 | |
|
joedow
2017/04/28 21:29:53
You should include 'remoting/client/viewport_geome
Yuwei
2017/04/28 23:53:40
Obsolete. I broke down viewport_geometry and moved
| |
| 13 namespace remoting { | |
| 14 | |
| 15 // The viewport is a sliding window on the desktop image. This class defines | |
| 16 // the viewport's position and size, provides methods to manipulate it, and | |
| 17 // outputs a desktop space -> surface space transformation matrix for drawing | |
| 18 // the desktop onto the client's view surface on the screen. | |
|
joedow
2017/04/28 21:29:53
This is a good comment, but I think it would be go
Yuwei
2017/04/28 23:53:40
Done.
| |
| 19 // | |
| 20 // You may either manipulate the desktop on the surface coordinate or manipulate | |
| 21 // the viewport on the desktop coordinate, depending on how you choose the | |
| 22 // reference frame. | |
| 23 class DesktopViewport { | |
| 24 public: | |
| 25 using TransformationCallback = | |
| 26 base::Callback<void(const std::array<float, 9>&)>; | |
| 27 | |
| 28 DesktopViewport(); | |
| 29 ~DesktopViewport(); | |
| 30 | |
| 31 // Sets the desktop size. | |
|
joedow
2017/04/28 21:29:53
nit: You could just refer to the actual member ->
Yuwei
2017/04/28 23:53:40
Done.
| |
| 32 void SetDesktopSize(int desktop_width, int desktop_height); | |
| 33 | |
| 34 // Sets the surface size. | |
| 35 void SetSurfaceSize(int surface_width, int surface_height); | |
| 36 | |
| 37 // Resizes the desktop such that the image is displayed without borders in | |
| 38 // minimum possible zoom-level. This will be called once both the desktop | |
| 39 // and the surface size are set. | |
|
joedow
2017/04/28 21:29:53
"This will be called once both the desktop and the
Yuwei
2017/04/28 23:53:40
I just moved it to the private block. SetDesktopSi
| |
| 40 void ResizeToFit(); | |
| 41 | |
| 42 // Translates the desktop on the surface's reference frame by <dx, dy>. | |
| 43 void MoveDesktop(float dx, float dy); | |
| 44 | |
| 45 // Scales the desktop on the surface's reference frame at pivot point (px, py) | |
| 46 // by |scale|. | |
| 47 void ScaleDesktop(float px, float py, float scale); | |
| 48 | |
| 49 // Sets the viewport center to (x, y) on the desktop's coordinate. | |
| 50 void SetViewportCenter(float x, float y); | |
| 51 | |
| 52 // Registers the callback to be called once the transformation has changed. | |
| 53 // run_immediately: If true and the viewport is ready to be used, the callback | |
| 54 // will be called immedately with the transformation matrix. | |
| 55 void RegisterOnTransformationChangedCallback( | |
| 56 const TransformationCallback& callback, | |
| 57 bool run_immediately); | |
| 58 | |
| 59 private: | |
| 60 // True if desktop size and surface size are set. | |
| 61 bool IsViewportReady() const; | |
| 62 | |
| 63 // Adjusts the size and position of the viewport so that the constrains always | |
| 64 // hold, then feed the matrix to |on_transformation_changed_|. | |
| 65 void UpdateViewport(); | |
| 66 | |
| 67 // Gets a rectangle of all possible positions where the viewport's center can | |
| 68 // locate. | |
| 69 Bounds GetViewportCenterBounds() const; | |
| 70 | |
| 71 // Returns the current center of the viewport on the desktop's coordinate. | |
| 72 Point GetViewportCenter() const; | |
| 73 | |
| 74 // Translates the viewport on the desktop's reference frame by <dx, dy>, | |
| 75 // without calling UpdateViewport(). | |
| 76 void MoveViewportCenterWithoutUpdate(float dx, float dy); | |
| 77 | |
| 78 Vector2D desktop_size_; | |
| 79 Vector2D surface_size_; | |
| 80 | |
| 81 bool desktop_size_ready_ = false; | |
| 82 bool surface_size_ready_ = false; | |
| 83 | |
| 84 SimpleMatrix desktop_to_surface_; | |
|
joedow
2017/04/28 21:29:53
desktop_to_surface_transform_?
Yuwei
2017/04/28 23:53:40
Done.
| |
| 85 | |
| 86 TransformationCallback on_transformation_changed_; | |
| 87 | |
| 88 // DesktopViewport is neither copyable nor movable. | |
| 89 DesktopViewport(const DesktopViewport&) = delete; | |
| 90 DesktopViewport& operator=(const DesktopViewport&) = delete; | |
| 91 }; | |
| 92 | |
| 93 } // namespace remoting | |
| 94 #endif // REMOTING_CLIENT_DESKTOP_VIEWPORT_H_ | |
| OLD | NEW |