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/examples/surfaces_app/child_impl.h" | 5 #include "mojo/examples/surfaces_app/child_impl.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/delegated_frame_data.h" | 9 #include "cc/output/delegated_frame_data.h" |
10 #include "cc/quads/render_pass.h" | 10 #include "cc/quads/render_pass.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 using cc::SolidColorDrawQuad; | 26 using cc::SolidColorDrawQuad; |
27 using cc::DelegatedFrameData; | 27 using cc::DelegatedFrameData; |
28 using cc::CompositorFrame; | 28 using cc::CompositorFrame; |
29 | 29 |
30 ChildImpl::ChildImpl(ApplicationConnection* surfaces_service_connection) { | 30 ChildImpl::ChildImpl(ApplicationConnection* surfaces_service_connection) { |
31 surfaces_service_connection->ConnectToService(&surface_); | 31 surfaces_service_connection->ConnectToService(&surface_); |
32 surface_.set_client(this); | 32 surface_.set_client(this); |
33 } | 33 } |
34 | 34 |
35 ChildImpl::~ChildImpl() { | 35 ChildImpl::~ChildImpl() { |
36 surface_->DestroySurface(mojo::surfaces::SurfaceId::From(id_)); | 36 surface_->DestroySurface(mojo::SurfaceId::From(id_)); |
37 } | 37 } |
38 | 38 |
39 void ChildImpl::ProduceFrame( | 39 void ChildImpl::ProduceFrame( |
40 surfaces::ColorPtr color, | 40 ColorPtr color, |
41 SizePtr size, | 41 SizePtr size, |
42 const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) { | 42 const mojo::Callback<void(SurfaceIdPtr id)>& callback) { |
43 color_ = color.To<SkColor>(); | 43 color_ = color.To<SkColor>(); |
44 size_ = size.To<gfx::Size>(); | 44 size_ = size.To<gfx::Size>(); |
45 produce_callback_ = callback; | 45 produce_callback_ = callback; |
46 if (allocator_) | 46 if (allocator_) |
47 Draw(); | 47 Draw(); |
48 } | 48 } |
49 | 49 |
50 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { | 50 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { |
51 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 51 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
52 if (!produce_callback_.is_null()) | 52 if (!produce_callback_.is_null()) |
53 Draw(); | 53 Draw(); |
54 } | 54 } |
55 | 55 |
56 void ChildImpl::ReturnResources( | 56 void ChildImpl::ReturnResources( |
57 Array<surfaces::ReturnedResourcePtr> resources) { | 57 Array<ReturnedResourcePtr> resources) { |
58 DCHECK(!resources.size()); | 58 DCHECK(!resources.size()); |
59 } | 59 } |
60 | 60 |
61 void ChildImpl::Draw() { | 61 void ChildImpl::Draw() { |
62 id_ = allocator_->GenerateId(); | 62 id_ = allocator_->GenerateId(); |
63 surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_), | 63 surface_->CreateSurface(mojo::SurfaceId::From(id_), |
64 mojo::Size::From(size_)); | 64 mojo::Size::From(size_)); |
65 gfx::Rect rect(size_); | 65 gfx::Rect rect(size_); |
66 RenderPass::Id id(1, 1); | 66 RenderPass::Id id(1, 1); |
67 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 67 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
68 pass->SetNew(id, rect, rect, gfx::Transform()); | 68 pass->SetNew(id, rect, rect, gfx::Transform()); |
69 | 69 |
70 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_); | 70 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_); |
71 | 71 |
72 SolidColorDrawQuad* color_quad = | 72 SolidColorDrawQuad* color_quad = |
73 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 73 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
74 bool force_anti_aliasing_off = false; | 74 bool force_anti_aliasing_off = false; |
75 color_quad->SetNew(pass->shared_quad_state_list.back(), | 75 color_quad->SetNew(pass->shared_quad_state_list.back(), |
76 rect, | 76 rect, |
77 rect, | 77 rect, |
78 color_, | 78 color_, |
79 force_anti_aliasing_off); | 79 force_anti_aliasing_off); |
80 | 80 |
81 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); | 81 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
82 delegated_frame_data->render_pass_list.push_back(pass.Pass()); | 82 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
83 | 83 |
84 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 84 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
85 frame->delegated_frame_data = delegated_frame_data.Pass(); | 85 frame->delegated_frame_data = delegated_frame_data.Pass(); |
86 | 86 |
87 surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_), | 87 surface_->SubmitFrame(mojo::SurfaceId::From(id_), |
88 mojo::surfaces::Frame::From(*frame)); | 88 mojo::Frame::From(*frame)); |
89 produce_callback_.Run(surfaces::SurfaceId::From(id_)); | 89 produce_callback_.Run(SurfaceId::From(id_)); |
90 } | 90 } |
91 | 91 |
92 } // namespace examples | 92 } // namespace examples |
93 } // namespace mojo | 93 } // namespace mojo |
OLD | NEW |