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

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: bring back DCHECK 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (level < TRIM_MEMORY_BACKGROUND && visible) 122 if (level < TRIM_MEMORY_BACKGROUND && visible)
123 return; 123 return;
124 124
125 // Just set the memory limit to 0 and drop all tiles. This will be reset to 125 // Just set the memory limit to 0 and drop all tiles. This will be reset to
126 // normal levels in the next DrawGL call. 126 // normal levels in the next DrawGL call.
127 SynchronousCompositorMemoryPolicy zero_policy; 127 SynchronousCompositorMemoryPolicy zero_policy;
128 if (memory_policy_ == zero_policy) 128 if (memory_policy_ == zero_policy)
129 return; 129 return;
130 130
131 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); 131 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory");
132 DCHECK(hardware_enabled_);
133 DCHECK(compositor_);
132 134
133 RequestMemoryPolicy(zero_policy); 135 RequestMemoryPolicy(zero_policy);
134 EnforceMemoryPolicyImmediately(zero_policy); 136 EnforceMemoryPolicyImmediately(zero_policy);
135 } 137 }
136 138
137 SynchronousCompositorMemoryPolicy 139 SynchronousCompositorMemoryPolicy
138 BrowserViewRenderer::CalculateDesiredMemoryPolicy() { 140 BrowserViewRenderer::CalculateDesiredMemoryPolicy() {
139 SynchronousCompositorMemoryPolicy policy; 141 SynchronousCompositorMemoryPolicy policy;
140 size_t width = last_on_draw_global_visible_rect_.width(); 142 size_t width = last_on_draw_global_visible_rect_.width();
141 size_t height = last_on_draw_global_visible_rect_.height(); 143 size_t height = last_on_draw_global_visible_rect_.height();
(...skipping 10 matching lines...) Expand all
152 // is also kTileAllocationStep. 154 // is also kTileAllocationStep.
153 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; 155 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep;
154 policy.num_resources_limit = tiles; 156 policy.num_resources_limit = tiles;
155 return policy; 157 return policy;
156 } 158 }
157 159
158 // This function updates the cached memory policy in shared renderer state, as 160 // This function updates the cached memory policy in shared renderer state, as
159 // well as the tile resource allocation in GlobalTileManager. 161 // well as the tile resource allocation in GlobalTileManager.
160 void BrowserViewRenderer::RequestMemoryPolicy( 162 void BrowserViewRenderer::RequestMemoryPolicy(
161 SynchronousCompositorMemoryPolicy& new_policy) { 163 SynchronousCompositorMemoryPolicy& new_policy) {
164 DCHECK(compositor_);
162 GlobalTileManager* manager = GlobalTileManager::GetInstance(); 165 GlobalTileManager* manager = GlobalTileManager::GetInstance();
163 166
164 // The following line will call BrowserViewRenderer::SetMemoryPolicy(). 167 // The following line will call BrowserViewRenderer::SetMemoryPolicy().
165 manager->RequestTiles(new_policy, tile_manager_key_); 168 manager->RequestTiles(new_policy, tile_manager_key_);
166 } 169 }
167 170
168 void BrowserViewRenderer::SetMemoryPolicy( 171 void BrowserViewRenderer::SetMemoryPolicy(
169 SynchronousCompositorMemoryPolicy new_policy, 172 SynchronousCompositorMemoryPolicy new_policy,
170 bool effective_immediately) { 173 bool effective_immediately) {
171 memory_policy_ = new_policy; 174 memory_policy_ = new_policy;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 291 }
289 292
290 void BrowserViewRenderer::ReturnUnusedResource( 293 void BrowserViewRenderer::ReturnUnusedResource(
291 scoped_ptr<cc::CompositorFrame> frame) { 294 scoped_ptr<cc::CompositorFrame> frame) {
292 if (!frame.get()) 295 if (!frame.get())
293 return; 296 return;
294 297
295 cc::CompositorFrameAck frame_ack; 298 cc::CompositorFrameAck frame_ack;
296 cc::TransferableResource::ReturnResources( 299 cc::TransferableResource::ReturnResources(
297 frame->delegated_frame_data->resource_list, &frame_ack.resources); 300 frame->delegated_frame_data->resource_list, &frame_ack.resources);
298 if (!frame_ack.resources.empty()) 301 if (compositor_ && !frame_ack.resources.empty())
299 compositor_->ReturnResources(frame_ack); 302 compositor_->ReturnResources(frame_ack);
300 } 303 }
301 304
302 void BrowserViewRenderer::ReturnResourceFromParent() { 305 void BrowserViewRenderer::ReturnResourceFromParent() {
303 cc::CompositorFrameAck frame_ack; 306 cc::CompositorFrameAck frame_ack;
304 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); 307 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources);
305 if (!frame_ack.resources.empty()) { 308 if (compositor_ && !frame_ack.resources.empty()) {
306 compositor_->ReturnResources(frame_ack); 309 compositor_->ReturnResources(frame_ack);
307 } 310 }
308 } 311 }
309 312
310 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) { 313 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) {
311 if (!compositor_) { 314 if (!compositor_) {
312 TRACE_EVENT_INSTANT0( 315 TRACE_EVENT_INSTANT0(
313 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); 316 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD);
314 return false; 317 return false;
315 } 318 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 attached_to_window_ = false; 429 attached_to_window_ = false;
427 DCHECK(!hardware_enabled_); 430 DCHECK(!hardware_enabled_);
428 } 431 }
429 432
430 void BrowserViewRenderer::ReleaseHardware() { 433 void BrowserViewRenderer::ReleaseHardware() {
431 DCHECK(hardware_enabled_); 434 DCHECK(hardware_enabled_);
432 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); 435 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame());
433 ReturnResourceFromParent(); 436 ReturnResourceFromParent();
434 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); 437 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty());
435 438
436 compositor_->ReleaseHwDraw(); 439 if (compositor_) {
440 compositor_->ReleaseHwDraw();
441 SynchronousCompositorMemoryPolicy zero_policy;
442 RequestMemoryPolicy(zero_policy);
443 }
444
437 hardware_enabled_ = false; 445 hardware_enabled_ = false;
438
439 SynchronousCompositorMemoryPolicy zero_policy;
440 RequestMemoryPolicy(zero_policy);
441 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); 446 GlobalTileManager::GetInstance()->Remove(tile_manager_key_);
442 } 447 }
443 448
444 bool BrowserViewRenderer::IsVisible() const { 449 bool BrowserViewRenderer::IsVisible() const {
445 // Ignore |window_visible_| if |attached_to_window_| is false. 450 // Ignore |window_visible_| if |attached_to_window_| is false.
446 return view_visible_ && (!attached_to_window_ || window_visible_); 451 return view_visible_ && (!attached_to_window_ || window_visible_);
447 } 452 }
448 453
449 gfx::Rect BrowserViewRenderer::GetScreenRect() const { 454 gfx::Rect BrowserViewRenderer::GetScreenRect() const {
450 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); 455 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_));
451 } 456 }
452 457
453 void BrowserViewRenderer::DidInitializeCompositor( 458 void BrowserViewRenderer::DidInitializeCompositor(
454 content::SynchronousCompositor* compositor) { 459 content::SynchronousCompositor* compositor) {
455 TRACE_EVENT0("android_webview", 460 TRACE_EVENT0("android_webview",
456 "BrowserViewRenderer::DidInitializeCompositor"); 461 "BrowserViewRenderer::DidInitializeCompositor");
457 DCHECK(compositor); 462 DCHECK(compositor);
458 DCHECK(!compositor_); 463 DCHECK(!compositor_);
459 compositor_ = compositor; 464 compositor_ = compositor;
460 } 465 }
461 466
462 void BrowserViewRenderer::DidDestroyCompositor( 467 void BrowserViewRenderer::DidDestroyCompositor(
463 content::SynchronousCompositor* compositor) { 468 content::SynchronousCompositor* compositor) {
464 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); 469 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor");
465 DCHECK(compositor_); 470 DCHECK(compositor_);
471 SynchronousCompositorMemoryPolicy zero_policy;
472 if (hardware_enabled_) {
473 RequestMemoryPolicy(zero_policy);
474 }
475 DCHECK(memory_policy_ == zero_policy);
466 compositor_ = NULL; 476 compositor_ = NULL;
467 SynchronousCompositorMemoryPolicy zero_policy;
468 DCHECK(memory_policy_ == zero_policy);
469 } 477 }
470 478
471 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { 479 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) {
472 if (compositor_needs_continuous_invalidate_ == invalidate) 480 if (compositor_needs_continuous_invalidate_ == invalidate)
473 return; 481 return;
474 482
475 TRACE_EVENT_INSTANT1("android_webview", 483 TRACE_EVENT_INSTANT1("android_webview",
476 "BrowserViewRenderer::SetContinuousInvalidate", 484 "BrowserViewRenderer::SetContinuousInvalidate",
477 TRACE_EVENT_SCOPE_THREAD, 485 TRACE_EVENT_SCOPE_THREAD,
478 "invalidate", 486 "invalidate",
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 base::StringAppendF(&str, 790 base::StringAppendF(&str,
783 "overscroll_rounding_error_: %s ", 791 "overscroll_rounding_error_: %s ",
784 overscroll_rounding_error_.ToString().c_str()); 792 overscroll_rounding_error_.ToString().c_str());
785 base::StringAppendF( 793 base::StringAppendF(
786 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 794 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
787 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 795 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
788 return str; 796 return str;
789 } 797 }
790 798
791 } // namespace android_webview 799 } // 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