OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" | 5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
10 #endif | 10 #endif |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 } // namespace anonymous | 66 } // namespace anonymous |
67 | 67 |
68 // static | 68 // static |
69 scoped_ptr<WebKit::WebGraphicsContext3D> | 69 scoped_ptr<WebKit::WebGraphicsContext3D> |
70 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | 70 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
71 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 71 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
72 gfx::AcceleratedWidget window) { | 72 gfx::AcceleratedWidget window) { |
73 scoped_ptr<WebKit::WebGraphicsContext3D> context; | 73 scoped_ptr<WebKit::WebGraphicsContext3D> context; |
74 if (gfx::GLSurface::InitializeOneOff()) { | 74 if (gfx::GLSurface::InitializeOneOff()) { |
75 context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( | 75 context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( |
76 attributes, false, window)); | 76 scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window)); |
77 } | 77 } |
78 return context.Pass(); | 78 return context.Pass(); |
79 } | 79 } |
80 | 80 |
81 // static | 81 // static |
82 scoped_ptr<WebKit::WebGraphicsContext3D> | 82 scoped_ptr<WebKit::WebGraphicsContext3D> |
83 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | 83 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( |
84 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | 84 const WebKit::WebGraphicsContext3D::Attributes& attributes) { |
85 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( | 85 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( |
86 attributes, true, gfx::kNullAcceleratedWidget)) | 86 scoped_ptr< ::gpu::GLInProcessContext>(), |
87 attributes, | |
88 true, | |
89 gfx::kNullAcceleratedWidget)) | |
90 .PassAs<WebKit::WebGraphicsContext3D>(); | |
91 } | |
92 | |
93 scoped_ptr<WebKit::WebGraphicsContext3D> | |
94 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | |
95 scoped_ptr< ::gpu::GLInProcessContext> context, | |
96 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | |
97 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( | |
98 context.Pass(), | |
joth
2013/08/04 00:45:16
nit: make indent consistent with line 86 (I think
boliu
2013/08/05 16:58:24
clang-formatted both. Not exactly as you suggested
| |
99 attributes, | |
100 true /* is_offscreen. Not used. */, | |
101 gfx::kNullAcceleratedWidget /* window. Not used. */)) | |
87 .PassAs<WebKit::WebGraphicsContext3D>(); | 102 .PassAs<WebKit::WebGraphicsContext3D>(); |
88 } | 103 } |
89 | 104 |
90 WebGraphicsContext3DInProcessCommandBufferImpl:: | 105 WebGraphicsContext3DInProcessCommandBufferImpl:: |
91 WebGraphicsContext3DInProcessCommandBufferImpl( | 106 WebGraphicsContext3DInProcessCommandBufferImpl( |
107 scoped_ptr< ::gpu::GLInProcessContext> context, | |
92 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 108 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
93 bool is_offscreen, | 109 bool is_offscreen, |
94 gfx::AcceleratedWidget window) | 110 gfx::AcceleratedWidget window) |
95 : is_offscreen_(is_offscreen), | 111 : is_offscreen_(is_offscreen), |
96 window_(window), | 112 window_(window), |
97 initialized_(false), | 113 initialized_(false), |
98 initialize_failed_(false), | 114 initialize_failed_(false), |
115 context_(context.Pass()), | |
99 gl_(NULL), | 116 gl_(NULL), |
100 context_lost_callback_(NULL), | 117 context_lost_callback_(NULL), |
101 context_lost_reason_(GL_NO_ERROR), | 118 context_lost_reason_(GL_NO_ERROR), |
102 attributes_(attributes), | 119 attributes_(attributes), |
103 cached_width_(0), | 120 cached_width_(0), |
104 cached_height_(0) { | 121 cached_height_(0) { |
105 } | 122 } |
106 | 123 |
107 WebGraphicsContext3DInProcessCommandBufferImpl:: | 124 WebGraphicsContext3DInProcessCommandBufferImpl:: |
108 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 125 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
109 } | 126 } |
110 | 127 |
111 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { | 128 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { |
112 if (initialized_) | 129 if (initialized_) |
113 return true; | 130 return true; |
114 | 131 |
115 if (initialize_failed_) | 132 if (initialize_failed_) |
116 return false; | 133 return false; |
117 | 134 |
118 // Ensure the gles2 library is initialized first in a thread safe way. | 135 // Ensure the gles2 library is initialized first in a thread safe way. |
119 g_gles2_initializer.Get(); | 136 g_gles2_initializer.Get(); |
120 | 137 |
121 // Convert WebGL context creation attributes into GLInProcessContext / EGL | 138 if (!context_) { |
122 // size requests. | 139 // Convert WebGL context creation attributes into GLInProcessContext / EGL |
123 const int alpha_size = attributes_.alpha ? 8 : 0; | 140 // size requests. |
joth
2013/08/04 00:45:16
ah ha, here's where it was copied from. I have no
boliu
2013/08/04 00:53:32
Oh I tried static method. But didn't figure out a
joth
2013/08/04 01:15:50
yeah it's mucky if you want to carry the size info
| |
124 const int depth_size = attributes_.depth ? 24 : 0; | 141 const int alpha_size = attributes_.alpha ? 8 : 0; |
125 const int stencil_size = attributes_.stencil ? 8 : 0; | 142 const int depth_size = attributes_.depth ? 24 : 0; |
126 const int samples = attributes_.antialias ? 4 : 0; | 143 const int stencil_size = attributes_.stencil ? 8 : 0; |
127 const int sample_buffers = attributes_.antialias ? 1 : 0; | 144 const int samples = attributes_.antialias ? 4 : 0; |
128 const int32 attribs[] = { | 145 const int sample_buffers = attributes_.antialias ? 1 : 0; |
129 GLInProcessContext::ALPHA_SIZE, alpha_size, | 146 const int32 attribs[] = { |
130 GLInProcessContext::DEPTH_SIZE, depth_size, | 147 GLInProcessContext::ALPHA_SIZE, alpha_size, |
131 GLInProcessContext::STENCIL_SIZE, stencil_size, | 148 GLInProcessContext::DEPTH_SIZE, depth_size, |
132 GLInProcessContext::SAMPLES, samples, | 149 GLInProcessContext::STENCIL_SIZE, stencil_size, |
133 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, | 150 GLInProcessContext::SAMPLES, samples, |
134 GLInProcessContext::NONE, | 151 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, |
135 }; | 152 GLInProcessContext::NONE, |
153 }; | |
136 | 154 |
137 const char* preferred_extensions = "*"; | 155 const char* preferred_extensions = "*"; |
138 | 156 |
139 // TODO(kbr): More work will be needed in this implementation to | 157 // TODO(kbr): More work will be needed in this implementation to |
140 // properly support GPU switching. Like in the out-of-process | 158 // properly support GPU switching. Like in the out-of-process |
141 // command buffer implementation, all previously created contexts | 159 // command buffer implementation, all previously created contexts |
142 // will need to be lost either when the first context requesting the | 160 // will need to be lost either when the first context requesting the |
143 // discrete GPU is created, or the last one is destroyed. | 161 // discrete GPU is created, or the last one is destroyed. |
144 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 162 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
145 | 163 |
146 base::Closure context_lost_callback = | 164 context_.reset(GLInProcessContext::CreateContext( |
147 base::Bind(&WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | 165 is_offscreen_, |
148 base::Unretained(this)); | 166 window_, |
167 gfx::Size(1, 1), | |
168 attributes_.shareResources, | |
169 preferred_extensions, | |
170 attribs, | |
171 gpu_preference)); | |
172 } | |
149 | 173 |
150 context_.reset(GLInProcessContext::CreateContext( | 174 if (context_) { |
151 is_offscreen_, | 175 base::Closure context_lost_callback = base::Bind( |
152 window_, | 176 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, |
153 gfx::Size(1, 1), | 177 base::Unretained(this)); |
154 attributes_.shareResources, | 178 context_->SetContextLostCallback(context_lost_callback); |
155 preferred_extensions, | 179 } else { |
156 attribs, | |
157 gpu_preference, | |
158 context_lost_callback)); | |
159 | |
160 if (!context_) { | |
161 initialize_failed_ = true; | 180 initialize_failed_ = true; |
162 return false; | 181 return false; |
163 } | 182 } |
164 | 183 |
165 gl_ = context_->GetImplementation(); | 184 gl_ = context_->GetImplementation(); |
166 | 185 |
167 if (gl_ && attributes_.noExtensions) | 186 if (gl_ && attributes_.noExtensions) |
168 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 187 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
169 | 188 |
170 // Set attributes_ from created offscreen context. | 189 // Set attributes_ from created offscreen context. |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 | 1204 |
1186 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1205 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
1187 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1206 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
1188 WGC3Denum, WGC3Denum, const void*) | 1207 WGC3Denum, WGC3Denum, const void*) |
1189 | 1208 |
1190 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1209 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
1191 WGC3Denum) | 1210 WGC3Denum) |
1192 | 1211 |
1193 } // namespace gpu | 1212 } // namespace gpu |
1194 } // namespace webkit | 1213 } // namespace webkit |
OLD | NEW |