OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "content/public/common/content_switches.h" | 69 #include "content/public/common/content_switches.h" |
70 #include "gpu/command_buffer/client/gles2_implementation.h" | 70 #include "gpu/command_buffer/client/gles2_implementation.h" |
71 #include "gpu/command_buffer/client/gles2_interface.h" | 71 #include "gpu/command_buffer/client/gles2_interface.h" |
72 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 72 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
73 #include "ipc/ipc_message_macros.h" | 73 #include "ipc/ipc_message_macros.h" |
74 #include "ipc/ipc_message_start.h" | 74 #include "ipc/ipc_message_start.h" |
75 #include "skia/ext/image_operations.h" | 75 #include "skia/ext/image_operations.h" |
76 #include "third_party/khronos/GLES2/gl2.h" | 76 #include "third_party/khronos/GLES2/gl2.h" |
77 #include "third_party/khronos/GLES2/gl2ext.h" | 77 #include "third_party/khronos/GLES2/gl2ext.h" |
78 #include "third_party/skia/include/core/SkCanvas.h" | 78 #include "third_party/skia/include/core/SkCanvas.h" |
79 #include "ui/android/context_provider_factory.h" | 79 #include "ui/android/delegated_frame_host_android.h" |
80 #include "ui/android/window_android.h" | 80 #include "ui/android/window_android.h" |
81 #include "ui/android/window_android_compositor.h" | 81 #include "ui/android/window_android_compositor.h" |
82 #include "ui/base/layout.h" | 82 #include "ui/base/layout.h" |
83 #include "ui/display/display.h" | 83 #include "ui/display/display.h" |
84 #include "ui/display/screen.h" | 84 #include "ui/display/screen.h" |
85 #include "ui/events/blink/blink_event_util.h" | 85 #include "ui/events/blink/blink_event_util.h" |
86 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 86 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
87 #include "ui/events/gesture_detection/motion_event.h" | 87 #include "ui/events/gesture_detection/motion_event.h" |
88 #include "ui/gfx/android/device_display_info.h" | 88 #include "ui/gfx/android/device_display_info.h" |
89 #include "ui/gfx/android/java_bitmap.h" | 89 #include "ui/gfx/android/java_bitmap.h" |
90 #include "ui/gfx/android/view_configuration.h" | 90 #include "ui/gfx/android/view_configuration.h" |
91 #include "ui/gfx/geometry/dip_util.h" | 91 #include "ui/gfx/geometry/dip_util.h" |
92 #include "ui/gfx/geometry/size_conversions.h" | 92 #include "ui/gfx/geometry/size_conversions.h" |
93 #include "ui/touch_selection/touch_selection_controller.h" | 93 #include "ui/touch_selection/touch_selection_controller.h" |
94 | 94 |
95 namespace content { | 95 namespace content { |
96 | 96 |
97 namespace { | 97 namespace { |
98 | 98 |
99 void SatisfyCallback(cc::SurfaceManager* manager, | |
100 const cc::SurfaceSequence& sequence) { | |
101 std::vector<uint32_t> sequences; | |
102 sequences.push_back(sequence.sequence); | |
103 manager->DidSatisfySequences(sequence.client_id, &sequences); | |
104 } | |
105 | |
106 void RequireCallback(cc::SurfaceManager* manager, | |
107 const cc::SurfaceId& id, | |
108 const cc::SurfaceSequence& sequence) { | |
109 cc::Surface* surface = manager->GetSurfaceForId(id); | |
110 if (!surface) { | |
111 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | |
112 return; | |
113 } | |
114 surface->AddDestructionDependency(sequence); | |
115 } | |
116 | |
117 const int kUndefinedOutputSurfaceId = -1; | 99 const int kUndefinedOutputSurfaceId = -1; |
118 | 100 |
119 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 101 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
120 | 102 |
121 class GLHelperHolder { | 103 class GLHelperHolder { |
122 public: | 104 public: |
123 static GLHelperHolder* Create(); | 105 static GLHelperHolder* Create(); |
124 | 106 |
125 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } | 107 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } |
126 bool IsLost() { | 108 bool IsLost() { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { | 262 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { |
281 gfx::RectF rect = controller.GetRectBetweenBounds(); | 263 gfx::RectF rect = controller.GetRectBetweenBounds(); |
282 if (rect.IsEmpty()) | 264 if (rect.IsEmpty()) |
283 return rect; | 265 return rect; |
284 | 266 |
285 rect.Union(controller.GetStartHandleRect()); | 267 rect.Union(controller.GetStartHandleRect()); |
286 rect.Union(controller.GetEndHandleRect()); | 268 rect.Union(controller.GetEndHandleRect()); |
287 return rect; | 269 return rect; |
288 } | 270 } |
289 | 271 |
290 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( | |
291 const cc::SurfaceId& surface_id, | |
292 const gfx::Size& size) { | |
293 DCHECK(!surface_id.is_null()); | |
294 cc::SurfaceManager* manager = | |
295 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); | |
296 DCHECK(manager); | |
297 // manager must outlive compositors using it. | |
298 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create( | |
299 base::Bind(&SatisfyCallback, base::Unretained(manager)), | |
300 base::Bind(&RequireCallback, base::Unretained(manager))); | |
301 surface_layer->SetSurfaceId(surface_id, 1.f, size); | |
302 surface_layer->SetBounds(size); | |
303 surface_layer->SetIsDrawable(true); | |
304 surface_layer->SetContentsOpaque(true); | |
305 | |
306 return surface_layer; | |
307 } | |
308 | |
309 } // anonymous namespace | 272 } // anonymous namespace |
310 | 273 |
311 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 274 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
312 uint32_t output_id, | 275 uint32_t output_id, |
313 cc::CompositorFrame output_frame) | 276 cc::CompositorFrame output_frame) |
314 : output_surface_id(output_id), frame(std::move(output_frame)) {} | 277 : output_surface_id(output_id), frame(std::move(output_frame)) {} |
315 | 278 |
316 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 279 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
317 | 280 |
318 void RenderWidgetHostViewAndroid::OnContextLost() { | 281 void RenderWidgetHostViewAndroid::OnContextLost() { |
(...skipping 21 matching lines...) Expand all Loading... |
340 last_output_surface_id_(kUndefinedOutputSurfaceId), | 303 last_output_surface_id_(kUndefinedOutputSurfaceId), |
341 gesture_provider_(ui::GetGestureProviderConfig( | 304 gesture_provider_(ui::GetGestureProviderConfig( |
342 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 305 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
343 this), | 306 this), |
344 stylus_text_selector_(this), | 307 stylus_text_selector_(this), |
345 using_browser_compositor_(CompositorImpl::IsInitialized()), | 308 using_browser_compositor_(CompositorImpl::IsInitialized()), |
346 frame_evictor_(new DelegatedFrameEvictor(this)), | 309 frame_evictor_(new DelegatedFrameEvictor(this)), |
347 locks_on_frame_count_(0), | 310 locks_on_frame_count_(0), |
348 observing_root_window_(false), | 311 observing_root_window_(false), |
349 weak_ptr_factory_(this) { | 312 weak_ptr_factory_(this) { |
350 id_allocator_.reset(new cc::SurfaceIdAllocator( | 313 // Set the layer which will hold the content layer for this view. The content |
351 ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId())); | 314 // layer is managed by the DelegatedFrameHost. |
352 ui::ContextProviderFactory::GetInstance() | 315 view_.SetLayer(cc::Layer::Create()); |
353 ->GetSurfaceManager() | 316 |
354 ->RegisterSurfaceClientId(id_allocator_->client_id()); | 317 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
| 318 &view_, cached_background_color_, |
| 319 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, |
| 320 weak_ptr_factory_.GetWeakPtr()))); |
| 321 |
355 host_->SetView(this); | 322 host_->SetView(this); |
356 SetContentViewCore(content_view_core); | 323 SetContentViewCore(content_view_core); |
357 } | 324 } |
358 | 325 |
359 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 326 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
360 if (content_view_core_) | 327 if (content_view_core_) |
361 content_view_core_->RemoveObserver(this); | 328 content_view_core_->RemoveObserver(this); |
362 SetContentViewCore(NULL); | 329 SetContentViewCore(NULL); |
363 DCHECK(ack_callbacks_.empty()); | 330 DCHECK(ack_callbacks_.empty()); |
364 DCHECK(!surface_factory_); | 331 DCHECK(!delegated_frame_host_); |
365 DCHECK(surface_id_.is_null()); | |
366 } | 332 } |
367 | 333 |
368 void RenderWidgetHostViewAndroid::Blur() { | 334 void RenderWidgetHostViewAndroid::Blur() { |
369 host_->Blur(); | 335 host_->Blur(); |
370 if (overscroll_controller_) | 336 if (overscroll_controller_) |
371 overscroll_controller_->Disable(); | 337 overscroll_controller_->Disable(); |
372 } | 338 } |
373 | 339 |
374 bool RenderWidgetHostViewAndroid::OnMessageReceived( | 340 bool RenderWidgetHostViewAndroid::OnMessageReceived( |
375 const IPC::Message& message) { | 341 const IPC::Message& message) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 RenderWidgetHostView* reference_host_view) { | 375 RenderWidgetHostView* reference_host_view) { |
410 NOTIMPLEMENTED(); | 376 NOTIMPLEMENTED(); |
411 } | 377 } |
412 | 378 |
413 RenderWidgetHost* | 379 RenderWidgetHost* |
414 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 380 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
415 return host_; | 381 return host_; |
416 } | 382 } |
417 | 383 |
418 void RenderWidgetHostViewAndroid::WasResized() { | 384 void RenderWidgetHostViewAndroid::WasResized() { |
| 385 delegated_frame_host_->UpdateSize(GetViewSize()); |
419 host_->WasResized(); | 386 host_->WasResized(); |
420 } | 387 } |
421 | 388 |
422 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 389 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
423 // Ignore the given size as only the Java code has the power to | 390 // Ignore the given size as only the Java code has the power to |
424 // resize the view on Android. | 391 // resize the view on Android. |
425 default_size_ = size; | 392 default_size_ = size; |
426 } | 393 } |
427 | 394 |
428 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 395 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
429 SetSize(rect.size()); | 396 SetSize(rect.size()); |
430 } | 397 } |
431 | 398 |
432 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 399 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
433 float scale, | 400 float scale, |
434 SkColorType preferred_color_type, | 401 SkColorType preferred_color_type, |
435 gfx::Rect src_subrect, | 402 gfx::Rect src_subrect, |
436 const ReadbackRequestCallback& result_callback) { | 403 const ReadbackRequestCallback& result_callback) { |
437 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { | 404 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { |
438 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 405 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
439 return; | 406 return; |
440 } | 407 } |
441 gfx::Size bounds = view_.GetLayer()->bounds(); | 408 gfx::Size bounds = delegated_frame_host_->GetContentLayer()->bounds(); |
442 if (src_subrect.IsEmpty()) | 409 if (src_subrect.IsEmpty()) |
443 src_subrect = gfx::Rect(bounds); | 410 src_subrect = gfx::Rect(bounds); |
444 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | 411 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); |
445 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | 412 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); |
446 const display::Display& display = | 413 const display::Display& display = |
447 display::Screen::GetScreen()->GetPrimaryDisplay(); | 414 display::Screen::GetScreen()->GetPrimaryDisplay(); |
448 float device_scale_factor = display.device_scale_factor(); | 415 float device_scale_factor = display.device_scale_factor(); |
449 DCHECK_GT(device_scale_factor, 0); | 416 DCHECK_GT(device_scale_factor, 0); |
450 gfx::Size dst_size( | 417 gfx::Size dst_size( |
451 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); | 418 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); |
452 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); | 419 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); |
453 | 420 |
454 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, | 421 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, |
455 preferred_color_type); | 422 preferred_color_type); |
456 } | 423 } |
457 | 424 |
458 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 425 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
459 if (!content_view_core_) | 426 if (!content_view_core_) |
460 return false; | 427 return false; |
461 if (!view_.GetLayer()) | 428 if (!delegated_frame_host_->GetContentLayer()) |
462 return false; | 429 return false; |
463 | 430 |
464 if (texture_size_in_layer_.IsEmpty()) | 431 if (texture_size_in_layer_.IsEmpty()) |
465 return false; | 432 return false; |
466 // This tell us whether a valid frame has arrived or not. | 433 // This tell us whether a valid frame has arrived or not. |
467 if (!frame_evictor_->HasFrame()) | 434 if (!frame_evictor_->HasFrame()) |
468 return false; | 435 return false; |
469 | 436 |
470 return true; | 437 return true; |
471 } | 438 } |
(...skipping 25 matching lines...) Expand all Loading... |
497 } | 464 } |
498 | 465 |
499 bool RenderWidgetHostViewAndroid::HasFocus() const { | 466 bool RenderWidgetHostViewAndroid::HasFocus() const { |
500 if (!content_view_core_) | 467 if (!content_view_core_) |
501 return false; // ContentViewCore not created yet. | 468 return false; // ContentViewCore not created yet. |
502 | 469 |
503 return content_view_core_->HasFocus(); | 470 return content_view_core_->HasFocus(); |
504 } | 471 } |
505 | 472 |
506 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 473 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
507 return !using_browser_compositor_ || | 474 return !using_browser_compositor_ || HasValidFrame(); |
508 (HasValidFrame() && surface_factory_.get()); | |
509 } | 475 } |
510 | 476 |
511 void RenderWidgetHostViewAndroid::Show() { | 477 void RenderWidgetHostViewAndroid::Show() { |
512 if (is_showing_) | 478 if (is_showing_) |
513 return; | 479 return; |
514 | 480 |
515 is_showing_ = true; | 481 is_showing_ = true; |
516 ShowInternal(); | 482 ShowInternal(); |
517 } | 483 } |
518 | 484 |
(...skipping 30 matching lines...) Expand all Loading... |
549 locks_on_frame_count_--; | 515 locks_on_frame_count_--; |
550 frame_evictor_->UnlockFrame(); | 516 frame_evictor_->UnlockFrame(); |
551 | 517 |
552 if (locks_on_frame_count_ == 0) { | 518 if (locks_on_frame_count_ == 0) { |
553 if (last_frame_info_) { | 519 if (last_frame_info_) { |
554 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, | 520 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, |
555 std::move(last_frame_info_->frame)); | 521 std::move(last_frame_info_->frame)); |
556 last_frame_info_.reset(); | 522 last_frame_info_.reset(); |
557 } | 523 } |
558 | 524 |
559 if (!is_showing_ && view_.GetLayer()) | 525 if (!is_showing_ && delegated_frame_host_->GetContentLayer()) |
560 view_.GetLayer()->SetHideLayerAndSubtree(true); | 526 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true); |
561 } | 527 } |
562 } | 528 } |
563 | 529 |
564 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, | 530 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, |
565 int y_dip) { | 531 int y_dip) { |
566 if (!content_view_core_) | 532 if (!content_view_core_) |
567 return; | 533 return; |
568 // Validate the coordinates are within the viewport. | 534 // Validate the coordinates are within the viewport. |
569 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); | 535 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); |
570 if (x_dip < 0 || x_dip > viewport_size.width() || | 536 if (x_dip < 0 || x_dip > viewport_size.width() || |
571 y_dip < 0 || y_dip > viewport_size.height()) | 537 y_dip < 0 || y_dip > viewport_size.height()) |
572 return; | 538 return; |
573 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); | 539 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); |
574 } | 540 } |
575 | 541 |
576 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { | 542 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { |
577 if (!frame_evictor_->HasFrame()) { | 543 if (!frame_evictor_->HasFrame()) { |
578 DCHECK_EQ(locks_on_frame_count_, 0u); | 544 DCHECK_EQ(locks_on_frame_count_, 0u); |
579 return; | 545 return; |
580 } | 546 } |
581 while (locks_on_frame_count_ > 0) { | 547 while (locks_on_frame_count_ > 0) { |
582 UnlockCompositingSurface(); | 548 UnlockCompositingSurface(); |
583 } | 549 } |
584 RunAckCallbacks(); | 550 RunAckCallbacks(); |
585 } | 551 } |
586 | 552 |
587 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 553 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
588 if (!content_view_core_) | 554 return gfx::Rect(GetViewSize()); |
589 return gfx::Rect(default_size_); | |
590 | |
591 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
592 switches::kEnableOSKOverscroll)) | |
593 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden()); | |
594 | |
595 return gfx::Rect(content_view_core_->GetViewSize()); | |
596 } | 555 } |
597 | 556 |
598 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { | 557 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { |
599 if (!content_view_core_) | 558 if (!content_view_core_) |
600 return default_size_; | 559 return default_size_; |
601 | 560 |
602 return content_view_core_->GetViewSize(); | 561 return content_view_core_->GetViewSize(); |
603 } | 562 } |
604 | 563 |
605 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { | 564 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 params.value, params.selection_start, params.selection_end, | 612 params.value, params.selection_start, params.selection_end, |
654 params.composition_start, params.composition_end, | 613 params.composition_start, params.composition_end, |
655 params.show_ime_if_needed, params.is_non_ime_change); | 614 params.show_ime_if_needed, params.is_non_ime_change); |
656 } | 615 } |
657 | 616 |
658 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { | 617 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { |
659 if (cached_background_color_ == color) | 618 if (cached_background_color_ == color) |
660 return; | 619 return; |
661 | 620 |
662 cached_background_color_ = color; | 621 cached_background_color_ = color; |
| 622 delegated_frame_host_->UpdateBackgroundColor(color); |
663 if (content_view_core_) | 623 if (content_view_core_) |
664 content_view_core_->OnBackgroundColorChanged(color); | 624 content_view_core_->OnBackgroundColorChanged(color); |
665 } | 625 } |
666 | 626 |
667 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { | 627 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { |
668 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", | 628 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", |
669 "enabled", enabled); | 629 "enabled", enabled); |
670 if (enabled) | 630 if (enabled) |
671 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); | 631 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); |
672 else | 632 else |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 ime_adapter_android_.FocusedNodeChanged(is_editable_node); | 745 ime_adapter_android_.FocusedNodeChanged(is_editable_node); |
786 } | 746 } |
787 | 747 |
788 void RenderWidgetHostViewAndroid::RenderProcessGone( | 748 void RenderWidgetHostViewAndroid::RenderProcessGone( |
789 base::TerminationStatus status, int error_code) { | 749 base::TerminationStatus status, int error_code) { |
790 Destroy(); | 750 Destroy(); |
791 } | 751 } |
792 | 752 |
793 void RenderWidgetHostViewAndroid::Destroy() { | 753 void RenderWidgetHostViewAndroid::Destroy() { |
794 host_->ViewDestroyed(); | 754 host_->ViewDestroyed(); |
795 RemoveLayers(); | |
796 SetContentViewCore(NULL); | 755 SetContentViewCore(NULL); |
797 | 756 delegated_frame_host_.reset(); |
798 if (!surface_id_.is_null()) { | |
799 DCHECK(surface_factory_.get()); | |
800 surface_factory_->Destroy(surface_id_); | |
801 surface_id_ = cc::SurfaceId(); | |
802 } | |
803 surface_factory_.reset(); | |
804 ui::ContextProviderFactory::GetInstance() | |
805 ->GetSurfaceManager() | |
806 ->InvalidateSurfaceClientId(id_allocator_->client_id()); | |
807 | 757 |
808 // The RenderWidgetHost's destruction led here, so don't call it. | 758 // The RenderWidgetHost's destruction led here, so don't call it. |
809 host_ = NULL; | 759 host_ = NULL; |
810 | 760 |
811 delete this; | 761 delete this; |
812 } | 762 } |
813 | 763 |
814 void RenderWidgetHostViewAndroid::SetTooltipText( | 764 void RenderWidgetHostViewAndroid::SetTooltipText( |
815 const base::string16& tooltip_text) { | 765 const base::string16& tooltip_text) { |
816 // Tooltips don't makes sense on Android. | 766 // Tooltips don't makes sense on Android. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 832 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
883 preferred_color_type); | 833 preferred_color_type); |
884 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 834 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
885 base::TimeTicks::Now() - start_time); | 835 base::TimeTicks::Now() - start_time); |
886 return; | 836 return; |
887 } | 837 } |
888 | 838 |
889 ui::WindowAndroidCompositor* compositor = | 839 ui::WindowAndroidCompositor* compositor = |
890 content_view_core_->GetWindowAndroid()->GetCompositor(); | 840 content_view_core_->GetWindowAndroid()->GetCompositor(); |
891 DCHECK(compositor); | 841 DCHECK(compositor); |
892 DCHECK(!surface_id_.is_null()); | 842 DCHECK(delegated_frame_host_->GetContentLayer()); |
893 std::unique_ptr<cc::CopyOutputRequest> request = | 843 std::unique_ptr<cc::CopyOutputRequest> request = |
894 cc::CopyOutputRequest::CreateRequest(base::Bind( | 844 cc::CopyOutputRequest::CreateRequest(base::Bind( |
895 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(), | 845 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(), |
896 dst_size_in_pixel, preferred_color_type, start_time, callback)); | 846 dst_size_in_pixel, preferred_color_type, start_time, callback)); |
897 if (!src_subrect_in_pixel.IsEmpty()) | 847 if (!src_subrect_in_pixel.IsEmpty()) |
898 request->set_area(src_subrect_in_pixel); | 848 request->set_area(src_subrect_in_pixel); |
899 // Make sure the current frame doesn't get deleted until we fulfill the | 849 // Make sure the current frame doesn't get deleted until we fulfill the |
900 // request. | 850 // request. |
901 LockCompositingSurface(); | 851 LockCompositingSurface(); |
902 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 852 delegated_frame_host_->RequestCopyOfSurface(std::move(request)); |
903 } | 853 } |
904 | 854 |
905 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 855 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
906 const gfx::Rect& src_subrect, | 856 const gfx::Rect& src_subrect, |
907 const scoped_refptr<media::VideoFrame>& target, | 857 const scoped_refptr<media::VideoFrame>& target, |
908 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 858 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
909 NOTIMPLEMENTED(); | 859 NOTIMPLEMENTED(); |
910 callback.Run(gfx::Rect(), false); | 860 callback.Run(gfx::Rect(), false); |
911 } | 861 } |
912 | 862 |
(...skipping 30 matching lines...) Expand all Loading... |
943 const cc::ReturnedResourceArray& resources) { | 893 const cc::ReturnedResourceArray& resources) { |
944 if (resources.empty()) | 894 if (resources.empty()) |
945 return; | 895 return; |
946 std::copy(resources.begin(), resources.end(), | 896 std::copy(resources.begin(), resources.end(), |
947 std::back_inserter(surface_returned_resources_)); | 897 std::back_inserter(surface_returned_resources_)); |
948 if (ack_callbacks_.empty()) | 898 if (ack_callbacks_.empty()) |
949 SendReclaimCompositorResources(last_output_surface_id_, | 899 SendReclaimCompositorResources(last_output_surface_id_, |
950 false /* is_swap_ack */); | 900 false /* is_swap_ack */); |
951 } | 901 } |
952 | 902 |
953 void RenderWidgetHostViewAndroid::SetBeginFrameSource( | |
954 cc::BeginFrameSource* begin_frame_source) { | |
955 // TODO(tansell): Hook this up. | |
956 } | |
957 | |
958 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | |
959 RemoveLayers(); | |
960 if (!surface_id_.is_null()) { | |
961 DCHECK(surface_factory_.get()); | |
962 surface_factory_->Destroy(surface_id_); | |
963 surface_id_ = cc::SurfaceId(); | |
964 } | |
965 view_.SetLayer(nullptr); | |
966 } | |
967 | |
968 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( | 903 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
969 uint32_t output_surface_id) { | 904 uint32_t output_surface_id) { |
970 if (output_surface_id == last_output_surface_id_) | 905 if (output_surface_id == last_output_surface_id_) |
971 return; | 906 return; |
972 DestroyDelegatedContent(); | 907 delegated_frame_host_->OutputSurfaceChanged(); |
973 surface_factory_.reset(); | 908 |
974 if (!surface_returned_resources_.empty()) | 909 if (!surface_returned_resources_.empty()) |
975 SendReclaimCompositorResources(last_output_surface_id_, | 910 SendReclaimCompositorResources(last_output_surface_id_, |
976 false /* is_swap_ack */); | 911 false /* is_swap_ack */); |
977 | 912 |
978 last_output_surface_id_ = output_surface_id; | 913 last_output_surface_id_ = output_surface_id; |
979 } | 914 } |
980 | 915 |
981 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | |
982 cc::CompositorFrame frame) { | |
983 cc::SurfaceManager* manager = | |
984 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); | |
985 if (!surface_factory_) { | |
986 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | |
987 } | |
988 if (surface_id_.is_null() || | |
989 texture_size_in_layer_ != current_surface_size_ || | |
990 location_bar_content_translation_ != | |
991 frame.metadata.location_bar_content_translation || | |
992 current_viewport_selection_ != frame.metadata.selection) { | |
993 RemoveLayers(); | |
994 if (!surface_id_.is_null()) | |
995 surface_factory_->Destroy(surface_id_); | |
996 surface_id_ = id_allocator_->GenerateId(); | |
997 surface_factory_->Create(surface_id_); | |
998 view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_)); | |
999 | |
1000 DCHECK(view_.GetLayer()); | |
1001 | |
1002 current_surface_size_ = texture_size_in_layer_; | |
1003 location_bar_content_translation_ = | |
1004 frame.metadata.location_bar_content_translation; | |
1005 current_viewport_selection_ = frame.metadata.selection; | |
1006 AttachLayers(); | |
1007 } | |
1008 | |
1009 cc::SurfaceFactory::DrawCallback ack_callback = | |
1010 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | |
1011 weak_ptr_factory_.GetWeakPtr()); | |
1012 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | |
1013 ack_callback); | |
1014 } | |
1015 | |
1016 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 916 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
1017 uint32_t output_surface_id, | 917 uint32_t output_surface_id, |
1018 cc::CompositorFrame frame) { | 918 cc::CompositorFrame frame) { |
1019 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 919 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1020 DCHECK(frame.delegated_frame_data); | 920 DCHECK(frame.delegated_frame_data); |
| 921 DCHECK(delegated_frame_host_); |
1021 | 922 |
1022 if (locks_on_frame_count_ > 0) { | 923 if (locks_on_frame_count_ > 0) { |
1023 DCHECK(HasValidFrame()); | 924 DCHECK(HasValidFrame()); |
1024 RetainFrame(output_surface_id, std::move(frame)); | 925 RetainFrame(output_surface_id, std::move(frame)); |
1025 return; | 926 return; |
1026 } | 927 } |
1027 | 928 |
1028 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); | 929 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); |
1029 | 930 |
1030 cc::RenderPass* root_pass = | 931 cc::RenderPass* root_pass = |
1031 frame.delegated_frame_data->render_pass_list.back().get(); | 932 frame.delegated_frame_data->render_pass_list.back().get(); |
1032 texture_size_in_layer_ = root_pass->output_rect.size(); | 933 texture_size_in_layer_ = root_pass->output_rect.size(); |
1033 | 934 |
1034 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 935 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
1035 | 936 |
1036 CheckOutputSurfaceChanged(output_surface_id); | 937 CheckOutputSurfaceChanged(output_surface_id); |
1037 bool has_content = !texture_size_in_layer_.IsEmpty(); | 938 bool has_content = !texture_size_in_layer_.IsEmpty(); |
1038 | 939 |
1039 base::Closure ack_callback = | 940 base::Closure ack_callback = |
1040 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 941 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
1041 weak_ptr_factory_.GetWeakPtr(), output_surface_id, | 942 weak_ptr_factory_.GetWeakPtr(), output_surface_id, |
1042 true /* is_swap_ack */); | 943 true /* is_swap_ack */); |
1043 | 944 |
1044 ack_callbacks_.push(ack_callback); | 945 ack_callbacks_.push(ack_callback); |
1045 | 946 |
1046 if (!has_content) { | 947 if (!has_content) { |
1047 DestroyDelegatedContent(); | 948 delegated_frame_host_->DestroyDelegatedContent(); |
1048 } else { | 949 } else { |
1049 SubmitCompositorFrame(std::move(frame)); | 950 cc::SurfaceFactory::DrawCallback ack_callback = |
1050 view_.GetLayer()->SetIsDrawable(true); | 951 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
1051 view_.GetLayer()->SetContentsOpaque(true); | 952 weak_ptr_factory_.GetWeakPtr()); |
1052 view_.GetLayer()->SetBounds(texture_size_in_layer_); | 953 delegated_frame_host_->SubmitCompositorFrame(std::move(frame), |
| 954 ack_callback); |
1053 } | 955 } |
1054 | 956 |
1055 if (host_->is_hidden()) | 957 if (host_->is_hidden()) |
1056 RunAckCallbacks(); | 958 RunAckCallbacks(); |
1057 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 959 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
1058 | 960 |
1059 // As the metadata update may trigger view invalidation, always call it after | 961 // As the metadata update may trigger view invalidation, always call it after |
1060 // any potential compositor scheduling. | 962 // any potential compositor scheduling. |
1061 OnFrameMetadataUpdated(std::move(metadata)); | 963 OnFrameMetadataUpdated(std::move(metadata)); |
1062 } | 964 } |
1063 | 965 |
1064 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 966 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
1065 uint32_t output_surface_id, | 967 uint32_t output_surface_id, |
1066 cc::CompositorFrame frame) { | 968 cc::CompositorFrame frame) { |
1067 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); | 969 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); |
1068 } | 970 } |
1069 | 971 |
1070 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 972 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
1071 DestroyDelegatedContent(); | 973 delegated_frame_host_->DestroyDelegatedContent(); |
1072 } | 974 } |
1073 | 975 |
1074 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, | 976 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, |
1075 cc::CompositorFrame frame) { | 977 cc::CompositorFrame frame) { |
1076 DCHECK(locks_on_frame_count_); | 978 DCHECK(locks_on_frame_count_); |
1077 | 979 |
1078 // Store the incoming frame so that it can be swapped when all the locks have | 980 // Store the incoming frame so that it can be swapped when all the locks have |
1079 // been released. If there is already a stored frame, then replace and skip | 981 // been released. If there is already a stored frame, then replace and skip |
1080 // the previous one but make sure we still eventually send the ACK. Holding | 982 // the previous one but make sure we still eventually send the ACK. Holding |
1081 // the ACK also blocks the renderer when its max_frames_pending is reached. | 983 // the ACK also blocks the renderer when its max_frames_pending is reached. |
(...skipping 28 matching lines...) Expand all Loading... |
1110 BrowserThread::PostTask( | 1012 BrowserThread::PostTask( |
1111 BrowserThread::UI, FROM_HERE, | 1013 BrowserThread::UI, FROM_HERE, |
1112 base::Bind( | 1014 base::Bind( |
1113 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, | 1015 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, |
1114 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), | 1016 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), |
1115 base::Passed(&frame_metadata))); | 1017 base::Passed(&frame_metadata))); |
1116 } | 1018 } |
1117 } | 1019 } |
1118 | 1020 |
1119 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { | 1021 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { |
1120 if (view_.GetLayer()) | 1022 if (delegated_frame_host_->GetContentLayer()) |
1121 view_.GetLayer()->SetContentsOpaque(!enabled); | 1023 delegated_frame_host_->GetContentLayer()->SetContentsOpaque(!enabled); |
1122 } | 1024 } |
1123 | 1025 |
1124 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { | 1026 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
1125 // The synchronous (WebView) compositor does not have a proper browser | 1027 // The synchronous (WebView) compositor does not have a proper browser |
1126 // compositor with which to drive animations. | 1028 // compositor with which to drive animations. |
1127 return using_browser_compositor_; | 1029 return using_browser_compositor_; |
1128 } | 1030 } |
1129 | 1031 |
1130 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | 1032 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { |
1131 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); | 1033 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 WebContents* web_contents = | 1169 WebContents* web_contents = |
1268 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_)); | 1170 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_)); |
1269 if (web_contents) { | 1171 if (web_contents) { |
1270 MediaWebContentsObserverAndroid::FromWebContents(web_contents) | 1172 MediaWebContentsObserverAndroid::FromWebContents(web_contents) |
1271 ->OnFrameInfoUpdated(); | 1173 ->OnFrameInfoUpdated(); |
1272 } | 1174 } |
1273 } | 1175 } |
1274 #endif // defined(VIDEO_HOLE) | 1176 #endif // defined(VIDEO_HOLE) |
1275 } | 1177 } |
1276 | 1178 |
| 1179 gfx::Size RenderWidgetHostViewAndroid::GetViewSize() const { |
| 1180 if (!content_view_core_) |
| 1181 return default_size_; |
| 1182 |
| 1183 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1184 switches::kEnableOSKOverscroll)) |
| 1185 return content_view_core_->GetViewSizeWithOSKHidden(); |
| 1186 |
| 1187 return content_view_core_->GetViewSize(); |
| 1188 } |
| 1189 |
1277 void RenderWidgetHostViewAndroid::ShowInternal() { | 1190 void RenderWidgetHostViewAndroid::ShowInternal() { |
1278 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; | 1191 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; |
1279 if (!show) | 1192 if (!show) |
1280 return; | 1193 return; |
1281 | 1194 |
1282 if (!host_ || !host_->is_hidden()) | 1195 if (!host_ || !host_->is_hidden()) |
1283 return; | 1196 return; |
1284 | 1197 |
1285 if (view_.GetLayer()) | 1198 if (delegated_frame_host_->GetContentLayer()) |
1286 view_.GetLayer()->SetHideLayerAndSubtree(false); | 1199 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(false); |
1287 | 1200 |
1288 frame_evictor_->SetVisible(true); | 1201 frame_evictor_->SetVisible(true); |
1289 | 1202 |
1290 if (overscroll_controller_) | 1203 if (overscroll_controller_) |
1291 overscroll_controller_->Enable(); | 1204 overscroll_controller_->Enable(); |
1292 | 1205 |
1293 host_->WasShown(ui::LatencyInfo()); | 1206 host_->WasShown(ui::LatencyInfo()); |
1294 | 1207 |
1295 if (content_view_core_) { | 1208 if (content_view_core_) { |
1296 StartObservingRootWindow(); | 1209 StartObservingRootWindow(); |
1297 RequestVSyncUpdate(BEGIN_FRAME); | 1210 RequestVSyncUpdate(BEGIN_FRAME); |
1298 } | 1211 } |
1299 } | 1212 } |
1300 | 1213 |
1301 void RenderWidgetHostViewAndroid::HideInternal() { | 1214 void RenderWidgetHostViewAndroid::HideInternal() { |
1302 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) | 1215 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) |
1303 << "Hide called when the widget should be shown."; | 1216 << "Hide called when the widget should be shown."; |
1304 | 1217 |
1305 // Only preserve the frontbuffer if the activity was stopped while the | 1218 // Only preserve the frontbuffer if the activity was stopped while the |
1306 // window is still visible. This avoids visual artificts when transitioning | 1219 // window is still visible. This avoids visual artificts when transitioning |
1307 // between activities. | 1220 // between activities. |
1308 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; | 1221 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; |
1309 | 1222 |
1310 // Only stop observing the root window if the widget has been explicitly | 1223 // Only stop observing the root window if the widget has been explicitly |
1311 // hidden and the frontbuffer is being cleared. This allows window visibility | 1224 // hidden and the frontbuffer is being cleared. This allows window visibility |
1312 // notifications to eventually clear the frontbuffer. | 1225 // notifications to eventually clear the frontbuffer. |
1313 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; | 1226 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; |
1314 | 1227 |
1315 if (hide_frontbuffer) { | 1228 if (hide_frontbuffer) { |
1316 if (view_.GetLayer() && locks_on_frame_count_ == 0) | 1229 if (delegated_frame_host_->GetContentLayer() && locks_on_frame_count_ == 0) |
1317 view_.GetLayer()->SetHideLayerAndSubtree(true); | 1230 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true); |
1318 | 1231 |
1319 frame_evictor_->SetVisible(false); | 1232 frame_evictor_->SetVisible(false); |
1320 } | 1233 } |
1321 | 1234 |
1322 if (stop_observing_root_window) { | 1235 if (stop_observing_root_window) { |
1323 DCHECK(!is_showing_); | 1236 DCHECK(!is_showing_); |
1324 StopObservingRootWindow(); | 1237 StopObservingRootWindow(); |
1325 } | 1238 } |
1326 | 1239 |
1327 if (!host_ || host_->is_hidden()) | 1240 if (!host_ || host_->is_hidden()) |
1328 return; | 1241 return; |
1329 | 1242 |
1330 if (overscroll_controller_) | 1243 if (overscroll_controller_) |
1331 overscroll_controller_->Disable(); | 1244 overscroll_controller_->Disable(); |
1332 | 1245 |
1333 RunAckCallbacks(); | 1246 RunAckCallbacks(); |
1334 | 1247 |
1335 // Inform the renderer that we are being hidden so it can reduce its resource | 1248 // Inform the renderer that we are being hidden so it can reduce its resource |
1336 // utilization. | 1249 // utilization. |
1337 host_->WasHidden(); | 1250 host_->WasHidden(); |
1338 } | 1251 } |
1339 | 1252 |
1340 void RenderWidgetHostViewAndroid::AttachLayers() { | |
1341 if (!content_view_core_) | |
1342 return; | |
1343 if (!view_.GetLayer()) | |
1344 return; | |
1345 | |
1346 content_view_core_->AttachLayer(view_.GetLayer()); | |
1347 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); | |
1348 } | |
1349 | |
1350 void RenderWidgetHostViewAndroid::RemoveLayers() { | |
1351 if (!content_view_core_) | |
1352 return; | |
1353 | |
1354 if (!view_.GetLayer()) | |
1355 return; | |
1356 | |
1357 content_view_core_->RemoveLayer(view_.GetLayer()); | |
1358 } | |
1359 | |
1360 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { | 1253 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { |
1361 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1254 bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
1362 outstanding_vsync_requests_ |= requests; | 1255 outstanding_vsync_requests_ |= requests; |
1363 | 1256 |
1364 // Note that if we're not currently observing the root window, outstanding | 1257 // Note that if we're not currently observing the root window, outstanding |
1365 // vsync requests will be pushed if/when we resume observing in | 1258 // vsync requests will be pushed if/when we resume observing in |
1366 // |StartObservingRootWindow()|. | 1259 // |StartObservingRootWindow()|. |
1367 if (observing_root_window_ && should_request_vsync) | 1260 if (observing_root_window_ && should_request_vsync) |
1368 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1261 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
1369 } | 1262 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 } | 1329 } |
1437 | 1330 |
1438 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { | 1331 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { |
1439 if (content_view_core_) | 1332 if (content_view_core_) |
1440 content_view_core_->RequestDisallowInterceptTouchEvent(); | 1333 content_view_core_->RequestDisallowInterceptTouchEvent(); |
1441 } | 1334 } |
1442 | 1335 |
1443 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { | 1336 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { |
1444 DCHECK_EQ(locks_on_frame_count_, 0u); | 1337 DCHECK_EQ(locks_on_frame_count_, 0u); |
1445 frame_evictor_->DiscardedFrame(); | 1338 frame_evictor_->DiscardedFrame(); |
1446 if (view_.GetLayer()) | 1339 delegated_frame_host_->DestroyDelegatedContent(); |
1447 DestroyDelegatedContent(); | |
1448 } | 1340 } |
1449 | 1341 |
1450 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 1342 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
1451 const gfx::Size& desired_size) { | 1343 const gfx::Size& desired_size) { |
1452 NOTREACHED(); | 1344 NOTREACHED(); |
1453 return false; | 1345 return false; |
1454 } | 1346 } |
1455 | 1347 |
1456 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { | 1348 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { |
1457 // ScreenInfo isn't tied to the widget on Android. Always return the default. | 1349 // ScreenInfo isn't tied to the widget on Android. Always return the default. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 | 1539 |
1648 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { | 1540 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { |
1649 return cached_background_color_; | 1541 return cached_background_color_; |
1650 } | 1542 } |
1651 | 1543 |
1652 void RenderWidgetHostViewAndroid::DidOverscroll( | 1544 void RenderWidgetHostViewAndroid::DidOverscroll( |
1653 const DidOverscrollParams& params) { | 1545 const DidOverscrollParams& params) { |
1654 if (sync_compositor_) | 1546 if (sync_compositor_) |
1655 sync_compositor_->DidOverscroll(params); | 1547 sync_compositor_->DidOverscroll(params); |
1656 | 1548 |
1657 if (!content_view_core_ || !view_.GetLayer() || !is_showing_) | 1549 if (!content_view_core_ || !delegated_frame_host_->GetContentLayer() || |
| 1550 !is_showing_) |
1658 return; | 1551 return; |
1659 | 1552 |
1660 if (overscroll_controller_) | 1553 if (overscroll_controller_) |
1661 overscroll_controller_->OnOverscrolled(params); | 1554 overscroll_controller_->OnOverscrolled(params); |
1662 } | 1555 } |
1663 | 1556 |
1664 void RenderWidgetHostViewAndroid::DidStopFlinging() { | 1557 void RenderWidgetHostViewAndroid::DidStopFlinging() { |
1665 if (content_view_core_) | 1558 if (content_view_core_) |
1666 content_view_core_->DidStopFlinging(); | 1559 content_view_core_->DidStopFlinging(); |
1667 } | 1560 } |
1668 | 1561 |
1669 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { | 1562 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { |
1670 if (id_allocator_) | 1563 if (!delegated_frame_host_) |
1671 return id_allocator_->client_id(); | 1564 return 0; |
1672 return 0; | 1565 |
| 1566 return delegated_frame_host_->GetSurfaceClientId(); |
1673 } | 1567 } |
1674 | 1568 |
1675 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1569 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1676 ContentViewCoreImpl* content_view_core) { | 1570 ContentViewCoreImpl* content_view_core) { |
1677 DCHECK(!content_view_core || !content_view_core_ || | 1571 DCHECK(!content_view_core || !content_view_core_ || |
1678 (content_view_core_ == content_view_core)); | 1572 (content_view_core_ == content_view_core)); |
1679 RemoveLayers(); | |
1680 StopObservingRootWindow(); | 1573 StopObservingRootWindow(); |
1681 | 1574 |
1682 bool resize = false; | 1575 bool resize = false; |
1683 if (content_view_core != content_view_core_) { | 1576 if (content_view_core != content_view_core_) { |
1684 overscroll_controller_.reset(); | 1577 overscroll_controller_.reset(); |
1685 selection_controller_.reset(); | 1578 selection_controller_.reset(); |
1686 ReleaseLocksOnSurface(); | 1579 ReleaseLocksOnSurface(); |
1687 // TODO(yusufo) : Get rid of the below conditions and have a better handling | 1580 // TODO(yusufo) : Get rid of the below conditions and have a better handling |
1688 // for resizing after crbug.com/628302 is handled. | 1581 // for resizing after crbug.com/628302 is handled. |
1689 bool is_size_initialized = !content_view_core | 1582 bool is_size_initialized = !content_view_core |
1690 || content_view_core->GetViewportSizeDip().width() != 0 | 1583 || content_view_core->GetViewportSizeDip().width() != 0 |
1691 || content_view_core->GetViewportSizeDip().height() != 0; | 1584 || content_view_core->GetViewportSizeDip().height() != 0; |
1692 if (content_view_core_ || is_size_initialized) | 1585 if (content_view_core_ || is_size_initialized) |
1693 resize = true; | 1586 resize = true; |
1694 if (content_view_core_) { | 1587 if (content_view_core_) { |
1695 content_view_core_->RemoveObserver(this); | 1588 content_view_core_->RemoveObserver(this); |
1696 view_.RemoveFromParent(); | 1589 view_.RemoveFromParent(); |
| 1590 view_.GetLayer()->RemoveFromParent(); |
1697 } | 1591 } |
1698 if (content_view_core) { | 1592 if (content_view_core) { |
1699 content_view_core->AddObserver(this); | 1593 content_view_core->AddObserver(this); |
1700 content_view_core->GetViewAndroid()->AddChild(&view_); | 1594 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid(); |
| 1595 parent_view->AddChild(&view_); |
| 1596 parent_view->GetLayer()->AddChild(view_.GetLayer()); |
1701 } | 1597 } |
1702 content_view_core_ = content_view_core; | 1598 content_view_core_ = content_view_core; |
1703 } | 1599 } |
1704 | 1600 |
1705 BrowserAccessibilityManager* manager = NULL; | 1601 BrowserAccessibilityManager* manager = NULL; |
1706 if (host_) | 1602 if (host_) |
1707 manager = host_->GetRootBrowserAccessibilityManager(); | 1603 manager = host_->GetRootBrowserAccessibilityManager(); |
1708 if (manager) { | 1604 if (manager) { |
1709 base::android::ScopedJavaLocalRef<jobject> obj; | 1605 base::android::ScopedJavaLocalRef<jobject> obj; |
1710 if (content_view_core_) | 1606 if (content_view_core_) |
1711 obj = content_view_core_->GetJavaObject(); | 1607 obj = content_view_core_->GetJavaObject(); |
1712 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1608 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
1713 } | 1609 } |
1714 | 1610 |
1715 AttachLayers(); | |
1716 if (!content_view_core_) { | 1611 if (!content_view_core_) { |
1717 sync_compositor_.reset(); | 1612 sync_compositor_.reset(); |
1718 return; | 1613 return; |
1719 } | 1614 } |
1720 | 1615 |
1721 if (is_showing_) | 1616 if (is_showing_) |
1722 StartObservingRootWindow(); | 1617 StartObservingRootWindow(); |
1723 | 1618 |
1724 if (resize) | 1619 if (resize) |
1725 WasResized(); | 1620 WasResized(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 | 1745 |
1851 void RenderWidgetHostViewAndroid::OnActivityStarted() { | 1746 void RenderWidgetHostViewAndroid::OnActivityStarted() { |
1852 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); | 1747 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); |
1853 DCHECK(observing_root_window_); | 1748 DCHECK(observing_root_window_); |
1854 is_window_activity_started_ = true; | 1749 is_window_activity_started_ = true; |
1855 ShowInternal(); | 1750 ShowInternal(); |
1856 } | 1751 } |
1857 | 1752 |
1858 void RenderWidgetHostViewAndroid::OnLostResources() { | 1753 void RenderWidgetHostViewAndroid::OnLostResources() { |
1859 ReleaseLocksOnSurface(); | 1754 ReleaseLocksOnSurface(); |
1860 if (view_.GetLayer()) | 1755 delegated_frame_host_->DestroyDelegatedContent(); |
1861 DestroyDelegatedContent(); | |
1862 DCHECK(ack_callbacks_.empty()); | 1756 DCHECK(ack_callbacks_.empty()); |
1863 } | 1757 } |
1864 | 1758 |
1865 // TODO(wjmaclean): There is significant overlap between | 1759 // TODO(wjmaclean): There is significant overlap between |
1866 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in | 1760 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in |
1867 // this file, and the versions in surface_utils.cc. They should | 1761 // this file, and the versions in surface_utils.cc. They should |
1868 // be merged. See https://crbug.com/582955 | 1762 // be merged. See https://crbug.com/582955 |
1869 | 1763 |
1870 // static | 1764 // static |
1871 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1765 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 case ui::MotionEvent::ACTION_UP: | 1882 case ui::MotionEvent::ACTION_UP: |
1989 case ui::MotionEvent::ACTION_POINTER_UP: | 1883 case ui::MotionEvent::ACTION_POINTER_UP: |
1990 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1884 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
1991 delta.InMicroseconds(), 1, 1000000, 50); | 1885 delta.InMicroseconds(), 1, 1000000, 50); |
1992 default: | 1886 default: |
1993 return; | 1887 return; |
1994 } | 1888 } |
1995 } | 1889 } |
1996 | 1890 |
1997 } // namespace content | 1891 } // namespace content |
OLD | NEW |