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