| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ |
| 6 | #define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ |
| 7 | |
| 8 | #include "base/containers/scoped_ptr_hash_map.h" |
| 9 | #include "base/memory/ref_counted.h" |
| 10 | #include "base/memory/scoped_ptr.h" |
| 11 | #include "gpu/command_buffer/client/gpu_control.h" |
| 12 | #include "gpu/command_buffer/service/feature_info.h" |
| Nick Bray | 27a3f6e | 2015-01-08 16:39:35 -0800 | [diff] [blame] | 13 | #include "ui/gfx/geometry/size.h" |
| James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 14 | #include "ui/gfx/gpu_memory_buffer.h" |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 15 | |
| Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 16 | namespace base { |
| 17 | class CommandLine; |
| 18 | } |
| 19 | |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 20 | namespace gfx { |
| 21 | |
| 22 | class GLContext; |
| 23 | class GLShareGroup; |
| 24 | class GLSurface; |
| 25 | |
| 26 | } |
| 27 | |
| 28 | namespace gpu { |
| 29 | |
| 30 | class CommandBufferService; |
| 31 | class GpuScheduler; |
| 32 | class TransferBuffer; |
| 33 | |
| 34 | namespace gles2 { |
| 35 | |
| 36 | class ContextGroup; |
| 37 | class MailboxManager; |
| 38 | class GLES2Decoder; |
| 39 | class GLES2CmdHelper; |
| 40 | class GLES2Implementation; |
| 41 | class ImageManager; |
| 42 | class ShareGroup; |
| 43 | |
| 44 | }; |
| 45 | |
| 46 | class GLManager : private GpuControl { |
| 47 | public: |
| 48 | struct Options { |
| 49 | Options(); |
| 50 | // The size of the backbuffer. |
| 51 | gfx::Size size; |
| 52 | // If not null will share resources with this context. |
| 53 | GLManager* share_group_manager; |
| 54 | // If not null will share a mailbox manager with this context. |
| 55 | GLManager* share_mailbox_manager; |
| 56 | // If not null will create a virtual manager based on this context. |
| 57 | GLManager* virtual_manager; |
| 58 | // Whether or not glBindXXX generates a resource. |
| 59 | bool bind_generates_resource; |
| 60 | // Whether or not the context is auto-lost when GL_OUT_OF_MEMORY occurs. |
| 61 | bool lose_context_when_out_of_memory; |
| 62 | // Whether or not it's ok to lose the context. |
| 63 | bool context_lost_allowed; |
| 64 | }; |
| 65 | GLManager(); |
| James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 66 | ~GLManager() override; |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 67 | |
| James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 68 | static scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer( |
| 69 | const gfx::Size& size, |
| 70 | gfx::GpuMemoryBuffer::Format format); |
| 71 | |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 72 | void Initialize(const Options& options); |
| Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 73 | void InitializeWithCommandLine(const Options& options, |
| 74 | base::CommandLine* command_line); |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 75 | void Destroy(); |
| 76 | |
| 77 | void MakeCurrent(); |
| 78 | |
| 79 | void SetSurface(gfx::GLSurface* surface); |
| 80 | |
| 81 | gles2::GLES2Decoder* decoder() const { |
| 82 | return decoder_.get(); |
| 83 | } |
| 84 | |
| 85 | gles2::MailboxManager* mailbox_manager() const { |
| 86 | return mailbox_manager_.get(); |
| 87 | } |
| 88 | |
| 89 | gfx::GLShareGroup* share_group() const { |
| 90 | return share_group_.get(); |
| 91 | } |
| 92 | |
| 93 | gles2::GLES2Implementation* gles2_implementation() const { |
| 94 | return gles2_implementation_.get(); |
| 95 | } |
| 96 | |
| 97 | gfx::GLContext* context() { |
| 98 | return context_.get(); |
| 99 | } |
| 100 | |
| 101 | const gpu::gles2::FeatureInfo::Workarounds& workarounds() const; |
| 102 | |
| 103 | // GpuControl implementation. |
| James Robinson | e1b30cf | 2014-10-21 12:25:40 -0700 | [diff] [blame] | 104 | Capabilities GetCapabilities() override; |
| 105 | int32 CreateImage(ClientBuffer buffer, |
| 106 | size_t width, |
| 107 | size_t height, |
| 108 | unsigned internalformat) override; |
| 109 | void DestroyImage(int32 id) override; |
| 110 | int32 CreateGpuMemoryBufferImage(size_t width, |
| 111 | size_t height, |
| 112 | unsigned internalformat, |
| 113 | unsigned usage) override; |
| 114 | uint32 InsertSyncPoint() override; |
| 115 | uint32 InsertFutureSyncPoint() override; |
| 116 | void RetireSyncPoint(uint32 sync_point) override; |
| 117 | void SignalSyncPoint(uint32 sync_point, |
| 118 | const base::Closure& callback) override; |
| 119 | void SignalQuery(uint32 query, const base::Closure& callback) override; |
| 120 | void SetSurfaceVisible(bool visible) override; |
| 121 | uint32 CreateStreamTexture(uint32 texture_id) override; |
| Etienne Membrives | 386015a | 2015-02-19 17:27:12 +0100 | [diff] [blame] | 122 | void SetLock(base::Lock*) override; |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 123 | |
| 124 | private: |
| 125 | void PumpCommands(); |
| 126 | bool GetBufferChanged(int32 transfer_buffer_id); |
| 127 | void SetupBaseContext(); |
| 128 | |
| 129 | scoped_refptr<gles2::MailboxManager> mailbox_manager_; |
| 130 | scoped_refptr<gfx::GLShareGroup> share_group_; |
| 131 | scoped_ptr<CommandBufferService> command_buffer_; |
| 132 | scoped_ptr<gles2::GLES2Decoder> decoder_; |
| 133 | scoped_ptr<GpuScheduler> gpu_scheduler_; |
| 134 | scoped_refptr<gfx::GLSurface> surface_; |
| 135 | scoped_refptr<gfx::GLContext> context_; |
| 136 | scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
| 137 | scoped_ptr<TransferBuffer> transfer_buffer_; |
| 138 | scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; |
| 139 | bool context_lost_allowed_; |
| 140 | |
| James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 141 | // Used on Android to virtualize GL for all contexts. |
| 142 | static int use_count_; |
| 143 | static scoped_refptr<gfx::GLShareGroup>* base_share_group_; |
| 144 | static scoped_refptr<gfx::GLSurface>* base_surface_; |
| 145 | static scoped_refptr<gfx::GLContext>* base_context_; |
| 146 | }; |
| 147 | |
| 148 | } // namespace gpu |
| 149 | |
| 150 | #endif // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_ |