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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
6 | 6 |
7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() { | 223 WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() { |
224 DCHECK(contexts_.empty()); | 224 DCHECK(contexts_.empty()); |
225 } | 225 } |
226 | 226 |
227 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 227 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( |
228 int surface_id, | 228 int surface_id, |
229 const GURL& active_url, | 229 const GURL& active_url, |
230 GpuChannelHost* host, | 230 GpuChannelHost* host, |
231 const Attributes& attributes, | 231 const Attributes& attributes, |
232 bool bind_generates_resources, | 232 bool bind_generates_resources, |
233 bool lose_context_when_out_of_memory, | |
234 const SharedMemoryLimits& limits, | 233 const SharedMemoryLimits& limits, |
235 WebGraphicsContext3DCommandBufferImpl* share_context) | 234 WebGraphicsContext3DCommandBufferImpl* share_context) |
236 : initialize_failed_(false), | 235 : initialize_failed_(false), |
237 visible_(false), | 236 visible_(false), |
238 host_(host), | 237 host_(host), |
239 surface_id_(surface_id), | 238 surface_id_(surface_id), |
240 active_url_(active_url), | 239 active_url_(active_url), |
241 context_lost_callback_(0), | 240 context_lost_callback_(0), |
242 context_lost_reason_(GL_NO_ERROR), | 241 context_lost_reason_(GL_NO_ERROR), |
243 error_message_callback_(0), | 242 error_message_callback_(0), |
244 attributes_(attributes), | 243 attributes_(attributes), |
245 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu | 244 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu |
246 : gfx::PreferIntegratedGpu), | 245 : gfx::PreferIntegratedGpu), |
247 weak_ptr_factory_(this), | 246 weak_ptr_factory_(this), |
248 initialized_(false), | 247 initialized_(false), |
249 gl_(NULL), | 248 gl_(NULL), |
250 bind_generates_resources_(bind_generates_resources), | 249 bind_generates_resources_(bind_generates_resources), |
251 lose_context_when_out_of_memory_(lose_context_when_out_of_memory), | |
252 mem_limits_(limits), | 250 mem_limits_(limits), |
253 flush_id_(0) { | 251 flush_id_(0) { |
254 if (share_context) { | 252 if (share_context) { |
255 DCHECK(!attributes_.shareResources); | 253 DCHECK(!attributes_.shareResources); |
256 share_group_ = share_context->share_group_; | 254 share_group_ = share_context->share_group_; |
257 } else { | 255 } else { |
258 share_group_ = attributes_.shareResources | 256 share_group_ = attributes_.shareResources |
259 ? GetDefaultShareGroupForHost(host) | 257 ? GetDefaultShareGroupForHost(host) |
260 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( | 258 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( |
261 new ShareGroup()); | 259 new ShareGroup()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 attribs.push_back(DEPTH_SIZE); | 343 attribs.push_back(DEPTH_SIZE); |
346 attribs.push_back(attributes_.depth ? 24 : 0); | 344 attribs.push_back(attributes_.depth ? 24 : 0); |
347 attribs.push_back(STENCIL_SIZE); | 345 attribs.push_back(STENCIL_SIZE); |
348 attribs.push_back(attributes_.stencil ? 8 : 0); | 346 attribs.push_back(attributes_.stencil ? 8 : 0); |
349 attribs.push_back(SAMPLES); | 347 attribs.push_back(SAMPLES); |
350 attribs.push_back(attributes_.antialias ? 4 : 0); | 348 attribs.push_back(attributes_.antialias ? 4 : 0); |
351 attribs.push_back(SAMPLE_BUFFERS); | 349 attribs.push_back(SAMPLE_BUFFERS); |
352 attribs.push_back(attributes_.antialias ? 1 : 0); | 350 attribs.push_back(attributes_.antialias ? 1 : 0); |
353 attribs.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); | 351 attribs.push_back(FAIL_IF_MAJOR_PERF_CAVEAT); |
354 attribs.push_back(attributes_.failIfMajorPerformanceCaveat ? 1 : 0); | 352 attribs.push_back(attributes_.failIfMajorPerformanceCaveat ? 1 : 0); |
355 attribs.push_back(LOSE_CONTEXT_WHEN_OUT_OF_MEMORY); | |
356 attribs.push_back(lose_context_when_out_of_memory_ ? 1 : 0); | |
357 attribs.push_back(NONE); | 353 attribs.push_back(NONE); |
358 | 354 |
359 // Create a proxy to a command buffer in the GPU process. | 355 // Create a proxy to a command buffer in the GPU process. |
360 if (onscreen) { | 356 if (onscreen) { |
361 command_buffer_.reset(host_->CreateViewCommandBuffer( | 357 command_buffer_.reset(host_->CreateViewCommandBuffer( |
362 surface_id_, | 358 surface_id_, |
363 share_group_command_buffer, | 359 share_group_command_buffer, |
364 attribs, | 360 attribs, |
365 active_url_, | 361 active_url_, |
366 gpu_preference_)); | 362 gpu_preference_)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 417 |
422 if (attributes_.noAutomaticFlushes) | 418 if (attributes_.noAutomaticFlushes) |
423 gles2_helper_->SetAutomaticFlushes(false); | 419 gles2_helper_->SetAutomaticFlushes(false); |
424 // Create a transfer buffer used to copy resources between the renderer | 420 // Create a transfer buffer used to copy resources between the renderer |
425 // process and the GPU process. | 421 // process and the GPU process. |
426 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); | 422 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get())); |
427 | 423 |
428 DCHECK(host_.get()); | 424 DCHECK(host_.get()); |
429 | 425 |
430 // Create the object exposing the OpenGL API. | 426 // Create the object exposing the OpenGL API. |
431 real_gl_.reset( | 427 real_gl_.reset(new gpu::gles2::GLES2Implementation( |
432 new gpu::gles2::GLES2Implementation(gles2_helper_.get(), | 428 gles2_helper_.get(), |
433 gles2_share_group, | 429 gles2_share_group, |
434 transfer_buffer_.get(), | 430 transfer_buffer_.get(), |
435 bind_generates_resources_, | 431 bind_generates_resources_, |
436 lose_context_when_out_of_memory_, | 432 command_buffer_.get())); |
437 command_buffer_.get())); | |
438 gl_ = real_gl_.get(); | 433 gl_ = real_gl_.get(); |
439 | 434 |
440 if (!real_gl_->Initialize( | 435 if (!real_gl_->Initialize( |
441 mem_limits_.start_transfer_buffer_size, | 436 mem_limits_.start_transfer_buffer_size, |
442 mem_limits_.min_transfer_buffer_size, | 437 mem_limits_.min_transfer_buffer_size, |
443 mem_limits_.max_transfer_buffer_size, | 438 mem_limits_.max_transfer_buffer_size, |
444 mem_limits_.mapped_memory_reclaim_limit)) { | 439 mem_limits_.mapped_memory_reclaim_limit)) { |
445 LOG(ERROR) << "Failed to initialize GLES2Implementation."; | 440 LOG(ERROR) << "Failed to initialize GLES2Implementation."; |
446 return false; | 441 return false; |
447 } | 442 } |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 return true; | 1184 return true; |
1190 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 1185 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
1191 return state.error == gpu::error::kLostContext; | 1186 return state.error == gpu::error::kLostContext; |
1192 } | 1187 } |
1193 | 1188 |
1194 // static | 1189 // static |
1195 WebGraphicsContext3DCommandBufferImpl* | 1190 WebGraphicsContext3DCommandBufferImpl* |
1196 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 1191 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
1197 GpuChannelHost* host, | 1192 GpuChannelHost* host, |
1198 const WebGraphicsContext3D::Attributes& attributes, | 1193 const WebGraphicsContext3D::Attributes& attributes, |
1199 bool lose_context_when_out_of_memory, | |
1200 const GURL& active_url, | 1194 const GURL& active_url, |
1201 const SharedMemoryLimits& limits, | 1195 const SharedMemoryLimits& limits, |
1202 WebGraphicsContext3DCommandBufferImpl* share_context) { | 1196 WebGraphicsContext3DCommandBufferImpl* share_context) { |
1203 if (!host) | 1197 if (!host) |
1204 return NULL; | 1198 return NULL; |
1205 | 1199 |
1206 if (share_context && share_context->IsCommandBufferContextLost()) | 1200 if (share_context && share_context->IsCommandBufferContextLost()) |
1207 return NULL; | 1201 return NULL; |
1208 | 1202 |
1209 bool bind_generates_resources = false; | 1203 return new WebGraphicsContext3DCommandBufferImpl(0, |
1210 return new WebGraphicsContext3DCommandBufferImpl( | 1204 active_url, |
1211 0, | 1205 host, |
1212 active_url, | 1206 attributes, |
1213 host, | 1207 false, |
1214 attributes, | 1208 limits, |
1215 bind_generates_resources, | 1209 share_context); |
1216 lose_context_when_out_of_memory, | |
1217 limits, | |
1218 share_context); | |
1219 } | 1210 } |
1220 | 1211 |
1221 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, | 1212 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, |
1222 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) | 1213 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) |
1223 | 1214 |
1224 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, | 1215 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, |
1225 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) | 1216 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) |
1226 | 1217 |
1227 WebGLId WebGraphicsContext3DCommandBufferImpl::createQueryEXT() { | 1218 WebGLId WebGraphicsContext3DCommandBufferImpl::createQueryEXT() { |
1228 GLuint o; | 1219 GLuint o; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 | 1391 |
1401 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1392 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
1402 const std::string& message, int id) { | 1393 const std::string& message, int id) { |
1403 if (error_message_callback_) { | 1394 if (error_message_callback_) { |
1404 blink::WebString str = blink::WebString::fromUTF8(message.c_str()); | 1395 blink::WebString str = blink::WebString::fromUTF8(message.c_str()); |
1405 error_message_callback_->onErrorMessage(str, id); | 1396 error_message_callback_->onErrorMessage(str, id); |
1406 } | 1397 } |
1407 } | 1398 } |
1408 | 1399 |
1409 } // namespace content | 1400 } // namespace content |
OLD | NEW |