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

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

Issue 15795002: Cache auxiliary bitmap across draw frames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bo & kaan comments Created 7 years, 7 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 (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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 picture->endRecording(); 337 picture->endRecording();
328 338
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. Pass false
348 // for |cache_result| as the picture we create will hold a shallow reference
349 // to the bitmap drawn, and we don't want subsequent draws to corrupt any
350 // previously returned pictures.
338 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap( 351 ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap(
339 env, picture->width(), picture->height())); 352 env, picture->width(), picture->height(), false));
340 if (!jbitmap.obj()) 353 if (!jbitmap.obj())
341 return ScopedJavaLocalRef<jobject>(); 354 return ScopedJavaLocalRef<jobject>();
342 355
343 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0, 356 if (!RasterizeIntoBitmap(env, jbitmap, 0, 0,
344 base::Bind(&RenderPictureToCanvas, 357 base::Bind(&RenderPictureToCanvas,
345 base::Unretained(picture.get())))) { 358 base::Unretained(picture.get())))) {
346 return ScopedJavaLocalRef<jobject>(); 359 return ScopedJavaLocalRef<jobject>();
347 } 360 }
348 361
349 return java_helper_->RecordBitmapIntoPicture(env, jbitmap); 362 return java_helper_->RecordBitmapIntoPicture(env, jbitmap);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page 436 // 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. 437 // scale here. Determine what if any needs bringing over to this class.
425 return CompositeSW(canvas); 438 return CompositeSW(canvas);
426 } 439 }
427 440
428 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { 441 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) {
429 return compositor_ && compositor_->DemandDrawSw(canvas); 442 return compositor_ && compositor_->DemandDrawSw(canvas);
430 } 443 }
431 444
432 } // namespace android_webview 445 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698