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_gl_impl.h" | 5 #include "mojo/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 25 matching lines...) Expand all Loading... |
36 using cc::TextureDrawQuad; | 36 using cc::TextureDrawQuad; |
37 using cc::DelegatedFrameData; | 37 using cc::DelegatedFrameData; |
38 using cc::CompositorFrame; | 38 using cc::CompositorFrame; |
39 | 39 |
40 static void ContextLostThunk(void*) { | 40 static void ContextLostThunk(void*) { |
41 LOG(FATAL) << "Context lost"; | 41 LOG(FATAL) << "Context lost"; |
42 } | 42 } |
43 | 43 |
44 ChildGLImpl::ChildGLImpl(ApplicationConnection* surfaces_service_connection, | 44 ChildGLImpl::ChildGLImpl(ApplicationConnection* surfaces_service_connection, |
45 CommandBufferPtr command_buffer) | 45 CommandBufferPtr command_buffer) |
46 : start_time_(base::TimeTicks::Now()), next_resource_id_(1) { | 46 : start_time_(base::TimeTicks::Now()), |
47 surfaces_service_connection->ConnectToService(&surface_); | 47 next_resource_id_(1), |
48 surface_.set_client(this); | 48 weak_factory_(this) { |
| 49 surfaces_service_connection->ConnectToService(&surfaces_service_); |
| 50 surfaces_service_->CreateSurfaceConnection(base::Bind( |
| 51 &ChildGLImpl::SurfaceConnectionCreated, weak_factory_.GetWeakPtr())); |
49 context_ = | 52 context_ = |
50 MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(), | 53 MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(), |
51 &ContextLostThunk, | 54 &ContextLostThunk, |
52 this, | 55 this, |
53 Environment::GetDefaultAsyncWaiter()); | 56 Environment::GetDefaultAsyncWaiter()); |
54 DCHECK(context_); | 57 DCHECK(context_); |
55 MojoGLES2MakeCurrent(context_); | 58 MojoGLES2MakeCurrent(context_); |
56 } | 59 } |
57 | 60 |
58 ChildGLImpl::~ChildGLImpl() { | 61 ChildGLImpl::~ChildGLImpl() { |
59 MojoGLES2DestroyContext(context_); | 62 MojoGLES2DestroyContext(context_); |
60 surface_->DestroySurface(mojo::SurfaceId::From(id_)); | 63 surface_->DestroySurface(mojo::SurfaceId::From(id_)); |
61 } | 64 } |
62 | 65 |
63 void ChildGLImpl::ProduceFrame( | 66 void ChildGLImpl::ProduceFrame( |
64 ColorPtr color, | 67 ColorPtr color, |
65 SizePtr size, | 68 SizePtr size, |
66 const mojo::Callback<void(SurfaceIdPtr id)>& callback) { | 69 const mojo::Callback<void(SurfaceIdPtr id)>& callback) { |
67 color_ = color.To<SkColor>(); | 70 color_ = color.To<SkColor>(); |
68 size_ = size.To<gfx::Size>(); | 71 size_ = size.To<gfx::Size>(); |
69 cube_.Init(size_.width(), size_.height()); | 72 cube_.Init(size_.width(), size_.height()); |
70 cube_.set_color( | 73 cube_.set_color( |
71 SkColorGetR(color_), SkColorGetG(color_), SkColorGetB(color_)); | 74 SkColorGetR(color_), SkColorGetG(color_), SkColorGetB(color_)); |
72 produce_callback_ = callback; | 75 produce_callback_ = callback; |
73 if (allocator_) | 76 AllocateSurface(); |
74 AllocateSurface(); | |
75 } | 77 } |
76 | 78 |
77 void ChildGLImpl::SetIdNamespace(uint32_t id_namespace) { | 79 void ChildGLImpl::SurfaceConnectionCreated(SurfacePtr surface, |
| 80 uint32_t id_namespace) { |
| 81 surface_ = surface.Pass(); |
| 82 surface_.set_client(this); |
78 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 83 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
79 if (!produce_callback_.is_null()) | 84 AllocateSurface(); |
80 AllocateSurface(); | |
81 } | 85 } |
82 | 86 |
83 void ChildGLImpl::ReturnResources(Array<ReturnedResourcePtr> resources) { | 87 void ChildGLImpl::ReturnResources(Array<ReturnedResourcePtr> resources) { |
84 for (size_t i = 0; i < resources.size(); ++i) { | 88 for (size_t i = 0; i < resources.size(); ++i) { |
85 cc::ReturnedResource res = resources[i].To<cc::ReturnedResource>(); | 89 cc::ReturnedResource res = resources[i].To<cc::ReturnedResource>(); |
86 GLuint returned_texture = id_to_tex_map_[res.id]; | 90 GLuint returned_texture = id_to_tex_map_[res.id]; |
87 glDeleteTextures(1, &returned_texture); | 91 glDeleteTextures(1, &returned_texture); |
88 } | 92 } |
89 } | 93 } |
90 | 94 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 surface_->SubmitFrame(mojo::SurfaceId::From(id_), mojo::Frame::From(*frame)); | 177 surface_->SubmitFrame(mojo::SurfaceId::From(id_), mojo::Frame::From(*frame)); |
174 | 178 |
175 base::MessageLoop::current()->PostDelayedTask( | 179 base::MessageLoop::current()->PostDelayedTask( |
176 FROM_HERE, | 180 FROM_HERE, |
177 base::Bind(&ChildGLImpl::Draw, base::Unretained(this)), | 181 base::Bind(&ChildGLImpl::Draw, base::Unretained(this)), |
178 base::TimeDelta::FromMilliseconds(50)); | 182 base::TimeDelta::FromMilliseconds(50)); |
179 } | 183 } |
180 | 184 |
181 } // namespace examples | 185 } // namespace examples |
182 } // namespace mojo | 186 } // namespace mojo |
OLD | NEW |