OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "base/weak_ptr.h" | 9 #include "base/weak_ptr.h" |
10 #include "chrome/renderer/command_buffer_proxy.h" | 10 #include "chrome/renderer/command_buffer_proxy.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } // namespace anonymous | 55 } // namespace anonymous |
56 | 56 |
57 // Manages a GL context. | 57 // Manages a GL context. |
58 class Context : public base::SupportsWeakPtr<Context> { | 58 class Context : public base::SupportsWeakPtr<Context> { |
59 public: | 59 public: |
60 Context(GpuChannelHost* channel, Context* parent); | 60 Context(GpuChannelHost* channel, Context* parent); |
61 ~Context(); | 61 ~Context(); |
62 | 62 |
63 // Initialize a GGL context that can be used in association with a a GPU | 63 // Initialize a GGL context that can be used in association with a a GPU |
64 // channel acquired from a RenderWidget or RenderView. | 64 // channel acquired from a RenderWidget or RenderView. |
65 bool Initialize(gfx::NativeViewId view, | 65 bool Initialize(bool onscreen, |
66 int render_view_id, | 66 int render_view_id, |
67 const gfx::Size& size, | 67 const gfx::Size& size, |
68 const char* allowed_extensions, | 68 const char* allowed_extensions, |
69 const int32* attrib_list); | 69 const int32* attrib_list); |
70 | 70 |
71 #if defined(OS_MACOSX) | 71 #if defined(OS_MACOSX) |
72 // Asynchronously resizes an onscreen frame buffer. | 72 // Asynchronously resizes an onscreen frame buffer. |
73 void ResizeOnscreen(const gfx::Size& size); | 73 void ResizeOnscreen(const gfx::Size& size); |
74 #endif | 74 #endif |
75 | 75 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 transfer_buffer_id_(0), | 149 transfer_buffer_id_(0), |
150 gles2_implementation_(NULL), | 150 gles2_implementation_(NULL), |
151 last_error_(SUCCESS) { | 151 last_error_(SUCCESS) { |
152 DCHECK(channel); | 152 DCHECK(channel); |
153 } | 153 } |
154 | 154 |
155 Context::~Context() { | 155 Context::~Context() { |
156 Destroy(); | 156 Destroy(); |
157 } | 157 } |
158 | 158 |
159 bool Context::Initialize(gfx::NativeViewId view, | 159 bool Context::Initialize(bool onscreen, |
160 int render_view_id, | 160 int render_view_id, |
161 const gfx::Size& size, | 161 const gfx::Size& size, |
162 const char* allowed_extensions, | 162 const char* allowed_extensions, |
163 const int32* attrib_list) { | 163 const int32* attrib_list) { |
164 DCHECK(size.width() >= 0 && size.height() >= 0); | 164 DCHECK(size.width() >= 0 && size.height() >= 0); |
165 | 165 |
166 if (channel_->state() != GpuChannelHost::kConnected) | 166 if (channel_->state() != GpuChannelHost::kConnected) |
167 return false; | 167 return false; |
168 | 168 |
169 // Ensure the gles2 library is initialized first in a thread safe way. | 169 // Ensure the gles2 library is initialized first in a thread safe way. |
(...skipping 30 matching lines...) Expand all Loading... |
200 break; | 200 break; |
201 default: | 201 default: |
202 SetError(ggl::BAD_ATTRIBUTE); | 202 SetError(ggl::BAD_ATTRIBUTE); |
203 attribs.push_back(ggl::GGL_NONE); | 203 attribs.push_back(ggl::GGL_NONE); |
204 attrib_list = NULL; | 204 attrib_list = NULL; |
205 break; | 205 break; |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 // Create a proxy to a command buffer in the GPU process. | 209 // Create a proxy to a command buffer in the GPU process. |
210 if (view) { | 210 if (onscreen) { |
211 command_buffer_ = channel_->CreateViewCommandBuffer( | 211 command_buffer_ = channel_->CreateViewCommandBuffer( |
212 view, | |
213 render_view_id, | 212 render_view_id, |
214 allowed_extensions, | 213 allowed_extensions, |
215 attribs); | 214 attribs); |
216 } else { | 215 } else { |
217 CommandBufferProxy* parent_command_buffer = | 216 CommandBufferProxy* parent_command_buffer = |
218 parent_.get() ? parent_->command_buffer_ : NULL; | 217 parent_.get() ? parent_->command_buffer_ : NULL; |
219 command_buffer_ = channel_->CreateOffscreenCommandBuffer( | 218 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
220 parent_command_buffer, | 219 parent_command_buffer, |
221 size, | 220 size, |
222 allowed_extensions, | 221 allowed_extensions, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 426 } |
428 | 427 |
429 void Context::OnSwapBuffers() { | 428 void Context::OnSwapBuffers() { |
430 if (swap_buffers_callback_.get()) | 429 if (swap_buffers_callback_.get()) |
431 swap_buffers_callback_->Run(); | 430 swap_buffers_callback_->Run(); |
432 } | 431 } |
433 | 432 |
434 #endif // ENABLE_GPU | 433 #endif // ENABLE_GPU |
435 | 434 |
436 Context* CreateViewContext(GpuChannelHost* channel, | 435 Context* CreateViewContext(GpuChannelHost* channel, |
437 gfx::NativeViewId view, | |
438 int render_view_id, | 436 int render_view_id, |
439 const char* allowed_extensions, | 437 const char* allowed_extensions, |
440 const int32* attrib_list) { | 438 const int32* attrib_list) { |
441 #if defined(ENABLE_GPU) | 439 #if defined(ENABLE_GPU) |
442 scoped_ptr<Context> context(new Context(channel, NULL)); | 440 scoped_ptr<Context> context(new Context(channel, NULL)); |
443 if (!context->Initialize( | 441 if (!context->Initialize( |
444 view, render_view_id, gfx::Size(), allowed_extensions, attrib_list)) | 442 true, render_view_id, gfx::Size(), allowed_extensions, attrib_list)) |
445 return NULL; | 443 return NULL; |
446 | 444 |
447 return context.release(); | 445 return context.release(); |
448 #else | 446 #else |
449 return NULL; | 447 return NULL; |
450 #endif | 448 #endif |
451 } | 449 } |
452 | 450 |
453 #if defined(OS_MACOSX) | 451 #if defined(OS_MACOSX) |
454 void ResizeOnscreenContext(Context* context, const gfx::Size& size) { | 452 void ResizeOnscreenContext(Context* context, const gfx::Size& size) { |
455 #if defined(ENABLE_GPU) | 453 #if defined(ENABLE_GPU) |
456 context->ResizeOnscreen(size); | 454 context->ResizeOnscreen(size); |
457 #endif | 455 #endif |
458 } | 456 } |
459 #endif | 457 #endif |
460 | 458 |
461 Context* CreateOffscreenContext(GpuChannelHost* channel, | 459 Context* CreateOffscreenContext(GpuChannelHost* channel, |
462 Context* parent, | 460 Context* parent, |
463 const gfx::Size& size, | 461 const gfx::Size& size, |
464 const char* allowed_extensions, | 462 const char* allowed_extensions, |
465 const int32* attrib_list) { | 463 const int32* attrib_list) { |
466 #if defined(ENABLE_GPU) | 464 #if defined(ENABLE_GPU) |
467 scoped_ptr<Context> context(new Context(channel, parent)); | 465 scoped_ptr<Context> context(new Context(channel, parent)); |
468 if (!context->Initialize(0, 0, size, allowed_extensions, attrib_list)) | 466 if (!context->Initialize(false, 0, size, allowed_extensions, attrib_list)) |
469 return NULL; | 467 return NULL; |
470 | 468 |
471 return context.release(); | 469 return context.release(); |
472 #else | 470 #else |
473 return NULL; | 471 return NULL; |
474 #endif | 472 #endif |
475 } | 473 } |
476 | 474 |
477 void ResizeOffscreenContext(Context* context, const gfx::Size& size) { | 475 void ResizeOffscreenContext(Context* context, const gfx::Size& size) { |
478 #if defined(ENABLE_GPU) | 476 #if defined(ENABLE_GPU) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 } | 569 } |
572 | 570 |
573 gpu::gles2::GLES2Implementation* GetImplementation(Context* context) { | 571 gpu::gles2::GLES2Implementation* GetImplementation(Context* context) { |
574 if (!context) | 572 if (!context) |
575 return NULL; | 573 return NULL; |
576 | 574 |
577 return context->gles2_implementation(); | 575 return context->gles2_implementation(); |
578 } | 576 } |
579 | 577 |
580 } // namespace ggl | 578 } // namespace ggl |
OLD | NEW |