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

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: 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
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 272 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 fallback_tick_.Reset(base::Bind(&InProcessViewRenderer::FallbackTick,
706 base::Unretained(this)));
joth 2013/06/21 20:22:01 comment cancelation
boliu 2013/06/21 21:49:41 Done.
707 base::MessageLoop::current()->PostDelayedTask(
708 FROM_HERE,
709 fallback_tick_.callback(),
710 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
711
701 block_invalidates_ = true; 712 block_invalidates_ = true;
702 } 713 }
703 } 714 }
704 715
716 void InProcessViewRenderer::FallbackTick() {
joth 2013/06/21 20:22:01 OnFallbackTick? meh FallbackTickFired()
boliu 2013/06/21 21:49:41 Done. FallbackTickFired.
717 TRACE_EVENT1("android_webview",
718 "InProcessViewRenderer::FallbackTick",
719 "continuous_invalidate_",
720 continuous_invalidate_);
721 if (continuous_invalidate_) {
722 SkBitmap bitmap;
723 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
724 bitmap.allocPixels();
joth 2013/06/21 20:22:01 SkDevice device(SkBitmap::kARGB_8888_Config, 1, 1)
boliu 2013/06/21 21:49:41 Done.
725 SkCanvas canvas(bitmap);
726 block_invalidates_ = true;
727 RenderSW(&canvas);
728 }
729 block_invalidates_ = false;
730 EnsureContinuousInvalidation(NULL);
731 }
732
705 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { 733 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) {
706 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page 734 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page
707 // scale here. Determine what if any needs bringing over to this class. 735 // scale here. Determine what if any needs bringing over to this class.
708 return CompositeSW(canvas); 736 return CompositeSW(canvas);
709 } 737 }
710 738
711 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { 739 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) {
712 return compositor_ && compositor_->DemandDrawSw(canvas); 740 return compositor_ && compositor_->DemandDrawSw(canvas);
713 } 741 }
714 742
715 } // namespace android_webview 743 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698