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

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2257533006: Free worker context resources on idle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cleanup2
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « cc/test/test_context_support.cc ('k') | gpu/command_buffer/client/context_support.h » ('j') | 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 "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #include "content/renderer/render_process_impl.h" 116 #include "content/renderer/render_process_impl.h"
117 #include "content/renderer/render_view_impl.h" 117 #include "content/renderer/render_view_impl.h"
118 #include "content/renderer/renderer_blink_platform_impl.h" 118 #include "content/renderer/renderer_blink_platform_impl.h"
119 #include "content/renderer/scheduler/resource_dispatch_throttler.h" 119 #include "content/renderer/scheduler/resource_dispatch_throttler.h"
120 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" 120 #include "content/renderer/service_worker/embedded_worker_dispatcher.h"
121 #include "content/renderer/service_worker/service_worker_context_client.h" 121 #include "content/renderer/service_worker/service_worker_context_client.h"
122 #include "content/renderer/service_worker/service_worker_context_message_filter. h" 122 #include "content/renderer/service_worker/service_worker_context_message_filter. h"
123 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" 123 #include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
124 #include "gin/public/debug.h" 124 #include "gin/public/debug.h"
125 #include "gpu/GLES2/gl2extchromium.h" 125 #include "gpu/GLES2/gl2extchromium.h"
126 #include "gpu/command_buffer/client/context_support.h"
126 #include "gpu/command_buffer/client/shared_memory_limits.h" 127 #include "gpu/command_buffer/client/shared_memory_limits.h"
127 #include "gpu/ipc/client/command_buffer_proxy_impl.h" 128 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
128 #include "gpu/ipc/client/gpu_channel_host.h" 129 #include "gpu/ipc/client/gpu_channel_host.h"
129 #include "ipc/ipc_channel_handle.h" 130 #include "ipc/ipc_channel_handle.h"
130 #include "ipc/ipc_channel_mojo.h" 131 #include "ipc/ipc_channel_mojo.h"
131 #include "ipc/ipc_platform_file.h" 132 #include "ipc/ipc_platform_file.h"
132 #include "media/base/media.h" 133 #include "media/base/media.h"
133 #include "media/renderers/gpu_video_accelerator_factories.h" 134 #include "media/renderers/gpu_video_accelerator_factories.h"
134 #include "mojo/common/common_type_converters.h" 135 #include "mojo/common/common_type_converters.h"
135 #include "mojo/public/cpp/bindings/strong_binding.h" 136 #include "mojo/public/cpp/bindings/strong_binding.h"
(...skipping 17 matching lines...) Expand all
153 #include "third_party/WebKit/public/web/WebDocument.h" 154 #include "third_party/WebKit/public/web/WebDocument.h"
154 #include "third_party/WebKit/public/web/WebFrame.h" 155 #include "third_party/WebKit/public/web/WebFrame.h"
155 #include "third_party/WebKit/public/web/WebKit.h" 156 #include "third_party/WebKit/public/web/WebKit.h"
156 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 157 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
157 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 158 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
158 #include "third_party/WebKit/public/web/WebScriptController.h" 159 #include "third_party/WebKit/public/web/WebScriptController.h"
159 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 160 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
160 #include "third_party/WebKit/public/web/WebView.h" 161 #include "third_party/WebKit/public/web/WebView.h"
161 #include "third_party/icu/source/i18n/unicode/timezone.h" 162 #include "third_party/icu/source/i18n/unicode/timezone.h"
162 #include "third_party/skia/include/core/SkGraphics.h" 163 #include "third_party/skia/include/core/SkGraphics.h"
164 #include "third_party/skia/include/gpu/GrContext.h"
163 #include "ui/base/layout.h" 165 #include "ui/base/layout.h"
164 #include "ui/base/ui_base_switches.h" 166 #include "ui/base/ui_base_switches.h"
165 167
166 #if defined(OS_ANDROID) 168 #if defined(OS_ANDROID)
167 #include <cpu-features.h> 169 #include <cpu-features.h>
168 #include "content/renderer/android/synchronous_compositor_filter.h" 170 #include "content/renderer/android/synchronous_compositor_filter.h"
169 #include "content/renderer/android/synchronous_compositor_output_surface.h" 171 #include "content/renderer/android/synchronous_compositor_output_surface.h"
170 #include "content/renderer/media/android/renderer_demuxer_android.h" 172 #include "content/renderer/media/android/renderer_demuxer_android.h"
171 #include "content/renderer/media/android/stream_texture_factory.h" 173 #include "content/renderer/media/android/stream_texture_factory.h"
172 #include "media/base/android/media_codec_util.h" 174 #include "media/base/android/media_codec_util.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 gpu::kNullSurfaceHandle, 435 gpu::kNullSurfaceHandle,
434 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext"), 436 GURL("chrome://gpu/RenderThreadImpl::CreateOffscreenContext"),
435 automatic_flushes, support_locking, limits, attributes, nullptr, type)); 437 automatic_flushes, support_locking, limits, attributes, nullptr, type));
436 } 438 }
437 439
438 bool IsRunningInMash() { 440 bool IsRunningInMash() {
439 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 441 const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
440 return cmdline->HasSwitch(switches::kIsRunningInMash); 442 return cmdline->HasSwitch(switches::kIsRunningInMash);
441 } 443 }
442 444
445 void OnSharedWorkerContextIdle(cc::ContextProvider* context_provider) {
446 // If we can't acquire the lock, someone has started using this context, so
447 // we are no longer idle.
448 base::Lock* lock = context_provider->GetLock();
449 if (!lock->Try())
450 return;
451
452 context_provider->DetachFromThread();
453 context_provider->BindToCurrentThread();
454
455 context_provider->DeleteCachedResources();
456
457 // Detach from thread to allow a new thread to attach.
458 context_provider->DetachFromThread();
459 lock->Release();
460 }
461
443 } // namespace 462 } // namespace
444 463
445 // For measuring memory usage after each task. Behind a command line flag. 464 // For measuring memory usage after each task. Behind a command line flag.
446 class MemoryObserver : public base::MessageLoop::TaskObserver { 465 class MemoryObserver : public base::MessageLoop::TaskObserver {
447 public: 466 public:
448 MemoryObserver() {} 467 MemoryObserver() {}
449 ~MemoryObserver() override {} 468 ~MemoryObserver() override {}
450 469
451 void WillProcessTask(const base::PendingTask& pending_task) override {} 470 void WillProcessTask(const base::PendingTask& pending_task) override {}
452 471
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 stream_priority = gpu::GpuStreamPriority::LOW; 2138 stream_priority = gpu::GpuStreamPriority::LOW;
2120 } 2139 }
2121 2140
2122 bool support_locking = true; 2141 bool support_locking = true;
2123 shared_worker_context_provider_ = CreateOffscreenContext( 2142 shared_worker_context_provider_ = CreateOffscreenContext(
2124 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking, 2143 std::move(gpu_channel_host), gpu::SharedMemoryLimits(), support_locking,
2125 command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id, 2144 command_buffer_metrics::RENDER_WORKER_CONTEXT, stream_id,
2126 stream_priority); 2145 stream_priority);
2127 if (!shared_worker_context_provider_->BindToCurrentThread()) 2146 if (!shared_worker_context_provider_->BindToCurrentThread())
2128 shared_worker_context_provider_ = nullptr; 2147 shared_worker_context_provider_ = nullptr;
2148
2149 // Set the idle callback. This callback is only called if ContextSupport
2150 // is alive, so we know that the unretained worker context provider
2151 // pointer will also be alive.
2152 shared_worker_context_provider_->ContextSupport()->SetIdleCallback(
2153 base::Bind(&OnSharedWorkerContextIdle,
2154 base::Unretained(shared_worker_context_provider_.get())));
2129 return shared_worker_context_provider_; 2155 return shared_worker_context_provider_;
2130 } 2156 }
2131 2157
2132 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { 2158 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) {
2133 blink_platform_impl_->sampleGamepads(*data); 2159 blink_platform_impl_->sampleGamepads(*data);
2134 } 2160 }
2135 2161
2136 bool RenderThreadImpl::RendererIsHidden() const { 2162 bool RenderThreadImpl::RendererIsHidden() const {
2137 return widget_count_ > 0 && hidden_widget_count_ == widget_count_; 2163 return widget_count_ > 0 && hidden_widget_count_ == widget_count_;
2138 } 2164 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical) 2257 v8_memory_pressure_level == v8::MemoryPressureLevel::kCritical)
2232 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate; 2258 v8_memory_pressure_level = v8::MemoryPressureLevel::kModerate;
2233 2259
2234 blink::mainThreadIsolate()->MemoryPressureNotification( 2260 blink::mainThreadIsolate()->MemoryPressureNotification(
2235 v8_memory_pressure_level); 2261 v8_memory_pressure_level);
2236 blink::MemoryPressureNotificationToWorkerThreadIsolates( 2262 blink::MemoryPressureNotificationToWorkerThreadIsolates(
2237 v8_memory_pressure_level); 2263 v8_memory_pressure_level);
2238 } 2264 }
2239 2265
2240 } // namespace content 2266 } // namespace content
OLDNEW
« no previous file with comments | « cc/test/test_context_support.cc ('k') | gpu/command_buffer/client/context_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698