• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }
26 }
27 
28 namespace gpu {
29 class GLInProcessContext;
30 struct GLInProcessContextAttribs;
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   // Convert WebGL context creation attributes into GLInProcessContext / EGL
58   // size requests.
59   static void ConvertAttributes(
60       const blink::WebGraphicsContext3D::Attributes& attributes,
61       ::gpu::GLInProcessContextAttribs* output_attribs);
62 
63   //----------------------------------------------------------------------
64   // WebGraphicsContext3D methods
65   virtual bool makeContextCurrent();
66 
67   virtual bool isContextLost();
68 
69   virtual WGC3Denum getGraphicsResetStatusARB();
70 
71   ::gpu::ContextSupport* GetContextSupport();
72 
GetImplementation()73   ::gpu::gles2::GLES2Implementation* GetImplementation() {
74     return real_gl_;
75   }
76 
77  private:
78   WebGraphicsContext3DInProcessCommandBufferImpl(
79       scoped_ptr< ::gpu::GLInProcessContext> context,
80       const blink::WebGraphicsContext3D::Attributes& attributes,
81       bool lose_context_when_out_of_memory,
82       bool is_offscreen,
83       gfx::AcceleratedWidget window);
84 
85   void OnContextLost();
86 
87   bool MaybeInitializeGL();
88 
89   // Used to try to find bugs in code that calls gl directly through the gl api
90   // instead of going through WebGraphicsContext3D.
91   void ClearContext();
92 
93   ::gpu::GLInProcessContextAttribs attribs_;
94   bool share_resources_;
95   bool webgl_context_;
96 
97   bool is_offscreen_;
98   // Only used when not offscreen.
99   gfx::AcceleratedWidget window_;
100 
101   // The context we use for OpenGL rendering.
102   scoped_ptr< ::gpu::GLInProcessContext> context_;
103   // The GLES2Implementation we use for OpenGL rendering.
104   ::gpu::gles2::GLES2Implementation* real_gl_;
105 };
106 
107 }  // namespace gpu
108 }  // namespace webkit
109 
110 #endif  // WEBKIT_COMMON_GPU_WEBGRAPHICSCONTEXT3D_IN_PROCESS_COMMAND_BUFFER_IMPL_H_
111