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

Side by Side Diff: mojo/services/native_viewport/native_viewport_impl.cc

Issue 687433002: Remove mojo/shell and (most) service implementations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove mojo/gles2, disable mojo apps in component build Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/services/native_viewport/native_viewport_impl.h"
6
7 #include "base/auto_reset.h"
8 #include "base/bind.h"
9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "mojo/converters/input_events/input_events_type_converters.h"
14 #include "mojo/converters/surfaces/surfaces_type_converters.h"
15 #include "mojo/public/cpp/application/application_delegate.h"
16 #include "mojo/public/cpp/application/application_impl.h"
17 #include "mojo/public/cpp/application/interface_factory.h"
18 #include "mojo/services/native_viewport/platform_viewport_headless.h"
19 #include "mojo/services/native_viewport/viewport_surface.h"
20 #include "ui/events/event.h"
21
22 namespace mojo {
23 namespace {
24
25 bool IsRateLimitedEventType(ui::Event* event) {
26 return event->type() == ui::ET_MOUSE_MOVED ||
27 event->type() == ui::ET_MOUSE_DRAGGED ||
28 event->type() == ui::ET_TOUCH_MOVED;
29 }
30
31 } // namespace
32
33 NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app, bool is_headless)
34 : is_headless_(is_headless),
35 widget_id_(0u),
36 waiting_for_event_ack_(false),
37 weak_factory_(this) {
38 app->ConnectToService("mojo:surfaces_service", &surfaces_service_);
39 // TODO(jamesr): Should be mojo_gpu_service
40 app->ConnectToService("mojo:native_viewport_service", &gpu_service_);
41 }
42
43 NativeViewportImpl::~NativeViewportImpl() {
44 // Destroy the NativeViewport early on as it may call us back during
45 // destruction and we want to be in a known state.
46 platform_viewport_.reset();
47 }
48
49 void NativeViewportImpl::Create(SizePtr size,
50 const Callback<void(uint64_t)>& callback) {
51 create_callback_ = callback;
52 size_ = size.To<gfx::Size>();
53 if (is_headless_)
54 platform_viewport_ = PlatformViewportHeadless::Create(this);
55 else
56 platform_viewport_ = PlatformViewport::Create(this);
57 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>()));
58 }
59
60 void NativeViewportImpl::Show() {
61 platform_viewport_->Show();
62 }
63
64 void NativeViewportImpl::Hide() {
65 platform_viewport_->Hide();
66 }
67
68 void NativeViewportImpl::Close() {
69 DCHECK(platform_viewport_);
70 platform_viewport_->Close();
71 }
72
73 void NativeViewportImpl::SetSize(SizePtr size) {
74 platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>()));
75 }
76
77 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) {
78 if (child_surface_id_.is_null()) {
79 // If this is the first indication that the client will use surfaces,
80 // initialize that system.
81 // TODO(jamesr): When everything is converted to surfaces initialize this
82 // eagerly.
83 viewport_surface_.reset(
84 new ViewportSurface(surfaces_service_.get(),
85 gpu_service_.get(),
86 size_,
87 child_surface_id.To<cc::SurfaceId>()));
88 if (widget_id_)
89 viewport_surface_->SetWidgetId(widget_id_);
90 }
91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>();
92 if (viewport_surface_)
93 viewport_surface_->SetChildId(child_surface_id_);
94 }
95
96 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
97 if (size_ == bounds.size())
98 return;
99
100 size_ = bounds.size();
101
102 // Wait for the accelerated widget before telling the client of the bounds.
103 if (create_callback_.is_null())
104 ProcessOnBoundsChanged();
105 }
106
107 void NativeViewportImpl::OnAcceleratedWidgetAvailable(
108 gfx::AcceleratedWidget widget) {
109 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget));
110 // TODO(jamesr): Remove once everything is converted to surfaces.
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();
116 if (viewport_surface_)
117 viewport_surface_->SetWidgetId(widget_id_);
118 }
119
120 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) {
121 // Must not return early before updating capture.
122 switch (ui_event->type()) {
123 case ui::ET_MOUSE_PRESSED:
124 case ui::ET_TOUCH_PRESSED:
125 platform_viewport_->SetCapture();
126 break;
127 case ui::ET_MOUSE_RELEASED:
128 case ui::ET_TOUCH_RELEASED:
129 platform_viewport_->ReleaseCapture();
130 break;
131 default:
132 break;
133 }
134
135 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event))
136 return false;
137
138 client()->OnEvent(
139 Event::From(*ui_event),
140 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr()));
141 waiting_for_event_ack_ = true;
142 return false;
143 }
144
145 void NativeViewportImpl::OnDestroyed() {
146 client()->OnDestroyed();
147 }
148
149 void NativeViewportImpl::AckEvent() {
150 waiting_for_event_ack_ = false;
151 }
152
153 void NativeViewportImpl::ProcessOnBoundsChanged() {
154 client()->OnSizeChanged(Size::From(size_));
155 if (viewport_surface_)
156 viewport_surface_->SetSize(size_);
157 }
158
159 } // namespace mojo
160
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_impl.h ('k') | mojo/services/native_viewport/platform_viewport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698