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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 7 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #ifndef GL_GLEXT_PROTOTYPES | 10 #ifndef GL_GLEXT_PROTOTYPES |
11 #define GL_GLEXT_PROTOTYPES 1 | 11 #define GL_GLEXT_PROTOTYPES 1 |
12 #endif | 12 #endif |
13 #include <GLES2/gl2ext.h> | 13 #include <GLES2/gl2ext.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include "base/string_tokenizer.h" | 18 #include "base/bind.h" |
| 19 #include "base/bind_helpers.h" |
| 20 #include "base/callback.h" |
19 #include "base/command_line.h" | 21 #include "base/command_line.h" |
20 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
21 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/memory/singleton.h" |
22 #include "base/message_loop.h" | 25 #include "base/message_loop.h" |
23 #include "base/memory/singleton.h" | |
24 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
| 27 #include "base/string_tokenizer.h" |
25 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
26 #include "gpu/command_buffer/client/gles2_lib.h" | 29 #include "gpu/command_buffer/client/gles2_lib.h" |
27 #include "gpu/command_buffer/client/gles2_implementation.h" | 30 #include "gpu/command_buffer/client/gles2_implementation.h" |
28 #include "gpu/command_buffer/common/constants.h" | 31 #include "gpu/command_buffer/common/constants.h" |
29 #include "gpu/command_buffer/service/context_group.h" | 32 #include "gpu/command_buffer/service/context_group.h" |
30 #include "gpu/command_buffer/service/gpu_scheduler.h" | 33 #include "gpu/command_buffer/service/gpu_scheduler.h" |
31 #include "gpu/command_buffer/service/command_buffer_service.h" | 34 #include "gpu/command_buffer/service/command_buffer_service.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 133 |
131 // Create a new texture in the parent's GLInProcessContext. Returns zero if | 134 // Create a new texture in the parent's GLInProcessContext. Returns zero if |
132 // GLInProcessContext does not have a parent. | 135 // GLInProcessContext does not have a parent. |
133 uint32 CreateParentTexture(const gfx::Size& size); | 136 uint32 CreateParentTexture(const gfx::Size& size); |
134 | 137 |
135 // Deletes a texture in the parent's GLInProcessContext. | 138 // Deletes a texture in the parent's GLInProcessContext. |
136 void DeleteParentTexture(uint32 texture); | 139 void DeleteParentTexture(uint32 texture); |
137 | 140 |
138 // Provides a callback that will be invoked when SwapBuffers has completed | 141 // Provides a callback that will be invoked when SwapBuffers has completed |
139 // service side. | 142 // service side. |
140 void SetSwapBuffersCallback(Callback0::Type* callback); | 143 void SetSwapBuffersCallback(const base::Closure& callback); |
141 | 144 |
142 void SetContextLostCallback(Callback0::Type* callback); | 145 void SetContextLostCallback(const base::Closure& callback); |
143 | 146 |
144 // Set the current GLInProcessContext for the calling thread. | 147 // Set the current GLInProcessContext for the calling thread. |
145 static bool MakeCurrent(GLInProcessContext* context); | 148 static bool MakeCurrent(GLInProcessContext* context); |
146 | 149 |
147 // For a view GLInProcessContext, display everything that has been rendered | 150 // For a view GLInProcessContext, display everything that has been rendered |
148 // since the last call. For an offscreen GLInProcessContext, resolve | 151 // since the last call. For an offscreen GLInProcessContext, resolve |
149 // everything that has been rendered since the last call to a copy that can be | 152 // everything that has been rendered since the last call to a copy that can be |
150 // accessed by the parent GLInProcessContext. | 153 // accessed by the parent GLInProcessContext. |
151 bool SwapBuffers(); | 154 bool SwapBuffers(); |
152 | 155 |
(...skipping 23 matching lines...) Expand all Loading... |
176 const char* allowed_extensions, | 179 const char* allowed_extensions, |
177 const int32* attrib_list, | 180 const int32* attrib_list, |
178 const GURL& active_url, | 181 const GURL& active_url, |
179 gfx::GpuPreference gpu_preference); | 182 gfx::GpuPreference gpu_preference); |
180 void Destroy(); | 183 void Destroy(); |
181 | 184 |
182 void OnSwapBuffers(); | 185 void OnSwapBuffers(); |
183 void OnContextLost(); | 186 void OnContextLost(); |
184 | 187 |
185 base::WeakPtr<GLInProcessContext> parent_; | 188 base::WeakPtr<GLInProcessContext> parent_; |
186 scoped_ptr<Callback0::Type> swap_buffers_callback_; | 189 base::Closure swap_buffers_callback_; |
187 scoped_ptr<Callback0::Type> context_lost_callback_; | 190 base::Closure context_lost_callback_; |
188 uint32 parent_texture_id_; | 191 uint32 parent_texture_id_; |
189 scoped_ptr<CommandBufferService> command_buffer_; | 192 scoped_ptr<CommandBufferService> command_buffer_; |
190 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 193 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
191 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 194 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
192 scoped_refptr<gfx::GLContext> context_; | 195 scoped_refptr<gfx::GLContext> context_; |
193 scoped_refptr<gfx::GLSurface> surface_; | 196 scoped_refptr<gfx::GLSurface> surface_; |
194 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 197 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
195 int32 transfer_buffer_id_; | 198 int32 transfer_buffer_id_; |
196 scoped_ptr<GLES2Implementation> gles2_implementation_; | 199 scoped_ptr<GLES2Implementation> gles2_implementation_; |
197 Error last_error_; | 200 Error last_error_; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 uint32 texture = 0; | 319 uint32 texture = 0; |
317 gles2_implementation_->GenTextures(1, &texture); | 320 gles2_implementation_->GenTextures(1, &texture); |
318 gles2_implementation_->Flush(); | 321 gles2_implementation_->Flush(); |
319 return texture; | 322 return texture; |
320 } | 323 } |
321 | 324 |
322 void GLInProcessContext::DeleteParentTexture(uint32 texture) { | 325 void GLInProcessContext::DeleteParentTexture(uint32 texture) { |
323 gles2_implementation_->DeleteTextures(1, &texture); | 326 gles2_implementation_->DeleteTextures(1, &texture); |
324 } | 327 } |
325 | 328 |
326 void GLInProcessContext::SetSwapBuffersCallback(Callback0::Type* callback) { | 329 void GLInProcessContext::SetSwapBuffersCallback(const base::Closure& callback) { |
327 swap_buffers_callback_.reset(callback); | 330 swap_buffers_callback_ = callback; |
328 } | 331 } |
329 | 332 |
330 void GLInProcessContext::SetContextLostCallback(Callback0::Type* callback) { | 333 void GLInProcessContext::SetContextLostCallback(const base::Closure& callback) { |
331 context_lost_callback_.reset(callback); | 334 context_lost_callback_ = callback; |
332 } | 335 } |
333 | 336 |
334 bool GLInProcessContext::MakeCurrent(GLInProcessContext* context) { | 337 bool GLInProcessContext::MakeCurrent(GLInProcessContext* context) { |
335 if (context) { | 338 if (context) { |
336 gles2::SetGLContext(context->gles2_implementation_.get()); | 339 gles2::SetGLContext(context->gles2_implementation_.get()); |
337 | 340 |
338 // Don't request latest error status from service. Just use the locally | 341 // Don't request latest error status from service. Just use the locally |
339 // cached information from the last flush. | 342 // cached information from the last flush. |
340 // TODO(apatrick): I'm not sure if this should actually change the | 343 // TODO(apatrick): I'm not sure if this should actually change the |
341 // current context if it fails. For now it gets changed even if it fails | 344 // current context if it fails. For now it gets changed even if it fails |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 515 |
513 if (!decoder_->SetParent( | 516 if (!decoder_->SetParent( |
514 parent_.get() ? parent_->decoder_.get() : NULL, | 517 parent_.get() ? parent_->decoder_.get() : NULL, |
515 parent_texture_id_)) { | 518 parent_texture_id_)) { |
516 LOG(ERROR) << "Could not set parent."; | 519 LOG(ERROR) << "Could not set parent."; |
517 Destroy(); | 520 Destroy(); |
518 return false; | 521 return false; |
519 } | 522 } |
520 | 523 |
521 command_buffer_->SetPutOffsetChangeCallback( | 524 command_buffer_->SetPutOffsetChangeCallback( |
522 NewCallback(this, &GLInProcessContext::PumpCommands)); | 525 base::Bind(&GLInProcessContext::PumpCommands, base::Unretained(this))); |
523 | 526 |
524 // Create the GLES2 helper, which writes the command buffer protocol. | 527 // Create the GLES2 helper, which writes the command buffer protocol. |
525 gles2_helper_.reset(new GLES2CmdHelper(command_buffer_.get())); | 528 gles2_helper_.reset(new GLES2CmdHelper(command_buffer_.get())); |
526 if (!gles2_helper_->Initialize(kCommandBufferSize)) { | 529 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
527 Destroy(); | 530 Destroy(); |
528 return false; | 531 return false; |
529 } | 532 } |
530 | 533 |
531 // Create a transfer buffer. | 534 // Create a transfer buffer. |
532 transfer_buffer_id_ = | 535 transfer_buffer_id_ = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_); | 581 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_); |
579 transfer_buffer_id_ = -1; | 582 transfer_buffer_id_ = -1; |
580 } | 583 } |
581 | 584 |
582 gles2_helper_.reset(); | 585 gles2_helper_.reset(); |
583 | 586 |
584 command_buffer_.reset(); | 587 command_buffer_.reset(); |
585 } | 588 } |
586 | 589 |
587 void GLInProcessContext::OnSwapBuffers() { | 590 void GLInProcessContext::OnSwapBuffers() { |
588 if (swap_buffers_callback_.get()) | 591 if (!swap_buffers_callback_.is_null()) |
589 swap_buffers_callback_->Run(); | 592 swap_buffers_callback_.Run(); |
590 } | 593 } |
591 | 594 |
592 void GLInProcessContext::OnContextLost() { | 595 void GLInProcessContext::OnContextLost() { |
593 if (context_lost_callback_.get()) | 596 if (!context_lost_callback_.is_null()) |
594 context_lost_callback_->Run(); | 597 context_lost_callback_.Run(); |
595 } | 598 } |
596 | 599 |
597 WebGraphicsContext3DInProcessCommandBufferImpl:: | 600 WebGraphicsContext3DInProcessCommandBufferImpl:: |
598 WebGraphicsContext3DInProcessCommandBufferImpl() | 601 WebGraphicsContext3DInProcessCommandBufferImpl() |
599 : context_(NULL), | 602 : context_(NULL), |
600 gl_(NULL), | 603 gl_(NULL), |
601 web_view_(NULL), | 604 web_view_(NULL), |
602 #if defined(OS_MACOSX) | 605 #if defined(OS_MACOSX) |
603 plugin_handle_(NULL), | 606 plugin_handle_(NULL), |
604 #endif // defined(OS_MACOSX) | 607 #endif // defined(OS_MACOSX) |
605 context_lost_callback_(0), | 608 context_lost_callback_(NULL), |
606 context_lost_reason_(GL_NO_ERROR), | 609 context_lost_reason_(GL_NO_ERROR), |
607 cached_width_(0), | 610 cached_width_(0), |
608 cached_height_(0), | 611 cached_height_(0), |
609 bound_fbo_(0) { | 612 bound_fbo_(0) { |
610 } | 613 } |
611 | 614 |
612 WebGraphicsContext3DInProcessCommandBufferImpl:: | 615 WebGraphicsContext3DInProcessCommandBufferImpl:: |
613 ~WebGraphicsContext3DInProcessCommandBufferImpl() { | 616 ~WebGraphicsContext3DInProcessCommandBufferImpl() { |
614 base::AutoLock a(g_all_shared_contexts_lock.Get()); | 617 base::AutoLock a(g_all_shared_contexts_lock.Get()); |
615 g_all_shared_contexts.Pointer()->erase(this); | 618 g_all_shared_contexts.Pointer()->erase(this); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 681 |
679 if (!context_) | 682 if (!context_) |
680 return false; | 683 return false; |
681 | 684 |
682 gl_ = context_->GetImplementation(); | 685 gl_ = context_->GetImplementation(); |
683 | 686 |
684 if (gl_ && attributes.noExtensions) | 687 if (gl_ && attributes.noExtensions) |
685 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 688 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
686 | 689 |
687 context_->SetContextLostCallback( | 690 context_->SetContextLostCallback( |
688 NewCallback( | 691 base::Bind( |
689 this, | 692 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, |
690 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost)); | 693 base::Unretained(this))); |
691 | 694 |
692 // Set attributes_ from created offscreen context. | 695 // Set attributes_ from created offscreen context. |
693 { | 696 { |
694 attributes_ = attributes; | 697 attributes_ = attributes; |
695 GLint alpha_bits = 0; | 698 GLint alpha_bits = 0; |
696 getIntegerv(GL_ALPHA_BITS, &alpha_bits); | 699 getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
697 attributes_.alpha = alpha_bits > 0; | 700 attributes_.alpha = alpha_bits > 0; |
698 GLint depth_bits = 0; | 701 GLint depth_bits = 0; |
699 getIntegerv(GL_DEPTH_BITS, &depth_bits); | 702 getIntegerv(GL_DEPTH_BITS, &depth_bits); |
700 attributes_.depth = depth_bits > 0; | 703 attributes_.depth = depth_bits > 0; |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1675 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
1673 if (context_lost_callback_) { | 1676 if (context_lost_callback_) { |
1674 context_lost_callback_->onContextLost(); | 1677 context_lost_callback_->onContextLost(); |
1675 } | 1678 } |
1676 } | 1679 } |
1677 | 1680 |
1678 } // namespace gpu | 1681 } // namespace gpu |
1679 } // namespace webkit | 1682 } // namespace webkit |
1680 | 1683 |
1681 #endif // defined(ENABLE_GPU) | 1684 #endif // defined(ENABLE_GPU) |
OLD | NEW |