| 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 "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/memory/weak_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/surfaces/surface_id_allocator.h" | 9 #include "cc/surfaces/surface_id_allocator.h" |
| 10 #include "examples/surfaces_app/child.mojom.h" | 10 #include "examples/surfaces_app/child.mojom.h" |
| 11 #include "examples/surfaces_app/embedder.h" | 11 #include "examples/surfaces_app/embedder.h" |
| 12 #include "mojo/application/application_runner_chromium.h" | 12 #include "mojo/application/application_runner_chromium.h" |
| 13 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 14 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 14 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 15 #include "mojo/public/c/system/main.h" | 15 #include "mojo/public/c/system/main.h" |
| 16 #include "mojo/public/cpp/application/application_connection.h" | 16 #include "mojo/public/cpp/application/application_connection.h" |
| 17 #include "mojo/public/cpp/application/application_delegate.h" | 17 #include "mojo/public/cpp/application/application_delegate.h" |
| 18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" | 19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" |
| 20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" | 20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
| 21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" | 21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" |
| 22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
| 23 #include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h" | |
| 24 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 25 | 24 |
| 26 namespace mojo { | 25 namespace mojo { |
| 27 namespace examples { | 26 namespace examples { |
| 28 | 27 |
| 29 class SurfacesApp : public ApplicationDelegate, | 28 class SurfacesApp : public ApplicationDelegate, |
| 30 public SurfaceClient, | 29 public SurfaceClient, |
| 31 public NativeViewportClient { | 30 public NativeViewportClient { |
| 32 public: | 31 public: |
| 33 SurfacesApp() : weak_factory_(this) {} | 32 SurfacesApp() : onscreen_id_(SurfaceId::New()), weak_factory_(this) {} |
| 34 virtual ~SurfacesApp() {} | 33 ~SurfacesApp() override {} |
| 35 | 34 |
| 36 // ApplicationDelegate implementation | 35 // ApplicationDelegate implementation |
| 37 virtual bool ConfigureIncomingConnection( | 36 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 38 ApplicationConnection* connection) override { | |
| 39 connection->ConnectToService("mojo:native_viewport_service", &viewport_); | 37 connection->ConnectToService("mojo:native_viewport_service", &viewport_); |
| 40 viewport_.set_client(this); | 38 viewport_.set_client(this); |
| 41 | 39 |
| 42 connection->ConnectToService("mojo:surfaces_service", &surfaces_service_); | 40 connection->ConnectToService("mojo:surfaces_service", &surface_); |
| 43 surfaces_service_->CreateSurfaceConnection(base::Bind( | 41 surface_.set_client(this); |
| 44 &SurfacesApp::SurfaceConnectionCreated, base::Unretained(this))); | 42 embedder_.set_surface(surface_.get()); |
| 45 | 43 |
| 46 size_ = gfx::Size(800, 600); | 44 size_ = gfx::Size(800, 600); |
| 47 | 45 |
| 48 viewport_->Create(Size::From(size_), | 46 viewport_->Create(Size::From(size_), |
| 49 base::Bind(&SurfacesApp::OnCreatedNativeViewport, | 47 base::Bind(&SurfacesApp::OnCreatedNativeViewport, |
| 50 weak_factory_.GetWeakPtr())); | 48 weak_factory_.GetWeakPtr())); |
| 51 viewport_->Show(); | 49 viewport_->Show(); |
| 52 | 50 |
| 53 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); | 51 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); |
| 54 connection->ConnectToService("mojo:surfaces_child_app", &child_one_); | 52 connection->ConnectToService("mojo:surfaces_child_app", &child_one_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 } | 67 } |
| 70 | 68 |
| 71 void ChildTwoProducedFrame(SurfaceIdPtr id) { | 69 void ChildTwoProducedFrame(SurfaceIdPtr id) { |
| 72 child_two_id_ = id.To<cc::SurfaceId>(); | 70 child_two_id_ = id.To<cc::SurfaceId>(); |
| 73 } | 71 } |
| 74 | 72 |
| 75 void Draw(int offset) { | 73 void Draw(int offset) { |
| 76 int bounced_offset = offset; | 74 int bounced_offset = offset; |
| 77 if (offset > 200) | 75 if (offset > 200) |
| 78 bounced_offset = 400 - offset; | 76 bounced_offset = 400 - offset; |
| 79 embedder_->ProduceFrame( | 77 embedder_.ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, |
| 80 child_one_id_, child_two_id_, child_size_, size_, bounced_offset); | 78 bounced_offset); |
| 81 base::MessageLoop::current()->PostDelayedTask( | 79 base::MessageLoop::current()->PostDelayedTask( |
| 82 FROM_HERE, | 80 FROM_HERE, |
| 83 base::Bind( | 81 base::Bind( |
| 84 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), | 82 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), |
| 85 base::TimeDelta::FromMilliseconds(50)); | 83 base::TimeDelta::FromMilliseconds(50)); |
| 86 } | 84 } |
| 87 | 85 |
| 88 void SurfaceConnectionCreated(SurfacePtr surface, uint32_t id_namespace) { | 86 // SurfaceClient implementation. |
| 89 surface_ = surface.Pass(); | 87 void SetIdNamespace(uint32_t id_namespace) override { |
| 90 surface_.set_client(this); | 88 onscreen_id_->id_namespace = id_namespace; |
| 91 embedder_.reset(new Embedder(surface_.get())); | 89 embedder_.set_surface_id(onscreen_id_.Clone()); |
| 92 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 90 surface_->CreateSurface(onscreen_id_.Clone()); |
| 93 | 91 viewport_->SubmittedFrame(onscreen_id_.Clone()); |
| 94 onscreen_id_ = allocator_->GenerateId(); | |
| 95 embedder_->SetSurfaceId(onscreen_id_); | |
| 96 surface_->CreateSurface(SurfaceId::From(onscreen_id_), Size::From(size_)); | |
| 97 viewport_->SubmittedFrame(SurfaceId::From(onscreen_id_)); | |
| 98 Draw(10); | 92 Draw(10); |
| 99 } | 93 } |
| 100 | 94 void ReturnResources(Array<ReturnedResourcePtr> resources) override { |
| 101 // SurfaceClient implementation. | |
| 102 virtual void ReturnResources(Array<ReturnedResourcePtr> resources) override { | |
| 103 DCHECK(!resources.size()); | 95 DCHECK(!resources.size()); |
| 104 } | 96 } |
| 105 // NativeViewportClient implementation. | 97 // NativeViewportClient implementation. |
| 106 virtual void OnSizeChanged(mojo::SizePtr size) override {} | 98 void OnSizeChanged(mojo::SizePtr size) override {} |
| 107 virtual void OnDestroyed() override {} | 99 void OnDestroyed() override {} |
| 108 | 100 |
| 109 private: | 101 private: |
| 110 void OnCreatedNativeViewport(uint64_t native_viewport_id) {} | 102 void OnCreatedNativeViewport(uint64_t native_viewport_id) {} |
| 111 | 103 |
| 112 SurfacesServicePtr surfaces_service_; | |
| 113 SurfacePtr surface_; | 104 SurfacePtr surface_; |
| 114 cc::SurfaceId onscreen_id_; | 105 SurfaceIdPtr onscreen_id_; |
| 115 scoped_ptr<cc::SurfaceIdAllocator> allocator_; | 106 Embedder embedder_; |
| 116 scoped_ptr<Embedder> embedder_; | |
| 117 ChildPtr child_one_; | 107 ChildPtr child_one_; |
| 118 cc::SurfaceId child_one_id_; | 108 cc::SurfaceId child_one_id_; |
| 119 ChildPtr child_two_; | 109 ChildPtr child_two_; |
| 120 cc::SurfaceId child_two_id_; | 110 cc::SurfaceId child_two_id_; |
| 121 gfx::Size size_; | 111 gfx::Size size_; |
| 122 gfx::Size child_size_; | 112 gfx::Size child_size_; |
| 123 | 113 |
| 124 NativeViewportPtr viewport_; | 114 NativeViewportPtr viewport_; |
| 125 | 115 |
| 126 base::WeakPtrFactory<SurfacesApp> weak_factory_; | 116 base::WeakPtrFactory<SurfacesApp> weak_factory_; |
| 127 | 117 |
| 128 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); | 118 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); |
| 129 }; | 119 }; |
| 130 | 120 |
| 131 } // namespace examples | 121 } // namespace examples |
| 132 } // namespace mojo | 122 } // namespace mojo |
| 133 | 123 |
| 134 MojoResult MojoMain(MojoHandle shell_handle) { | 124 MojoResult MojoMain(MojoHandle shell_handle) { |
| 135 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); | 125 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); |
| 136 return runner.Run(shell_handle); | 126 return runner.Run(shell_handle); |
| 137 } | 127 } |
| OLD | NEW |