Chromium Code Reviews| 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( | |
| 98 new WebGraphicsContext3DInProcessCommandBufferImpl( | |
| 99 context.Pass(), | |
| 100 attributes, | |
| 101 true /* is_offscreen. Not used. */, | |
| 102 gfx::kNullAcceleratedWidget /* window. Not used. */)) | |
| 87 .PassAs<WebKit::WebGraphicsContext3D>(); | 103 .PassAs<WebKit::WebGraphicsContext3D>(); |
| 88 } | 104 } |
| 89 | 105 |
| 90 WebGraphicsContext3DInProcessCommandBufferImpl:: | 106 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 91 WebGraphicsContext3DInProcessCommandBufferImpl( | 107 WebGraphicsContext3DInProcessCommandBufferImpl( |
| 108 scoped_ptr< ::gpu::GLInProcessContext> context, | |
| 92 const WebKit::WebGraphicsContext3D::Attributes& attributes, | 109 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 93 bool is_offscreen, | 110 bool is_offscreen, |
| 94 gfx::AcceleratedWidget window) | 111 gfx::AcceleratedWidget window) |
| 95 : is_offscreen_(is_offscreen), | 112 : is_offscreen_(is_offscreen), |
| 96 window_(window), | 113 window_(window), |
| 97 initialized_(false), | 114 initialized_(false), |
| 98 initialize_failed_(false), | 115 initialize_failed_(false), |
| 116 context_(context.Pass()), | |
| 99 gl_(NULL), | 117 gl_(NULL), |
| 100 context_lost_callback_(NULL), | 118 context_lost_callback_(NULL), |
| 101 context_lost_reason_(GL_NO_ERROR), | 119 context_lost_reason_(GL_NO_ERROR), |
| 102 attributes_(attributes), | 120 attributes_(attributes), |
| 103 cached_width_(0), | 121 cached_width_(0), |
| 104 cached_height_(0) { | 122 cached_height_(0) { |
| 105 } | 123 } |
| 106 | 124 |
| 107 WebGraphicsContext3DInProcessCommandBufferImpl:: | 125 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 108 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 126 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
| 109 } | 127 } |
| 110 | 128 |
| 129 // static | |
| 130 void WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes( | |
| 131 const WebKit::WebGraphicsContext3D::Attributes& attributes, | |
| 132 ::gpu::GLInProcessContextAttribs* output_attribs) { | |
| 133 output_attribs->alpha_size = attributes.alpha ? 8 : 0; | |
| 134 output_attribs->depth_size = attributes.depth ? 24 : 0; | |
| 135 output_attribs->stencil_size = attributes.stencil ? 8 : 0; | |
| 136 output_attribs->samples = attributes.antialias ? 4 : 0; | |
| 137 output_attribs->sample_buffers = attributes.antialias ? 1 : 0; | |
| 138 } | |
| 139 | |
| 111 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { | 140 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { |
| 112 if (initialized_) | 141 if (initialized_) |
| 113 return true; | 142 return true; |
| 114 | 143 |
| 115 if (initialize_failed_) | 144 if (initialize_failed_) |
| 116 return false; | 145 return false; |
| 117 | 146 |
| 118 // Ensure the gles2 library is initialized first in a thread safe way. | 147 // Ensure the gles2 library is initialized first in a thread safe way. |
| 119 g_gles2_initializer.Get(); | 148 g_gles2_initializer.Get(); |
| 120 | 149 |
| 121 // Convert WebGL context creation attributes into GLInProcessContext / EGL | 150 if (!context_) { |
| 122 // size requests. | 151 const char* preferred_extensions = "*"; |
| 123 const int alpha_size = attributes_.alpha ? 8 : 0; | |
| 124 const int depth_size = attributes_.depth ? 24 : 0; | |
| 125 const int stencil_size = attributes_.stencil ? 8 : 0; | |
| 126 const int samples = attributes_.antialias ? 4 : 0; | |
| 127 const int sample_buffers = attributes_.antialias ? 1 : 0; | |
| 128 const int32 attribs[] = { | |
| 129 GLInProcessContext::ALPHA_SIZE, alpha_size, | |
| 130 GLInProcessContext::DEPTH_SIZE, depth_size, | |
| 131 GLInProcessContext::STENCIL_SIZE, stencil_size, | |
| 132 GLInProcessContext::SAMPLES, samples, | |
| 133 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, | |
| 134 GLInProcessContext::NONE, | |
| 135 }; | |
| 136 | 152 |
| 137 const char* preferred_extensions = "*"; | 153 // TODO(kbr): More work will be needed in this implementation to |
| 154 // properly support GPU switching. Like in the out-of-process | |
| 155 // command buffer implementation, all previously created contexts | |
| 156 // will need to be lost either when the first context requesting the | |
| 157 // discrete GPU is created, or the last one is destroyed. | |
| 158 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | |
| 138 | 159 |
| 139 // TODO(kbr): More work will be needed in this implementation to | 160 ::gpu::GLInProcessContextAttribs attrib_struct; |
| 140 // properly support GPU switching. Like in the out-of-process | 161 ConvertAttributes(attributes_, &attrib_struct), |
| 141 // command buffer implementation, all previously created contexts | |
| 142 // will need to be lost either when the first context requesting the | |
| 143 // discrete GPU is created, or the last one is destroyed. | |
| 144 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | |
| 145 | 162 |
| 146 base::Closure context_lost_callback = | 163 context_.reset(GLInProcessContext::CreateContext( |
| 147 base::Bind(&WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, | 164 is_offscreen_, |
| 148 base::Unretained(this)); | 165 window_, |
| 166 gfx::Size(1, 1), | |
| 167 attributes_.shareResources, | |
| 168 preferred_extensions, | |
| 169 attrib_struct, | |
| 170 gpu_preference)); | |
| 171 } | |
| 149 | 172 |
| 150 context_.reset(GLInProcessContext::CreateContext( | 173 if (context_) { |
| 151 is_offscreen_, | 174 base::Closure context_lost_callback = base::Bind( |
| 152 window_, | 175 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, |
| 153 gfx::Size(1, 1), | 176 base::Unretained(this)); |
|
no sievers
2013/08/07 01:52:38
interesting that we pass in 1,1 here
| |
| 154 attributes_.shareResources, | 177 context_->SetContextLostCallback(context_lost_callback); |
| 155 preferred_extensions, | 178 } else { |
| 156 attribs, | |
| 157 gpu_preference, | |
| 158 context_lost_callback)); | |
| 159 | |
| 160 if (!context_) { | |
| 161 initialize_failed_ = true; | 179 initialize_failed_ = true; |
| 162 return false; | 180 return false; |
| 163 } | 181 } |
| 164 | 182 |
| 165 gl_ = context_->GetImplementation(); | 183 gl_ = context_->GetImplementation(); |
| 166 | 184 |
| 167 if (gl_ && attributes_.noExtensions) | 185 if (gl_ && attributes_.noExtensions) |
| 168 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 186 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| 169 | 187 |
| 170 // Set attributes_ from created offscreen context. | 188 // Set attributes_ from created offscreen context. |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 | 1203 |
| 1186 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1204 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1187 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1205 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1188 WGC3Denum, WGC3Denum, const void*) | 1206 WGC3Denum, WGC3Denum, const void*) |
| 1189 | 1207 |
| 1190 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1208 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1191 WGC3Denum) | 1209 WGC3Denum) |
| 1192 | 1210 |
| 1193 } // namespace gpu | 1211 } // namespace gpu |
| 1194 } // namespace webkit | 1212 } // namespace webkit |
| OLD | NEW |