OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/public/cpp/window_surface.h" | 5 #include "components/mus/public/cpp/window_surface.h" |
6 | 6 |
7 #include "components/mus/public/cpp/window_surface_client.h" | 7 #include "components/mus/public/cpp/window_surface_client.h" |
8 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 8 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
9 | 9 |
10 namespace mus { | 10 namespace mus { |
11 | 11 |
| 12 // static |
| 13 scoped_ptr<WindowSurface> WindowSurface::Create( |
| 14 scoped_ptr<WindowSurfaceBinding>* surface_binding) { |
| 15 mojom::SurfacePtr surface; |
| 16 mojom::SurfaceClientPtr surface_client; |
| 17 mojo::InterfaceRequest<mojom::SurfaceClient> surface_client_request = |
| 18 GetProxy(&surface_client); |
| 19 |
| 20 surface_binding->reset( |
| 21 new WindowSurfaceBinding(GetProxy(&surface), surface_client.Pass())); |
| 22 return make_scoped_ptr(new WindowSurface(surface.PassInterface(), |
| 23 surface_client_request.Pass())); |
| 24 } |
| 25 |
12 WindowSurface::~WindowSurface() {} | 26 WindowSurface::~WindowSurface() {} |
13 | 27 |
14 void WindowSurface::BindToThread() { | 28 void WindowSurface::BindToThread() { |
15 DCHECK(!bound_to_thread_); | 29 DCHECK(!thread_checker_); |
16 bound_to_thread_ = true; | 30 thread_checker_.reset(new base::ThreadChecker()); |
17 surface_.Bind(surface_info_.Pass()); | 31 surface_.Bind(surface_info_.Pass()); |
18 client_binding_.reset( | 32 client_binding_.reset( |
19 new mojo::Binding<mojom::SurfaceClient>(this, client_request_.Pass())); | 33 new mojo::Binding<mojom::SurfaceClient>(this, client_request_.Pass())); |
20 } | 34 } |
21 | 35 |
22 void WindowSurface::SubmitCompositorFrame(mojom::CompositorFramePtr frame, | 36 void WindowSurface::SubmitCompositorFrame(mojom::CompositorFramePtr frame, |
23 const mojo::Closure& callback) { | 37 const mojo::Closure& callback) { |
24 DCHECK(bound_to_thread_); | 38 DCHECK(thread_checker_); |
| 39 DCHECK(thread_checker_->CalledOnValidThread()); |
25 if (!surface_) | 40 if (!surface_) |
26 return; | 41 return; |
27 surface_->SubmitCompositorFrame(frame.Pass(), callback); | 42 surface_->SubmitCompositorFrame(frame.Pass(), callback); |
28 } | 43 } |
29 | 44 |
30 WindowSurface::WindowSurface( | 45 WindowSurface::WindowSurface( |
31 mojo::InterfacePtrInfo<mojom::Surface> surface_info, | 46 mojo::InterfacePtrInfo<mojom::Surface> surface_info, |
32 mojo::InterfaceRequest<mojom::SurfaceClient> client_request) | 47 mojo::InterfaceRequest<mojom::SurfaceClient> client_request) |
33 : client_(nullptr), | 48 : client_(nullptr), |
34 surface_info_(surface_info.Pass()), | 49 surface_info_(surface_info.Pass()), |
35 client_request_(client_request.Pass()), | 50 client_request_(client_request.Pass()) {} |
36 bound_to_thread_(false) {} | |
37 | 51 |
38 void WindowSurface::ReturnResources( | 52 void WindowSurface::ReturnResources( |
39 mojo::Array<mojom::ReturnedResourcePtr> resources) { | 53 mojo::Array<mojom::ReturnedResourcePtr> resources) { |
| 54 DCHECK(thread_checker_); |
| 55 DCHECK(thread_checker_->CalledOnValidThread()); |
40 if (!client_) | 56 if (!client_) |
41 return; | 57 return; |
42 client_->OnResourcesReturned(this, resources.Pass()); | 58 client_->OnResourcesReturned(this, resources.Pass()); |
43 } | 59 } |
44 | 60 |
| 61 WindowSurfaceBinding::~WindowSurfaceBinding() {} |
| 62 |
| 63 WindowSurfaceBinding::WindowSurfaceBinding( |
| 64 mojo::InterfaceRequest<mojom::Surface> surface_request, |
| 65 mojom::SurfaceClientPtr surface_client) |
| 66 : surface_request_(surface_request.Pass()), |
| 67 surface_client_(surface_client.Pass()) {} |
| 68 |
45 } // namespace mus | 69 } // namespace mus |
OLD | NEW |