OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "mojo/services/native_viewport/native_viewport_impl.h" | 5 #include "mojo/services/native_viewport/native_viewport_impl.h" |
6 | 6 |
| 7 #include "base/auto_reset.h" |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/interface_factory.h" | 14 #include "mojo/public/cpp/application/interface_factory.h" |
14 #include "mojo/services/native_viewport/platform_viewport_headless.h" | 15 #include "mojo/services/native_viewport/platform_viewport_headless.h" |
15 #include "mojo/services/native_viewport/viewport_surface.h" | 16 #include "mojo/services/native_viewport/viewport_surface.h" |
16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 17 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
(...skipping 24 matching lines...) Expand all Loading... |
41 | 42 |
42 NativeViewportImpl::~NativeViewportImpl() { | 43 NativeViewportImpl::~NativeViewportImpl() { |
43 // Destroy the NativeViewport early on as it may call us back during | 44 // Destroy the NativeViewport early on as it may call us back during |
44 // destruction and we want to be in a known state. | 45 // destruction and we want to be in a known state. |
45 platform_viewport_.reset(); | 46 platform_viewport_.reset(); |
46 } | 47 } |
47 | 48 |
48 void NativeViewportImpl::Create(SizePtr size, | 49 void NativeViewportImpl::Create(SizePtr size, |
49 const Callback<void(uint64_t)>& callback) { | 50 const Callback<void(uint64_t)>& callback) { |
50 create_callback_ = callback; | 51 create_callback_ = callback; |
| 52 size_ = size.To<gfx::Size>(); |
51 if (is_headless_) | 53 if (is_headless_) |
52 platform_viewport_ = PlatformViewportHeadless::Create(this); | 54 platform_viewport_ = PlatformViewportHeadless::Create(this); |
53 else | 55 else |
54 platform_viewport_ = PlatformViewport::Create(this); | 56 platform_viewport_ = PlatformViewport::Create(this); |
55 const gfx::Rect bounds(gfx::Rect(size.To<gfx::Size>())); | 57 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); |
56 platform_viewport_->Init(bounds); | |
57 OnBoundsChanged(bounds); | |
58 } | 58 } |
59 | 59 |
60 void NativeViewportImpl::Show() { | 60 void NativeViewportImpl::Show() { |
61 platform_viewport_->Show(); | 61 platform_viewport_->Show(); |
62 } | 62 } |
63 | 63 |
64 void NativeViewportImpl::Hide() { | 64 void NativeViewportImpl::Hide() { |
65 platform_viewport_->Hide(); | 65 platform_viewport_->Hide(); |
66 } | 66 } |
67 | 67 |
(...skipping 19 matching lines...) Expand all Loading... |
87 child_surface_id.To<cc::SurfaceId>())); | 87 child_surface_id.To<cc::SurfaceId>())); |
88 if (widget_id_) | 88 if (widget_id_) |
89 viewport_surface_->SetWidgetId(widget_id_); | 89 viewport_surface_->SetWidgetId(widget_id_); |
90 } | 90 } |
91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); | 91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); |
92 if (viewport_surface_) | 92 if (viewport_surface_) |
93 viewport_surface_->SetChildId(child_surface_id_); | 93 viewport_surface_->SetChildId(child_surface_id_); |
94 } | 94 } |
95 | 95 |
96 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 96 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
| 97 if (size_ == bounds.size()) |
| 98 return; |
| 99 |
97 size_ = bounds.size(); | 100 size_ = bounds.size(); |
98 client()->OnSizeChanged(Size::From(size_)); | 101 |
99 if (viewport_surface_) | 102 // Wait for the accelerated widget before telling the client of the bounds. |
100 viewport_surface_->SetSize(size_); | 103 if (create_callback_.is_null()) |
| 104 ProcessOnBoundsChanged(); |
101 } | 105 } |
102 | 106 |
103 void NativeViewportImpl::OnAcceleratedWidgetAvailable( | 107 void NativeViewportImpl::OnAcceleratedWidgetAvailable( |
104 gfx::AcceleratedWidget widget) { | 108 gfx::AcceleratedWidget widget) { |
105 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); | 109 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); |
106 // TODO(jamesr): Remove once everything is converted to surfaces. | 110 // TODO(jamesr): Remove once everything is converted to surfaces. |
107 create_callback_.Run(widget_id_); | 111 create_callback_.Run(widget_id_); |
| 112 create_callback_.reset(); |
| 113 // Immediately tell the client of the size. The size may be wrong, if so we'll |
| 114 // get the right one in the next OnBoundsChanged() call. |
| 115 ProcessOnBoundsChanged(); |
108 if (viewport_surface_) | 116 if (viewport_surface_) |
109 viewport_surface_->SetWidgetId(widget_id_); | 117 viewport_surface_->SetWidgetId(widget_id_); |
110 } | 118 } |
111 | 119 |
112 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { | 120 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { |
113 // Must not return early before updating capture. | 121 // Must not return early before updating capture. |
114 switch (ui_event->type()) { | 122 switch (ui_event->type()) { |
115 case ui::ET_MOUSE_PRESSED: | 123 case ui::ET_MOUSE_PRESSED: |
116 case ui::ET_TOUCH_PRESSED: | 124 case ui::ET_TOUCH_PRESSED: |
117 platform_viewport_->SetCapture(); | 125 platform_viewport_->SetCapture(); |
(...skipping 17 matching lines...) Expand all Loading... |
135 } | 143 } |
136 | 144 |
137 void NativeViewportImpl::OnDestroyed() { | 145 void NativeViewportImpl::OnDestroyed() { |
138 client()->OnDestroyed(); | 146 client()->OnDestroyed(); |
139 } | 147 } |
140 | 148 |
141 void NativeViewportImpl::AckEvent() { | 149 void NativeViewportImpl::AckEvent() { |
142 waiting_for_event_ack_ = false; | 150 waiting_for_event_ack_ = false; |
143 } | 151 } |
144 | 152 |
| 153 void NativeViewportImpl::ProcessOnBoundsChanged() { |
| 154 client()->OnSizeChanged(Size::From(size_)); |
| 155 if (viewport_surface_) |
| 156 viewport_surface_->SetSize(size_); |
| 157 } |
| 158 |
145 } // namespace mojo | 159 } // namespace mojo |
146 | 160 |
OLD | NEW |