OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/gles2/command_buffer_local.h" | 5 #include "components/mus/gles2/command_buffer_local.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/mus/gles2/command_buffer_local_client.h" | 8 #include "components/mus/gles2/command_buffer_local_client.h" |
9 #include "components/mus/gles2/gpu_memory_tracker.h" | 9 #include "components/mus/gles2/gpu_memory_tracker.h" |
10 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 10 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
11 #include "gpu/command_buffer/service/command_buffer_service.h" | 11 #include "gpu/command_buffer/service/command_buffer_service.h" |
12 #include "gpu/command_buffer/service/context_group.h" | 12 #include "gpu/command_buffer/service/context_group.h" |
13 #include "gpu/command_buffer/service/gpu_scheduler.h" | 13 #include "gpu/command_buffer/service/gpu_scheduler.h" |
14 #include "gpu/command_buffer/service/image_factory.h" | 14 #include "gpu/command_buffer/service/image_factory.h" |
15 #include "gpu/command_buffer/service/image_manager.h" | 15 #include "gpu/command_buffer/service/image_manager.h" |
16 #include "gpu/command_buffer/service/memory_tracking.h" | 16 #include "gpu/command_buffer/service/memory_tracking.h" |
17 #include "gpu/command_buffer/service/shader_translator_cache.h" | 17 #include "gpu/command_buffer/service/shader_translator_cache.h" |
18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
19 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 19 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
20 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
21 #include "ui/gl/gl_context.h" | 21 #include "ui/gl/gl_context.h" |
22 #include "ui/gl/gl_image_memory.h" | 22 #include "ui/gl/gl_image_memory.h" |
23 #include "ui/gl/gl_surface.h" | 23 #include "ui/gl/gl_surface.h" |
24 | 24 |
25 namespace mus { | 25 namespace gles2 { |
26 | 26 |
27 const unsigned int GL_MAP_CHROMIUM = 0x78F1; | 27 const unsigned int GL_MAP_CHROMIUM = 0x78F1; |
28 | 28 |
29 CommandBufferLocal::CommandBufferLocal(CommandBufferLocalClient* client, | 29 CommandBufferLocal::CommandBufferLocal( |
30 gfx::AcceleratedWidget widget, | 30 CommandBufferLocalClient* client, |
31 const scoped_refptr<GpuState>& gpu_state) | 31 gfx::AcceleratedWidget widget, |
| 32 const scoped_refptr<gles2::GpuState>& gpu_state) |
32 : widget_(widget), | 33 : widget_(widget), |
33 gpu_state_(gpu_state), | 34 gpu_state_(gpu_state), |
34 client_(client), | 35 client_(client), |
35 weak_factory_(this) {} | 36 weak_factory_(this) {} |
36 | 37 |
37 CommandBufferLocal::~CommandBufferLocal() { | 38 CommandBufferLocal::~CommandBufferLocal() { |
38 command_buffer_.reset(); | 39 command_buffer_.reset(); |
39 if (decoder_.get()) { | 40 if (decoder_.get()) { |
40 bool have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); | 41 bool have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); |
41 decoder_->Destroy(have_context); | 42 decoder_->Destroy(have_context); |
(...skipping 25 matching lines...) Expand all Loading... |
67 return false; | 68 return false; |
68 | 69 |
69 if (!context_->MakeCurrent(surface_.get())) | 70 if (!context_->MakeCurrent(surface_.get())) |
70 return false; | 71 return false; |
71 | 72 |
72 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but | 73 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but |
73 // only needs to be per-thread. | 74 // only needs to be per-thread. |
74 bool bind_generates_resource = false; | 75 bool bind_generates_resource = false; |
75 scoped_refptr<gpu::gles2::ContextGroup> context_group = | 76 scoped_refptr<gpu::gles2::ContextGroup> context_group = |
76 new gpu::gles2::ContextGroup( | 77 new gpu::gles2::ContextGroup( |
77 gpu_state_->mailbox_manager(), new GpuMemoryTracker, | 78 gpu_state_->mailbox_manager(), new gles2::GpuMemoryTracker, |
78 new gpu::gles2::ShaderTranslatorCache, | 79 new gpu::gles2::ShaderTranslatorCache, |
79 new gpu::gles2::FramebufferCompletenessCache, nullptr, nullptr, | 80 new gpu::gles2::FramebufferCompletenessCache, nullptr, nullptr, |
80 nullptr, bind_generates_resource); | 81 nullptr, bind_generates_resource); |
81 | 82 |
82 command_buffer_.reset( | 83 command_buffer_.reset( |
83 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 84 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
84 bool result = command_buffer_->Initialize(); | 85 bool result = command_buffer_->Initialize(); |
85 DCHECK(result); | 86 DCHECK(result); |
86 | 87 |
87 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 88 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /******************************************************************************/ | 121 /******************************************************************************/ |
121 | 122 |
122 gpu::Capabilities CommandBufferLocal::GetCapabilities() { | 123 gpu::Capabilities CommandBufferLocal::GetCapabilities() { |
123 return decoder_->GetCapabilities(); | 124 return decoder_->GetCapabilities(); |
124 } | 125 } |
125 | 126 |
126 int32_t CommandBufferLocal::CreateImage(ClientBuffer buffer, | 127 int32_t CommandBufferLocal::CreateImage(ClientBuffer buffer, |
127 size_t width, | 128 size_t width, |
128 size_t height, | 129 size_t height, |
129 unsigned internalformat) { | 130 unsigned internalformat) { |
130 MojoGpuMemoryBufferImpl* gpu_memory_buffer = | 131 gles2::MojoGpuMemoryBufferImpl* gpu_memory_buffer = |
131 MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); | 132 gles2::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); |
132 | 133 |
133 scoped_refptr<gfx::GLImageMemory> image(new gfx::GLImageMemory( | 134 scoped_refptr<gfx::GLImageMemory> image(new gfx::GLImageMemory( |
134 gfx::Size(static_cast<int>(width), static_cast<int>(height)), | 135 gfx::Size(static_cast<int>(width), static_cast<int>(height)), |
135 internalformat)); | 136 internalformat)); |
136 if (!image->Initialize( | 137 if (!image->Initialize( |
137 static_cast<const unsigned char*>(gpu_memory_buffer->GetMemory()), | 138 static_cast<const unsigned char*>(gpu_memory_buffer->GetMemory()), |
138 gpu_memory_buffer->GetFormat())) { | 139 gpu_memory_buffer->GetFormat())) { |
139 return -1; | 140 return -1; |
140 } | 141 } |
141 | 142 |
(...skipping 10 matching lines...) Expand all Loading... |
152 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 153 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
153 DCHECK(image_manager); | 154 DCHECK(image_manager); |
154 image_manager->RemoveImage(id); | 155 image_manager->RemoveImage(id); |
155 } | 156 } |
156 | 157 |
157 int32_t CommandBufferLocal::CreateGpuMemoryBufferImage(size_t width, | 158 int32_t CommandBufferLocal::CreateGpuMemoryBufferImage(size_t width, |
158 size_t height, | 159 size_t height, |
159 unsigned internalformat, | 160 unsigned internalformat, |
160 unsigned usage) { | 161 unsigned usage) { |
161 DCHECK_EQ(usage, static_cast<unsigned>(GL_MAP_CHROMIUM)); | 162 DCHECK_EQ(usage, static_cast<unsigned>(GL_MAP_CHROMIUM)); |
162 scoped_ptr<gfx::GpuMemoryBuffer> buffer(MojoGpuMemoryBufferImpl::Create( | 163 scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
163 gfx::Size(static_cast<int>(width), static_cast<int>(height)), | 164 gles2::MojoGpuMemoryBufferImpl::Create( |
164 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), | 165 gfx::Size(static_cast<int>(width), static_cast<int>(height)), |
165 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | 166 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), |
| 167 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); |
166 if (!buffer) | 168 if (!buffer) |
167 return -1; | 169 return -1; |
168 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 170 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
169 } | 171 } |
170 | 172 |
171 uint32_t CommandBufferLocal::InsertSyncPoint() { | 173 uint32_t CommandBufferLocal::InsertSyncPoint() { |
172 return 0; | 174 return 0; |
173 } | 175 } |
174 | 176 |
175 uint32_t CommandBufferLocal::InsertFutureSyncPoint() { | 177 uint32_t CommandBufferLocal::InsertFutureSyncPoint() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 252 |
251 void CommandBufferLocal::OnContextLost(uint32_t reason) { | 253 void CommandBufferLocal::OnContextLost(uint32_t reason) { |
252 if (client_) | 254 if (client_) |
253 client_->DidLoseContext(); | 255 client_->DidLoseContext(); |
254 } | 256 } |
255 | 257 |
256 void CommandBufferLocal::OnSyncPointRetired() { | 258 void CommandBufferLocal::OnSyncPointRetired() { |
257 scheduler_->SetScheduled(true); | 259 scheduler_->SetScheduled(true); |
258 } | 260 } |
259 | 261 |
260 } // namespace mus | 262 } // namespace gles2 |
OLD | NEW |