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