Chromium Code Reviews| 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 static const uint32_t kLocalId = 1u; |
| 32 | |
| 33 ChildImpl::ChildImpl(ApplicationConnection* surfaces_service_connection) | |
| 34 : id_namespace_(0u) { | |
| 32 surfaces_service_connection->ConnectToService(&surface_); | 35 surfaces_service_connection->ConnectToService(&surface_); |
| 33 surface_.set_client(this); | 36 surface_.set_client(this); |
| 34 surface_.WaitForIncomingMethodCall(); // Wait for ID namespace to arrive. | 37 surface_.WaitForIncomingMethodCall(); // Wait for ID namespace to arrive. |
| 38 DCHECK_NE(0u, id_namespace_); | |
| 35 } | 39 } |
| 36 | 40 |
| 37 ChildImpl::~ChildImpl() { | 41 ChildImpl::~ChildImpl() { |
| 38 if (surface_) | 42 surface_->DestroySurface(kLocalId); |
| 39 surface_->DestroySurface(mojo::SurfaceId::From(id_)); | |
| 40 } | 43 } |
| 41 | 44 |
| 42 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { | 45 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { |
| 43 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 46 id_namespace_ = id_namespace; |
| 44 } | 47 } |
| 45 | 48 |
| 46 void ChildImpl::ReturnResources( | 49 void ChildImpl::ReturnResources( |
| 47 Array<ReturnedResourcePtr> resources) { | 50 Array<ReturnedResourcePtr> resources) { |
| 48 DCHECK(!resources.size()); | 51 DCHECK(!resources.size()); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void ChildImpl::ProduceFrame( | 54 void ChildImpl::ProduceFrame(ColorPtr color, |
| 52 ColorPtr color, | 55 SizePtr size_ptr, |
| 53 SizePtr size_ptr, | 56 const ProduceCallback& callback) { |
| 54 const mojo::Callback<void(SurfaceIdPtr id)>& callback) { | |
| 55 id_ = allocator_->GenerateId(); | |
| 56 surface_->CreateSurface(mojo::SurfaceId::From(id_)); | |
| 57 gfx::Size size = size_ptr.To<gfx::Size>(); | 57 gfx::Size size = size_ptr.To<gfx::Size>(); |
| 58 gfx::Rect rect(size); | 58 gfx::Rect rect(size); |
| 59 RenderPassId id(1, 1); | 59 RenderPassId id(1, 1); |
| 60 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 60 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 61 pass->SetNew(id, rect, rect, gfx::Transform()); | 61 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 62 | 62 |
| 63 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size); | 63 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size); |
| 64 | 64 |
| 65 SolidColorDrawQuad* color_quad = | 65 SolidColorDrawQuad* color_quad = |
| 66 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 66 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 67 bool force_anti_aliasing_off = false; | 67 bool force_anti_aliasing_off = false; |
| 68 color_quad->SetNew(pass->shared_quad_state_list.back(), | 68 color_quad->SetNew(pass->shared_quad_state_list.back(), rect, rect, |
| 69 rect, | 69 color.To<SkColor>(), force_anti_aliasing_off); |
| 70 rect, | |
| 71 color.To<SkColor>(), | |
| 72 force_anti_aliasing_off); | |
| 73 | 70 |
| 74 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); | 71 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 75 delegated_frame_data->render_pass_list.push_back(pass.Pass()); | 72 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 76 | 73 |
| 77 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 74 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 78 frame->delegated_frame_data = delegated_frame_data.Pass(); | 75 frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 79 | 76 |
| 80 surface_->SubmitFrame(mojo::SurfaceId::From(id_), mojo::Frame::From(*frame), | 77 surface_->CreateSurface(kLocalId); |
|
sky
2015/01/13 18:14:27
I'm not familiar with this class. Is ProduceFrame
jamesr
2015/01/14 01:50:29
That's right - this app produces exactly one frame
| |
| 81 mojo::Closure()); | 78 surface_->SubmitFrame(kLocalId, mojo::Frame::From(*frame), mojo::Closure()); |
| 82 callback.Run(SurfaceId::From(id_)); | 79 auto qualified_id = mojo::SurfaceId::New(); |
| 80 qualified_id->id_namespace = id_namespace_; | |
| 81 qualified_id->local = kLocalId; | |
| 82 callback.Run(qualified_id.Pass()); | |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace examples | 85 } // namespace examples |
| 86 } // namespace mojo | 86 } // namespace mojo |
| OLD | NEW |