| 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_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/debug/trace_event.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
| 15 #include "content/public/browser/android/synchronous_compositor.h" |
| 15 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/renderer/android/synchronous_compositor.h" | |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkDevice.h" | 20 #include "third_party/skia/include/core/SkDevice.h" |
| 21 #include "third_party/skia/include/core/SkGraphics.h" | 21 #include "third_party/skia/include/core/SkGraphics.h" |
| 22 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
| 23 #include "ui/gfx/size_conversions.h" | 23 #include "ui/gfx/size_conversions.h" |
| 24 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
| 25 #include "ui/gfx/vector2d_f.h" | 25 #include "ui/gfx/vector2d_f.h" |
| 26 #include "ui/gl/gl_bindings.h" | 26 #include "ui/gl/gl_bindings.h" |
| 27 | 27 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 width_(0), | 271 width_(0), |
| 272 height_(0), | 272 height_(0), |
| 273 attached_to_window_(false), | 273 attached_to_window_(false), |
| 274 hardware_initialized_(false), | 274 hardware_initialized_(false), |
| 275 hardware_failed_(false), | 275 hardware_failed_(false), |
| 276 egl_context_at_init_(NULL), | 276 egl_context_at_init_(NULL), |
| 277 weak_factory_(this) { | 277 weak_factory_(this) { |
| 278 } | 278 } |
| 279 | 279 |
| 280 InProcessViewRenderer::~InProcessViewRenderer() { | 280 InProcessViewRenderer::~InProcessViewRenderer() { |
| 281 if (compositor_) | |
| 282 compositor_->SetClient(NULL); | |
| 283 SetContents(NULL); | 281 SetContents(NULL); |
| 282 DCHECK(compositor_ == NULL); |
| 284 } | 283 } |
| 285 | 284 |
| 286 // static | 285 // static |
| 287 InProcessViewRenderer* InProcessViewRenderer::FromWebContents( | 286 InProcessViewRenderer* InProcessViewRenderer::FromWebContents( |
| 288 content::WebContents* contents) { | 287 content::WebContents* contents) { |
| 289 return UserData::GetInstance(contents); | 288 return UserData::GetInstance(contents); |
| 290 } | 289 } |
| 291 | 290 |
| 292 // static | |
| 293 InProcessViewRenderer* InProcessViewRenderer::FromId(int render_process_id, | |
| 294 int render_view_id) { | |
| 295 const content::RenderViewHost* rvh = | |
| 296 content::RenderViewHost::FromID(render_process_id, render_view_id); | |
| 297 if (!rvh) return NULL; | |
| 298 return InProcessViewRenderer::FromWebContents( | |
| 299 content::WebContents::FromRenderViewHost(rvh)); | |
| 300 } | |
| 301 | |
| 302 void InProcessViewRenderer::BindSynchronousCompositor( | |
| 303 content::SynchronousCompositor* compositor) { | |
| 304 DCHECK(compositor && compositor_ != compositor); | |
| 305 if (compositor_) | |
| 306 compositor_->SetClient(NULL); | |
| 307 compositor_ = compositor; | |
| 308 hardware_initialized_ = false; | |
| 309 hardware_failed_ = false; | |
| 310 compositor_->SetClient(this); | |
| 311 | |
| 312 if (attached_to_window_) | |
| 313 client_->RequestProcessMode(); | |
| 314 } | |
| 315 | |
| 316 void InProcessViewRenderer::SetContents( | 291 void InProcessViewRenderer::SetContents( |
| 317 content::ContentViewCore* content_view_core) { | 292 content::ContentViewCore* content_view_core) { |
| 318 // First remove association from the prior ContentViewCore / WebContents. | 293 // First remove association from the prior ContentViewCore / WebContents. |
| 294 if (compositor_) |
| 295 compositor_->SetClient(NULL); |
| 296 compositor_ = NULL; |
| 319 if (web_contents_) { | 297 if (web_contents_) { |
| 320 web_contents_->SetUserData(kUserDataKey, NULL); | 298 web_contents_->SetUserData(kUserDataKey, NULL); |
| 321 DCHECK(!web_contents_); // WebContentsGone should have been called. | 299 DCHECK(!web_contents_); // WebContentsGone should have been called. |
| 322 } | 300 } |
| 323 | 301 |
| 324 if (!content_view_core) | 302 if (!content_view_core) |
| 325 return; | 303 return; |
| 326 | 304 |
| 327 web_contents_ = content_view_core->GetWebContents(); | 305 web_contents_ = content_view_core->GetWebContents(); |
| 328 web_contents_->SetUserData(kUserDataKey, new UserData(this)); | 306 web_contents_->SetUserData(kUserDataKey, new UserData(this)); |
| 307 content::SynchronousCompositor::GetOrCreateForWebContents(web_contents_)-> |
| 308 SetClient(this); |
| 309 // Currently the logic in this class relies on |compositor_| remaining NULL |
| 310 // until the DidInitializeCompositor() call, hence it is not set here. |
| 329 } | 311 } |
| 330 | 312 |
| 331 void InProcessViewRenderer::WebContentsGone() { | 313 void InProcessViewRenderer::WebContentsGone() { |
| 332 web_contents_ = NULL; | 314 web_contents_ = NULL; |
| 333 } | 315 } |
| 334 | 316 |
| 335 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { | 317 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { |
| 336 // No harm in updating |hw_rendering_scroll_| even if we return false. | 318 // No harm in updating |hw_rendering_scroll_| even if we return false. |
| 337 hw_rendering_scroll_ = gfx::Point(x, y); | 319 hw_rendering_scroll_ = gfx::Point(x, y); |
| 338 return attached_to_window_ && compositor_ && compositor_->IsHwReady() && | 320 return attached_to_window_ && compositor_ && compositor_->IsHwReady() && |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 524 } |
| 543 | 525 |
| 544 bool InProcessViewRenderer::IsViewVisible() { | 526 bool InProcessViewRenderer::IsViewVisible() { |
| 545 return view_visible_; | 527 return view_visible_; |
| 546 } | 528 } |
| 547 | 529 |
| 548 gfx::Rect InProcessViewRenderer::GetScreenRect() { | 530 gfx::Rect InProcessViewRenderer::GetScreenRect() { |
| 549 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); | 531 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); |
| 550 } | 532 } |
| 551 | 533 |
| 534 void InProcessViewRenderer::DidInitializeCompositor( |
| 535 content::SynchronousCompositor* compositor) { |
| 536 DCHECK(compositor && compositor_ == NULL); |
| 537 compositor_ = compositor; |
| 538 hardware_initialized_ = false; |
| 539 hardware_failed_ = false; |
| 540 |
| 541 if (attached_to_window_) |
| 542 client_->RequestProcessMode(); |
| 543 } |
| 544 |
| 552 void InProcessViewRenderer::DidDestroyCompositor( | 545 void InProcessViewRenderer::DidDestroyCompositor( |
| 553 content::SynchronousCompositor* compositor) { | 546 content::SynchronousCompositor* compositor) { |
| 554 // Allow for transient hand-over when two compositors may reference | 547 DCHECK(compositor_ == compositor); |
| 555 // a single client. | 548 compositor_ = NULL; |
| 556 if (compositor_ == compositor) | |
| 557 compositor_ = NULL; | |
| 558 } | 549 } |
| 559 | 550 |
| 560 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { | 551 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 561 if (continuous_invalidate_ == invalidate) | 552 if (continuous_invalidate_ == invalidate) |
| 562 return; | 553 return; |
| 563 | 554 |
| 564 continuous_invalidate_ = invalidate; | 555 continuous_invalidate_ = invalidate; |
| 565 // TODO(boliu): Handle if not attached to window case. | 556 // TODO(boliu): Handle if not attached to window case. |
| 566 EnsureContinuousInvalidation(); | 557 EnsureContinuousInvalidation(); |
| 567 } | 558 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 585 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 576 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
| 586 // scale here. Determine what if any needs bringing over to this class. | 577 // scale here. Determine what if any needs bringing over to this class. |
| 587 return CompositeSW(canvas); | 578 return CompositeSW(canvas); |
| 588 } | 579 } |
| 589 | 580 |
| 590 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 581 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 591 return compositor_ && compositor_->DemandDrawSw(canvas); | 582 return compositor_ && compositor_->DemandDrawSw(canvas); |
| 592 } | 583 } |
| 593 | 584 |
| 594 } // namespace android_webview | 585 } // namespace android_webview |
| OLD | NEW |