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

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

Issue 1280613003: Allow native_viewport to create new native windows on demand on Android. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
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 "services/native_viewport/native_viewport_impl.h" 5 #include "services/native_viewport/native_viewport_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h" 12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "mojo/converters/native_viewport/surface_configuration_type_converters. h" 13 #include "mojo/converters/native_viewport/surface_configuration_type_converters. h"
14 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/public/cpp/application/interface_factory.h" 15 #include "mojo/public/cpp/application/interface_factory.h"
15 #include "services/gles2/gpu_state.h" 16 #include "services/gles2/gpu_state.h"
16 #include "services/native_viewport/platform_viewport_headless.h" 17 #include "services/native_viewport/platform_viewport_headless.h"
17 #include "ui/events/event.h" 18 #include "ui/events/event.h"
18 #include "ui/gl/gl_surface.h" 19 #include "ui/gl/gl_surface.h"
19 20
20 namespace native_viewport { 21 namespace native_viewport {
21 22
22 NativeViewportImpl::NativeViewportImpl( 23 NativeViewportImpl::NativeViewportImpl(
24 mojo::ApplicationImpl* application,
23 bool is_headless, 25 bool is_headless,
24 const scoped_refptr<gles2::GpuState>& gpu_state, 26 const scoped_refptr<gles2::GpuState>& gpu_state,
25 mojo::InterfaceRequest<mojo::NativeViewport> request) 27 mojo::InterfaceRequest<mojo::NativeViewport> request)
26 : is_headless_(is_headless), 28 : application_(application),
29 is_headless_(is_headless),
27 context_provider_(gpu_state), 30 context_provider_(gpu_state),
28 sent_metrics_(false), 31 sent_metrics_(false),
29 metrics_(mojo::ViewportMetrics::New()), 32 metrics_(mojo::ViewportMetrics::New()),
30 binding_(this, request.Pass()), 33 binding_(this, request.Pass()),
31 weak_factory_(this) { 34 weak_factory_(this) {}
32 }
33 35
34 NativeViewportImpl::~NativeViewportImpl() { 36 NativeViewportImpl::~NativeViewportImpl() {
35 // Destroy the NativeViewport early on as it may call us back during 37 // Destroy the NativeViewport early on as it may call us back during
36 // destruction and we want to be in a known state. 38 // destruction and we want to be in a known state.
37 platform_viewport_.reset(); 39 platform_viewport_.reset();
38 } 40 }
39 41
40 void NativeViewportImpl::Create( 42 void NativeViewportImpl::Create(
41 mojo::SizePtr size, 43 mojo::SizePtr size,
42 mojo::SurfaceConfigurationPtr requested_configuration, 44 mojo::SurfaceConfigurationPtr requested_configuration,
43 const CreateCallback& callback) { 45 const CreateCallback& callback) {
44 if (requested_configuration == nullptr) 46 if (requested_configuration == nullptr)
45 requested_configuration = mojo::SurfaceConfiguration::New(); 47 requested_configuration = mojo::SurfaceConfiguration::New();
46 48
47 create_callback_ = callback; 49 create_callback_ = callback;
48 metrics_->size = size.Clone(); 50 metrics_->size = size.Clone();
49 context_provider_.set_surface_configuration( 51 context_provider_.set_surface_configuration(
50 requested_configuration.To<gfx::SurfaceConfiguration>()); 52 requested_configuration.To<gfx::SurfaceConfiguration>());
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(application_, this);
55 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); 57 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>()));
56 } 58 }
57 59
58 void NativeViewportImpl::RequestMetrics( 60 void NativeViewportImpl::RequestMetrics(
59 const RequestMetricsCallback& callback) { 61 const RequestMetricsCallback& callback) {
60 if (!sent_metrics_) { 62 if (!sent_metrics_) {
61 callback.Run(metrics_.Clone()); 63 callback.Run(metrics_.Clone());
62 sent_metrics_ = true; 64 sent_metrics_ = true;
63 return; 65 return;
64 } 66 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 159
158 void NativeViewportImpl::OnDestroyed() { 160 void NativeViewportImpl::OnDestroyed() {
159 delete this; 161 delete this;
160 } 162 }
161 163
162 void NativeViewportImpl::AckEvent(int32 pointer_id) { 164 void NativeViewportImpl::AckEvent(int32 pointer_id) {
163 pointers_waiting_on_ack_.erase(pointer_id); 165 pointers_waiting_on_ack_.erase(pointer_id);
164 } 166 }
165 167
166 } // namespace native_viewport 168 } // namespace native_viewport
OLDNEW
« no previous file with comments | « services/native_viewport/native_viewport_impl.h ('k') | services/native_viewport/native_viewport_internal.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698