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.
5 #ifndef GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
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"
13 #include "ui/gfx/size.h"
25 class CommandBufferService
;
35 class GLES2Implementation
;
41 class GLManager
: private GpuControl
{
45 // The size of the backbuffer.
47 // If not null will share resources with this context.
48 GLManager
* share_group_manager
;
49 // If not null will share a mailbox manager with this context.
50 GLManager
* share_mailbox_manager
;
51 // If not null will create a virtual manager based on this context.
52 GLManager
* virtual_manager
;
53 // Whether or not glBindXXX generates a resource.
54 bool bind_generates_resource
;
55 // Whether or not the context is auto-lost when GL_OUT_OF_MEMORY occurs.
56 bool lose_context_when_out_of_memory
;
57 // Whether or not it's ok to lose the context.
58 bool context_lost_allowed
;
63 void Initialize(const Options
& options
);
68 void SetSurface(gfx::GLSurface
* surface
);
70 gles2::GLES2Decoder
* decoder() const {
71 return decoder_
.get();
74 gles2::MailboxManager
* mailbox_manager() const {
75 return mailbox_manager_
.get();
78 gfx::GLShareGroup
* share_group() const {
79 return share_group_
.get();
82 gles2::GLES2Implementation
* gles2_implementation() const {
83 return gles2_implementation_
.get();
86 gfx::GLContext
* context() {
87 return context_
.get();
90 const gpu::gles2::FeatureInfo::Workarounds
& workarounds() const;
92 // GpuControl implementation.
93 virtual Capabilities
GetCapabilities() OVERRIDE
;
94 virtual gfx::GpuMemoryBuffer
* CreateGpuMemoryBuffer(size_t width
,
96 unsigned internalformat
,
99 virtual void DestroyGpuMemoryBuffer(int32 id
) OVERRIDE
;
100 virtual uint32
InsertSyncPoint() OVERRIDE
;
101 virtual uint32
InsertFutureSyncPoint() OVERRIDE
;
102 virtual void RetireSyncPoint(uint32 sync_point
) OVERRIDE
;
103 virtual void SignalSyncPoint(uint32 sync_point
,
104 const base::Closure
& callback
) OVERRIDE
;
105 virtual void SignalQuery(uint32 query
,
106 const base::Closure
& callback
) OVERRIDE
;
107 virtual void SetSurfaceVisible(bool visible
) OVERRIDE
;
108 virtual void Echo(const base::Closure
& callback
) OVERRIDE
;
109 virtual uint32
CreateStreamTexture(uint32 texture_id
) OVERRIDE
;
113 bool GetBufferChanged(int32 transfer_buffer_id
);
114 void SetupBaseContext();
116 scoped_refptr
<gles2::MailboxManager
> mailbox_manager_
;
117 scoped_refptr
<gfx::GLShareGroup
> share_group_
;
118 scoped_ptr
<CommandBufferService
> command_buffer_
;
119 scoped_ptr
<gles2::GLES2Decoder
> decoder_
;
120 scoped_ptr
<GpuScheduler
> gpu_scheduler_
;
121 scoped_refptr
<gfx::GLSurface
> surface_
;
122 scoped_refptr
<gfx::GLContext
> context_
;
123 scoped_ptr
<gles2::GLES2CmdHelper
> gles2_helper_
;
124 scoped_ptr
<TransferBuffer
> transfer_buffer_
;
125 scoped_ptr
<gles2::GLES2Implementation
> gles2_implementation_
;
126 bool context_lost_allowed_
;
128 // Client GpuControl implementation.
129 base::ScopedPtrHashMap
<int32
, gfx::GpuMemoryBuffer
> gpu_memory_buffers_
;
131 // Used on Android to virtualize GL for all contexts.
132 static int use_count_
;
133 static scoped_refptr
<gfx::GLShareGroup
>* base_share_group_
;
134 static scoped_refptr
<gfx::GLSurface
>* base_surface_
;
135 static scoped_refptr
<gfx::GLContext
>* base_context_
;
140 #endif // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_