| 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" |
| 11 #include "cc/quads/solid_color_draw_quad.h" | 11 #include "cc/quads/solid_color_draw_quad.h" |
| 12 #include "mojo/examples/surfaces_app/surfaces_util.h" | 12 #include "mojo/examples/surfaces_app/surfaces_util.h" |
| 13 #include "mojo/public/cpp/application/application_connection.h" | 13 #include "mojo/public/cpp/application/application_connection.h" |
| 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 15 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" | 15 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
| 16 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h" | 16 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h" |
| 17 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h" | 17 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 20 | 20 |
| 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::DrawQuad; | 25 using cc::DrawQuad; |
| 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 class SurfaceClientImpl : public surfaces::SurfaceClient { | 30 ChildImpl::ChildImpl(ApplicationConnection* surfaces_service_connection) { |
| 31 public: | 31 surfaces_service_connection->ConnectToService(&surface_); |
| 32 explicit SurfaceClientImpl(ChildImpl* impl) : impl_(impl) {} | 32 surface_.set_client(this); |
| 33 virtual ~SurfaceClientImpl() {} | |
| 34 | |
| 35 // surfaces::SurfaceClient implementation | |
| 36 virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE { | |
| 37 impl_->SetIdNamespace(id_namespace); | |
| 38 } | |
| 39 | |
| 40 virtual void ReturnResources( | |
| 41 Array<surfaces::ReturnedResourcePtr> resources) OVERRIDE { | |
| 42 DCHECK(!resources.size()); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 ChildImpl* impl_; | |
| 47 }; | |
| 48 | |
| 49 ChildImpl::ChildImpl(ApplicationConnection* connection, Context* context) | |
| 50 : surface_client_(new SurfaceClientImpl(this)) { | |
| 51 context->ShellConnection("mojo:mojo_surfaces_service") | |
| 52 ->ConnectToService(&surface_); | |
| 53 surface_.set_client(surface_client_.get()); | |
| 54 } | 33 } |
| 55 | 34 |
| 56 ChildImpl::~ChildImpl() { | 35 ChildImpl::~ChildImpl() { |
| 57 surface_->DestroySurface(mojo::surfaces::SurfaceId::From(id_)); | 36 surface_->DestroySurface(mojo::surfaces::SurfaceId::From(id_)); |
| 58 } | 37 } |
| 59 | 38 |
| 60 void ChildImpl::ProduceFrame( | 39 void ChildImpl::ProduceFrame( |
| 61 surfaces::ColorPtr color, | 40 surfaces::ColorPtr color, |
| 62 SizePtr size, | 41 SizePtr size, |
| 63 const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) { | 42 const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) { |
| 64 color_ = color.To<SkColor>(); | 43 color_ = color.To<SkColor>(); |
| 65 size_ = size.To<gfx::Size>(); | 44 size_ = size.To<gfx::Size>(); |
| 66 produce_callback_ = callback; | 45 produce_callback_ = callback; |
| 67 if (allocator_) | 46 if (allocator_) |
| 68 Draw(); | 47 Draw(); |
| 69 } | 48 } |
| 70 | 49 |
| 71 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { | 50 void ChildImpl::SetIdNamespace(uint32_t id_namespace) { |
| 72 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 51 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
| 73 if (!produce_callback_.is_null()) | 52 if (!produce_callback_.is_null()) |
| 74 Draw(); | 53 Draw(); |
| 75 } | 54 } |
| 76 | 55 |
| 56 void ChildImpl::ReturnResources( |
| 57 Array<surfaces::ReturnedResourcePtr> resources) { |
| 58 DCHECK(!resources.size()); |
| 59 } |
| 60 |
| 77 void ChildImpl::Draw() { | 61 void ChildImpl::Draw() { |
| 78 id_ = allocator_->GenerateId(); | 62 id_ = allocator_->GenerateId(); |
| 79 surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_), | 63 surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_), |
| 80 mojo::Size::From(size_)); | 64 mojo::Size::From(size_)); |
| 81 gfx::Rect rect(size_); | 65 gfx::Rect rect(size_); |
| 82 RenderPass::Id id(1, 1); | 66 RenderPass::Id id(1, 1); |
| 83 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 67 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 84 pass->SetNew(id, rect, rect, gfx::Transform()); | 68 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 85 | 69 |
| 86 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_); | 70 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 84 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 101 frame->delegated_frame_data = delegated_frame_data.Pass(); | 85 frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 102 | 86 |
| 103 surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_), | 87 surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_), |
| 104 mojo::surfaces::Frame::From(*frame)); | 88 mojo::surfaces::Frame::From(*frame)); |
| 105 produce_callback_.Run(surfaces::SurfaceId::From(id_)); | 89 produce_callback_.Run(surfaces::SurfaceId::From(id_)); |
| 106 } | 90 } |
| 107 | 91 |
| 108 } // namespace examples | 92 } // namespace examples |
| 109 } // namespace mojo | 93 } // namespace mojo |
| OLD | NEW |