| 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 "gpu/command_buffer/service/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
| 37 #include "ui/gl/gl_context.h" | 37 #include "ui/gl/gl_context.h" |
| 38 #include "ui/gl/gl_image.h" | 38 #include "ui/gl/gl_image.h" |
| 39 #include "ui/gl/gl_share_group.h" | 39 #include "ui/gl/gl_share_group.h" |
| 40 | 40 |
| 41 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" | 42 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h
" |
| 43 #include "ui/gl/android/surface_texture.h" | 43 #include "ui/gl/android/surface_texture.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #if defined(OS_WIN) |
| 47 #include <windows.h> |
| 48 #include "base/process/process_handle.h" |
| 49 #endif |
| 50 |
| 46 namespace gpu { | 51 namespace gpu { |
| 47 | 52 |
| 48 namespace { | 53 namespace { |
| 49 | 54 |
| 50 template <typename T> | 55 template <typename T> |
| 51 static void RunTaskWithResult(base::Callback<T(void)> task, | 56 static void RunTaskWithResult(base::Callback<T(void)> task, |
| 52 T* result, | 57 T* result, |
| 53 base::WaitableEvent* completion) { | 58 base::WaitableEvent* completion) { |
| 54 *result = task.Run(); | 59 *result = task.Run(); |
| 55 completion->Signal(); | 60 completion->Signal(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { | 178 void SyncPointManager::WaitSyncPoint(uint32 sync_point) { |
| 174 base::AutoLock lock(lock_); | 179 base::AutoLock lock(lock_); |
| 175 while (pending_sync_points_.count(sync_point)) { | 180 while (pending_sync_points_.count(sync_point)) { |
| 176 cond_var_.Wait(); | 181 cond_var_.Wait(); |
| 177 } | 182 } |
| 178 } | 183 } |
| 179 | 184 |
| 180 base::LazyInstance<SyncPointManager> g_sync_point_manager = | 185 base::LazyInstance<SyncPointManager> g_sync_point_manager = |
| 181 LAZY_INSTANCE_INITIALIZER; | 186 LAZY_INSTANCE_INITIALIZER; |
| 182 | 187 |
| 188 base::SharedMemoryHandle ShareToGpuThread( |
| 189 base::SharedMemoryHandle source_handle) { |
| 190 #if defined(OS_WIN) |
| 191 // Windows needs to explicitly duplicate the handle to current process. |
| 192 base::SharedMemoryHandle target_handle; |
| 193 if (!DuplicateHandle(GetCurrentProcess(), |
| 194 source_handle, |
| 195 GetCurrentProcess(), |
| 196 &target_handle, |
| 197 FILE_GENERIC_READ | FILE_GENERIC_WRITE, |
| 198 FALSE, |
| 199 0)) { |
| 200 return base::SharedMemory::NULLHandle(); |
| 201 } |
| 202 |
| 203 return target_handle; |
| 204 #else |
| 205 int duped_handle = HANDLE_EINTR(dup(source_handle.fd)); |
| 206 if (duped_handle < 0) |
| 207 return base::SharedMemory::NULLHandle(); |
| 208 |
| 209 return base::FileDescriptor(duped_handle, true); |
| 210 #endif |
| 211 } |
| 212 |
| 213 gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuThread( |
| 214 const gfx::GpuMemoryBufferHandle& source_handle, |
| 215 bool* requires_sync_point) { |
| 216 switch (source_handle.type) { |
| 217 case gfx::SHARED_MEMORY_BUFFER: { |
| 218 gfx::GpuMemoryBufferHandle handle; |
| 219 handle.type = gfx::SHARED_MEMORY_BUFFER; |
| 220 handle.handle = ShareToGpuThread(source_handle.handle); |
| 221 *requires_sync_point = false; |
| 222 return handle; |
| 223 } |
| 224 case gfx::IO_SURFACE_BUFFER: |
| 225 case gfx::SURFACE_TEXTURE_BUFFER: |
| 226 case gfx::OZONE_NATIVE_BUFFER: |
| 227 *requires_sync_point = true; |
| 228 return source_handle; |
| 229 default: |
| 230 NOTREACHED(); |
| 231 return gfx::GpuMemoryBufferHandle(); |
| 232 } |
| 233 } |
| 234 |
| 183 } // anonyous namespace | 235 } // anonyous namespace |
| 184 | 236 |
| 185 InProcessCommandBuffer::Service::Service() {} | 237 InProcessCommandBuffer::Service::Service() {} |
| 186 | 238 |
| 187 InProcessCommandBuffer::Service::~Service() {} | 239 InProcessCommandBuffer::Service::~Service() {} |
| 188 | 240 |
| 189 scoped_refptr<gles2::MailboxManager> | 241 scoped_refptr<gles2::MailboxManager> |
| 190 InProcessCommandBuffer::Service::mailbox_manager() { | 242 InProcessCommandBuffer::Service::mailbox_manager() { |
| 191 if (!mailbox_manager_.get()) { | 243 if (!mailbox_manager_.get()) { |
| 192 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 244 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 687 |
| 636 DCHECK(gpu_memory_buffer_manager_); | 688 DCHECK(gpu_memory_buffer_manager_); |
| 637 gfx::GpuMemoryBuffer* gpu_memory_buffer = | 689 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| 638 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffer); | 690 gpu_memory_buffer_manager_->GpuMemoryBufferFromClientBuffer(buffer); |
| 639 DCHECK(gpu_memory_buffer); | 691 DCHECK(gpu_memory_buffer); |
| 640 | 692 |
| 641 int32 new_id = next_image_id_.GetNext(); | 693 int32 new_id = next_image_id_.GetNext(); |
| 642 | 694 |
| 643 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 695 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| 644 internalformat, gpu_memory_buffer->GetFormat())); | 696 internalformat, gpu_memory_buffer->GetFormat())); |
| 697 |
| 698 // This handle is owned by the GPU thread and must be passed to it or it |
| 699 // will leak. In otherwords, do not early out on error between here and the |
| 700 // queuing of the CreateImage task below. |
| 701 bool requires_sync_point = false; |
| 702 gfx::GpuMemoryBufferHandle handle = |
| 703 ShareGpuMemoryBufferToGpuThread(gpu_memory_buffer->GetHandle(), |
| 704 &requires_sync_point); |
| 705 |
| 645 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, | 706 QueueTask(base::Bind(&InProcessCommandBuffer::CreateImageOnGpuThread, |
| 646 base::Unretained(this), | 707 base::Unretained(this), |
| 647 new_id, | 708 new_id, |
| 648 gpu_memory_buffer->GetHandle(), | 709 handle, |
| 649 gfx::Size(width, height), | 710 gfx::Size(width, height), |
| 650 gpu_memory_buffer->GetFormat(), | 711 gpu_memory_buffer->GetFormat(), |
| 651 internalformat)); | 712 internalformat)); |
| 713 |
| 714 if (requires_sync_point) { |
| 715 gpu_memory_buffer_manager_->SetDestructionSyncPoint(gpu_memory_buffer, |
| 716 InsertSyncPoint()); |
| 717 } |
| 718 |
| 652 return new_id; | 719 return new_id; |
| 653 } | 720 } |
| 654 | 721 |
| 655 void InProcessCommandBuffer::CreateImageOnGpuThread( | 722 void InProcessCommandBuffer::CreateImageOnGpuThread( |
| 656 int32 id, | 723 int32 id, |
| 657 const gfx::GpuMemoryBufferHandle& handle, | 724 const gfx::GpuMemoryBufferHandle& handle, |
| 658 const gfx::Size& size, | 725 const gfx::Size& size, |
| 659 gfx::GpuMemoryBuffer::Format format, | 726 gfx::GpuMemoryBuffer::Format format, |
| 660 uint32 internalformat) { | 727 uint32 internalformat) { |
| 661 if (!decoder_) | 728 if (!decoder_) |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 945 |
| 879 #if defined(OS_ANDROID) | 946 #if defined(OS_ANDROID) |
| 880 scoped_refptr<gfx::SurfaceTexture> | 947 scoped_refptr<gfx::SurfaceTexture> |
| 881 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 948 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
| 882 DCHECK(stream_texture_manager_); | 949 DCHECK(stream_texture_manager_); |
| 883 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 950 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
| 884 } | 951 } |
| 885 #endif | 952 #endif |
| 886 | 953 |
| 887 } // namespace gpu | 954 } // namespace gpu |
| OLD | NEW |