OLD | NEW |
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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); | 431 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); |
432 return true; | 432 return true; |
433 } | 433 } |
434 | 434 |
435 JNIEnv* env = AttachCurrentThread(); | 435 JNIEnv* env = AttachCurrentThread(); |
436 | 436 |
437 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); | 437 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); |
438 AwPixelInfo* pixels = sw_functions ? | 438 AwPixelInfo* pixels = sw_functions ? |
439 sw_functions->access_pixels(env, java_canvas) : NULL; | 439 sw_functions->access_pixels(env, java_canvas) : NULL; |
440 // Render into an auxiliary bitmap if pixel info is not available. | 440 // Render into an auxiliary bitmap if pixel info is not available. |
| 441 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); |
441 if (pixels == NULL) { | 442 if (pixels == NULL) { |
442 TRACE_EVENT0("android_webview", "RenderToAuxBitmap"); | 443 TRACE_EVENT0("android_webview", "RenderToAuxBitmap"); |
443 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 444 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
444 env, clip.width(), clip.height())); | 445 env, clip.width(), clip.height(), jcanvas)); |
445 if (!jbitmap.obj()) { | 446 if (!jbitmap.obj()) { |
446 TRACE_EVENT_INSTANT0("android_webview", | 447 TRACE_EVENT_INSTANT0("android_webview", |
447 "EarlyOut_BitmapAllocFail", | 448 "EarlyOut_BitmapAllocFail", |
448 TRACE_EVENT_SCOPE_THREAD); | 449 TRACE_EVENT_SCOPE_THREAD); |
449 return false; | 450 return false; |
450 } | 451 } |
451 | 452 |
452 if (!RasterizeIntoBitmap(env, jbitmap, | 453 if (!RasterizeIntoBitmap(env, jbitmap, |
453 clip.x() - scroll_at_start_of_frame_.x(), | 454 clip.x() - scroll_at_start_of_frame_.x(), |
454 clip.y() - scroll_at_start_of_frame_.y(), | 455 clip.y() - scroll_at_start_of_frame_.y(), |
455 base::Bind(&InProcessViewRenderer::RenderSW, | 456 base::Bind(&InProcessViewRenderer::RenderSW, |
456 base::Unretained(this)))) { | 457 base::Unretained(this)))) { |
457 TRACE_EVENT_INSTANT0("android_webview", | 458 TRACE_EVENT_INSTANT0("android_webview", |
458 "EarlyOut_RasterizeFail", | 459 "EarlyOut_RasterizeFail", |
459 TRACE_EVENT_SCOPE_THREAD); | 460 TRACE_EVENT_SCOPE_THREAD); |
460 return false; | 461 return false; |
461 } | 462 } |
462 | 463 |
463 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); | |
464 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, | 464 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, |
465 clip.x(), clip.y()); | 465 clip.x(), clip.y()); |
466 return true; | 466 return true; |
467 } | 467 } |
468 | 468 |
469 // Draw in a SkCanvas built over the pixel information. | 469 // Draw in a SkCanvas built over the pixel information. |
470 bool succeeded = false; | 470 bool succeeded = false; |
471 { | 471 { |
472 SkBitmap bitmap; | 472 SkBitmap bitmap; |
473 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), | 473 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 picture->endRecording(); | 523 picture->endRecording(); |
524 | 524 |
525 if (IsSkiaVersionCompatible()) { | 525 if (IsSkiaVersionCompatible()) { |
526 // Add a reference that the create_picture() will take ownership of. | 526 // Add a reference that the create_picture() will take ownership of. |
527 picture->ref(); | 527 picture->ref(); |
528 return ScopedJavaLocalRef<jobject>(env, | 528 return ScopedJavaLocalRef<jobject>(env, |
529 GetAwDrawSWFunctionTable()->create_picture(env, picture.get())); | 529 GetAwDrawSWFunctionTable()->create_picture(env, picture.get())); |
530 } | 530 } |
531 | 531 |
532 // If Skia versions are not compatible, workaround it by rasterizing the | 532 // If Skia versions are not compatible, workaround it by rasterizing the |
533 // picture into a bitmap and drawing it into a new Java picture. Pass false | 533 // picture into a bitmap and drawing it into a new Java picture. Pass null |
534 // for |cache_result| as the picture we create will hold a shallow reference | 534 // for |canvas| as we don't have java canvas at this point (and it would be |
535 // to the bitmap drawn, and we don't want subsequent draws to corrupt any | 535 // software anyway). |
536 // previously returned pictures. | |
537 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 536 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
538 env, picture->width(), picture->height())); | 537 env, picture->width(), picture->height(), ScopedJavaLocalRef<jobject>())); |
539 if (!jbitmap.obj()) | 538 if (!jbitmap.obj()) |
540 return ScopedJavaLocalRef<jobject>(); | 539 return ScopedJavaLocalRef<jobject>(); |
541 | 540 |
542 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, | 541 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, |
543 base::Bind(&RenderPictureToCanvas, | 542 base::Bind(&RenderPictureToCanvas, |
544 base::Unretained(picture.get())))) { | 543 base::Unretained(picture.get())))) { |
545 return ScopedJavaLocalRef<jobject>(); | 544 return ScopedJavaLocalRef<jobject>(); |
546 } | 545 } |
547 | 546 |
548 return java_helper_->RecordBitmapIntoPicture(env, jbitmap); | 547 return java_helper_->RecordBitmapIntoPicture(env, jbitmap); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 672 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
674 // scale here. Determine what if any needs bringing over to this class. | 673 // scale here. Determine what if any needs bringing over to this class. |
675 return CompositeSW(canvas); | 674 return CompositeSW(canvas); |
676 } | 675 } |
677 | 676 |
678 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 677 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
679 return compositor_ && compositor_->DemandDrawSw(canvas); | 678 return compositor_ && compositor_->DemandDrawSw(canvas); |
680 } | 679 } |
681 | 680 |
682 } // namespace android_webview | 681 } // namespace android_webview |
OLD | NEW |