Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / webkit / common / gpu / webgraphicscontext3d_in_process_command_buffer_impl.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 WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_
6 #define WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_
7
8 #include <vector>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gpu/command_buffer/client/gl_in_process_context.h"
13 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "webkit/common/gpu/webgraphicscontext3d_impl.h"
17 #include "webkit/common/gpu/webkit_gpu_export.h"
18
19 namespace gpu {
20 class ContextSupport;
21
22 namespace gles2 {
23 class GLES2Interface;
24 class GLES2Implementation;
25 struct ContextCreationAttribHelper;
26 }
27 }
28
29 namespace gpu {
30 class GLInProcessContext;
31 }
32
33 namespace webkit {
34 namespace gpu {
35
36 class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
37     : public WebGraphicsContext3DImpl {
38  public:
39   static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
40       CreateViewContext(
41           const blink::WebGraphicsContext3D::Attributes& attributes,
42           bool lose_context_when_out_of_memory,
43           gfx::AcceleratedWidget window);
44
45   static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
46       CreateOffscreenContext(
47           const blink::WebGraphicsContext3D::Attributes& attributes,
48           bool lose_context_when_out_of_memory);
49
50   static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
51       WrapContext(
52           scoped_ptr< ::gpu::GLInProcessContext> context,
53           const blink::WebGraphicsContext3D::Attributes& attributes);
54
55   virtual ~WebGraphicsContext3DInProcessCommandBufferImpl();
56
57   //----------------------------------------------------------------------
58   // WebGraphicsContext3D methods
59   virtual bool makeContextCurrent();
60
61   virtual bool isContextLost();
62
63   virtual WGC3Denum getGraphicsResetStatusARB();
64
65   ::gpu::ContextSupport* GetContextSupport();
66
67   ::gpu::gles2::GLES2Implementation* GetImplementation() {
68     return real_gl_;
69   }
70
71  private:
72   WebGraphicsContext3DInProcessCommandBufferImpl(
73       scoped_ptr< ::gpu::GLInProcessContext> context,
74       const blink::WebGraphicsContext3D::Attributes& attributes,
75       bool lose_context_when_out_of_memory,
76       bool is_offscreen,
77       gfx::AcceleratedWidget window);
78
79   void OnContextLost();
80
81   bool MaybeInitializeGL();
82
83   // Used to try to find bugs in code that calls gl directly through the gl api
84   // instead of going through WebGraphicsContext3D.
85   void ClearContext();
86
87   ::gpu::gles2::ContextCreationAttribHelper attribs_;
88   bool share_resources_;
89   bool webgl_context_;
90
91   bool is_offscreen_;
92   // Only used when not offscreen.
93   gfx::AcceleratedWidget window_;
94
95   // The context we use for OpenGL rendering.
96   scoped_ptr< ::gpu::GLInProcessContext> context_;
97   // The GLES2Implementation we use for OpenGL rendering.
98   ::gpu::gles2::GLES2Implementation* real_gl_;
99 };
100
101 }  // namespace gpu
102 }  // namespace webkit
103
104 #endif  // WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_