Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/gpu/renderer_gl_context.h" | 5 #include "content/renderer/gpu/renderer_gl_context.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 75 |
| 76 } // namespace anonymous | 76 } // namespace anonymous |
| 77 | 77 |
| 78 RendererGLContext::~RendererGLContext() { | 78 RendererGLContext::~RendererGLContext() { |
| 79 Destroy(); | 79 Destroy(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 RendererGLContext* RendererGLContext::CreateViewContext( | 82 RendererGLContext* RendererGLContext::CreateViewContext( |
| 83 GpuChannelHost* channel, | 83 GpuChannelHost* channel, |
| 84 int render_view_id, | 84 int render_view_id, |
| 85 bool share_resources, | |
| 86 RendererGLContext* share_group, | 85 RendererGLContext* share_group, |
| 87 const char* allowed_extensions, | 86 const char* allowed_extensions, |
| 88 const int32* attrib_list, | 87 const int32* attrib_list, |
| 89 const GURL& active_url) { | 88 const GURL& active_url) { |
| 90 #if defined(ENABLE_GPU) | 89 #if defined(ENABLE_GPU) |
| 91 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); | 90 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); |
| 92 if (!context->Initialize( | 91 if (!context->Initialize( |
| 93 true, | 92 true, |
| 94 render_view_id, | 93 render_view_id, |
| 95 gfx::Size(), | 94 gfx::Size(), |
| 96 share_resources, | |
| 97 false, | |
| 98 share_group, | 95 share_group, |
| 99 allowed_extensions, | 96 allowed_extensions, |
| 100 attrib_list, | 97 attrib_list, |
| 101 active_url)) | 98 active_url)) |
| 102 return NULL; | 99 return NULL; |
| 103 | 100 |
| 104 return context.release(); | 101 return context.release(); |
| 105 #else | 102 #else |
| 106 return NULL; | 103 return NULL; |
| 107 #endif | 104 #endif |
| 108 } | 105 } |
| 109 | 106 |
| 110 #if defined(OS_MACOSX) | 107 #if defined(OS_MACOSX) |
| 111 void RendererGLContext::ResizeOnscreen(const gfx::Size& size) { | 108 void RendererGLContext::ResizeOnscreen(const gfx::Size& size) { |
| 112 DCHECK(size.width() > 0 && size.height() > 0); | 109 DCHECK(size.width() > 0 && size.height() > 0); |
| 113 size_ = size; | 110 size_ = size; |
| 114 command_buffer_->SetWindowSize(size); | 111 command_buffer_->SetWindowSize(size); |
| 115 } | 112 } |
| 116 #endif | 113 #endif |
| 117 | 114 |
| 118 RendererGLContext* RendererGLContext::CreateOffscreenContext( | 115 RendererGLContext* RendererGLContext::CreateOffscreenContext( |
| 119 GpuChannelHost* channel, | 116 GpuChannelHost* channel, |
| 120 const gfx::Size& size, | 117 const gfx::Size& size, |
| 121 bool share_resources, | |
| 122 RendererGLContext* share_group, | 118 RendererGLContext* share_group, |
| 123 const char* allowed_extensions, | 119 const char* allowed_extensions, |
| 124 const int32* attrib_list, | 120 const int32* attrib_list, |
| 125 const GURL& active_url) { | 121 const GURL& active_url) { |
| 126 #if defined(ENABLE_GPU) | 122 #if defined(ENABLE_GPU) |
| 127 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); | 123 scoped_ptr<RendererGLContext> context(new RendererGLContext(channel)); |
| 128 if (!context->Initialize( | 124 if (!context->Initialize( |
| 129 false, | 125 false, |
| 130 0, | 126 0, |
| 131 size, | 127 size, |
| 132 share_resources, | |
| 133 false, | |
| 134 share_group, | 128 share_group, |
| 135 allowed_extensions, | 129 allowed_extensions, |
| 136 attrib_list, | 130 attrib_list, |
| 137 active_url)) | 131 active_url)) |
| 138 return NULL; | 132 return NULL; |
| 139 | 133 |
| 140 return context.release(); | 134 return context.release(); |
| 141 #else | 135 #else |
| 142 return NULL; | 136 return NULL; |
| 143 #endif | 137 #endif |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 transfer_buffer_id_(-1), | 294 transfer_buffer_id_(-1), |
| 301 gles2_implementation_(NULL), | 295 gles2_implementation_(NULL), |
| 302 last_error_(SUCCESS), | 296 last_error_(SUCCESS), |
| 303 frame_number_(0) { | 297 frame_number_(0) { |
| 304 DCHECK(channel); | 298 DCHECK(channel); |
| 305 } | 299 } |
| 306 | 300 |
| 307 bool RendererGLContext::Initialize(bool onscreen, | 301 bool RendererGLContext::Initialize(bool onscreen, |
| 308 int render_view_id, | 302 int render_view_id, |
| 309 const gfx::Size& size, | 303 const gfx::Size& size, |
| 310 bool share_resources, | |
| 311 bool bind_generates_resource, | |
| 312 RendererGLContext* share_group, | 304 RendererGLContext* share_group, |
| 313 const char* allowed_extensions, | 305 const char* allowed_extensions, |
| 314 const int32* attrib_list, | 306 const int32* attrib_list, |
| 315 const GURL& active_url) { | 307 const GURL& active_url) { |
| 316 DCHECK(size.width() >= 0 && size.height() >= 0); | 308 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 317 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", | 309 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", |
| 318 "on_screen", onscreen, "num_pixels", size.GetArea()); | 310 "on_screen", onscreen, "num_pixels", size.GetArea()); |
| 319 | 311 |
| 320 if (channel_->state() != GpuChannelHost::kConnected) | 312 if (channel_->state() != GpuChannelHost::kConnected) |
| 321 return false; | 313 return false; |
| 322 | 314 |
| 323 // Ensure the gles2 library is initialized first in a thread safe way. | 315 // Ensure the gles2 library is initialized first in a thread safe way. |
| 324 g_gles2_initializer.Get(); | 316 g_gles2_initializer.Get(); |
| 325 | 317 |
| 318 bool share_resources = true; | |
| 319 bool bind_generates_resources = true; | |
|
piman
2011/08/26 23:18:57
The default was false before (see callers). Is it
apatrick_chromium
2011/08/26 23:40:01
I was deliberate. I want the default semantics to
| |
| 326 std::vector<int32> attribs; | 320 std::vector<int32> attribs; |
| 327 while (attrib_list) { | 321 while (attrib_list) { |
|
apatrick_chromium
2011/08/26 19:21:13
If attrib_list is null then it want get beyond the
| |
| 328 int32 attrib = *attrib_list++; | 322 int32 attrib = *attrib_list++; |
| 329 switch (attrib) { | 323 switch (attrib) { |
| 330 // Known attributes | 324 // Known attributes |
| 331 case ALPHA_SIZE: | 325 case ALPHA_SIZE: |
| 332 case BLUE_SIZE: | 326 case BLUE_SIZE: |
| 333 case GREEN_SIZE: | 327 case GREEN_SIZE: |
| 334 case RED_SIZE: | 328 case RED_SIZE: |
| 335 case DEPTH_SIZE: | 329 case DEPTH_SIZE: |
| 336 case STENCIL_SIZE: | 330 case STENCIL_SIZE: |
| 337 case SAMPLES: | 331 case SAMPLES: |
| 338 case SAMPLE_BUFFERS: | 332 case SAMPLE_BUFFERS: |
| 339 attribs.push_back(attrib); | 333 attribs.push_back(attrib); |
| 340 attribs.push_back(*attrib_list++); | 334 attribs.push_back(*attrib_list++); |
|
jbates
2011/08/26 19:04:35
I know this was already here, but should this chec
| |
| 341 break; | 335 break; |
| 336 case SHARE_RESOURCES: | |
| 337 share_resources = !!(*attrib_list++); | |
|
jbates
2011/08/26 19:04:35
(same here)
| |
| 338 break; | |
| 339 case BIND_GENERATES_RESOURCES: | |
| 340 bind_generates_resources = !!(*attrib_list++); | |
|
jbates
2011/08/26 19:04:35
(same here)
| |
| 341 break; | |
| 342 case NONE: | 342 case NONE: |
| 343 attribs.push_back(attrib); | 343 attribs.push_back(attrib); |
| 344 attrib_list = NULL; | 344 attrib_list = NULL; |
| 345 break; | 345 break; |
| 346 default: | 346 default: |
| 347 last_error_ = BAD_ATTRIBUTE; | 347 last_error_ = BAD_ATTRIBUTE; |
| 348 attribs.push_back(NONE); | 348 attribs.push_back(NONE); |
| 349 attrib_list = NULL; | 349 attrib_list = NULL; |
| 350 break; | 350 break; |
| 351 } | 351 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 return false; | 417 return false; |
| 418 } | 418 } |
| 419 | 419 |
| 420 // Create the object exposing the OpenGL API. | 420 // Create the object exposing the OpenGL API. |
| 421 gles2_implementation_ = new gpu::gles2::GLES2Implementation( | 421 gles2_implementation_ = new gpu::gles2::GLES2Implementation( |
| 422 gles2_helper_, | 422 gles2_helper_, |
| 423 transfer_buffer.size, | 423 transfer_buffer.size, |
| 424 transfer_buffer.ptr, | 424 transfer_buffer.ptr, |
| 425 transfer_buffer_id_, | 425 transfer_buffer_id_, |
| 426 share_resources, | 426 share_resources, |
| 427 bind_generates_resource); | 427 bind_generates_resources); |
| 428 | 428 |
| 429 size_ = size; | 429 size_ = size; |
| 430 | 430 |
| 431 return true; | 431 return true; |
| 432 } | 432 } |
| 433 | 433 |
| 434 void RendererGLContext::Destroy() { | 434 void RendererGLContext::Destroy() { |
| 435 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); | 435 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); |
| 436 SetParent(NULL); | 436 SetParent(NULL); |
| 437 | 437 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 void RendererGLContext::OnContextLost() { | 471 void RendererGLContext::OnContextLost() { |
| 472 if (context_lost_callback_.get()) { | 472 if (context_lost_callback_.get()) { |
| 473 RendererGLContext::ContextLostReason reason = kUnknown; | 473 RendererGLContext::ContextLostReason reason = kUnknown; |
| 474 if (command_buffer_) { | 474 if (command_buffer_) { |
| 475 reason = ConvertReason( | 475 reason = ConvertReason( |
| 476 command_buffer_->GetLastState().context_lost_reason); | 476 command_buffer_->GetLastState().context_lost_reason); |
| 477 } | 477 } |
| 478 context_lost_callback_->Run(reason); | 478 context_lost_callback_->Run(reason); |
| 479 } | 479 } |
| 480 } | 480 } |
| OLD | NEW |