ash_window_tree_host_mirroring_unified.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "ash/host/ash_window_tree_host_mirroring_unified.h"
  5. #include "ash/host/ash_window_tree_host_delegate.h"
  6. #include "ui/gfx/geometry/point3_f.h"
  7. #include "ui/gfx/geometry/point_conversions.h"
  8. #include "ui/gfx/geometry/transform.h"
  9. #include "ui/platform_window/platform_window_init_properties.h"
  10. namespace ash {
  11. AshWindowTreeHostMirroringUnified::AshWindowTreeHostMirroringUnified(
  12. const gfx::Rect& initial_bounds,
  13. int64_t mirroring_display_id,
  14. AshWindowTreeHostDelegate* delegate)
  15. : AshWindowTreeHostPlatform(
  16. ui::PlatformWindowInitProperties{initial_bounds},
  17. delegate),
  18. mirroring_display_id_(mirroring_display_id) {
  19. DCHECK(delegate_);
  20. }
  21. AshWindowTreeHostMirroringUnified::~AshWindowTreeHostMirroringUnified() =
  22. default;
  23. gfx::Transform
  24. AshWindowTreeHostMirroringUnified::GetRootTransformForLocalEventCoordinates()
  25. const {
  26. gfx::Transform trans = GetRootTransform();
  27. if (!is_shutting_down_) {
  28. const auto* display = delegate_->GetDisplayById(mirroring_display_id_);
  29. DCHECK(display);
  30. // Undo the translation in the root window transform, since this transform
  31. // should be applied on local points to this host.
  32. trans.Translate(SkIntToScalar(display->bounds().x()),
  33. SkIntToScalar(display->bounds().y()));
  34. }
  35. return trans;
  36. }
  37. void AshWindowTreeHostMirroringUnified::ConvertDIPToPixels(
  38. gfx::PointF* point) const {
  39. // GetRootTransform() returns a transform that takes a point from the
  40. // *unified* host coordinates to the *mirroring* host's pixel coordinates.
  41. // ConvertDIPToPixels() and ConvertDIPToScreenInPixels() are called on local
  42. // points in the *mirroring* host's root window, not on points in the unified
  43. // host's. That's why we use the GetRootTransformForLocalEventCoordinates()
  44. // defined above, which only scales those local points to the right size, and
  45. // leaves the translation to be done by the MirroringScreenPositionClient
  46. // functions.
  47. GetRootTransformForLocalEventCoordinates().TransformPoint(point);
  48. }
  49. void AshWindowTreeHostMirroringUnified::ConvertPixelsToDIP(
  50. gfx::PointF* point) const {
  51. GetInverseRootTransformForLocalEventCoordinates().TransformPoint(point);
  52. }
  53. void AshWindowTreeHostMirroringUnified::PrepareForShutdown() {
  54. is_shutting_down_ = true;
  55. AshWindowTreeHostPlatform::PrepareForShutdown();
  56. }
  57. void AshWindowTreeHostMirroringUnified::OnMouseEnter() {
  58. // No logical display change in unified desktop mode,so do nothing.
  59. }
  60. } // namespace ash