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