Chromium Code Reviews| 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/browser/scoped_app_gl_state_restore.h" | 9 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| 10 #include "android_webview/public/browser/draw_gl.h" | 10 #include "android_webview/public/browser/draw_gl.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 gfx::Rect(draw_info->clip_left, | 269 gfx::Rect(draw_info->clip_left, |
| 270 draw_info->clip_top, | 270 draw_info->clip_top, |
| 271 draw_info->clip_right - draw_info->clip_left, | 271 draw_info->clip_right - draw_info->clip_left, |
| 272 draw_info->clip_bottom - draw_info->clip_top)); | 272 draw_info->clip_bottom - draw_info->clip_top)); |
| 273 block_invalidates_ = false; | 273 block_invalidates_ = false; |
| 274 | 274 |
| 275 EnsureContinuousInvalidation(draw_info); | 275 EnsureContinuousInvalidation(draw_info); |
| 276 } | 276 } |
| 277 | 277 |
| 278 bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, | 278 bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, |
| 279 const gfx::Rect& clip) { | 279 const gfx::Rect& clip) { |
|
Kristian Monsen
2013/07/25 03:35:17
This is now only used for the early out, do we sti
joth
2013/08/04 06:04:08
still needed for the RasterizeIntoBitmap() call
| |
| 280 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); | 280 TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); |
| 281 fallback_tick_.Cancel(); | 281 fallback_tick_.Cancel(); |
| 282 | 282 |
| 283 if (clip.IsEmpty()) { | 283 if (clip.IsEmpty()) { |
| 284 TRACE_EVENT_INSTANT0( | 284 TRACE_EVENT_INSTANT0( |
| 285 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); | 285 "android_webview", "EarlyOut_EmptyClip", TRACE_EVENT_SCOPE_THREAD); |
| 286 return true; | 286 return true; |
| 287 } | 287 } |
| 288 | 288 |
| 289 if (!compositor_) { | 289 if (!compositor_) { |
| 290 TRACE_EVENT_INSTANT0( | 290 TRACE_EVENT_INSTANT0( |
| 291 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); | 291 "android_webview", "EarlyOut_NoCompositor", TRACE_EVENT_SCOPE_THREAD); |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 JNIEnv* env = AttachCurrentThread(); | 295 JNIEnv* env = AttachCurrentThread(); |
|
Kristian Monsen
2013/07/25 03:35:17
I think this is only needed for the kNo_Config?
joth
2013/08/04 06:04:08
Done.
joth
2013/08/10 00:54:50
...actually, is needed for sw_functions->access_pi
| |
| 296 | 296 |
| 297 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); | 297 AwDrawSWFunctionTable* sw_functions = GetAwDrawSWFunctionTable(); |
| 298 AwPixelInfo* pixels = sw_functions ? | 298 AwPixelInfo* pixels = sw_functions ? |
| 299 sw_functions->access_pixels(env, java_canvas) : NULL; | 299 sw_functions->access_pixels(env, java_canvas) : NULL; |
| 300 // Render into an auxiliary bitmap if pixel info is not available. | 300 SkBitmap::Config config = !pixels ? SkBitmap::kNo_Config : |
| 301 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); | 301 pixels->config == AwConfig_ARGB_8888 ? SkBitmap::kARGB_8888_Config : |
| 302 if (pixels == NULL) { | 302 pixels->config == AwConfig_ARGB_4444 ? SkBitmap::kARGB_4444_Config : |
| 303 pixels->config == AwConfig_RGB_565 ? SkBitmap::kRGB_565_Config : | |
| 304 SkBitmap::kNo_Config; | |
| 305 if (config == SkBitmap::kNo_Config) { | |
| 306 // Render into an auxiliary bitmap if pixel info is not available. | |
| 307 ScopedJavaLocalRef<jobject> jcanvas(env, java_canvas); | |
| 303 TRACE_EVENT0("android_webview", "RenderToAuxBitmap"); | 308 TRACE_EVENT0("android_webview", "RenderToAuxBitmap"); |
| 304 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( | 309 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( |
| 305 env, clip.width(), clip.height(), jcanvas, web_contents_)); | 310 env, clip.width(), clip.height(), jcanvas, web_contents_)); |
| 306 if (!jbitmap.obj()) { | 311 if (!jbitmap.obj()) { |
| 307 TRACE_EVENT_INSTANT0("android_webview", | 312 TRACE_EVENT_INSTANT0("android_webview", |
| 308 "EarlyOut_BitmapAllocFail", | 313 "EarlyOut_BitmapAllocFail", |
| 309 TRACE_EVENT_SCOPE_THREAD); | 314 TRACE_EVENT_SCOPE_THREAD); |
| 310 return false; | 315 return false; |
| 311 } | 316 } |
| 312 | 317 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 323 | 328 |
| 324 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, | 329 java_helper_->DrawBitmapIntoCanvas(env, jbitmap, jcanvas, |
| 325 clip.x(), clip.y()); | 330 clip.x(), clip.y()); |
| 326 return true; | 331 return true; |
| 327 } | 332 } |
| 328 | 333 |
| 329 // Draw in a SkCanvas built over the pixel information. | 334 // Draw in a SkCanvas built over the pixel information. |
| 330 bool succeeded = false; | 335 bool succeeded = false; |
| 331 { | 336 { |
| 332 SkBitmap bitmap; | 337 SkBitmap bitmap; |
| 333 bitmap.setConfig(static_cast<SkBitmap::Config>(pixels->config), | 338 bitmap.setConfig(config, |
| 334 pixels->width, | 339 pixels->width, |
| 335 pixels->height, | 340 pixels->height, |
| 336 pixels->row_bytes); | 341 pixels->row_bytes); |
| 337 bitmap.setPixels(pixels->pixels); | 342 bitmap.setPixels(pixels->pixels); |
| 338 SkDevice device(bitmap); | 343 SkDevice device(bitmap); |
| 339 SkCanvas canvas(&device); | 344 SkCanvas canvas(&device); |
| 340 SkMatrix matrix; | 345 SkMatrix matrix; |
| 341 for (int i = 0; i < 9; i++) | 346 for (int i = 0; i < 9; i++) |
| 342 matrix.set(i, pixels->matrix[i]); | 347 matrix.set(i, pixels->matrix[i]); |
| 343 canvas.setMatrix(matrix); | 348 canvas.setMatrix(matrix); |
| 344 | 349 |
| 345 if (pixels->clip_region_size) { | 350 if (pixels->clip_rect_count) { |
| 351 SkRegion clip; | |
| 352 for (int i = 0; i < pixels->clip_rect_count; ++i) { | |
| 353 clip.op(SkIRect::MakeXYWH(pixels->clip_rects[i + 0], | |
| 354 pixels->clip_rects[i + 1], | |
| 355 pixels->clip_rects[i + 2], | |
| 356 pixels->clip_rects[i + 3]), | |
| 357 SkRegion::kUnion_Op); | |
| 358 } | |
| 359 canvas.setClipRegion(clip); | |
| 360 } else if (pixels->clip_region && pixels->clip_region_size) { | |
| 346 SkRegion clip_region; | 361 SkRegion clip_region; |
| 347 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region); | 362 size_t bytes_read = clip_region.readFromMemory(pixels->clip_region); |
| 348 DCHECK_EQ(pixels->clip_region_size, bytes_read); | 363 DCHECK_EQ(pixels->clip_region_size, bytes_read); |
| 349 canvas.setClipRegion(clip_region); | 364 canvas.setClipRegion(clip_region); |
| 350 } else { | 365 } else { |
| 366 NOTREACHED(); | |
| 367 // The |clip| passed in is relative to the canvas, not necessarily to | |
| 368 // |pixels|, so in general it's not safe to use it as a fallback. | |
| 351 canvas.clipRect(gfx::RectToSkRect(clip)); | 369 canvas.clipRect(gfx::RectToSkRect(clip)); |
| 352 } | 370 } |
| 353 canvas.translate(scroll_at_start_of_frame_.x(), | 371 canvas.translate(scroll_at_start_of_frame_.x(), |
| 354 scroll_at_start_of_frame_.y()); | 372 scroll_at_start_of_frame_.y()); |
| 355 | 373 |
| 356 succeeded = CompositeSW(&canvas); | 374 succeeded = CompositeSW(&canvas); |
| 357 } | 375 } |
| 358 | 376 |
| 359 sw_functions->release_pixels(pixels); | 377 sw_functions->release_pixels(pixels); |
| 360 return succeeded; | 378 return succeeded; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 base::StringAppendF(&str, | 683 base::StringAppendF(&str, |
| 666 "surface width height: [%d %d] ", | 684 "surface width height: [%d %d] ", |
| 667 draw_info->width, | 685 draw_info->width, |
| 668 draw_info->height); | 686 draw_info->height); |
| 669 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 687 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 670 } | 688 } |
| 671 return str; | 689 return str; |
| 672 } | 690 } |
| 673 | 691 |
| 674 } // namespace android_webview | 692 } // namespace android_webview |
| OLD | NEW |