Chromium Code Reviews| 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); |
|
mkosiba (inactive)
2013/05/30 11:05:29
add a DCHECK(compositor_ == NULL)?
joth
2013/05/30 19:18:05
Done.
| |
| 284 } | 282 } |
| 285 | 283 |
| 286 // static | 284 // static |
| 287 InProcessViewRenderer* InProcessViewRenderer::FromWebContents( | 285 InProcessViewRenderer* InProcessViewRenderer::FromWebContents( |
| 288 content::WebContents* contents) { | 286 content::WebContents* contents) { |
| 289 return UserData::GetInstance(contents); | 287 return UserData::GetInstance(contents); |
| 290 } | 288 } |
| 291 | 289 |
| 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( | 290 void InProcessViewRenderer::SetContents( |
| 317 content::ContentViewCore* content_view_core) { | 291 content::ContentViewCore* content_view_core) { |
| 318 // First remove association from the prior ContentViewCore / WebContents. | 292 // First remove association from the prior ContentViewCore / WebContents. |
| 293 if (compositor_) | |
| 294 compositor_->SetClient(NULL); | |
| 295 compositor_ = NULL; | |
| 319 if (web_contents_) { | 296 if (web_contents_) { |
| 320 web_contents_->SetUserData(kUserDataKey, NULL); | 297 web_contents_->SetUserData(kUserDataKey, NULL); |
| 321 DCHECK(!web_contents_); // WebContentsGone should have been called. | 298 DCHECK(!web_contents_); // WebContentsGone should have been called. |
| 322 } | 299 } |
| 323 | 300 |
| 324 if (!content_view_core) | 301 if (!content_view_core) |
| 325 return; | 302 return; |
| 326 | 303 |
| 327 web_contents_ = content_view_core->GetWebContents(); | 304 web_contents_ = content_view_core->GetWebContents(); |
| 328 web_contents_->SetUserData(kUserDataKey, new UserData(this)); | 305 web_contents_->SetUserData(kUserDataKey, new UserData(this)); |
| 306 content::SynchronousCompositor::GetOrCreateForWebContents(web_contents_)-> | |
| 307 SetClient(this); | |
| 308 // Currently the logic in this class relies on |compositor_| remaining NULL | |
| 309 // until the DidInitializeCompositor() call, hence it is not set here. | |
| 329 } | 310 } |
| 330 | 311 |
| 331 void InProcessViewRenderer::WebContentsGone() { | 312 void InProcessViewRenderer::WebContentsGone() { |
| 332 web_contents_ = NULL; | 313 web_contents_ = NULL; |
| 333 } | 314 } |
| 334 | 315 |
| 335 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { | 316 bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { |
| 336 // No harm in updating |hw_rendering_scroll_| even if we return false. | 317 // No harm in updating |hw_rendering_scroll_| even if we return false. |
| 337 hw_rendering_scroll_ = gfx::Point(x, y); | 318 hw_rendering_scroll_ = gfx::Point(x, y); |
| 338 return attached_to_window_ && compositor_ && compositor_->IsHwReady() && | 319 return attached_to_window_ && compositor_ && compositor_->IsHwReady() && |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 523 } |
| 543 | 524 |
| 544 bool InProcessViewRenderer::IsViewVisible() { | 525 bool InProcessViewRenderer::IsViewVisible() { |
| 545 return view_visible_; | 526 return view_visible_; |
| 546 } | 527 } |
| 547 | 528 |
| 548 gfx::Rect InProcessViewRenderer::GetScreenRect() { | 529 gfx::Rect InProcessViewRenderer::GetScreenRect() { |
| 549 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); | 530 return gfx::Rect(client_->GetLocationOnScreen(), gfx::Size(width_, height_)); |
| 550 } | 531 } |
| 551 | 532 |
| 533 void InProcessViewRenderer::DidInitializeCompositor( | |
| 534 content::SynchronousCompositor* compositor) { | |
| 535 DCHECK(compositor && compositor_ == NULL); | |
| 536 compositor_ = compositor; | |
| 537 hardware_initialized_ = false; | |
| 538 hardware_failed_ = false; | |
| 539 | |
| 540 if (attached_to_window_) | |
| 541 client_->RequestProcessMode(); | |
| 542 } | |
| 543 | |
| 552 void InProcessViewRenderer::DidDestroyCompositor( | 544 void InProcessViewRenderer::DidDestroyCompositor( |
| 553 content::SynchronousCompositor* compositor) { | 545 content::SynchronousCompositor* compositor) { |
| 554 // Allow for transient hand-over when two compositors may reference | 546 DCHECK(compositor_ == compositor); |
| 555 // a single client. | 547 compositor_ = NULL; |
| 556 if (compositor_ == compositor) | |
| 557 compositor_ = NULL; | |
| 558 } | 548 } |
| 559 | 549 |
| 560 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { | 550 void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 561 if (continuous_invalidate_ == invalidate) | 551 if (continuous_invalidate_ == invalidate) |
| 562 return; | 552 return; |
| 563 | 553 |
| 564 continuous_invalidate_ = invalidate; | 554 continuous_invalidate_ = invalidate; |
| 565 // TODO(boliu): Handle if not attached to window case. | 555 // TODO(boliu): Handle if not attached to window case. |
| 566 EnsureContinuousInvalidation(); | 556 EnsureContinuousInvalidation(); |
| 567 } | 557 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 585 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 575 // 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. | 576 // scale here. Determine what if any needs bringing over to this class. |
| 587 return CompositeSW(canvas); | 577 return CompositeSW(canvas); |
| 588 } | 578 } |
| 589 | 579 |
| 590 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 580 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
| 591 return compositor_ && compositor_->DemandDrawSw(canvas); | 581 return compositor_ && compositor_->DemandDrawSw(canvas); |
| 592 } | 582 } |
| 593 | 583 |
| 594 } // namespace android_webview | 584 } // namespace android_webview |
| OLD | NEW |