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_gl_impl.h" | 5 #include "examples/surfaces_app/child_gl_impl.h" |
6 | 6 |
7 #ifndef GL_GLEXT_PROTOTYPES | 7 #ifndef GL_GLEXT_PROTOTYPES |
8 #define GL_GLEXT_PROTOTYPES | 8 #define GL_GLEXT_PROTOTYPES |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 using cc::TextureDrawQuad; | 39 using cc::TextureDrawQuad; |
40 using cc::DelegatedFrameData; | 40 using cc::DelegatedFrameData; |
41 using cc::CompositorFrame; | 41 using cc::CompositorFrame; |
42 | 42 |
43 static void ContextLostThunk(void*) { | 43 static void ContextLostThunk(void*) { |
44 LOG(FATAL) << "Context lost"; | 44 LOG(FATAL) << "Context lost"; |
45 } | 45 } |
46 | 46 |
47 ChildGLImpl::ChildGLImpl(ApplicationConnection* surfaces_service_connection, | 47 ChildGLImpl::ChildGLImpl(ApplicationConnection* surfaces_service_connection, |
48 CommandBufferPtr command_buffer) | 48 CommandBufferPtr command_buffer) |
49 : start_time_(base::TimeTicks::Now()), | 49 : id_namespace_(0u), |
50 next_resource_id_(1), | 50 local_id_(1u), |
51 weak_factory_(this) { | 51 start_time_(base::TimeTicks::Now()), |
| 52 next_resource_id_(1) { |
52 surfaces_service_connection->ConnectToService(&surface_); | 53 surfaces_service_connection->ConnectToService(&surface_); |
53 surface_.set_client(this); | 54 surface_.set_client(this); |
54 surface_.WaitForIncomingMethodCall(); // Wait for ID namespace to arrive. | |
55 context_ = | 55 context_ = |
56 MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(), | 56 MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(), |
57 &ContextLostThunk, | 57 &ContextLostThunk, |
58 this, | 58 this, |
59 Environment::GetDefaultAsyncWaiter()); | 59 Environment::GetDefaultAsyncWaiter()); |
60 DCHECK(context_); | 60 DCHECK(context_); |
61 MojoGLES2MakeCurrent(context_); | 61 MojoGLES2MakeCurrent(context_); |
62 } | 62 } |
63 | 63 |
64 ChildGLImpl::~ChildGLImpl() { | 64 ChildGLImpl::~ChildGLImpl() { |
65 MojoGLES2DestroyContext(context_); | 65 MojoGLES2DestroyContext(context_); |
66 surface_->DestroySurface(mojo::SurfaceId::From(id_)); | 66 surface_->DestroySurface(local_id_); |
67 } | 67 } |
68 | 68 |
69 void ChildGLImpl::ProduceFrame( | 69 void ChildGLImpl::ProduceFrame(ColorPtr color, |
70 ColorPtr color, | 70 SizePtr size, |
71 SizePtr size, | 71 const ProduceCallback& callback) { |
72 const mojo::Callback<void(SurfaceIdPtr id)>& callback) { | |
73 color_ = color.To<SkColor>(); | 72 color_ = color.To<SkColor>(); |
74 size_ = size.To<gfx::Size>(); | 73 size_ = size.To<gfx::Size>(); |
75 cube_.Init(size_.width(), size_.height()); | 74 cube_.Init(size_.width(), size_.height()); |
76 cube_.set_color( | 75 cube_.set_color( |
77 SkColorGetR(color_), SkColorGetG(color_), SkColorGetB(color_)); | 76 SkColorGetR(color_), SkColorGetG(color_), SkColorGetB(color_)); |
78 id_ = allocator_->GenerateId(); | 77 surface_->CreateSurface(local_id_); |
79 surface_->CreateSurface(mojo::SurfaceId::From(id_)); | 78 produce_callback_ = callback; |
80 callback.Run(SurfaceId::From(id_)); | 79 if (id_namespace_ != 0u) |
| 80 RunProduceCallback(); |
81 Draw(); | 81 Draw(); |
82 } | 82 } |
83 | 83 |
84 void ChildGLImpl::SetIdNamespace(uint32_t id_namespace) { | 84 void ChildGLImpl::SetIdNamespace(uint32_t id_namespace) { |
85 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 85 id_namespace_ = id_namespace; |
| 86 if (!produce_callback_.is_null()) |
| 87 RunProduceCallback(); |
| 88 produce_callback_.reset(); |
| 89 } |
| 90 |
| 91 void ChildGLImpl::RunProduceCallback() { |
| 92 auto id = SurfaceId::New(); |
| 93 id->id_namespace = id_namespace_; |
| 94 id->local = local_id_; |
| 95 produce_callback_.Run(id.Pass()); |
86 } | 96 } |
87 | 97 |
88 void ChildGLImpl::ReturnResources(Array<ReturnedResourcePtr> resources) { | 98 void ChildGLImpl::ReturnResources(Array<ReturnedResourcePtr> resources) { |
89 for (size_t i = 0; i < resources.size(); ++i) { | 99 for (size_t i = 0; i < resources.size(); ++i) { |
90 cc::ReturnedResource res = resources[i].To<cc::ReturnedResource>(); | 100 cc::ReturnedResource res = resources[i].To<cc::ReturnedResource>(); |
91 GLuint returned_texture = id_to_tex_map_[res.id]; | 101 GLuint returned_texture = id_to_tex_map_[res.id]; |
92 glDeleteTextures(1, &returned_texture); | 102 glDeleteTextures(1, &returned_texture); |
93 } | 103 } |
94 } | 104 } |
95 | 105 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 flipped, | 172 flipped, |
163 nearest_neighbor); | 173 nearest_neighbor); |
164 | 174 |
165 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); | 175 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
166 delegated_frame_data->render_pass_list.push_back(pass.Pass()); | 176 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
167 delegated_frame_data->resource_list.push_back(resource); | 177 delegated_frame_data->resource_list.push_back(resource); |
168 | 178 |
169 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 179 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
170 frame->delegated_frame_data = delegated_frame_data.Pass(); | 180 frame->delegated_frame_data = delegated_frame_data.Pass(); |
171 | 181 |
172 surface_->SubmitFrame(mojo::SurfaceId::From(id_), mojo::Frame::From(*frame), | 182 surface_->SubmitFrame(local_id_, mojo::Frame::From(*frame), mojo::Closure()); |
173 mojo::Closure()); | |
174 | 183 |
175 base::MessageLoop::current()->PostDelayedTask( | 184 base::MessageLoop::current()->PostDelayedTask( |
176 FROM_HERE, | 185 FROM_HERE, |
177 base::Bind(&ChildGLImpl::Draw, base::Unretained(this)), | 186 base::Bind(&ChildGLImpl::Draw, base::Unretained(this)), |
178 base::TimeDelta::FromMilliseconds(50)); | 187 base::TimeDelta::FromMilliseconds(50)); |
179 } | 188 } |
180 | 189 |
181 } // namespace examples | 190 } // namespace examples |
182 } // namespace mojo | 191 } // namespace mojo |
OLD | NEW |