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/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 | 82 |
83 // Terminate the library. This must be called after any other functions | 83 // Terminate the library. This must be called after any other functions |
84 // have completed. | 84 // have completed. |
85 static bool Terminate(); | 85 static bool Terminate(); |
86 | 86 |
87 ~GLInProcessContext(); | 87 ~GLInProcessContext(); |
88 | 88 |
89 void PumpCommands(); | 89 void PumpCommands(); |
90 bool GetBufferChanged(int32 transfer_buffer_id); | 90 bool GetBufferChanged(int32 transfer_buffer_id); |
91 | 91 |
92 // Create a GLInProcessContext that renders to an offscreen frame buffer. If | 92 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an |
93 // parent is not NULL, that GLInProcessContext can access a copy of the | 93 // offscreen context. If parent is not NULL, that GLInProcessContext can |
jamesr
2013/04/19 00:52:28
since you're updating this comment anyway, can you
boliu
2013/04/19 00:57:31
That's most of this block of comment. Done.
| |
94 // created GLInProcessContext's frame buffer that is updated every time | 94 // access a copy of the created GLInProcessContext's frame buffer that is |
95 // SwapBuffers is called. It is not as general as shared GLInProcessContexts | 95 // updated every time SwapBuffers is called. It is not as general as shared |
96 // in other implementations of OpenGL. If parent is not NULL, it must be used | 96 // GLInProcessContexts in other implementations of OpenGL. If parent is not |
97 // on the same thread as the parent. A child GLInProcessContext may not | 97 // NULL, it must be used on the same thread as the parent. A child |
98 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of | 98 // GLInProcessContext may not outlive its parent. attrib_list must be NULL |
99 // attribute/value pairs. | 99 // or a NONE-terminated list of attribute/value pairs. |
100 static GLInProcessContext* CreateOffscreenContext( | 100 static GLInProcessContext* CreateContext( |
101 bool is_offscreen, | |
102 gfx::AcceleratedWidget window, | |
101 const gfx::Size& size, | 103 const gfx::Size& size, |
102 bool share_resources, | 104 bool share_resources, |
103 const char* allowed_extensions, | 105 const char* allowed_extensions, |
104 const int32* attrib_list, | 106 const int32* attrib_list, |
105 gfx::GpuPreference gpu_preference); | 107 gfx::GpuPreference gpu_preference); |
106 | 108 |
107 // For an offscreen frame buffer GLInProcessContext, return the texture ID | 109 // For an offscreen frame buffer GLInProcessContext, return the texture ID |
108 // with respect to the parent GLInProcessContext. Returns zero if | 110 // with respect to the parent GLInProcessContext. Returns zero if |
109 // GLInProcessContext does not have a parent. | 111 // GLInProcessContext does not have a parent. |
110 uint32 GetParentTextureId(); | 112 uint32 GetParentTextureId(); |
(...skipping 30 matching lines...) Expand all Loading... | |
141 // problem communicating with the GPU process. | 143 // problem communicating with the GPU process. |
142 bool IsCommandBufferContextLost(); | 144 bool IsCommandBufferContextLost(); |
143 | 145 |
144 CommandBufferService* GetCommandBufferService(); | 146 CommandBufferService* GetCommandBufferService(); |
145 | 147 |
146 ::gpu::gles2::GLES2Decoder* GetDecoder(); | 148 ::gpu::gles2::GLES2Decoder* GetDecoder(); |
147 | 149 |
148 private: | 150 private: |
149 explicit GLInProcessContext(bool share_resources); | 151 explicit GLInProcessContext(bool share_resources); |
150 | 152 |
151 bool Initialize(const gfx::Size& size, | 153 bool Initialize(bool is_offscreen, |
154 gfx::AcceleratedWidget window, | |
155 const gfx::Size& size, | |
152 const char* allowed_extensions, | 156 const char* allowed_extensions, |
153 const int32* attrib_list, | 157 const int32* attrib_list, |
154 gfx::GpuPreference gpu_preference); | 158 gfx::GpuPreference gpu_preference); |
155 void Destroy(); | 159 void Destroy(); |
156 | 160 |
157 void OnContextLost(); | 161 void OnContextLost(); |
158 | 162 |
159 base::Closure context_lost_callback_; | 163 base::Closure context_lost_callback_; |
160 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 164 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
161 scoped_ptr<CommandBufferService> command_buffer_; | 165 scoped_ptr<CommandBufferService> command_buffer_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 205 |
202 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = | 206 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
203 LAZY_INSTANCE_INITIALIZER; | 207 LAZY_INSTANCE_INITIALIZER; |
204 | 208 |
205 } // namespace anonymous | 209 } // namespace anonymous |
206 | 210 |
207 GLInProcessContext::~GLInProcessContext() { | 211 GLInProcessContext::~GLInProcessContext() { |
208 Destroy(); | 212 Destroy(); |
209 } | 213 } |
210 | 214 |
211 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( | 215 GLInProcessContext* GLInProcessContext::CreateContext( |
216 bool is_offscreen, | |
217 gfx::AcceleratedWidget window, | |
212 const gfx::Size& size, | 218 const gfx::Size& size, |
213 bool share_resources, | 219 bool share_resources, |
214 const char* allowed_extensions, | 220 const char* allowed_extensions, |
215 const int32* attrib_list, | 221 const int32* attrib_list, |
216 gfx::GpuPreference gpu_preference) { | 222 gfx::GpuPreference gpu_preference) { |
217 scoped_ptr<GLInProcessContext> context( | 223 scoped_ptr<GLInProcessContext> context( |
218 new GLInProcessContext(share_resources)); | 224 new GLInProcessContext(share_resources)); |
219 if (!context->Initialize( | 225 if (!context->Initialize( |
226 is_offscreen, | |
227 window, | |
220 size, | 228 size, |
221 allowed_extensions, | 229 allowed_extensions, |
222 attrib_list, | 230 attrib_list, |
223 gpu_preference)) | 231 gpu_preference)) |
224 return NULL; | 232 return NULL; |
225 | 233 |
226 return context.release(); | 234 return context.release(); |
227 } | 235 } |
228 | 236 |
229 // In the normal command buffer implementation, all commands are passed over IPC | 237 // In the normal command buffer implementation, all commands are passed over IPC |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 GLES2Implementation* GLInProcessContext::GetImplementation() { | 386 GLES2Implementation* GLInProcessContext::GetImplementation() { |
379 return gles2_implementation_.get(); | 387 return gles2_implementation_.get(); |
380 } | 388 } |
381 | 389 |
382 GLInProcessContext::GLInProcessContext(bool share_resources) | 390 GLInProcessContext::GLInProcessContext(bool share_resources) |
383 : last_error_(SUCCESS), | 391 : last_error_(SUCCESS), |
384 share_resources_(share_resources), | 392 share_resources_(share_resources), |
385 context_lost_(false) { | 393 context_lost_(false) { |
386 } | 394 } |
387 | 395 |
388 bool GLInProcessContext::Initialize(const gfx::Size& size, | 396 bool GLInProcessContext::Initialize( |
389 const char* allowed_extensions, | 397 bool is_offscreen, |
390 const int32* attrib_list, | 398 gfx::AcceleratedWidget window, |
391 gfx::GpuPreference gpu_preference) { | 399 const gfx::Size& size, |
400 const char* allowed_extensions, | |
401 const int32* attrib_list, | |
402 gfx::GpuPreference gpu_preference) { | |
392 // Use one share group for all contexts. | 403 // Use one share group for all contexts. |
393 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, | 404 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, |
394 (new gfx::GLShareGroup)); | 405 (new gfx::GLShareGroup)); |
395 | 406 |
396 DCHECK(size.width() >= 0 && size.height() >= 0); | 407 DCHECK(size.width() >= 0 && size.height() >= 0); |
397 | 408 |
398 // Ensure the gles2 library is initialized first in a thread safe way. | 409 // Ensure the gles2 library is initialized first in a thread safe way. |
399 g_gles2_initializer.Get(); | 410 g_gles2_initializer.Get(); |
400 | 411 |
401 std::vector<int32> attribs; | 412 std::vector<int32> attribs; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 context_group->decoder_->GetContextGroup() : | 465 context_group->decoder_->GetContextGroup() : |
455 new ::gpu::gles2::ContextGroup( | 466 new ::gpu::gles2::ContextGroup( |
456 NULL, NULL, NULL, bind_generates_resource))); | 467 NULL, NULL, NULL, bind_generates_resource))); |
457 | 468 |
458 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 469 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), |
459 decoder_.get(), | 470 decoder_.get(), |
460 decoder_.get())); | 471 decoder_.get())); |
461 | 472 |
462 decoder_->set_engine(gpu_scheduler_.get()); | 473 decoder_->set_engine(gpu_scheduler_.get()); |
463 | 474 |
464 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); | 475 if (is_offscreen) |
476 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); | |
477 else | |
478 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); | |
465 | 479 |
466 if (!surface_.get()) { | 480 if (!surface_.get()) { |
467 LOG(ERROR) << "Could not create GLSurface."; | 481 LOG(ERROR) << "Could not create GLSurface."; |
468 Destroy(); | 482 Destroy(); |
469 return false; | 483 return false; |
470 } | 484 } |
471 | 485 |
472 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | 486 context_ = gfx::GLContext::CreateGLContext(share_group.get(), |
473 surface_.get(), | 487 surface_.get(), |
474 gpu_preference); | 488 gpu_preference); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 } | 581 } |
568 | 582 |
569 g_all_shared_contexts.Pointer()->erase(this); | 583 g_all_shared_contexts.Pointer()->erase(this); |
570 } | 584 } |
571 | 585 |
572 void GLInProcessContext::OnContextLost() { | 586 void GLInProcessContext::OnContextLost() { |
573 if (!context_lost_callback_.is_null()) | 587 if (!context_lost_callback_.is_null()) |
574 context_lost_callback_.Run(); | 588 context_lost_callback_.Run(); |
575 } | 589 } |
576 | 590 |
591 | |
592 // static | |
593 WebGraphicsContext3DInProcessCommandBufferImpl* | |
594 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | |
595 const WebKit::WebGraphicsContext3D::Attributes& attributes, | |
596 gfx::AcceleratedWidget window) { | |
597 return new WebGraphicsContext3DInProcessCommandBufferImpl( | |
598 attributes, false, window); | |
599 } | |
600 | |
601 // static | |
602 WebGraphicsContext3DInProcessCommandBufferImpl* | |
603 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | |
604 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | |
605 return new WebGraphicsContext3DInProcessCommandBufferImpl( | |
606 attributes, true, gfx::kNullAcceleratedWidget); | |
607 } | |
608 | |
577 WebGraphicsContext3DInProcessCommandBufferImpl:: | 609 WebGraphicsContext3DInProcessCommandBufferImpl:: |
578 WebGraphicsContext3DInProcessCommandBufferImpl( | 610 WebGraphicsContext3DInProcessCommandBufferImpl( |
579 const WebKit::WebGraphicsContext3D::Attributes& attributes) | 611 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
580 : initialized_(false), | 612 bool is_offscreen, |
613 gfx::AcceleratedWidget window) | |
614 : is_offscreen_(is_offscreen), | |
615 window_(window), | |
616 initialized_(false), | |
581 initialize_failed_(false), | 617 initialize_failed_(false), |
582 context_(NULL), | 618 context_(NULL), |
583 gl_(NULL), | 619 gl_(NULL), |
584 context_lost_callback_(NULL), | 620 context_lost_callback_(NULL), |
585 context_lost_reason_(GL_NO_ERROR), | 621 context_lost_reason_(GL_NO_ERROR), |
586 attributes_(attributes), | 622 attributes_(attributes), |
587 cached_width_(0), | 623 cached_width_(0), |
588 cached_height_(0), | 624 cached_height_(0), |
589 bound_fbo_(0) { | 625 bound_fbo_(0) { |
590 } | 626 } |
(...skipping 27 matching lines...) Expand all Loading... | |
618 | 654 |
619 const char* preferred_extensions = "*"; | 655 const char* preferred_extensions = "*"; |
620 | 656 |
621 // TODO(kbr): More work will be needed in this implementation to | 657 // TODO(kbr): More work will be needed in this implementation to |
622 // properly support GPU switching. Like in the out-of-process | 658 // properly support GPU switching. Like in the out-of-process |
623 // command buffer implementation, all previously created contexts | 659 // command buffer implementation, all previously created contexts |
624 // will need to be lost either when the first context requesting the | 660 // will need to be lost either when the first context requesting the |
625 // discrete GPU is created, or the last one is destroyed. | 661 // discrete GPU is created, or the last one is destroyed. |
626 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 662 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
627 | 663 |
628 context_ = GLInProcessContext::CreateOffscreenContext( | 664 context_ = GLInProcessContext::CreateContext( |
665 is_offscreen_, | |
666 window_, | |
629 gfx::Size(1, 1), | 667 gfx::Size(1, 1), |
630 attributes_.shareResources, | 668 attributes_.shareResources, |
631 preferred_extensions, | 669 preferred_extensions, |
632 attribs, | 670 attribs, |
633 gpu_preference); | 671 gpu_preference); |
634 | 672 |
635 if (!context_) { | 673 if (!context_) { |
636 initialize_failed_ = true; | 674 initialize_failed_ = true; |
637 return false; | 675 return false; |
638 } | 676 } |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1716 | 1754 |
1717 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1755 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
1718 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1756 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
1719 WGC3Denum, WGC3Denum, const void*) | 1757 WGC3Denum, WGC3Denum, const void*) |
1720 | 1758 |
1721 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1759 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
1722 WGC3Denum) | 1760 WGC3Denum) |
1723 | 1761 |
1724 } // namespace gpu | 1762 } // namespace gpu |
1725 } // namespace webkit | 1763 } // namespace webkit |
OLD | NEW |