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