OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/services/gles2/command_buffer_impl.h" | 5 #include "mojo/services/gles2/command_buffer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 | 9 |
10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void CommandBufferImpl::Initialize( | 66 void CommandBufferImpl::Initialize( |
67 CommandBufferSyncClientPtr sync_client, | 67 CommandBufferSyncClientPtr sync_client, |
68 mojo::ScopedSharedBufferHandle shared_state) { | 68 mojo::ScopedSharedBufferHandle shared_state) { |
69 sync_client_ = sync_client.Pass(); | 69 sync_client_ = sync_client.Pass(); |
70 sync_client_->DidInitialize(DoInitialize(shared_state.Pass())); | 70 sync_client_->DidInitialize(DoInitialize(shared_state.Pass())); |
71 } | 71 } |
72 | 72 |
73 bool CommandBufferImpl::DoInitialize( | 73 bool CommandBufferImpl::DoInitialize( |
74 mojo::ScopedSharedBufferHandle shared_state) { | 74 mojo::ScopedSharedBufferHandle shared_state) { |
75 // TODO(piman): offscreen surface. | 75 // TODO(piman): offscreen surface. |
76 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | 76 scoped_refptr<gfx::GLSurface> surface = |
77 if (!surface_.get()) | 77 gfx::GLSurface::CreateViewGLSurface(widget_); |
| 78 if (!surface.get()) |
78 return false; | 79 return false; |
79 | 80 |
80 // TODO(piman): context sharing, virtual contexts, gpu preference. | 81 // TODO(piman): context sharing, virtual contexts, gpu preference. |
81 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( | 82 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( |
82 NULL, surface_.get(), gfx::PreferIntegratedGpu); | 83 NULL, surface.get(), gfx::PreferIntegratedGpu); |
83 if (!context.get()) | 84 if (!context.get()) |
84 return false; | 85 return false; |
85 | 86 |
86 if (!context->MakeCurrent(surface_.get())) | 87 if (!context->MakeCurrent(surface.get())) |
87 return false; | 88 return false; |
88 | 89 |
89 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but | 90 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but |
90 // only needs to be per-thread. | 91 // only needs to be per-thread. |
91 scoped_refptr<gpu::gles2::ContextGroup> context_group = | 92 scoped_refptr<gpu::gles2::ContextGroup> context_group = |
92 new gpu::gles2::ContextGroup(NULL, | 93 new gpu::gles2::ContextGroup(NULL, |
93 NULL, | 94 NULL, |
94 new MemoryTrackerStub, | 95 new MemoryTrackerStub, |
95 new gpu::gles2::ShaderTranslatorCache, | 96 new gpu::gles2::ShaderTranslatorCache, |
96 NULL, | 97 NULL, |
97 true); | 98 true); |
98 | 99 |
99 command_buffer_.reset( | 100 command_buffer_.reset( |
100 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 101 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
101 bool result = command_buffer_->Initialize(); | 102 bool result = command_buffer_->Initialize(); |
102 DCHECK(result); | 103 DCHECK(result); |
103 | 104 |
104 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 105 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
105 scheduler_.reset(new gpu::GpuScheduler( | 106 scheduler_.reset(new gpu::GpuScheduler( |
106 command_buffer_.get(), decoder_.get(), decoder_.get())); | 107 command_buffer_.get(), decoder_.get(), decoder_.get())); |
107 decoder_->set_engine(scheduler_.get()); | 108 decoder_->set_engine(scheduler_.get()); |
108 decoder_->SetResizeCallback( | |
109 base::Bind(&CommandBufferImpl::OnResize, base::Unretained(this))); | |
110 | 109 |
111 gpu::gles2::DisallowedFeatures disallowed_features; | 110 gpu::gles2::DisallowedFeatures disallowed_features; |
112 | 111 |
113 // TODO(piman): attributes. | 112 // TODO(piman): attributes. |
114 std::vector<int32> attrib_vector; | 113 std::vector<int32> attrib_vector; |
115 if (!decoder_->Initialize(surface_, | 114 if (!decoder_->Initialize(surface, |
116 context, | 115 context, |
117 false /* offscreen */, | 116 false /* offscreen */, |
118 size_, | 117 size_, |
119 disallowed_features, | 118 disallowed_features, |
120 attrib_vector)) | 119 attrib_vector)) |
121 return false; | 120 return false; |
122 | 121 |
123 gpu_control_.reset( | 122 gpu_control_.reset( |
124 new gpu::GpuControlService(context_group->image_manager(), NULL)); | 123 new gpu::GpuControlService(context_group->image_manager(), NULL)); |
125 | 124 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 187 |
189 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } | 188 void CommandBufferImpl::CancelAnimationFrames() { timer_.Stop(); } |
190 | 189 |
191 void CommandBufferImpl::OnParseError() { | 190 void CommandBufferImpl::OnParseError() { |
192 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 191 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
193 client()->LostContext(state.context_lost_reason); | 192 client()->LostContext(state.context_lost_reason); |
194 } | 193 } |
195 | 194 |
196 void CommandBufferImpl::DrawAnimationFrame() { client()->DrawAnimationFrame(); } | 195 void CommandBufferImpl::DrawAnimationFrame() { client()->DrawAnimationFrame(); } |
197 | 196 |
198 void CommandBufferImpl::OnResize(gfx::Size size, float scale_factor) { | |
199 surface_->Resize(size); | |
200 } | |
201 | |
202 } // namespace services | 197 } // namespace services |
203 } // namespace mojo | 198 } // namespace mojo |
OLD | NEW |