OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_UI_GLES2_GPU_STATE_H_ |
| 6 #define SERVICES_UI_GLES2_GPU_STATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread.h" |
| 13 #include "gpu/command_buffer/service/gpu_preferences.h" |
| 14 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
| 15 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 16 #include "gpu/config/gpu_driver_bug_workarounds.h" |
| 17 #include "gpu/config/gpu_info.h" |
| 18 #include "services/ui/gles2/command_buffer_driver_manager.h" |
| 19 #include "services/ui/gles2/command_buffer_task_runner.h" |
| 20 #include "ui/gl/gl_share_group.h" |
| 21 |
| 22 namespace { |
| 23 class WaitableEvent; |
| 24 } |
| 25 |
| 26 namespace ui { |
| 27 |
| 28 // We need to share these across all CommandBuffer instances so that contexts |
| 29 // they create can share resources with each other via mailboxes. |
| 30 class GpuState : public base::RefCountedThreadSafe<GpuState> { |
| 31 public: |
| 32 GpuState(); |
| 33 |
| 34 // We run the CommandBufferImpl on the control_task_runner, which forwards |
| 35 // most method class to the CommandBufferDriver, which runs on the "driver", |
| 36 // thread (i.e., the thread on which GpuImpl instances are created). |
| 37 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner() { |
| 38 return control_thread_task_runner_; |
| 39 } |
| 40 |
| 41 void StopThreads(); |
| 42 |
| 43 const gpu::GpuPreferences& gpu_preferences() const { |
| 44 return gpu_preferences_; |
| 45 } |
| 46 |
| 47 const gpu::GpuDriverBugWorkarounds& gpu_driver_bug_workarounds() const { |
| 48 return gpu_driver_bug_workarounds_; |
| 49 } |
| 50 |
| 51 CommandBufferTaskRunner* command_buffer_task_runner() const { |
| 52 return command_buffer_task_runner_.get(); |
| 53 } |
| 54 |
| 55 CommandBufferDriverManager* driver_manager() const { |
| 56 return driver_manager_.get(); |
| 57 } |
| 58 |
| 59 // These objects are intended to be used on the "driver" thread (i.e., the |
| 60 // thread on which GpuImpl instances are created). |
| 61 gl::GLShareGroup* share_group() const { return share_group_.get(); } |
| 62 gpu::gles2::MailboxManager* mailbox_manager() const { |
| 63 return mailbox_manager_.get(); |
| 64 } |
| 65 gpu::SyncPointManager* sync_point_manager() const { |
| 66 return sync_point_manager_.get(); |
| 67 } |
| 68 |
| 69 const gpu::GPUInfo& gpu_info() const { |
| 70 return gpu_info_; |
| 71 } |
| 72 |
| 73 bool HardwareRenderingAvailable() const { |
| 74 return hardware_rendering_available_; |
| 75 } |
| 76 |
| 77 private: |
| 78 friend class base::RefCountedThreadSafe<GpuState>; |
| 79 ~GpuState(); |
| 80 |
| 81 void InitializeOnGpuThread(base::WaitableEvent* event); |
| 82 |
| 83 void DestroyGpuSpecificStateOnGpuThread(); |
| 84 |
| 85 // |gpu_thread_| is for executing OS GL calls. |
| 86 base::Thread gpu_thread_; |
| 87 // |control_thread_| is for mojo incoming calls of CommandBufferImpl. |
| 88 base::Thread control_thread_; |
| 89 |
| 90 // Same as control_thread_->task_runner(). The TaskRunner is cached as it may |
| 91 // be needed during shutdown. |
| 92 scoped_refptr<base::SingleThreadTaskRunner> control_thread_task_runner_; |
| 93 |
| 94 gpu::GpuPreferences gpu_preferences_; |
| 95 const gpu::GpuDriverBugWorkarounds gpu_driver_bug_workarounds_; |
| 96 scoped_refptr<CommandBufferTaskRunner> command_buffer_task_runner_; |
| 97 std::unique_ptr<CommandBufferDriverManager> driver_manager_; |
| 98 std::unique_ptr<gpu::SyncPointManager> sync_point_manager_; |
| 99 scoped_refptr<gl::GLShareGroup> share_group_; |
| 100 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 101 gpu::GPUInfo gpu_info_; |
| 102 bool hardware_rendering_available_; |
| 103 }; |
| 104 |
| 105 } // namespace ui |
| 106 |
| 107 #endif // SERVICES_UI_GLES2_GPU_STATE_H_ |
OLD | NEW |