Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 14318004: Add option to use GLContextVirtual in WGC3DIPCBI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix logic, remove ui/gl change (into separate patch) Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 #include "base/memory/singleton.h" 24 #include "base/memory/singleton.h"
25 #include "base/message_loop.h" 25 #include "base/message_loop.h"
26 #include "base/metrics/histogram.h" 26 #include "base/metrics/histogram.h"
27 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "gpu/command_buffer/client/gles2_implementation.h" 28 #include "gpu/command_buffer/client/gles2_implementation.h"
29 #include "gpu/command_buffer/client/gles2_lib.h" 29 #include "gpu/command_buffer/client/gles2_lib.h"
30 #include "gpu/command_buffer/client/transfer_buffer.h" 30 #include "gpu/command_buffer/client/transfer_buffer.h"
31 #include "gpu/command_buffer/common/constants.h" 31 #include "gpu/command_buffer/common/constants.h"
32 #include "gpu/command_buffer/service/command_buffer_service.h" 32 #include "gpu/command_buffer/service/command_buffer_service.h"
33 #include "gpu/command_buffer/service/context_group.h" 33 #include "gpu/command_buffer/service/context_group.h"
34 #include "gpu/command_buffer/service/gl_context_virtual.h"
35 #include "gpu/command_buffer/service/gpu_scheduler.h"
34 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 36 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
35 #include "gpu/command_buffer/service/gpu_scheduler.h"
36 #include "ui/gl/gl_context.h" 37 #include "ui/gl/gl_context.h"
37 #include "ui/gl/gl_share_group.h" 38 #include "ui/gl/gl_share_group.h"
38 #include "ui/gl/gl_surface.h" 39 #include "ui/gl/gl_surface.h"
39 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" 40 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h"
40 41
41 using gpu::Buffer; 42 using gpu::Buffer;
42 using gpu::CommandBuffer; 43 using gpu::CommandBuffer;
43 using gpu::CommandBufferService; 44 using gpu::CommandBufferService;
44 using gpu::gles2::GLES2CmdHelper; 45 using gpu::gles2::GLES2CmdHelper;
45 using gpu::gles2::GLES2Implementation; 46 using gpu::gles2::GLES2Implementation;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an 93 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an
93 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list 94 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list
94 // of attribute/value pairs. 95 // of attribute/value pairs.
95 static GLInProcessContext* CreateContext( 96 static GLInProcessContext* CreateContext(
96 bool is_offscreen, 97 bool is_offscreen,
97 gfx::AcceleratedWidget window, 98 gfx::AcceleratedWidget window,
98 const gfx::Size& size, 99 const gfx::Size& size,
99 bool share_resources, 100 bool share_resources,
100 const char* allowed_extensions, 101 const char* allowed_extensions,
101 const int32* attrib_list, 102 const int32* attrib_list,
102 gfx::GpuPreference gpu_preference); 103 gfx::GpuPreference gpu_preference,
104 bool use_virtualized_gl_context);
103 105
104 // For an offscreen frame buffer GLInProcessContext, return the texture ID 106 // For an offscreen frame buffer GLInProcessContext, return the texture ID
105 // with respect to the parent GLInProcessContext. Returns zero if 107 // with respect to the parent GLInProcessContext. Returns zero if
106 // GLInProcessContext does not have a parent. 108 // GLInProcessContext does not have a parent.
107 uint32 GetParentTextureId(); 109 uint32 GetParentTextureId();
108 110
109 // Create a new texture in the parent's GLInProcessContext. Returns zero if 111 // Create a new texture in the parent's GLInProcessContext. Returns zero if
110 // GLInProcessContext does not have a parent. 112 // GLInProcessContext does not have a parent.
111 uint32 CreateParentTexture(const gfx::Size& size); 113 uint32 CreateParentTexture(const gfx::Size& size);
112 114
(...skipping 30 matching lines...) Expand all
143 ::gpu::gles2::GLES2Decoder* GetDecoder(); 145 ::gpu::gles2::GLES2Decoder* GetDecoder();
144 146
145 private: 147 private:
146 explicit GLInProcessContext(bool share_resources); 148 explicit GLInProcessContext(bool share_resources);
147 149
148 bool Initialize(bool is_offscreen, 150 bool Initialize(bool is_offscreen,
149 gfx::AcceleratedWidget window, 151 gfx::AcceleratedWidget window,
150 const gfx::Size& size, 152 const gfx::Size& size,
151 const char* allowed_extensions, 153 const char* allowed_extensions,
152 const int32* attrib_list, 154 const int32* attrib_list,
153 gfx::GpuPreference gpu_preference); 155 gfx::GpuPreference gpu_preference,
156 bool use_virtualized_gl_context);
154 void Destroy(); 157 void Destroy();
155 158
156 void OnContextLost(); 159 void OnContextLost();
157 160
158 base::Closure context_lost_callback_; 161 base::Closure context_lost_callback_;
159 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 162 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
160 scoped_ptr<CommandBufferService> command_buffer_; 163 scoped_ptr<CommandBufferService> command_buffer_;
161 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; 164 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_;
162 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; 165 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_;
163 scoped_refptr<gfx::GLContext> context_; 166 scoped_refptr<gfx::GLContext> context_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 Destroy(); 210 Destroy();
208 } 211 }
209 212
210 GLInProcessContext* GLInProcessContext::CreateContext( 213 GLInProcessContext* GLInProcessContext::CreateContext(
211 bool is_offscreen, 214 bool is_offscreen,
212 gfx::AcceleratedWidget window, 215 gfx::AcceleratedWidget window,
213 const gfx::Size& size, 216 const gfx::Size& size,
214 bool share_resources, 217 bool share_resources,
215 const char* allowed_extensions, 218 const char* allowed_extensions,
216 const int32* attrib_list, 219 const int32* attrib_list,
217 gfx::GpuPreference gpu_preference) { 220 gfx::GpuPreference gpu_preference,
221 bool use_virtualized_gl_context) {
218 scoped_ptr<GLInProcessContext> context( 222 scoped_ptr<GLInProcessContext> context(
219 new GLInProcessContext(share_resources)); 223 new GLInProcessContext(share_resources));
220 if (!context->Initialize( 224 if (!context->Initialize(
221 is_offscreen, 225 is_offscreen,
222 window, 226 window,
223 size, 227 size,
224 allowed_extensions, 228 allowed_extensions,
225 attrib_list, 229 attrib_list,
226 gpu_preference)) 230 gpu_preference,
231 use_virtualized_gl_context))
227 return NULL; 232 return NULL;
228 233
229 return context.release(); 234 return context.release();
230 } 235 }
231 236
232 // 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
233 // to the gpu process where they are fed to the GLES2Decoder from a single 238 // to the gpu process where they are fed to the GLES2Decoder from a single
234 // thread. In layout tests, any thread could call this function. GLES2Decoder, 239 // thread. In layout tests, any thread could call this function. GLES2Decoder,
235 // and in particular the GL implementations behind it, are not generally 240 // and in particular the GL implementations behind it, are not generally
236 // threadsafe, so we guard entry points with a mutex. 241 // threadsafe, so we guard entry points with a mutex.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 share_resources_(share_resources), 392 share_resources_(share_resources),
388 context_lost_(false) { 393 context_lost_(false) {
389 } 394 }
390 395
391 bool GLInProcessContext::Initialize( 396 bool GLInProcessContext::Initialize(
392 bool is_offscreen, 397 bool is_offscreen,
393 gfx::AcceleratedWidget window, 398 gfx::AcceleratedWidget window,
394 const gfx::Size& size, 399 const gfx::Size& size,
395 const char* allowed_extensions, 400 const char* allowed_extensions,
396 const int32* attrib_list, 401 const int32* attrib_list,
397 gfx::GpuPreference gpu_preference) { 402 gfx::GpuPreference gpu_preference,
403 bool use_virtualized_gl_context) {
398 // Use one share group for all contexts. 404 // Use one share group for all contexts.
399 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, 405 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group,
400 (new gfx::GLShareGroup)); 406 (new gfx::GLShareGroup));
401 407
402 DCHECK(size.width() >= 0 && size.height() >= 0); 408 DCHECK(size.width() >= 0 && size.height() >= 0);
403 409
404 // Ensure the gles2 library is initialized first in a thread safe way. 410 // Ensure the gles2 library is initialized first in a thread safe way.
405 g_gles2_initializer.Get(); 411 g_gles2_initializer.Get();
406 412
407 std::vector<int32> attribs; 413 std::vector<int32> attribs;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); 477 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size);
472 else 478 else
473 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); 479 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window);
474 480
475 if (!surface_.get()) { 481 if (!surface_.get()) {
476 LOG(ERROR) << "Could not create GLSurface."; 482 LOG(ERROR) << "Could not create GLSurface.";
477 Destroy(); 483 Destroy();
478 return false; 484 return false;
479 } 485 }
480 486
481 context_ = gfx::GLContext::CreateGLContext(share_group.get(), 487 if (use_virtualized_gl_context) {
482 surface_.get(), 488 context_ = share_group->GetSharedContext();
483 gpu_preference); 489 if (!context_) {
490 context_ = gfx::GLContext::CreateGLContext(share_group.get(),
491 surface_.get(),
492 gpu_preference);
493 share_group->SetSharedContext(context_);
494 }
495
496 // This should be a non-virtual GL context.
497 DCHECK(context_->GetHandle());
no sievers 2013/04/19 18:38:40 Won't this DCHECK() fail for WebView (where we nev
498 context_ = new ::gpu::GLContextVirtual(share_group.get(),
499 context_,
500 decoder_->AsWeakPtr());
501 if (context_->Initialize(surface_, gpu_preference)) {
no sievers 2013/04/19 18:39:45 Oh, and you could fall back to the else-path in he
502 LOG(INFO) << "Created virtual GL context.";
503 }
504 } else {
505 context_ = gfx::GLContext::CreateGLContext(share_group.get(),
506 surface_.get(),
507 gpu_preference);
508 }
509
484 if (!context_.get()) { 510 if (!context_.get()) {
485 LOG(ERROR) << "Could not create GLContext."; 511 LOG(ERROR) << "Could not create GLContext.";
486 Destroy(); 512 Destroy();
487 return false; 513 return false;
488 } 514 }
489 515
490 if (!context_->MakeCurrent(surface_.get())) { 516 if (!context_->MakeCurrent(surface_.get())) {
491 LOG(ERROR) << "Could not make context current."; 517 LOG(ERROR) << "Could not make context current.";
492 Destroy(); 518 Destroy();
493 return false; 519 return false;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void GLInProcessContext::OnContextLost() { 607 void GLInProcessContext::OnContextLost() {
582 if (!context_lost_callback_.is_null()) 608 if (!context_lost_callback_.is_null())
583 context_lost_callback_.Run(); 609 context_lost_callback_.Run();
584 } 610 }
585 611
586 612
587 // static 613 // static
588 WebGraphicsContext3DInProcessCommandBufferImpl* 614 WebGraphicsContext3DInProcessCommandBufferImpl*
589 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 615 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
590 const WebKit::WebGraphicsContext3D::Attributes& attributes, 616 const WebKit::WebGraphicsContext3D::Attributes& attributes,
591 gfx::AcceleratedWidget window) { 617 gfx::AcceleratedWidget window,
618 bool use_virtualized_gl_context) {
592 return new WebGraphicsContext3DInProcessCommandBufferImpl( 619 return new WebGraphicsContext3DInProcessCommandBufferImpl(
593 attributes, false, window); 620 attributes, false, window, use_virtualized_gl_context);
594 } 621 }
595 622
596 // static 623 // static
597 WebGraphicsContext3DInProcessCommandBufferImpl* 624 WebGraphicsContext3DInProcessCommandBufferImpl*
598 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( 625 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
599 const WebKit::WebGraphicsContext3D::Attributes& attributes) { 626 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
600 return new WebGraphicsContext3DInProcessCommandBufferImpl( 627 return new WebGraphicsContext3DInProcessCommandBufferImpl(
601 attributes, true, gfx::kNullAcceleratedWidget); 628 attributes, true, gfx::kNullAcceleratedWidget, false);
602 } 629 }
603 630
604 WebGraphicsContext3DInProcessCommandBufferImpl:: 631 WebGraphicsContext3DInProcessCommandBufferImpl::
605 WebGraphicsContext3DInProcessCommandBufferImpl( 632 WebGraphicsContext3DInProcessCommandBufferImpl(
606 const WebKit::WebGraphicsContext3D::Attributes& attributes, 633 const WebKit::WebGraphicsContext3D::Attributes& attributes,
607 bool is_offscreen, 634 bool is_offscreen,
608 gfx::AcceleratedWidget window) 635 gfx::AcceleratedWidget window,
636 bool use_virtualized_gl_context)
609 : is_offscreen_(is_offscreen), 637 : is_offscreen_(is_offscreen),
610 window_(window), 638 window_(window),
639 use_virtualized_gl_context_(use_virtualized_gl_context),
611 initialized_(false), 640 initialized_(false),
612 initialize_failed_(false), 641 initialize_failed_(false),
613 context_(NULL), 642 context_(NULL),
614 gl_(NULL), 643 gl_(NULL),
615 context_lost_callback_(NULL), 644 context_lost_callback_(NULL),
616 context_lost_reason_(GL_NO_ERROR), 645 context_lost_reason_(GL_NO_ERROR),
617 attributes_(attributes), 646 attributes_(attributes),
618 cached_width_(0), 647 cached_width_(0),
619 cached_height_(0), 648 cached_height_(0),
620 bound_fbo_(0) { 649 bound_fbo_(0) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // discrete GPU is created, or the last one is destroyed. 685 // discrete GPU is created, or the last one is destroyed.
657 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 686 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
658 687
659 context_ = GLInProcessContext::CreateContext( 688 context_ = GLInProcessContext::CreateContext(
660 is_offscreen_, 689 is_offscreen_,
661 window_, 690 window_,
662 gfx::Size(1, 1), 691 gfx::Size(1, 1),
663 attributes_.shareResources, 692 attributes_.shareResources,
664 preferred_extensions, 693 preferred_extensions,
665 attribs, 694 attribs,
666 gpu_preference); 695 gpu_preference,
696 use_virtualized_gl_context_);
667 697
668 if (!context_) { 698 if (!context_) {
669 initialize_failed_ = true; 699 initialize_failed_ = true;
670 return false; 700 return false;
671 } 701 }
672 702
673 gl_ = context_->GetImplementation(); 703 gl_ = context_->GetImplementation();
674 704
675 if (gl_ && attributes_.noExtensions) 705 if (gl_ && attributes_.noExtensions)
676 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); 706 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1779
1750 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, 1780 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1751 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, 1781 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1752 WGC3Denum, WGC3Denum, const void*) 1782 WGC3Denum, WGC3Denum, const void*)
1753 1783
1754 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, 1784 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1755 WGC3Denum) 1785 WGC3Denum)
1756 1786
1757 } // namespace gpu 1787 } // namespace gpu
1758 } // namespace webkit 1788 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698