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