Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: mojo/examples/surfaces_app/child_impl.cc

Issue 361123002: Mojo surfaces service and example app (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/surfaces_app/child_impl.h ('k') | mojo/examples/surfaces_app/embedder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/examples/surfaces_app/child_impl.h"
6
7 #include "base/bind.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/delegated_frame_data.h"
10 #include "cc/quads/render_pass.h"
11 #include "cc/quads/solid_color_draw_quad.h"
12 #include "mojo/examples/surfaces_app/surfaces_util.h"
13 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/services/public/cpp/geometry/geometry_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"
17 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/transform.h"
20
21 namespace mojo {
22 namespace examples {
23
24 using cc::RenderPass;
25 using cc::DrawQuad;
26 using cc::SolidColorDrawQuad;
27 using cc::DelegatedFrameData;
28 using cc::CompositorFrame;
29
30 class SurfaceClientImpl : public surfaces::SurfaceClient {
31 public:
32 explicit SurfaceClientImpl(ChildImpl* impl) : impl_(impl) {}
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 }
55
56 ChildImpl::~ChildImpl() {
57 surface_->DestroySurface(mojo::surfaces::SurfaceId::From(id_));
58 }
59
60 void ChildImpl::ProduceFrame(
61 surfaces::ColorPtr color,
62 SizePtr size,
63 const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) {
64 color_ = color.To<SkColor>();
65 size_ = size.To<gfx::Size>();
66 produce_callback_ = callback;
67 if (allocator_)
68 Draw();
69 }
70
71 void ChildImpl::SetIdNamespace(uint32_t id_namespace) {
72 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
73 if (!produce_callback_.is_null())
74 Draw();
75 }
76
77 void ChildImpl::Draw() {
78 id_ = allocator_->GenerateId();
79 surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_),
80 mojo::Size::From(size_));
81 gfx::Rect rect(size_);
82 RenderPass::Id id(1, 1);
83 scoped_ptr<RenderPass> pass = RenderPass::Create();
84 pass->SetNew(id, rect, rect, gfx::Transform());
85
86 CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_);
87
88 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
89 bool force_anti_aliasing_off = false;
90 color_quad->SetNew(pass->shared_quad_state_list.back(),
91 rect,
92 rect,
93 color_,
94 force_anti_aliasing_off);
95 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
96
97 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
98 delegated_frame_data->render_pass_list.push_back(pass.Pass());
99
100 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
101 frame->delegated_frame_data = delegated_frame_data.Pass();
102
103 surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_),
104 mojo::surfaces::Frame::From(*frame));
105 produce_callback_.Run(surfaces::SurfaceId::From(id_));
106 }
107
108 } // namespace examples
109 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/surfaces_app/child_impl.h ('k') | mojo/examples/surfaces_app/embedder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698