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

Side by Side Diff: mojo/examples/surfaces_app/surfaces_app.cc

Issue 607233002: Nukes NativeViewportClient::OnCreated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build Created 6 years, 2 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
« no previous file with comments | « mojo/examples/sample_app/sample_app.cc ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/weak_ptr.h"
7 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
8 #include "cc/surfaces/surface_id_allocator.h" 9 #include "cc/surfaces/surface_id_allocator.h"
9 #include "mojo/application/application_runner_chromium.h" 10 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/examples/surfaces_app/child.mojom.h" 11 #include "mojo/examples/surfaces_app/child.mojom.h"
11 #include "mojo/examples/surfaces_app/embedder.h" 12 #include "mojo/examples/surfaces_app/embedder.h"
12 #include "mojo/public/c/system/main.h" 13 #include "mojo/public/c/system/main.h"
13 #include "mojo/public/cpp/application/application_connection.h" 14 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 15 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/system/core.h" 16 #include "mojo/public/cpp/system/core.h"
16 #include "mojo/services/gles2/command_buffer.mojom.h" 17 #include "mojo/services/gles2/command_buffer.mojom.h"
17 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 18 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
18 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" 19 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
19 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 20 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
20 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h" 21 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
21 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h" 22 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
22 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" 23 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h"
23 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
24 25
25 namespace mojo { 26 namespace mojo {
26 namespace examples { 27 namespace examples {
27 28
28 class SurfacesApp : public ApplicationDelegate, 29 class SurfacesApp : public ApplicationDelegate,
29 public SurfaceClient, 30 public SurfaceClient,
30 public NativeViewportClient { 31 public NativeViewportClient {
31 public: 32 public:
32 SurfacesApp() {} 33 SurfacesApp() : weak_factory_(this) {}
33 virtual ~SurfacesApp() {} 34 virtual ~SurfacesApp() {}
34 35
35 // ApplicationDelegate implementation 36 // ApplicationDelegate implementation
36 virtual bool ConfigureIncomingConnection( 37 virtual bool ConfigureIncomingConnection(
37 ApplicationConnection* connection) OVERRIDE { 38 ApplicationConnection* connection) OVERRIDE {
38 connection->ConnectToService("mojo:mojo_native_viewport_service", 39 connection->ConnectToService("mojo:mojo_native_viewport_service",
39 &viewport_); 40 &viewport_);
40 viewport_.set_client(this); 41 viewport_.set_client(this);
41 42
42 connection->ConnectToService("mojo:mojo_surfaces_service", 43 connection->ConnectToService("mojo:mojo_surfaces_service",
43 &surfaces_service_); 44 &surfaces_service_);
44 surfaces_service_->CreateSurfaceConnection(base::Bind( 45 surfaces_service_->CreateSurfaceConnection(base::Bind(
45 &SurfacesApp::SurfaceConnectionCreated, base::Unretained(this))); 46 &SurfacesApp::SurfaceConnectionCreated, base::Unretained(this)));
46 47
47 size_ = gfx::Size(800, 600); 48 size_ = gfx::Size(800, 600);
48 49
49 viewport_->Create(Size::From(size_)); 50 viewport_->Create(Size::From(size_),
51 base::Bind(&SurfacesApp::OnCreatedNativeViewport,
52 weak_factory_.GetWeakPtr()));
50 viewport_->Show(); 53 viewport_->Show();
51 54
52 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); 55 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
53 connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_); 56 connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_);
54 connection->ConnectToService("mojo:mojo_surfaces_child_gl_app", 57 connection->ConnectToService("mojo:mojo_surfaces_child_gl_app",
55 &child_two_); 58 &child_two_);
56 child_one_->ProduceFrame(Color::From(SK_ColorBLUE), 59 child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
57 Size::From(child_size_), 60 Size::From(child_size_),
58 base::Bind(&SurfacesApp::ChildOneProducedFrame, 61 base::Bind(&SurfacesApp::ChildOneProducedFrame,
59 base::Unretained(this))); 62 base::Unretained(this)));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 surface_->CreateSurface(SurfaceId::From(onscreen_id_), Size::From(size_)); 99 surface_->CreateSurface(SurfaceId::From(onscreen_id_), Size::From(size_));
97 viewport_->SubmittedFrame(SurfaceId::From(onscreen_id_)); 100 viewport_->SubmittedFrame(SurfaceId::From(onscreen_id_));
98 Draw(10); 101 Draw(10);
99 } 102 }
100 103
101 // SurfaceClient implementation. 104 // SurfaceClient implementation.
102 virtual void ReturnResources(Array<ReturnedResourcePtr> resources) OVERRIDE { 105 virtual void ReturnResources(Array<ReturnedResourcePtr> resources) OVERRIDE {
103 DCHECK(!resources.size()); 106 DCHECK(!resources.size());
104 } 107 }
105 // NativeViewportClient implementation. 108 // NativeViewportClient implementation.
106 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {} 109 virtual void OnSizeChanged(mojo::SizePtr size) OVERRIDE {}
107 virtual void OnBoundsChanged(mojo::SizePtr bounds) OVERRIDE {}
108 virtual void OnDestroyed() OVERRIDE {} 110 virtual void OnDestroyed() OVERRIDE {}
109 virtual void OnEvent(mojo::EventPtr event, 111 virtual void OnEvent(mojo::EventPtr event,
110 const mojo::Callback<void()>& callback) OVERRIDE { 112 const mojo::Callback<void()>& callback) OVERRIDE {
111 callback.Run(); 113 callback.Run();
112 } 114 }
113 115
114 private: 116 private:
117 void OnCreatedNativeViewport(uint64_t native_viewport_id) {}
118
115 SurfacesServicePtr surfaces_service_; 119 SurfacesServicePtr surfaces_service_;
116 SurfacePtr surface_; 120 SurfacePtr surface_;
117 cc::SurfaceId onscreen_id_; 121 cc::SurfaceId onscreen_id_;
118 scoped_ptr<cc::SurfaceIdAllocator> allocator_; 122 scoped_ptr<cc::SurfaceIdAllocator> allocator_;
119 scoped_ptr<Embedder> embedder_; 123 scoped_ptr<Embedder> embedder_;
120 ChildPtr child_one_; 124 ChildPtr child_one_;
121 cc::SurfaceId child_one_id_; 125 cc::SurfaceId child_one_id_;
122 ChildPtr child_two_; 126 ChildPtr child_two_;
123 cc::SurfaceId child_two_id_; 127 cc::SurfaceId child_two_id_;
124 gfx::Size size_; 128 gfx::Size size_;
125 gfx::Size child_size_; 129 gfx::Size child_size_;
126 130
127 NativeViewportPtr viewport_; 131 NativeViewportPtr viewport_;
128 132
133 base::WeakPtrFactory<SurfacesApp> weak_factory_;
134
129 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); 135 DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
130 }; 136 };
131 137
132 } // namespace examples 138 } // namespace examples
133 } // namespace mojo 139 } // namespace mojo
134 140
135 MojoResult MojoMain(MojoHandle shell_handle) { 141 MojoResult MojoMain(MojoHandle shell_handle) {
136 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); 142 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp);
137 return runner.Run(shell_handle); 143 return runner.Run(shell_handle);
138 } 144 }
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/sample_app.cc ('k') | mojo/mojo_examples.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698