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

Side by Side Diff: content/browser/compositor/gpu_process_transport_factory.cc

Issue 1900993002: Move SharedMemoryLimits out of WebGraphicsContext3DCommandBufferImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@limits
Patch Set: move-limits: . Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/compositor/gpu_process_transport_factory.h" 5 #include "content/browser/compositor/gpu_process_transport_factory.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 27 matching lines...) Expand all
38 #include "content/browser/gpu/gpu_data_manager_impl.h" 38 #include "content/browser/gpu/gpu_data_manager_impl.h"
39 #include "content/browser/gpu/gpu_surface_tracker.h" 39 #include "content/browser/gpu/gpu_surface_tracker.h"
40 #include "content/browser/renderer_host/render_widget_host_impl.h" 40 #include "content/browser/renderer_host/render_widget_host_impl.h"
41 #include "content/common/gpu/client/context_provider_command_buffer.h" 41 #include "content/common/gpu/client/context_provider_command_buffer.h"
42 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 42 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
43 #include "content/common/gpu_process_launch_causes.h" 43 #include "content/common/gpu_process_launch_causes.h"
44 #include "content/common/host_shared_bitmap_manager.h" 44 #include "content/common/host_shared_bitmap_manager.h"
45 #include "content/public/common/content_switches.h" 45 #include "content/public/common/content_switches.h"
46 #include "gpu/GLES2/gl2extchromium.h" 46 #include "gpu/GLES2/gl2extchromium.h"
47 #include "gpu/command_buffer/client/gles2_interface.h" 47 #include "gpu/command_buffer/client/gles2_interface.h"
48 #include "gpu/command_buffer/client/shared_memory_limits.h"
48 #include "gpu/command_buffer/common/mailbox.h" 49 #include "gpu/command_buffer/common/mailbox.h"
49 #include "gpu/ipc/client/gpu_channel_host.h" 50 #include "gpu/ipc/client/gpu_channel_host.h"
50 #include "third_party/khronos/GLES2/gl2.h" 51 #include "third_party/khronos/GLES2/gl2.h"
51 #include "ui/compositor/compositor.h" 52 #include "ui/compositor/compositor.h"
52 #include "ui/compositor/compositor_constants.h" 53 #include "ui/compositor/compositor_constants.h"
53 #include "ui/compositor/compositor_switches.h" 54 #include "ui/compositor/compositor_switches.h"
54 #include "ui/compositor/layer.h" 55 #include "ui/compositor/layer.h"
55 #include "ui/gfx/geometry/size.h" 56 #include "ui/gfx/geometry/size.h"
56 57
57 #if defined(MOJO_RUNNER_CLIENT) 58 #if defined(MOJO_RUNNER_CLIENT)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 attributes.bind_generates_resource = false; 114 attributes.bind_generates_resource = false;
114 attributes.lose_context_when_out_of_memory = true; 115 attributes.lose_context_when_out_of_memory = true;
115 116
116 bool share_resources = true; 117 bool share_resources = true;
117 bool automatic_flushes = false; 118 bool automatic_flushes = false;
118 119
119 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); 120 GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon");
120 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl( 121 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl(
121 surface_handle, url, gpu_channel_host.get(), attributes, 122 surface_handle, url, gpu_channel_host.get(), attributes,
122 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, 123 gfx::PreferIntegratedGpu, share_resources, automatic_flushes,
123 content::WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits(),
124 nullptr)); 124 nullptr));
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 namespace content { 129 namespace content {
130 130
131 struct GpuProcessTransportFactory::PerCompositorData { 131 struct GpuProcessTransportFactory::PerCompositorData {
132 int surface_id; 132 int surface_id;
133 BrowserCompositorOutputSurface* surface; 133 BrowserCompositorOutputSurface* surface;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 #endif 300 #endif
301 301
302 scoped_refptr<ContextProviderCommandBuffer> context_provider; 302 scoped_refptr<ContextProviderCommandBuffer> context_provider;
303 if (create_gpu_output_surface) { 303 if (create_gpu_output_surface) {
304 // Try to reuse existing worker context provider. 304 // Try to reuse existing worker context provider.
305 if (shared_worker_context_provider_) { 305 if (shared_worker_context_provider_) {
306 bool lost; 306 bool lost;
307 { 307 {
308 // Note: If context is lost, we delete reference after releasing the 308 // Note: If context is lost, we delete reference after releasing the
309 // lock. 309 // lock.
310 cc::ContextProvider::ScopedContextLock(
311 shared_worker_context_provider_.get());
310 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); 312 base::AutoLock lock(*shared_worker_context_provider_->GetLock());
311 lost = shared_worker_context_provider_->ContextGL() 313 lost = shared_worker_context_provider_->ContextGL()
312 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR; 314 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
313 } 315 }
314 if (lost) 316 if (lost)
315 shared_worker_context_provider_ = nullptr; 317 shared_worker_context_provider_ = nullptr;
316 } 318 }
317 319
318 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; 320 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
319 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { 321 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) {
320 // We attempted to do EstablishGpuChannel already, so we just use 322 // We attempted to do EstablishGpuChannel already, so we just use
321 // GetGpuChannel() instead of EstablishGpuChannelSync(). 323 // GetGpuChannel() instead of EstablishGpuChannelSync().
322 gpu_channel_host = 324 gpu_channel_host =
323 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); 325 BrowserGpuChannelHostFactory::instance()->GetGpuChannel();
324 } 326 }
325 327
326 if (!gpu_channel_host) { 328 if (!gpu_channel_host) {
327 shared_worker_context_provider_ = nullptr; 329 shared_worker_context_provider_ = nullptr;
328 } else { 330 } else {
329 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); 331 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get();
330 gpu::SurfaceHandle surface_handle = 332 gpu::SurfaceHandle surface_handle =
331 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id) 333 data->surface_id ? tracker->GetSurfaceHandle(data->surface_id)
332 : gpu::kNullSurfaceHandle; 334 : gpu::kNullSurfaceHandle;
333 335
334 // This context is used for both the browser compositor and the display 336 // This context is used for both the browser compositor and the display
335 // compositor. 337 // compositor.
336 context_provider = new ContextProviderCommandBuffer( 338 context_provider = new ContextProviderCommandBuffer(
337 CreateContextCommon(gpu_channel_host, surface_handle), 339 CreateContextCommon(gpu_channel_host, surface_handle),
338 DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); 340 gpu::SharedMemoryLimits(), DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
339 if (!context_provider->BindToCurrentThread()) 341 if (!context_provider->BindToCurrentThread())
340 context_provider = nullptr; 342 context_provider = nullptr;
341 343
342 if (!shared_worker_context_provider_) { 344 if (!shared_worker_context_provider_) {
343 shared_worker_context_provider_ = new ContextProviderCommandBuffer( 345 shared_worker_context_provider_ = new ContextProviderCommandBuffer(
344 CreateContextCommon(std::move(gpu_channel_host), 346 CreateContextCommon(std::move(gpu_channel_host),
345 gpu::kNullSurfaceHandle), 347 gpu::kNullSurfaceHandle),
346 BROWSER_WORKER_CONTEXT); 348 gpu::SharedMemoryLimits(), BROWSER_WORKER_CONTEXT);
347 if (shared_worker_context_provider_->BindToCurrentThread()) 349 if (shared_worker_context_provider_->BindToCurrentThread())
348 shared_worker_context_provider_->SetupLock(); 350 shared_worker_context_provider_->SetupLock();
349 else 351 else
350 shared_worker_context_provider_ = nullptr; 352 shared_worker_context_provider_ = nullptr;
351 } 353 }
352 } 354 }
353 355
354 bool created_gpu_browser_compositor = 356 bool created_gpu_browser_compositor =
355 !!context_provider && !!shared_worker_context_provider_; 357 !!context_provider && !!shared_worker_context_provider_;
356 358
(...skipping 12 matching lines...) Expand all
369 } 371 }
370 } 372 }
371 373
372 std::unique_ptr<BrowserCompositorOutputSurface> surface; 374 std::unique_ptr<BrowserCompositorOutputSurface> surface;
373 if (!create_gpu_output_surface) { 375 if (!create_gpu_output_surface) {
374 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface( 376 surface = base::WrapUnique(new SoftwareBrowserCompositorOutputSurface(
375 CreateSoftwareOutputDevice(compositor.get()), 377 CreateSoftwareOutputDevice(compositor.get()),
376 compositor->vsync_manager(), compositor->task_runner().get())); 378 compositor->vsync_manager(), compositor->task_runner().get()));
377 } else { 379 } else {
378 DCHECK(context_provider); 380 DCHECK(context_provider);
379 ContextProvider::Capabilities capabilities = 381 const auto& capabilities = context_provider->ContextCapabilities();
380 context_provider->ContextCapabilities();
381 if (!data->surface_id) { 382 if (!data->surface_id) {
382 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface( 383 surface = base::WrapUnique(new OffscreenBrowserCompositorOutputSurface(
383 context_provider, shared_worker_context_provider_, 384 context_provider, shared_worker_context_provider_,
384 compositor->vsync_manager(), compositor->task_runner().get(), 385 compositor->vsync_manager(), compositor->task_runner().get(),
385 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>())); 386 std::unique_ptr<BrowserCompositorOverlayCandidateValidator>()));
386 } else if (capabilities.gpu.surfaceless) { 387 } else if (capabilities.surfaceless) {
387 GLenum target = GL_TEXTURE_2D; 388 GLenum target = GL_TEXTURE_2D;
388 GLenum format = GL_RGB; 389 GLenum format = GL_RGB;
389 #if defined(OS_MACOSX) 390 #if defined(OS_MACOSX)
390 target = GL_TEXTURE_RECTANGLE_ARB; 391 target = GL_TEXTURE_RECTANGLE_ARB;
391 format = GL_RGBA; 392 format = GL_RGBA;
392 #endif 393 #endif
393 surface = 394 surface =
394 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( 395 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface(
395 context_provider, shared_worker_context_provider_, 396 context_provider, shared_worker_context_provider_,
396 data->surface_id, compositor->vsync_manager(), 397 data->surface_id, compositor->vsync_manager(),
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; 622 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
622 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( 623 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
623 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause)); 624 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
624 if (!gpu_channel_host) 625 if (!gpu_channel_host)
625 return nullptr; 626 return nullptr;
626 627
627 // We need a separate context from the compositor's so that skia and gl_helper 628 // We need a separate context from the compositor's so that skia and gl_helper
628 // don't step on each other. 629 // don't step on each other.
629 shared_main_thread_contexts_ = new ContextProviderCommandBuffer( 630 shared_main_thread_contexts_ = new ContextProviderCommandBuffer(
630 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle), 631 CreateContextCommon(std::move(gpu_channel_host), gpu::kNullSurfaceHandle),
631 BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); 632 gpu::SharedMemoryLimits(), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
632 shared_main_thread_contexts_->SetLostContextCallback(base::Bind( 633 shared_main_thread_contexts_->SetLostContextCallback(base::Bind(
633 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback, 634 &GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback,
634 callback_factory_.GetWeakPtr())); 635 callback_factory_.GetWeakPtr()));
635 if (!shared_main_thread_contexts_->BindToCurrentThread()) 636 if (!shared_main_thread_contexts_->BindToCurrentThread())
636 shared_main_thread_contexts_ = nullptr; 637 shared_main_thread_contexts_ = nullptr;
637 return shared_main_thread_contexts_; 638 return shared_main_thread_contexts_;
638 } 639 }
639 640
640 GpuProcessTransportFactory::PerCompositorData* 641 GpuProcessTransportFactory::PerCompositorData*
641 GpuProcessTransportFactory::CreatePerCompositorData( 642 GpuProcessTransportFactory::CreatePerCompositorData(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, 681 FOR_EACH_OBSERVER(ImageTransportFactoryObserver,
681 observer_list_, 682 observer_list_,
682 OnLostResources()); 683 OnLostResources());
683 684
684 // Kill things that use the shared context before killing the shared context. 685 // Kill things that use the shared context before killing the shared context.
685 lost_gl_helper.reset(); 686 lost_gl_helper.reset();
686 lost_shared_main_thread_contexts = NULL; 687 lost_shared_main_thread_contexts = NULL;
687 } 688 }
688 689
689 } // namespace content 690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698