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

Side by Side Diff: android_webview/browser/browser_view_renderer.cc

Issue 654623002: aw: Check compositor pointer before use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: realz fixz Created 6 years, 2 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 | « no previous file | 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 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 "android_webview/browser/browser_view_renderer.h" 5 #include "android_webview/browser/browser_view_renderer.h"
6 6
7 #include "android_webview/browser/browser_view_renderer_client.h" 7 #include "android_webview/browser/browser_view_renderer_client.h"
8 #include "android_webview/browser/shared_renderer_state.h" 8 #include "android_webview/browser/shared_renderer_state.h"
9 #include "android_webview/common/aw_switches.h" 9 #include "android_webview/common/aw_switches.h"
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // This function updates the resource allocation in GlobalTileManager. 105 // This function updates the resource allocation in GlobalTileManager.
106 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { 106 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) {
107 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 107 DCHECK(ui_task_runner_->BelongsToCurrentThread());
108 // Constants from Android ComponentCallbacks2. 108 // Constants from Android ComponentCallbacks2.
109 enum { 109 enum {
110 TRIM_MEMORY_RUNNING_LOW = 10, 110 TRIM_MEMORY_RUNNING_LOW = 10,
111 TRIM_MEMORY_UI_HIDDEN = 20, 111 TRIM_MEMORY_UI_HIDDEN = 20,
112 TRIM_MEMORY_BACKGROUND = 40, 112 TRIM_MEMORY_BACKGROUND = 40,
113 }; 113 };
114 114
115 if (!compositor_ || !hardware_enabled_)
116 return;
hush (inactive) 2014/10/18 01:34:01 ideally, (memory_policy_ != zero_policy) means com
boliu 2014/10/18 17:08:15 Done.
117
115 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because 118 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because
116 // it does not indicate memory pressure, but merely that the app is 119 // it does not indicate memory pressure, but merely that the app is
117 // backgrounded. 120 // backgrounded.
118 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) 121 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN)
119 return; 122 return;
120 123
121 // Do not release resources on view we expect to get DrawGL soon. 124 // Do not release resources on view we expect to get DrawGL soon.
122 if (level < TRIM_MEMORY_BACKGROUND && visible) 125 if (level < TRIM_MEMORY_BACKGROUND && visible)
123 return; 126 return;
124 127
(...skipping 27 matching lines...) Expand all
152 // is also kTileAllocationStep. 155 // is also kTileAllocationStep.
153 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; 156 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep;
154 policy.num_resources_limit = tiles; 157 policy.num_resources_limit = tiles;
155 return policy; 158 return policy;
156 } 159 }
157 160
158 // This function updates the cached memory policy in shared renderer state, as 161 // This function updates the cached memory policy in shared renderer state, as
159 // well as the tile resource allocation in GlobalTileManager. 162 // well as the tile resource allocation in GlobalTileManager.
160 void BrowserViewRenderer::RequestMemoryPolicy( 163 void BrowserViewRenderer::RequestMemoryPolicy(
161 SynchronousCompositorMemoryPolicy& new_policy) { 164 SynchronousCompositorMemoryPolicy& new_policy) {
165 DCHECK(compositor_);
162 GlobalTileManager* manager = GlobalTileManager::GetInstance(); 166 GlobalTileManager* manager = GlobalTileManager::GetInstance();
163 167
164 // The following line will call BrowserViewRenderer::SetMemoryPolicy(). 168 // The following line will call BrowserViewRenderer::SetMemoryPolicy().
165 manager->RequestTiles(new_policy, tile_manager_key_); 169 manager->RequestTiles(new_policy, tile_manager_key_);
166 } 170 }
167 171
168 void BrowserViewRenderer::SetMemoryPolicy( 172 void BrowserViewRenderer::SetMemoryPolicy(
169 SynchronousCompositorMemoryPolicy new_policy, 173 SynchronousCompositorMemoryPolicy new_policy,
170 bool effective_immediately) { 174 bool effective_immediately) {
171 memory_policy_ = new_policy; 175 memory_policy_ = new_policy;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); 241 scoped_ptr<cc::CompositorFrame> frame = CompositeHw();
238 if (!frame.get()) 242 if (!frame.get())
239 return false; 243 return false;
240 244
241 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false); 245 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false);
242 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); 246 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_);
243 return client_->RequestDrawGL(java_canvas, false); 247 return client_->RequestDrawGL(java_canvas, false);
244 } 248 }
245 249
246 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { 250 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() {
247 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); 251 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy();
hush (inactive) 2014/10/18 01:34:01 what is the policy to add DCHECK(compositor_)? if
boliu 2014/10/18 17:08:15 Generally only DCHECK public methods that rely on
248 RequestMemoryPolicy(new_policy); 252 RequestMemoryPolicy(new_policy);
249 compositor_->SetMemoryPolicy(memory_policy_); 253 compositor_->SetMemoryPolicy(memory_policy_);
250 254
251 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); 255 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints();
252 gfx::Size surface_size(width_, height_); 256 gfx::Size surface_size(width_, height_);
253 gfx::Rect viewport(surface_size); 257 gfx::Rect viewport(surface_size);
254 gfx::Rect clip = viewport; 258 gfx::Rect clip = viewport;
255 gfx::Transform transform_for_tile_priority = 259 gfx::Transform transform_for_tile_priority =
256 parent_draw_constraints_.transform; 260 parent_draw_constraints_.transform;
257 261
(...skipping 30 matching lines...) Expand all
288 } 292 }
289 293
290 void BrowserViewRenderer::ReturnUnusedResource( 294 void BrowserViewRenderer::ReturnUnusedResource(
291 scoped_ptr<cc::CompositorFrame> frame) { 295 scoped_ptr<cc::CompositorFrame> frame) {
292 if (!frame.get()) 296 if (!frame.get())
293 return; 297 return;
294 298
295 cc::CompositorFrameAck frame_ack; 299 cc::CompositorFrameAck frame_ack;
296 cc::TransferableResource::ReturnResources( 300 cc::TransferableResource::ReturnResources(
297 frame->delegated_frame_data->resource_list, &frame_ack.resources); 301 frame->delegated_frame_data->resource_list, &frame_ack.resources);
298 if (!frame_ack.resources.empty()) 302 if (compositor_ && !frame_ack.resources.empty())
299 compositor_->ReturnResources(frame_ack); 303 compositor_->ReturnResources(frame_ack);
300 } 304 }
301 305
302 void BrowserViewRenderer::ReturnResourceFromParent() { 306 void BrowserViewRenderer::ReturnResourceFromParent() {
303 cc::CompositorFrameAck frame_ack; 307 cc::CompositorFrameAck frame_ack;
304 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); 308 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources);
305 if (!frame_ack.resources.empty()) { 309 if (compositor_ && !frame_ack.resources.empty()) {
306 compositor_->ReturnResources(frame_ack); 310 compositor_->ReturnResources(frame_ack);
307 } 311 }
308 } 312 }
309 313
310 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) { 314 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) {
311 if (!compositor_) { 315 if (!compositor_) {
312 TRACE_EVENT_INSTANT0( 316 TRACE_EVENT_INSTANT0(
313 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); 317 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD);
314 return false; 318 return false;
315 } 319 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); 429 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow");
426 attached_to_window_ = false; 430 attached_to_window_ = false;
427 DCHECK(!hardware_enabled_); 431 DCHECK(!hardware_enabled_);
428 } 432 }
429 433
430 void BrowserViewRenderer::ReleaseHardware() { 434 void BrowserViewRenderer::ReleaseHardware() {
431 DCHECK(hardware_enabled_); 435 DCHECK(hardware_enabled_);
432 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); 436 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame());
433 ReturnResourceFromParent(); 437 ReturnResourceFromParent();
434 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); 438 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty());
439 hardware_enabled_ = false;
440 GlobalTileManager::GetInstance()->Remove(tile_manager_key_);
boliu 2014/10/18 17:08:15 Woo this is wrong. Ned to request 0 policy *before
441
442 if (!compositor_)
443 return;
435 444
436 compositor_->ReleaseHwDraw(); 445 compositor_->ReleaseHwDraw();
437 hardware_enabled_ = false;
438
439 SynchronousCompositorMemoryPolicy zero_policy; 446 SynchronousCompositorMemoryPolicy zero_policy;
440 RequestMemoryPolicy(zero_policy); 447 RequestMemoryPolicy(zero_policy);
441 GlobalTileManager::GetInstance()->Remove(tile_manager_key_);
442 } 448 }
443 449
444 bool BrowserViewRenderer::IsVisible() const { 450 bool BrowserViewRenderer::IsVisible() const {
445 // Ignore |window_visible_| if |attached_to_window_| is false. 451 // Ignore |window_visible_| if |attached_to_window_| is false.
446 return view_visible_ && (!attached_to_window_ || window_visible_); 452 return view_visible_ && (!attached_to_window_ || window_visible_);
447 } 453 }
448 454
449 gfx::Rect BrowserViewRenderer::GetScreenRect() const { 455 gfx::Rect BrowserViewRenderer::GetScreenRect() const {
450 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); 456 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_));
451 } 457 }
452 458
453 void BrowserViewRenderer::DidInitializeCompositor( 459 void BrowserViewRenderer::DidInitializeCompositor(
454 content::SynchronousCompositor* compositor) { 460 content::SynchronousCompositor* compositor) {
455 TRACE_EVENT0("android_webview", 461 TRACE_EVENT0("android_webview",
456 "BrowserViewRenderer::DidInitializeCompositor"); 462 "BrowserViewRenderer::DidInitializeCompositor");
457 DCHECK(compositor); 463 DCHECK(compositor);
458 DCHECK(!compositor_); 464 DCHECK(!compositor_);
459 compositor_ = compositor; 465 compositor_ = compositor;
460 } 466 }
461 467
462 void BrowserViewRenderer::DidDestroyCompositor( 468 void BrowserViewRenderer::DidDestroyCompositor(
463 content::SynchronousCompositor* compositor) { 469 content::SynchronousCompositor* compositor) {
464 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); 470 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor");
465 DCHECK(compositor_); 471 DCHECK(compositor_);
472 SynchronousCompositorMemoryPolicy zero_policy;
473 RequestMemoryPolicy(zero_policy);
466 compositor_ = NULL; 474 compositor_ = NULL;
hush (inactive) 2014/10/18 01:34:01 since didDestroyCompositor could be called before
boliu 2014/10/18 17:08:15 We do already, both OnDrawHardware and will skip i
467 SynchronousCompositorMemoryPolicy zero_policy;
468 DCHECK(memory_policy_ == zero_policy);
469 } 475 }
470 476
471 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { 477 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) {
472 if (compositor_needs_continuous_invalidate_ == invalidate) 478 if (compositor_needs_continuous_invalidate_ == invalidate)
473 return; 479 return;
474 480
475 TRACE_EVENT_INSTANT1("android_webview", 481 TRACE_EVENT_INSTANT1("android_webview",
476 "BrowserViewRenderer::SetContinuousInvalidate", 482 "BrowserViewRenderer::SetContinuousInvalidate",
477 TRACE_EVENT_SCOPE_THREAD, 483 TRACE_EVENT_SCOPE_THREAD,
478 "invalidate", 484 "invalidate",
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 base::StringAppendF(&str, 788 base::StringAppendF(&str,
783 "overscroll_rounding_error_: %s ", 789 "overscroll_rounding_error_: %s ",
784 overscroll_rounding_error_.ToString().c_str()); 790 overscroll_rounding_error_.ToString().c_str());
785 base::StringAppendF( 791 base::StringAppendF(
786 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 792 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
787 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 793 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
788 return str; 794 return str;
789 } 795 }
790 796
791 } // namespace android_webview 797 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698