| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 28 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 29 #include "mojo/converters/geometry/geometry_type_converters.h" | 29 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 30 #include "mojo/platform_handle/platform_handle_functions.h" | 30 #include "mojo/platform_handle/platform_handle_functions.h" |
| 31 #include "ui/gfx/buffer_format_util.h" | 31 #include "ui/gfx/buffer_format_util.h" |
| 32 #include "ui/gfx/gpu_memory_buffer.h" | 32 #include "ui/gfx/gpu_memory_buffer.h" |
| 33 #include "ui/gfx/vsync_provider.h" | 33 #include "ui/gfx/vsync_provider.h" |
| 34 #include "ui/gl/gl_context.h" | 34 #include "ui/gl/gl_context.h" |
| 35 #include "ui/gl/gl_image_shared_memory.h" | 35 #include "ui/gl/gl_image_shared_memory.h" |
| 36 #include "ui/gl/gl_surface.h" | 36 #include "ui/gl/gl_surface.h" |
| 37 | 37 |
| 38 #if defined(USE_OZONE) |
| 39 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 40 #endif |
| 41 |
| 38 namespace mus { | 42 namespace mus { |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 // The first time polling a fence, delay some extra time to allow other | 46 // The first time polling a fence, delay some extra time to allow other |
| 43 // stubs to process some work, or else the timing of the fences could | 47 // stubs to process some work, or else the timing of the fences could |
| 44 // allow a pattern of alternating fast and slow frames to occur. | 48 // allow a pattern of alternating fast and slow frames to occur. |
| 45 const int64_t kHandleMoreWorkPeriodMs = 2; | 49 const int64_t kHandleMoreWorkPeriodMs = 2; |
| 46 const int64_t kHandleMoreWorkPeriodBusyMs = 1; | 50 const int64_t kHandleMoreWorkPeriodBusyMs = 1; |
| 47 | 51 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 77 mojo::ScopedSharedBufferHandle shared_state, | 81 mojo::ScopedSharedBufferHandle shared_state, |
| 78 mojo::Array<int32_t> attribs) { | 82 mojo::Array<int32_t> attribs) { |
| 79 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 80 gpu::gles2::ContextCreationAttribHelper attrib_helper; | 84 gpu::gles2::ContextCreationAttribHelper attrib_helper; |
| 81 if (!attrib_helper.Parse(attribs.storage())) | 85 if (!attrib_helper.Parse(attribs.storage())) |
| 82 return false; | 86 return false; |
| 83 | 87 |
| 84 const bool offscreen = widget_ == gfx::kNullAcceleratedWidget; | 88 const bool offscreen = widget_ == gfx::kNullAcceleratedWidget; |
| 85 static scoped_refptr<gfx::GLSurface> underlying_surface; | 89 static scoped_refptr<gfx::GLSurface> underlying_surface; |
| 86 if (offscreen) { | 90 if (offscreen) { |
| 87 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); | 91 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(0, 0)); |
| 88 } else { | 92 } else { |
| 93 #if defined(USE_OZONE) |
| 94 scoped_refptr<gfx::GLSurface> underlying_surface = |
| 95 gfx::GLSurface::CreateSurfacelessViewGLSurface(widget_); |
| 96 if (!underlying_surface) |
| 97 underlying_surface = gfx::GLSurface::CreateViewGLSurface(widget_); |
| 98 #else |
| 99 scoped_refptr<gfx::GLSurface> underlying_surface = |
| 100 gfx::GLSurface::CreateViewGLSurface(widget_); |
| 101 #endif |
| 89 scoped_refptr<GLSurfaceAdapterMus> surface_adapter = | 102 scoped_refptr<GLSurfaceAdapterMus> surface_adapter = |
| 90 new GLSurfaceAdapterMus(gfx::GLSurface::CreateViewGLSurface(widget_)); | 103 new GLSurfaceAdapterMus(underlying_surface); |
| 91 surface_adapter->SetGpuCompletedSwapBuffersCallback( | 104 surface_adapter->SetGpuCompletedSwapBuffersCallback( |
| 92 base::Bind(&CommandBufferDriver::OnGpuCompletedSwapBuffers, | 105 base::Bind(&CommandBufferDriver::OnGpuCompletedSwapBuffers, |
| 93 weak_factory_.GetWeakPtr())); | 106 weak_factory_.GetWeakPtr())); |
| 94 surface_ = surface_adapter; | 107 surface_ = surface_adapter; |
| 95 | 108 |
| 96 gfx::VSyncProvider* vsync_provider = | 109 gfx::VSyncProvider* vsync_provider = |
| 97 surface_ ? surface_->GetVSyncProvider() : nullptr; | 110 surface_ ? surface_->GetVSyncProvider() : nullptr; |
| 98 if (vsync_provider) { | 111 if (vsync_provider) { |
| 99 vsync_provider->GetVSyncParameters( | 112 vsync_provider->GetVSyncParameters( |
| 100 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, | 113 base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 if (!image->Initialize( | 278 if (!image->Initialize( |
| 266 handle, gfx::GpuMemoryBufferId(id), gpu_format, 0, | 279 handle, gfx::GpuMemoryBufferId(id), gpu_format, 0, |
| 267 gfx::RowSizeForBufferFormat(gfx_size.width(), gpu_format, 0))) { | 280 gfx::RowSizeForBufferFormat(gfx_size.width(), gpu_format, 0))) { |
| 268 NOTREACHED(); | 281 NOTREACHED(); |
| 269 return; | 282 return; |
| 270 } | 283 } |
| 271 | 284 |
| 272 image_manager->AddImage(image.get(), id); | 285 image_manager->AddImage(image.get(), id); |
| 273 } | 286 } |
| 274 | 287 |
| 288 // TODO(rjkroege): It is conceivable that this code belongs in |
| 289 // ozone_gpu_memory_buffer.cc |
| 290 void CommandBufferDriver::CreateImageNativeOzone(int32_t id, |
| 291 int32_t type, |
| 292 gfx::Size size, |
| 293 gfx::BufferFormat format, |
| 294 uint32_t internal_format, |
| 295 ui::NativePixmap* pixmap) { |
| 296 #if defined(USE_OZONE) |
| 297 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 298 if (image_manager->LookupImage(id)) { |
| 299 LOG(ERROR) << "Image already exists with same ID."; |
| 300 return; |
| 301 } |
| 302 |
| 303 scoped_refptr<gfx::GLImageOzoneNativePixmap> image = |
| 304 new gfx::GLImageOzoneNativePixmap(size, internal_format); |
| 305 if (!image->Initialize(pixmap, format)) { |
| 306 NOTREACHED(); |
| 307 return; |
| 308 } |
| 309 |
| 310 image_manager->AddImage(image.get(), id); |
| 311 #endif |
| 312 } |
| 313 |
| 275 void CommandBufferDriver::DestroyImage(int32_t id) { | 314 void CommandBufferDriver::DestroyImage(int32_t id) { |
| 276 DCHECK(CalledOnValidThread()); | 315 DCHECK(CalledOnValidThread()); |
| 277 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 316 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
| 278 if (!image_manager->LookupImage(id)) { | 317 if (!image_manager->LookupImage(id)) { |
| 279 LOG(ERROR) << "Image with ID doesn't exist."; | 318 LOG(ERROR) << "Image with ID doesn't exist."; |
| 280 return; | 319 return; |
| 281 } | 320 } |
| 282 if (!MakeCurrent()) | 321 if (!MakeCurrent()) |
| 283 return; | 322 return; |
| 284 image_manager->RemoveImage(id); | 323 image_manager->RemoveImage(id); |
| 285 } | 324 } |
| 286 | 325 |
| 287 bool CommandBufferDriver::IsScheduled() const { | 326 bool CommandBufferDriver::IsScheduled() const { |
| 288 DCHECK(CalledOnValidThread()); | 327 DCHECK(CalledOnValidThread()); |
| 328 DCHECK(executor_); |
| 289 return executor_->scheduled(); | 329 return executor_->scheduled(); |
| 290 } | 330 } |
| 291 | 331 |
| 292 bool CommandBufferDriver::HasUnprocessedCommands() const { | 332 bool CommandBufferDriver::HasUnprocessedCommands() const { |
| 293 DCHECK(CalledOnValidThread()); | 333 DCHECK(CalledOnValidThread()); |
| 294 if (command_buffer_) { | 334 if (command_buffer_) { |
| 295 gpu::CommandBuffer::State state = GetLastState(); | 335 gpu::CommandBuffer::State state = GetLastState(); |
| 296 return command_buffer_->GetPutOffset() != state.get_offset && | 336 return command_buffer_->GetPutOffset() != state.get_offset && |
| 297 !gpu::error::IsError(state.error); | 337 !gpu::error::IsError(state.error); |
| 298 } | 338 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 544 } |
| 505 | 545 |
| 506 void CommandBufferDriver::OnGpuCompletedSwapBuffers(gfx::SwapResult result) { | 546 void CommandBufferDriver::OnGpuCompletedSwapBuffers(gfx::SwapResult result) { |
| 507 DCHECK(CalledOnValidThread()); | 547 DCHECK(CalledOnValidThread()); |
| 508 if (client_) { | 548 if (client_) { |
| 509 client_->OnGpuCompletedSwapBuffers(result); | 549 client_->OnGpuCompletedSwapBuffers(result); |
| 510 } | 550 } |
| 511 } | 551 } |
| 512 | 552 |
| 513 } // namespace mus | 553 } // namespace mus |
| OLD | NEW |