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

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

Issue 17136003: [Android WebView] Fallback tick (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 6 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 | « android_webview/browser/in_process_view_renderer.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/in_process_view_renderer.h" 5 #include "android_webview/browser/in_process_view_renderer.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "android_webview/public/browser/draw_gl.h" 9 #include "android_webview/public/browser/draw_gl.h"
10 #include "android_webview/public/browser/draw_sw.h" 10 #include "android_webview/public/browser/draw_sw.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // Allows preventing extra copies of data when rendering. 268 // Allows preventing extra copies of data when rendering.
269 AwDrawSWFunctionTable* g_sw_draw_functions = NULL; 269 AwDrawSWFunctionTable* g_sw_draw_functions = NULL;
270 270
271 // Tells if the Skia library versions in Android and Chromium are compatible. 271 // Tells if the Skia library versions in Android and Chromium are compatible.
272 // If they are then it's possible to pass Skia objects like SkPictures to the 272 // If they are then it's possible to pass Skia objects like SkPictures to the
273 // Android glue layer via the SW rendering functions. 273 // Android glue layer via the SW rendering functions.
274 // If they are not, then additional copies and rasterizations are required 274 // If they are not, then additional copies and rasterizations are required
275 // as a fallback mechanism, which will have an important performance impact. 275 // as a fallback mechanism, which will have an important performance impact.
276 bool g_is_skia_version_compatible = false; 276 bool g_is_skia_version_compatible = false;
277 277
278 const int64 kFallbackTickTimeoutInMilliseconds = 500;
279
278 } // namespace 280 } // namespace
279 281
280 // static 282 // static
281 void BrowserViewRenderer::SetAwDrawSWFunctionTable( 283 void BrowserViewRenderer::SetAwDrawSWFunctionTable(
282 AwDrawSWFunctionTable* table) { 284 AwDrawSWFunctionTable* table) {
283 g_sw_draw_functions = table; 285 g_sw_draw_functions = table;
284 g_is_skia_version_compatible = 286 g_is_skia_version_compatible =
285 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion); 287 g_sw_draw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
286 LOG_IF(WARNING, !g_is_skia_version_compatible) 288 LOG_IF(WARNING, !g_is_skia_version_compatible)
287 << "Skia versions are not compatible, rendering performance will suffer."; 289 << "Skia versions are not compatible, rendering performance will suffer.";
(...skipping 24 matching lines...) Expand all
312 block_invalidates_(false), 314 block_invalidates_(false),
313 width_(0), 315 width_(0),
314 height_(0), 316 height_(0),
315 attached_to_window_(false), 317 attached_to_window_(false),
316 hardware_initialized_(false), 318 hardware_initialized_(false),
317 hardware_failed_(false), 319 hardware_failed_(false),
318 last_egl_context_(NULL) { 320 last_egl_context_(NULL) {
319 CHECK(web_contents_); 321 CHECK(web_contents_);
320 web_contents_->SetUserData(kUserDataKey, new UserData(this)); 322 web_contents_->SetUserData(kUserDataKey, new UserData(this));
321 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); 323 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this);
324
322 // Currently the logic in this class relies on |compositor_| remaining NULL 325 // Currently the logic in this class relies on |compositor_| remaining NULL
323 // until the DidInitializeCompositor() call, hence it is not set here. 326 // until the DidInitializeCompositor() call, hence it is not set here.
324 } 327 }
325 328
326 InProcessViewRenderer::~InProcessViewRenderer() { 329 InProcessViewRenderer::~InProcessViewRenderer() {
327 CHECK(web_contents_); 330 CHECK(web_contents_);
328 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); 331 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL);
329 web_contents_->SetUserData(kUserDataKey, NULL); 332 web_contents_->SetUserData(kUserDataKey, NULL);
330 DCHECK(web_contents_ == NULL); // WebContentsGone should have been called. 333 DCHECK(web_contents_ == NULL); // WebContentsGone should have been called.
331 } 334 }
332 335
333 // static 336 // static
334 InProcessViewRenderer* InProcessViewRenderer::FromWebContents( 337 InProcessViewRenderer* InProcessViewRenderer::FromWebContents(
335 content::WebContents* contents) { 338 content::WebContents* contents) {
336 return UserData::GetInstance(contents); 339 return UserData::GetInstance(contents);
337 } 340 }
338 341
339 void InProcessViewRenderer::WebContentsGone() { 342 void InProcessViewRenderer::WebContentsGone() {
340 web_contents_ = NULL; 343 web_contents_ = NULL;
341 compositor_ = NULL; 344 compositor_ = NULL;
342 } 345 }
343 346
344 bool InProcessViewRenderer::OnDraw(jobject java_canvas, 347 bool InProcessViewRenderer::OnDraw(jobject java_canvas,
345 bool is_hardware_canvas, 348 bool is_hardware_canvas,
346 const gfx::Vector2d& scroll, 349 const gfx::Vector2d& scroll,
347 const gfx::Rect& clip) { 350 const gfx::Rect& clip) {
351 fallback_tick_.Cancel();
348 scroll_at_start_of_frame_ = scroll; 352 scroll_at_start_of_frame_ = scroll;
349 if (is_hardware_canvas && attached_to_window_ && compositor_ && 353 if (is_hardware_canvas && attached_to_window_ && compositor_ &&
350 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { 354 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) {
351 // All set: we'll get a call on DrawGL when the time comes. 355 // All set: we'll get a call on DrawGL when the time comes.
352 return true; 356 return true;
353 } 357 }
354 // Perform a software draw 358 // Perform a software draw
355 block_invalidates_ = true; 359 block_invalidates_ = true;
356 bool result = DrawSWInternal(java_canvas, clip); 360 bool result = DrawSWInternal(java_canvas, clip);
357 block_invalidates_ = false; 361 block_invalidates_ = false;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (!jbitmap.obj()) { 452 if (!jbitmap.obj()) {
449 TRACE_EVENT_INSTANT0("android_webview", 453 TRACE_EVENT_INSTANT0("android_webview",
450 "EarlyOut_BitmapAllocFail", 454 "EarlyOut_BitmapAllocFail",
451 TRACE_EVENT_SCOPE_THREAD); 455 TRACE_EVENT_SCOPE_THREAD);
452 return false; 456 return false;
453 } 457 }
454 458
455 if (!RasterizeIntoBitmap(env, jbitmap, 459 if (!RasterizeIntoBitmap(env, jbitmap,
456 clip.x() - scroll_at_start_of_frame_.x(), 460 clip.x() - scroll_at_start_of_frame_.x(),
457 clip.y() - scroll_at_start_of_frame_.y(), 461 clip.y() - scroll_at_start_of_frame_.y(),
458 base::Bind(&InProcessViewRenderer::RenderSW, 462 base::Bind(&InProcessViewRenderer::CompositeSW,
459 base::Unretained(this)))) { 463 base::Unretained(this)))) {
460 TRACE_EVENT_INSTANT0("android_webview", 464 TRACE_EVENT_INSTANT0("android_webview",
461 "EarlyOut_RasterizeFail", 465 "EarlyOut_RasterizeFail",
462 TRACE_EVENT_SCOPE_THREAD); 466 TRACE_EVENT_SCOPE_THREAD);
463 return false; 467 return false;
464 } 468 }
465 469
466 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, 470 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas,
467 clip.x(), clip.y()); 471 clip.x(), clip.y());
468 return true; 472 return true;
(...skipping 19 matching lines...) Expand all
488 SkRegion clip_region; 492 SkRegion clip_region;
489 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region); 493 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region);
490 DCHECK_EQ(pixels->clip_region_size, bytes_read); 494 DCHECK_EQ(pixels->clip_region_size, bytes_read);
491 canvas.setClipRegion(clip_region); 495 canvas.setClipRegion(clip_region);
492 } else { 496 } else {
493 canvas.clipRect(gfx::RectToSkRect(clip)); 497 canvas.clipRect(gfx::RectToSkRect(clip));
494 } 498 }
495 canvas.translate(scroll_at_start_of_frame_.x(), 499 canvas.translate(scroll_at_start_of_frame_.x(),
496 scroll_at_start_of_frame_.y()); 500 scroll_at_start_of_frame_.y());
497 501
498 succeeded = RenderSW(&canvas); 502 succeeded = CompositeSW(&canvas);
499 } 503 }
500 504
501 sw_functions->release_pixels(pixels); 505 sw_functions->release_pixels(pixels);
502 return succeeded; 506 return succeeded;
503 } 507 }
504 508
505 base::android::ScopedJavaLocalRef<jobject> 509 base::android::ScopedJavaLocalRef<jobject>
506 InProcessViewRenderer::CapturePicture() { 510 InProcessViewRenderer::CapturePicture() {
507 if (!GetAwDrawSWFunctionTable()) 511 if (!GetAwDrawSWFunctionTable())
508 return ScopedJavaLocalRef<jobject>(); 512 return ScopedJavaLocalRef<jobject>();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { 634 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) {
631 if (continuous_invalidate_ == invalidate) 635 if (continuous_invalidate_ == invalidate)
632 return; 636 return;
633 637
634 TRACE_EVENT_INSTANT1("android_webview", 638 TRACE_EVENT_INSTANT1("android_webview",
635 "InProcessViewRenderer::SetContinuousInvalidate", 639 "InProcessViewRenderer::SetContinuousInvalidate",
636 TRACE_EVENT_SCOPE_THREAD, 640 TRACE_EVENT_SCOPE_THREAD,
637 "invalidate", 641 "invalidate",
638 invalidate); 642 invalidate);
639 continuous_invalidate_ = invalidate; 643 continuous_invalidate_ = invalidate;
640 // TODO(boliu): Handle if not attached to window case.
641 EnsureContinuousInvalidation(NULL); 644 EnsureContinuousInvalidation(NULL);
642 } 645 }
643 646
644 void InProcessViewRenderer::SetDipScale(float dip_scale) { 647 void InProcessViewRenderer::SetDipScale(float dip_scale) {
645 dip_scale_ = dip_scale; 648 dip_scale_ = dip_scale;
646 CHECK(dip_scale_ > 0); 649 CHECK(dip_scale_ > 0);
647 } 650 }
648 651
649 void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) { 652 void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) {
650 DCHECK(dip_scale_ > 0); 653 DCHECK(dip_scale_ > 0);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 if (continuous_invalidate_ && !block_invalidates_) { 694 if (continuous_invalidate_ && !block_invalidates_) {
692 if (draw_info) { 695 if (draw_info) {
693 draw_info->dirty_left = draw_info->clip_left; 696 draw_info->dirty_left = draw_info->clip_left;
694 draw_info->dirty_top = draw_info->clip_top; 697 draw_info->dirty_top = draw_info->clip_top;
695 draw_info->dirty_right = draw_info->clip_right; 698 draw_info->dirty_right = draw_info->clip_right;
696 draw_info->dirty_bottom = draw_info->clip_bottom; 699 draw_info->dirty_bottom = draw_info->clip_bottom;
697 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw; 700 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw;
698 } else { 701 } else {
699 client_->PostInvalidate(); 702 client_->PostInvalidate();
700 } 703 }
704
705 // Unretained here is safe because the callback is cancelled when
706 // |fallback_tick_| is destroyed.
707 fallback_tick_.Reset(base::Bind(&InProcessViewRenderer::FallbackTickFired,
708 base::Unretained(this)));
709 base::MessageLoop::current()->PostDelayedTask(
710 FROM_HERE,
711 fallback_tick_.callback(),
712 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
713
701 block_invalidates_ = true; 714 block_invalidates_ = true;
702 } 715 }
703 } 716 }
704 717
705 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { 718 void InProcessViewRenderer::FallbackTickFired() {
706 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page 719 TRACE_EVENT1("android_webview",
707 // scale here. Determine what if any needs bringing over to this class. 720 "InProcessViewRenderer::FallbackTickFired",
708 return CompositeSW(canvas); 721 "continuous_invalidate_",
722 continuous_invalidate_);
723 if (continuous_invalidate_) {
724 SkDevice device(SkBitmap::kARGB_8888_Config, 1, 1);
725 SkCanvas canvas(&device);
726 block_invalidates_ = true;
727 CompositeSW(&canvas);
728 }
729 block_invalidates_ = false;
730 EnsureContinuousInvalidation(NULL);
709 } 731 }
710 732
711 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { 733 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) {
712 return compositor_ && compositor_->DemandDrawSw(canvas); 734 return compositor_ && compositor_->DemandDrawSw(canvas);
713 } 735 }
714 736
715 } // namespace android_webview 737 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/in_process_view_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698