| 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 "components/mus/gles2/command_buffer_driver.h" | 5 #include "components/mus/gles2/command_buffer_driver.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "components/mus/gles2/gl_surface_adapter.h" | 14 #include "components/mus/gles2/gl_surface_adapter.h" |
| 15 #include "components/mus/gles2/gpu_memory_tracker.h" | 15 #include "components/mus/gles2/gpu_memory_tracker.h" |
| 16 #include "components/mus/gles2/gpu_state.h" | 16 #include "components/mus/gles2/gpu_state.h" |
| 17 #include "components/mus/gles2/mojo_buffer_backing.h" | 17 #include "components/mus/gles2/mojo_buffer_backing.h" |
| 18 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 18 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 19 #include "gpu/command_buffer/service/command_buffer_service.h" | 19 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 20 #include "gpu/command_buffer/service/command_executor.h" | 20 #include "gpu/command_buffer/service/command_executor.h" |
| 21 #include "gpu/command_buffer/service/context_group.h" | 21 #include "gpu/command_buffer/service/context_group.h" |
| 22 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 22 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 23 #include "gpu/command_buffer/service/image_manager.h" | 23 #include "gpu/command_buffer/service/image_manager.h" |
| 24 #include "gpu/command_buffer/service/mailbox_manager.h" | 24 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 25 #include "gpu/command_buffer/service/query_manager.h" | 25 #include "gpu/command_buffer/service/query_manager.h" |
| 26 #include "gpu/command_buffer/service/sync_point_manager.h" | 26 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 27 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 27 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 28 #include "mojo/public/cpp/system/platform_handle.h" | 28 #include "mojo/public/cpp/system/platform_handle.h" |
| 29 #include "ui/gfx/buffer_format_util.h" | 29 #include "ui/gfx/buffer_format_util.h" |
| 30 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | |
| 31 #include "ui/gfx/gpu_memory_buffer.h" | 30 #include "ui/gfx/gpu_memory_buffer.h" |
| 32 #include "ui/gfx/vsync_provider.h" | 31 #include "ui/gfx/vsync_provider.h" |
| 33 #include "ui/gl/gl_context.h" | 32 #include "ui/gl/gl_context.h" |
| 34 #include "ui/gl/gl_image_shared_memory.h" | 33 #include "ui/gl/gl_image_shared_memory.h" |
| 35 #include "ui/gl/gl_surface.h" | 34 #include "ui/gl/gl_surface.h" |
| 36 #include "ui/gl/init/gl_factory.h" | 35 #include "ui/gl/init/gl_factory.h" |
| 37 | 36 |
| 38 #if defined(USE_OZONE) | 37 #if defined(USE_OZONE) |
| 39 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 38 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 40 #endif | 39 #endif |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 210 } |
| 212 | 211 |
| 213 void CommandBufferDriver::DestroyTransferBuffer(int32_t id) { | 212 void CommandBufferDriver::DestroyTransferBuffer(int32_t id) { |
| 214 DCHECK(CalledOnValidThread()); | 213 DCHECK(CalledOnValidThread()); |
| 215 command_buffer_->DestroyTransferBuffer(id); | 214 command_buffer_->DestroyTransferBuffer(id); |
| 216 } | 215 } |
| 217 | 216 |
| 218 void CommandBufferDriver::CreateImage(int32_t id, | 217 void CommandBufferDriver::CreateImage(int32_t id, |
| 219 mojo::ScopedHandle memory_handle, | 218 mojo::ScopedHandle memory_handle, |
| 220 int32_t type, | 219 int32_t type, |
| 221 mojo::SizePtr size, | 220 const gfx::Size& size, |
| 222 int32_t format, | 221 int32_t format, |
| 223 int32_t internal_format) { | 222 int32_t internal_format) { |
| 224 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 225 if (!MakeCurrent()) | 224 if (!MakeCurrent()) |
| 226 return; | 225 return; |
| 227 | 226 |
| 228 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 227 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 229 if (image_manager->LookupImage(id)) { | 228 if (image_manager->LookupImage(id)) { |
| 230 LOG(ERROR) << "Image already exists with same ID."; | 229 LOG(ERROR) << "Image already exists with same ID."; |
| 231 return; | 230 return; |
| 232 } | 231 } |
| 233 | 232 |
| 234 gfx::BufferFormat gpu_format = static_cast<gfx::BufferFormat>(format); | 233 gfx::BufferFormat gpu_format = static_cast<gfx::BufferFormat>(format); |
| 235 if (!gpu::IsGpuMemoryBufferFormatSupported(gpu_format, | 234 if (!gpu::IsGpuMemoryBufferFormatSupported(gpu_format, |
| 236 decoder_->GetCapabilities())) { | 235 decoder_->GetCapabilities())) { |
| 237 LOG(ERROR) << "Format is not supported."; | 236 LOG(ERROR) << "Format is not supported."; |
| 238 return; | 237 return; |
| 239 } | 238 } |
| 240 | 239 |
| 241 gfx::Size gfx_size = size.To<gfx::Size>(); | 240 if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat(size, gpu_format)) { |
| 242 if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat(gfx_size, gpu_format)) { | |
| 243 LOG(ERROR) << "Invalid image size for format."; | 241 LOG(ERROR) << "Invalid image size for format."; |
| 244 return; | 242 return; |
| 245 } | 243 } |
| 246 | 244 |
| 247 if (!gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(internal_format, | 245 if (!gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(internal_format, |
| 248 gpu_format)) { | 246 gpu_format)) { |
| 249 LOG(ERROR) << "Incompatible image format."; | 247 LOG(ERROR) << "Incompatible image format."; |
| 250 return; | 248 return; |
| 251 } | 249 } |
| 252 | 250 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 263 return; | 261 return; |
| 264 } | 262 } |
| 265 | 263 |
| 266 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| 267 base::SharedMemoryHandle handle(platform_file, base::GetCurrentProcId()); | 265 base::SharedMemoryHandle handle(platform_file, base::GetCurrentProcId()); |
| 268 #else | 266 #else |
| 269 base::FileDescriptor handle(platform_file, false); | 267 base::FileDescriptor handle(platform_file, false); |
| 270 #endif | 268 #endif |
| 271 | 269 |
| 272 scoped_refptr<gl::GLImageSharedMemory> image = | 270 scoped_refptr<gl::GLImageSharedMemory> image = |
| 273 new gl::GLImageSharedMemory(gfx_size, internal_format); | 271 new gl::GLImageSharedMemory(size, internal_format); |
| 274 // TODO(jam): also need a mojo enum for this enum | 272 // TODO(jam): also need a mojo enum for this enum |
| 275 if (!image->Initialize( | 273 if (!image->Initialize( |
| 276 handle, gfx::GpuMemoryBufferId(id), gpu_format, 0, | 274 handle, gfx::GpuMemoryBufferId(id), gpu_format, 0, |
| 277 gfx::RowSizeForBufferFormat(gfx_size.width(), gpu_format, 0))) { | 275 gfx::RowSizeForBufferFormat(size.width(), gpu_format, 0))) { |
| 278 NOTREACHED(); | 276 NOTREACHED(); |
| 279 return; | 277 return; |
| 280 } | 278 } |
| 281 | 279 |
| 282 image_manager->AddImage(image.get(), id); | 280 image_manager->AddImage(image.get(), id); |
| 283 } | 281 } |
| 284 | 282 |
| 285 // TODO(rjkroege): It is conceivable that this code belongs in | 283 // TODO(rjkroege): It is conceivable that this code belongs in |
| 286 // ozone_gpu_memory_buffer.cc | 284 // ozone_gpu_memory_buffer.cc |
| 287 void CommandBufferDriver::CreateImageNativeOzone(int32_t id, | 285 void CommandBufferDriver::CreateImageNativeOzone(int32_t id, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 539 } |
| 542 | 540 |
| 543 void CommandBufferDriver::OnGpuCompletedSwapBuffers(gfx::SwapResult result) { | 541 void CommandBufferDriver::OnGpuCompletedSwapBuffers(gfx::SwapResult result) { |
| 544 DCHECK(CalledOnValidThread()); | 542 DCHECK(CalledOnValidThread()); |
| 545 if (client_) { | 543 if (client_) { |
| 546 client_->OnGpuCompletedSwapBuffers(result); | 544 client_->OnGpuCompletedSwapBuffers(result); |
| 547 } | 545 } |
| 548 } | 546 } |
| 549 | 547 |
| 550 } // namespace mus | 548 } // namespace mus |
| OLD | NEW |