| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop_proxy.h" | |
| 18 #include "base/sequence_checker.h" | 18 #include "base/sequence_checker.h" |
| 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/synchronization/condition_variable.h" | 20 #include "base/synchronization/condition_variable.h" |
| 21 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 23 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 22 #include "gpu/command_buffer/common/value_state.h" | 24 #include "gpu/command_buffer/common/value_state.h" |
| 23 #include "gpu/command_buffer/service/command_buffer_service.h" | 25 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 24 #include "gpu/command_buffer/service/context_group.h" | 26 #include "gpu/command_buffer/service/context_group.h" |
| 25 #include "gpu/command_buffer/service/gl_context_virtual.h" | 27 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 26 #include "gpu/command_buffer/service/gpu_scheduler.h" | 28 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 27 #include "gpu/command_buffer/service/gpu_switches.h" | 29 #include "gpu/command_buffer/service/gpu_switches.h" |
| 28 #include "gpu/command_buffer/service/image_factory.h" | 30 #include "gpu/command_buffer/service/image_factory.h" |
| 29 #include "gpu/command_buffer/service/image_manager.h" | 31 #include "gpu/command_buffer/service/image_manager.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 93 |
| 92 GpuInProcessThread::GpuInProcessThread() : base::Thread("GpuThread") { | 94 GpuInProcessThread::GpuInProcessThread() : base::Thread("GpuThread") { |
| 93 Start(); | 95 Start(); |
| 94 } | 96 } |
| 95 | 97 |
| 96 GpuInProcessThread::~GpuInProcessThread() { | 98 GpuInProcessThread::~GpuInProcessThread() { |
| 97 Stop(); | 99 Stop(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void GpuInProcessThread::ScheduleTask(const base::Closure& task) { | 102 void GpuInProcessThread::ScheduleTask(const base::Closure& task) { |
| 101 message_loop()->PostTask(FROM_HERE, task); | 103 task_runner()->PostTask(FROM_HERE, task); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void GpuInProcessThread::ScheduleIdleWork(const base::Closure& callback) { | 106 void GpuInProcessThread::ScheduleIdleWork(const base::Closure& callback) { |
| 105 // Match delay with GpuCommandBufferStub. | 107 // Match delay with GpuCommandBufferStub. |
| 106 message_loop()->PostDelayedTask( | 108 task_runner()->PostDelayedTask(FROM_HERE, callback, |
| 107 FROM_HERE, callback, base::TimeDelta::FromMilliseconds(2)); | 109 base::TimeDelta::FromMilliseconds(2)); |
| 108 } | 110 } |
| 109 | 111 |
| 110 scoped_refptr<gles2::ShaderTranslatorCache> | 112 scoped_refptr<gles2::ShaderTranslatorCache> |
| 111 GpuInProcessThread::shader_translator_cache() { | 113 GpuInProcessThread::shader_translator_cache() { |
| 112 if (!shader_translator_cache_.get()) | 114 if (!shader_translator_cache_.get()) |
| 113 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; | 115 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; |
| 114 return shader_translator_cache_; | 116 return shader_translator_cache_; |
| 115 } | 117 } |
| 116 | 118 |
| 117 struct GpuInProcessThreadHolder { | 119 struct GpuInProcessThreadHolder { |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 return last_state_.error; | 925 return last_state_.error; |
| 924 } | 926 } |
| 925 | 927 |
| 926 bool InProcessCommandBuffer::Initialize() { | 928 bool InProcessCommandBuffer::Initialize() { |
| 927 NOTREACHED(); | 929 NOTREACHED(); |
| 928 return false; | 930 return false; |
| 929 } | 931 } |
| 930 | 932 |
| 931 namespace { | 933 namespace { |
| 932 | 934 |
| 933 void PostCallback(const scoped_refptr<base::MessageLoopProxy>& loop, | 935 void PostCallback( |
| 934 const base::Closure& callback) { | 936 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 935 // The loop.get() check is to support using InProcessCommandBuffer on a thread | 937 const base::Closure& callback) { |
| 936 // without a message loop. | 938 // The task_runner.get() check is to support using InProcessCommandBuffer on |
| 937 if (loop.get() && !loop->BelongsToCurrentThread()) { | 939 // a thread without a message loop. |
| 938 loop->PostTask(FROM_HERE, callback); | 940 if (task_runner.get() && !task_runner->BelongsToCurrentThread()) { |
| 941 task_runner->PostTask(FROM_HERE, callback); |
| 939 } else { | 942 } else { |
| 940 callback.Run(); | 943 callback.Run(); |
| 941 } | 944 } |
| 942 } | 945 } |
| 943 | 946 |
| 944 void RunOnTargetThread(scoped_ptr<base::Closure> callback) { | 947 void RunOnTargetThread(scoped_ptr<base::Closure> callback) { |
| 945 DCHECK(callback.get()); | 948 DCHECK(callback.get()); |
| 946 callback->Run(); | 949 callback->Run(); |
| 947 } | 950 } |
| 948 | 951 |
| 949 } // anonymous namespace | 952 } // anonymous namespace |
| 950 | 953 |
| 951 base::Closure InProcessCommandBuffer::WrapCallback( | 954 base::Closure InProcessCommandBuffer::WrapCallback( |
| 952 const base::Closure& callback) { | 955 const base::Closure& callback) { |
| 953 // Make sure the callback gets deleted on the target thread by passing | 956 // Make sure the callback gets deleted on the target thread by passing |
| 954 // ownership. | 957 // ownership. |
| 955 scoped_ptr<base::Closure> scoped_callback(new base::Closure(callback)); | 958 scoped_ptr<base::Closure> scoped_callback(new base::Closure(callback)); |
| 956 base::Closure callback_on_client_thread = | 959 base::Closure callback_on_client_thread = |
| 957 base::Bind(&RunOnTargetThread, base::Passed(&scoped_callback)); | 960 base::Bind(&RunOnTargetThread, base::Passed(&scoped_callback)); |
| 958 base::Closure wrapped_callback = | 961 base::Closure wrapped_callback = |
| 959 base::Bind(&PostCallback, base::MessageLoopProxy::current(), | 962 base::Bind(&PostCallback, base::ThreadTaskRunnerHandle::IsSet() |
| 963 ? base::ThreadTaskRunnerHandle::Get() |
| 964 : nullptr, |
| 960 callback_on_client_thread); | 965 callback_on_client_thread); |
| 961 return wrapped_callback; | 966 return wrapped_callback; |
| 962 } | 967 } |
| 963 | 968 |
| 964 #if defined(OS_ANDROID) | 969 #if defined(OS_ANDROID) |
| 965 scoped_refptr<gfx::SurfaceTexture> | 970 scoped_refptr<gfx::SurfaceTexture> |
| 966 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { | 971 InProcessCommandBuffer::GetSurfaceTexture(uint32 stream_id) { |
| 967 DCHECK(stream_texture_manager_); | 972 DCHECK(stream_texture_manager_); |
| 968 return stream_texture_manager_->GetSurfaceTexture(stream_id); | 973 return stream_texture_manager_->GetSurfaceTexture(stream_id); |
| 969 } | 974 } |
| 970 #endif | 975 #endif |
| 971 | 976 |
| 972 } // namespace gpu | 977 } // namespace gpu |
| OLD | NEW |