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 "mojo/cc/output_surface_mojo.h" | 5 #include "mojo/cc/output_surface_mojo.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/output_surface_client.h" | 9 #include "cc/output/output_surface_client.h" |
10 #include "mojo/converters/geometry/geometry_type_converters.h" | 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
11 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 11 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 | 14 |
15 OutputSurfaceMojo::OutputSurfaceMojo( | 15 OutputSurfaceMojo::OutputSurfaceMojo( |
16 OutputSurfaceMojoClient* client, | 16 OutputSurfaceMojoClient* client, |
17 const scoped_refptr<cc::ContextProvider>& context_provider, | 17 const scoped_refptr<cc::ContextProvider>& context_provider, |
18 ScopedMessagePipeHandle surface_handle) | 18 ScopedMessagePipeHandle compositor_frame_receiver_handle) |
19 : cc::OutputSurface(context_provider), | 19 : cc::OutputSurface(context_provider), |
20 output_surface_mojo_client_(client), | 20 output_surface_mojo_client_(client), |
21 surface_handle_(surface_handle.Pass()), | 21 compositor_frame_receiver_handle_( |
| 22 compositor_frame_receiver_handle.Pass()), |
22 id_namespace_(0u), | 23 id_namespace_(0u), |
23 local_id_(0u) { | 24 local_id_(0u) { |
24 capabilities_.delegated_rendering = true; | 25 capabilities_.delegated_rendering = true; |
25 capabilities_.max_frames_pending = 1; | 26 capabilities_.max_frames_pending = 1; |
26 } | 27 } |
27 | 28 |
28 OutputSurfaceMojo::~OutputSurfaceMojo() { | 29 OutputSurfaceMojo::~OutputSurfaceMojo() { |
29 } | 30 } |
30 | 31 |
31 void OutputSurfaceMojo::SetIdNamespace(uint32_t id_namespace) { | 32 void OutputSurfaceMojo::SetIdNamespace(uint32_t id_namespace) { |
32 id_namespace_ = id_namespace; | 33 id_namespace_ = id_namespace; |
33 if (local_id_) { | 34 if (local_id_) { |
34 cc::SurfaceId qualified_id(static_cast<uint64_t>(id_namespace_) << 32 | | 35 cc::SurfaceId qualified_id(static_cast<uint64_t>(id_namespace_) << 32 | |
35 local_id_); | 36 local_id_); |
36 output_surface_mojo_client_->DidCreateSurface(qualified_id); | 37 output_surface_mojo_client_->DidCreateSurface(qualified_id); |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient* client) { | 41 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient* client) { |
41 surface_.Bind(InterfacePtrInfo<Surface>(surface_handle_.Pass(), 0u)); | 42 receiver_.Bind(InterfacePtrInfo<CompositorFrameReceiver>( |
42 surface_->GetIdNamespace( | 43 compositor_frame_receiver_handle_.Pass(), 0u)); |
43 base::Bind(&OutputSurfaceMojo::SetIdNamespace, base::Unretained(this))); | |
44 return cc::OutputSurface::BindToClient(client); | 44 return cc::OutputSurface::BindToClient(client); |
45 } | 45 } |
46 | 46 |
47 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame* frame) { | 47 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame* frame) { |
48 gfx::Size frame_size = | 48 receiver_->SubmitCompositorFrame(CompositorFrame::From(*frame), |
49 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 49 mojo::Closure()); |
50 if (frame_size != surface_size_) { | |
51 if (local_id_ != 0u) { | |
52 surface_->DestroySurface(local_id_); | |
53 } | |
54 local_id_++; | |
55 surface_->CreateSurface(local_id_); | |
56 if (id_namespace_) { | |
57 cc::SurfaceId qualified_id(static_cast<uint64_t>(id_namespace_) << 32 | | |
58 local_id_); | |
59 output_surface_mojo_client_->DidCreateSurface(qualified_id); | |
60 } | |
61 surface_size_ = frame_size; | |
62 } | |
63 | |
64 surface_->SubmitFrame(local_id_, | |
65 CompositorFrame::From(*frame), | |
66 mojo::Closure()); | |
67 | 50 |
68 client_->DidSwapBuffers(); | 51 client_->DidSwapBuffers(); |
69 client_->DidSwapBuffersComplete(); | 52 client_->DidSwapBuffersComplete(); |
70 } | 53 } |
71 | 54 |
72 } // namespace mojo | 55 } // namespace mojo |
OLD | NEW |