| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_renderer/in_process_view_renderer.h
" | 5 #include "android_webview/browser/in_process_renderer/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" |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/debug/trace_event.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
| 14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/renderer/android/synchronous_compositor.h" | 17 #include "content/public/renderer/android/synchronous_compositor.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 19 #include "third_party/skia/include/core/SkDevice.h" | 20 #include "third_party/skia/include/core/SkDevice.h" |
| 20 #include "third_party/skia/include/core/SkGraphics.h" | 21 #include "third_party/skia/include/core/SkGraphics.h" |
| 21 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 const gfx::Rect& clip) { | 240 const gfx::Rect& clip) { |
| 240 bool result = DrawSWInternal(java_canvas, clip); | 241 bool result = DrawSWInternal(java_canvas, clip); |
| 241 EnsureContinuousInvalidation(); | 242 EnsureContinuousInvalidation(); |
| 242 return result; | 243 return result; |
| 243 } | 244 } |
| 244 | 245 |
| 245 bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, | 246 bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, |
| 246 const gfx::Rect& clip) { | 247 const gfx::Rect& clip) { |
| 247 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); | 248 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); |
| 248 | 249 |
| 249 if (clip.IsEmpty()) | 250 if (clip.IsEmpty()) { |
| 251 TRACE_EVENT_INSTANT0("android_webview", "Empty Clip", |
| 252 TRACE_EVENT_SCOPE_THREAD); |
| 250 return true; | 253 return true; |
| 254 } |
| 251 | 255 |
| 252 JNIEnv* env = AttachCurrentThread(); | 256 JNIEnv* env = AttachCurrentThread(); |
| 253 | 257 |
| 254 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); | 258 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); |
| 255 AwPixelInfo* pixels = sw_functions ? | 259 AwPixelInfo* pixels = sw_functions ? |
| 256 sw_functions->access_pixels(env, java_canvas) : NULL; | 260 sw_functions->access_pixels(env, java_canvas) : NULL; |
| 257 // Render into an auxiliary bitmap if pixel info is not available. | 261 // Render into an auxiliary bitmap if pixel info is not available. |
| 258 if (pixels == NULL) { | 262 if (pixels == NULL) { |
| 263 TRACE_EVENT0("android_webview", "Render to Aux Bitmap"); |
| 259 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 264 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
| 260 env, clip.width(), clip.height())); | 265 env, clip.width(), clip.height(), true)); |
| 261 if (!jbitmap.obj()) | 266 if (!jbitmap.obj()) { |
| 267 TRACE_EVENT_INSTANT0("android_webview", "Bitmap Alloc Fail", |
| 268 TRACE_EVENT_SCOPE_THREAD); |
| 262 return false; | 269 return false; |
| 270 } |
| 263 | 271 |
| 264 if (!RasterizeIntoBitmap(env, jbitmap, clip.x(), clip.y(), | 272 if (!RasterizeIntoBitmap(env, jbitmap, clip.x(), clip.y(), |
| 265 base::Bind(&InProcessViewRenderer::RenderSW, | 273 base::Bind(&InProcessViewRenderer::RenderSW, |
| 266 base::Unretained(this)))) { | 274 base::Unretained(this)))) { |
| 275 TRACE_EVENT_INSTANT0("android_webview", "Rasterize Fail", |
| 276 TRACE_EVENT_SCOPE_THREAD); |
| 267 return false; | 277 return false; |
| 268 } | 278 } |
| 269 | 279 |
| 270 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); | 280 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); |
| 271 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas); | 281 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas); |
| 272 return true; | 282 return true; |
| 273 } | 283 } |
| 274 | 284 |
| 275 // Draw in a SkCanvas built over the pixel information. | 285 // Draw in a SkCanvas built over the pixel information. |
| 276 bool succeeded = false; | 286 bool succeeded = false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 if (IsSkiaVersionCompatible()) { | 339 if (IsSkiaVersionCompatible()) { |
| 330 // Add a reference that the create_picture() will take ownership of. | 340 // Add a reference that the create_picture() will take ownership of. |
| 331 picture->ref(); | 341 picture->ref(); |
| 332 return ScopedJavaLocalRef<jobject>(env, | 342 return ScopedJavaLocalRef<jobject>(env, |
| 333 GetAwDrawSWFunctionTable()->create_picture(env, picture.get())); | 343 GetAwDrawSWFunctionTable()->create_picture(env, picture.get())); |
| 334 } | 344 } |
| 335 | 345 |
| 336 // If Skia versions are not compatible, workaround it by rasterizing the | 346 // If Skia versions are not compatible, workaround it by rasterizing the |
| 337 // picture into a bitmap and drawing it into a new Java picture. | 347 // picture into a bitmap and drawing it into a new Java picture. |
| 338 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 348 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
| 339 env, picture->width(), picture->height())); | 349 env, picture->width(), picture->height(), false)); |
| 340 if (!jbitmap.obj()) | 350 if (!jbitmap.obj()) |
| 341 return ScopedJavaLocalRef<jobject>(); | 351 return ScopedJavaLocalRef<jobject>(); |
| 342 | 352 |
| 343 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, | 353 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, |
| 344 base::Bind(&RenderPictureToCanvas, | 354 base::Bind(&RenderPictureToCanvas, |
| 345 base::Unretained(picture.get())))) { | 355 base::Unretained(picture.get())))) { |
| 346 return ScopedJavaLocalRef<jobject>(); | 356 return ScopedJavaLocalRef<jobject>(); |
| 347 } | 357 } |
| 348 | 358 |
| 349 return java_helper_->RecordBitmapIntoPicture(env, jbitmap); | 359 return java_helper_->RecordBitmapIntoPicture(env, jbitmap); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 433 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
| 424 // scale here. Determine what if any needs bringing over to this class. | 434 // scale here. Determine what if any needs bringing over to this class. |
| 425 return CompositeSW(canvas); | 435 return CompositeSW(canvas); |
| 426 } | 436 } |
| 427 | 437 |
| 428 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 438 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 429 return compositor_ && compositor_->DemandDrawSw(canvas); | 439 return compositor_ && compositor_->DemandDrawSw(canvas); |
| 430 } | 440 } |
| 431 | 441 |
| 432 } // namespace android_webview | 442 } // namespace android_webview |
| OLD | NEW |