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 |
11 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | |
19 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
20 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
22 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/threading/worker_pool.h" | 23 #include "base/threading/worker_pool.h" |
25 #include "cc/layers/layer.h" | 24 #include "cc/layers/layer.h" |
26 #include "cc/layers/surface_layer.h" | 25 #include "cc/layers/surface_layer.h" |
27 #include "cc/output/compositor_frame.h" | 26 #include "cc/output/compositor_frame.h" |
28 #include "cc/output/copy_output_request.h" | 27 #include "cc/output/copy_output_request.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 #include "content/public/common/content_switches.h" | 67 #include "content/public/common/content_switches.h" |
69 #include "gpu/command_buffer/client/gles2_implementation.h" | 68 #include "gpu/command_buffer/client/gles2_implementation.h" |
70 #include "gpu/command_buffer/client/gles2_interface.h" | 69 #include "gpu/command_buffer/client/gles2_interface.h" |
71 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 70 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
72 #include "ipc/ipc_message_macros.h" | 71 #include "ipc/ipc_message_macros.h" |
73 #include "ipc/ipc_message_start.h" | 72 #include "ipc/ipc_message_start.h" |
74 #include "skia/ext/image_operations.h" | 73 #include "skia/ext/image_operations.h" |
75 #include "third_party/khronos/GLES2/gl2.h" | 74 #include "third_party/khronos/GLES2/gl2.h" |
76 #include "third_party/khronos/GLES2/gl2ext.h" | 75 #include "third_party/khronos/GLES2/gl2ext.h" |
77 #include "third_party/skia/include/core/SkCanvas.h" | 76 #include "third_party/skia/include/core/SkCanvas.h" |
78 #include "ui/android/context_provider_factory.h" | 77 #include "ui/android/delegated_frame_host_android.h" |
79 #include "ui/android/window_android.h" | 78 #include "ui/android/window_android.h" |
80 #include "ui/android/window_android_compositor.h" | 79 #include "ui/android/window_android_compositor.h" |
81 #include "ui/base/layout.h" | 80 #include "ui/base/layout.h" |
82 #include "ui/display/display.h" | 81 #include "ui/display/display.h" |
83 #include "ui/display/screen.h" | 82 #include "ui/display/screen.h" |
84 #include "ui/events/blink/blink_event_util.h" | 83 #include "ui/events/blink/blink_event_util.h" |
85 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 84 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
86 #include "ui/events/gesture_detection/motion_event.h" | 85 #include "ui/events/gesture_detection/motion_event.h" |
87 #include "ui/gfx/android/device_display_info.h" | 86 #include "ui/gfx/android/device_display_info.h" |
88 #include "ui/gfx/android/java_bitmap.h" | 87 #include "ui/gfx/android/java_bitmap.h" |
89 #include "ui/gfx/android/view_configuration.h" | 88 #include "ui/gfx/android/view_configuration.h" |
90 #include "ui/gfx/geometry/dip_util.h" | 89 #include "ui/gfx/geometry/dip_util.h" |
91 #include "ui/gfx/geometry/size_conversions.h" | 90 #include "ui/gfx/geometry/size_conversions.h" |
92 #include "ui/touch_selection/touch_selection_controller.h" | 91 #include "ui/touch_selection/touch_selection_controller.h" |
93 | 92 |
94 namespace content { | 93 namespace content { |
95 | 94 |
96 namespace { | 95 namespace { |
97 | 96 |
98 void SatisfyCallback(cc::SurfaceManager* manager, | |
99 const cc::SurfaceSequence& sequence) { | |
100 std::vector<uint32_t> sequences; | |
101 sequences.push_back(sequence.sequence); | |
102 manager->DidSatisfySequences(sequence.client_id, &sequences); | |
103 } | |
104 | |
105 void RequireCallback(cc::SurfaceManager* manager, | |
106 const cc::SurfaceId& id, | |
107 const cc::SurfaceSequence& sequence) { | |
108 cc::Surface* surface = manager->GetSurfaceForId(id); | |
109 if (!surface) { | |
110 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | |
111 return; | |
112 } | |
113 surface->AddDestructionDependency(sequence); | |
114 } | |
115 | |
116 const int kUndefinedOutputSurfaceId = -1; | 97 const int kUndefinedOutputSurfaceId = -1; |
117 | 98 |
118 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 99 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
119 | 100 |
120 class GLHelperHolder { | 101 class GLHelperHolder { |
121 public: | 102 public: |
122 static GLHelperHolder* Create(); | 103 static GLHelperHolder* Create(); |
123 | 104 |
124 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } | 105 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } |
125 bool IsLost() { | 106 bool IsLost() { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { | 260 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { |
280 gfx::RectF rect = controller.GetRectBetweenBounds(); | 261 gfx::RectF rect = controller.GetRectBetweenBounds(); |
281 if (rect.IsEmpty()) | 262 if (rect.IsEmpty()) |
282 return rect; | 263 return rect; |
283 | 264 |
284 rect.Union(controller.GetStartHandleRect()); | 265 rect.Union(controller.GetStartHandleRect()); |
285 rect.Union(controller.GetEndHandleRect()); | 266 rect.Union(controller.GetEndHandleRect()); |
286 return rect; | 267 return rect; |
287 } | 268 } |
288 | 269 |
289 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( | |
290 const cc::SurfaceId& surface_id, | |
291 const gfx::Size& size) { | |
292 DCHECK(!surface_id.is_null()); | |
293 cc::SurfaceManager* manager = | |
294 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); | |
295 DCHECK(manager); | |
296 // manager must outlive compositors using it. | |
297 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create( | |
298 base::Bind(&SatisfyCallback, base::Unretained(manager)), | |
299 base::Bind(&RequireCallback, base::Unretained(manager))); | |
300 surface_layer->SetSurfaceId(surface_id, 1.f, size); | |
301 surface_layer->SetBounds(size); | |
302 surface_layer->SetIsDrawable(true); | |
303 surface_layer->SetContentsOpaque(true); | |
304 | |
305 return surface_layer; | |
306 } | |
307 | |
308 } // anonymous namespace | 270 } // anonymous namespace |
309 | 271 |
310 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 272 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
311 uint32_t output_id, | 273 uint32_t output_id, |
312 cc::CompositorFrame output_frame) | 274 cc::CompositorFrame output_frame) |
313 : output_surface_id(output_id), frame(std::move(output_frame)) {} | 275 : output_surface_id(output_id), frame(std::move(output_frame)) {} |
314 | 276 |
315 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 277 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
316 | 278 |
317 void RenderWidgetHostViewAndroid::OnContextLost() { | 279 void RenderWidgetHostViewAndroid::OnContextLost() { |
(...skipping 21 matching lines...) Expand all Loading... | |
339 last_output_surface_id_(kUndefinedOutputSurfaceId), | 301 last_output_surface_id_(kUndefinedOutputSurfaceId), |
340 gesture_provider_(ui::GetGestureProviderConfig( | 302 gesture_provider_(ui::GetGestureProviderConfig( |
341 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 303 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
342 this), | 304 this), |
343 stylus_text_selector_(this), | 305 stylus_text_selector_(this), |
344 using_browser_compositor_(CompositorImpl::IsInitialized()), | 306 using_browser_compositor_(CompositorImpl::IsInitialized()), |
345 frame_evictor_(new DelegatedFrameEvictor(this)), | 307 frame_evictor_(new DelegatedFrameEvictor(this)), |
346 locks_on_frame_count_(0), | 308 locks_on_frame_count_(0), |
347 observing_root_window_(false), | 309 observing_root_window_(false), |
348 weak_ptr_factory_(this) { | 310 weak_ptr_factory_(this) { |
311 // Set the layer which will hold the content layer for this view. The content | |
312 // layer is managed by the DelegatedFrameHost. | |
313 view_.SetLayer(cc::Layer::Create()); | |
349 if (using_browser_compositor_) { | 314 if (using_browser_compositor_) { |
350 id_allocator_.reset(new cc::SurfaceIdAllocator( | 315 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
351 ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId())); | 316 &view_, cached_background_color_, |
352 ui::ContextProviderFactory::GetInstance() | 317 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, |
353 ->GetSurfaceManager() | 318 weak_ptr_factory_.GetWeakPtr()))); |
354 ->RegisterSurfaceClientId(id_allocator_->client_id()); | |
355 } | 319 } |
356 | 320 |
357 host_->SetView(this); | 321 host_->SetView(this); |
358 SetContentViewCore(content_view_core); | 322 SetContentViewCore(content_view_core); |
359 } | 323 } |
360 | 324 |
361 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 325 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
362 if (content_view_core_) | 326 if (content_view_core_) |
363 content_view_core_->RemoveObserver(this); | 327 content_view_core_->RemoveObserver(this); |
364 SetContentViewCore(NULL); | 328 SetContentViewCore(NULL); |
365 DCHECK(ack_callbacks_.empty()); | 329 DCHECK(ack_callbacks_.empty()); |
366 DCHECK(!surface_factory_); | 330 DCHECK(!delegated_frame_host_); |
Khushal
2016/08/16 17:36:13
Looks like this is failing because RenderWidgetHos
Khushal
2016/08/16 18:37:36
Pingy!
no sievers
2016/08/16 20:36:36
yes, and in fact 'delete this' is triggered from D
Khushal
2016/08/16 20:38:47
I was actually going to ask why its public if it s
| |
367 DCHECK(surface_id_.is_null()); | |
368 } | 331 } |
369 | 332 |
370 void RenderWidgetHostViewAndroid::Blur() { | 333 void RenderWidgetHostViewAndroid::Blur() { |
371 host_->Blur(); | 334 host_->Blur(); |
372 if (overscroll_controller_) | 335 if (overscroll_controller_) |
373 overscroll_controller_->Disable(); | 336 overscroll_controller_->Disable(); |
374 } | 337 } |
375 | 338 |
376 bool RenderWidgetHostViewAndroid::OnMessageReceived( | 339 bool RenderWidgetHostViewAndroid::OnMessageReceived( |
377 const IPC::Message& message) { | 340 const IPC::Message& message) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 RenderWidgetHostView* reference_host_view) { | 374 RenderWidgetHostView* reference_host_view) { |
412 NOTIMPLEMENTED(); | 375 NOTIMPLEMENTED(); |
413 } | 376 } |
414 | 377 |
415 RenderWidgetHost* | 378 RenderWidgetHost* |
416 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { | 379 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { |
417 return host_; | 380 return host_; |
418 } | 381 } |
419 | 382 |
420 void RenderWidgetHostViewAndroid::WasResized() { | 383 void RenderWidgetHostViewAndroid::WasResized() { |
384 if (delegated_frame_host_) | |
385 delegated_frame_host_->UpdateContainerSizeinDIP(GetVisibleViewportSize()); | |
421 host_->WasResized(); | 386 host_->WasResized(); |
422 } | 387 } |
423 | 388 |
424 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 389 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
425 // 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 |
426 // resize the view on Android. | 391 // resize the view on Android. |
427 default_size_ = size; | 392 default_size_ = size; |
428 } | 393 } |
429 | 394 |
430 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 395 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
431 SetSize(rect.size()); | 396 SetSize(rect.size()); |
432 } | 397 } |
433 | 398 |
434 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 399 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
435 float scale, | 400 float scale, |
436 SkColorType preferred_color_type, | 401 SkColorType preferred_color_type, |
437 gfx::Rect src_subrect, | 402 gfx::Rect src_subrect, |
438 const ReadbackRequestCallback& result_callback) { | 403 const ReadbackRequestCallback& result_callback) { |
439 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { | 404 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { |
440 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 405 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
441 return; | 406 return; |
442 } | 407 } |
443 gfx::Size bounds = view_.GetLayer()->bounds(); | 408 gfx::Size bounds = current_surface_size_; |
444 if (src_subrect.IsEmpty()) | 409 if (src_subrect.IsEmpty()) |
445 src_subrect = gfx::Rect(bounds); | 410 src_subrect = gfx::Rect(bounds); |
446 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | 411 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); |
447 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | 412 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); |
448 const display::Display& display = | 413 const display::Display& display = |
449 display::Screen::GetScreen()->GetPrimaryDisplay(); | 414 display::Screen::GetScreen()->GetPrimaryDisplay(); |
450 float device_scale_factor = display.device_scale_factor(); | 415 float device_scale_factor = display.device_scale_factor(); |
451 DCHECK_GT(device_scale_factor, 0); | 416 DCHECK_GT(device_scale_factor, 0); |
452 gfx::Size dst_size( | 417 gfx::Size dst_size( |
453 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); | 418 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); |
454 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); | 419 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); |
455 | 420 |
456 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, | 421 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, |
457 preferred_color_type); | 422 preferred_color_type); |
458 } | 423 } |
459 | 424 |
460 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 425 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
461 if (!content_view_core_) | 426 if (!content_view_core_) |
462 return false; | 427 return false; |
463 if (!view_.GetLayer()) | |
464 return false; | |
465 | 428 |
466 if (texture_size_in_layer_.IsEmpty()) | 429 if (current_surface_size_.IsEmpty()) |
467 return false; | 430 return false; |
468 // This tell us whether a valid frame has arrived or not. | 431 // This tell us whether a valid frame has arrived or not. |
469 if (!frame_evictor_->HasFrame()) | 432 if (!frame_evictor_->HasFrame()) |
470 return false; | 433 return false; |
471 | 434 |
435 DCHECK(!delegated_frame_host_ || | |
436 delegated_frame_host_->HasDelegatedContent()); | |
472 return true; | 437 return true; |
473 } | 438 } |
474 | 439 |
475 gfx::Vector2dF RenderWidgetHostViewAndroid::GetLastScrollOffset() const { | 440 gfx::Vector2dF RenderWidgetHostViewAndroid::GetLastScrollOffset() const { |
476 return last_scroll_offset_; | 441 return last_scroll_offset_; |
477 } | 442 } |
478 | 443 |
479 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { | 444 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { |
480 return &view_; | 445 return &view_; |
481 } | 446 } |
(...skipping 17 matching lines...) Expand all Loading... | |
499 } | 464 } |
500 | 465 |
501 bool RenderWidgetHostViewAndroid::HasFocus() const { | 466 bool RenderWidgetHostViewAndroid::HasFocus() const { |
502 if (!content_view_core_) | 467 if (!content_view_core_) |
503 return false; // ContentViewCore not created yet. | 468 return false; // ContentViewCore not created yet. |
504 | 469 |
505 return content_view_core_->HasFocus(); | 470 return content_view_core_->HasFocus(); |
506 } | 471 } |
507 | 472 |
508 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 473 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
509 return !using_browser_compositor_ || | 474 return !using_browser_compositor_ || HasValidFrame(); |
510 (HasValidFrame() && surface_factory_.get()); | |
511 } | 475 } |
512 | 476 |
513 void RenderWidgetHostViewAndroid::Show() { | 477 void RenderWidgetHostViewAndroid::Show() { |
514 if (is_showing_) | 478 if (is_showing_) |
515 return; | 479 return; |
516 | 480 |
517 is_showing_ = true; | 481 is_showing_ = true; |
518 ShowInternal(); | 482 ShowInternal(); |
519 } | 483 } |
520 | 484 |
(...skipping 30 matching lines...) Expand all Loading... | |
551 locks_on_frame_count_--; | 515 locks_on_frame_count_--; |
552 frame_evictor_->UnlockFrame(); | 516 frame_evictor_->UnlockFrame(); |
553 | 517 |
554 if (locks_on_frame_count_ == 0) { | 518 if (locks_on_frame_count_ == 0) { |
555 if (last_frame_info_) { | 519 if (last_frame_info_) { |
556 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, | 520 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, |
557 std::move(last_frame_info_->frame)); | 521 std::move(last_frame_info_->frame)); |
558 last_frame_info_.reset(); | 522 last_frame_info_.reset(); |
559 } | 523 } |
560 | 524 |
561 if (!is_showing_ && view_.GetLayer()) | 525 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); |
562 view_.GetLayer()->SetHideLayerAndSubtree(true); | |
563 } | 526 } |
564 } | 527 } |
565 | 528 |
566 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, | 529 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, |
567 int y_dip) { | 530 int y_dip) { |
568 if (!content_view_core_) | 531 if (!content_view_core_) |
569 return; | 532 return; |
570 // Validate the coordinates are within the viewport. | 533 // Validate the coordinates are within the viewport. |
571 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); | 534 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); |
572 if (x_dip < 0 || x_dip > viewport_size.width() || | 535 if (x_dip < 0 || x_dip > viewport_size.width() || |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 params.value, params.selection_start, params.selection_end, | 618 params.value, params.selection_start, params.selection_end, |
656 params.composition_start, params.composition_end, | 619 params.composition_start, params.composition_end, |
657 params.show_ime_if_needed, params.is_non_ime_change); | 620 params.show_ime_if_needed, params.is_non_ime_change); |
658 } | 621 } |
659 | 622 |
660 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { | 623 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { |
661 if (cached_background_color_ == color) | 624 if (cached_background_color_ == color) |
662 return; | 625 return; |
663 | 626 |
664 cached_background_color_ = color; | 627 cached_background_color_ = color; |
628 | |
629 if (delegated_frame_host_) | |
630 delegated_frame_host_->UpdateBackgroundColor(color); | |
631 | |
665 if (content_view_core_) | 632 if (content_view_core_) |
666 content_view_core_->OnBackgroundColorChanged(color); | 633 content_view_core_->OnBackgroundColorChanged(color); |
667 } | 634 } |
668 | 635 |
669 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { | 636 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { |
670 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", | 637 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", |
671 "enabled", enabled); | 638 "enabled", enabled); |
672 if (enabled) | 639 if (enabled) |
673 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); | 640 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); |
674 else | 641 else |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 ime_adapter_android_.FocusedNodeChanged(is_editable_node); | 754 ime_adapter_android_.FocusedNodeChanged(is_editable_node); |
788 } | 755 } |
789 | 756 |
790 void RenderWidgetHostViewAndroid::RenderProcessGone( | 757 void RenderWidgetHostViewAndroid::RenderProcessGone( |
791 base::TerminationStatus status, int error_code) { | 758 base::TerminationStatus status, int error_code) { |
792 Destroy(); | 759 Destroy(); |
793 } | 760 } |
794 | 761 |
795 void RenderWidgetHostViewAndroid::Destroy() { | 762 void RenderWidgetHostViewAndroid::Destroy() { |
796 host_->ViewDestroyed(); | 763 host_->ViewDestroyed(); |
797 RemoveLayers(); | |
798 SetContentViewCore(NULL); | 764 SetContentViewCore(NULL); |
799 | 765 delegated_frame_host_.reset(); |
800 if (!surface_id_.is_null()) { | |
801 DCHECK(surface_factory_.get()); | |
802 surface_factory_->Destroy(surface_id_); | |
803 surface_id_ = cc::SurfaceId(); | |
804 } | |
805 surface_factory_.reset(); | |
806 if (id_allocator_) { | |
807 ui::ContextProviderFactory::GetInstance() | |
808 ->GetSurfaceManager() | |
809 ->InvalidateSurfaceClientId(id_allocator_->client_id()); | |
810 } | |
811 | 766 |
812 // The RenderWidgetHost's destruction led here, so don't call it. | 767 // The RenderWidgetHost's destruction led here, so don't call it. |
813 host_ = NULL; | 768 host_ = NULL; |
814 | 769 |
815 delete this; | 770 delete this; |
816 } | 771 } |
817 | 772 |
818 void RenderWidgetHostViewAndroid::SetTooltipText( | 773 void RenderWidgetHostViewAndroid::SetTooltipText( |
819 const base::string16& tooltip_text) { | 774 const base::string16& tooltip_text) { |
820 // Tooltips don't makes sense on Android. | 775 // Tooltips don't makes sense on Android. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 841 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
887 preferred_color_type); | 842 preferred_color_type); |
888 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 843 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
889 base::TimeTicks::Now() - start_time); | 844 base::TimeTicks::Now() - start_time); |
890 return; | 845 return; |
891 } | 846 } |
892 | 847 |
893 ui::WindowAndroidCompositor* compositor = | 848 ui::WindowAndroidCompositor* compositor = |
894 content_view_core_->GetWindowAndroid()->GetCompositor(); | 849 content_view_core_->GetWindowAndroid()->GetCompositor(); |
895 DCHECK(compositor); | 850 DCHECK(compositor); |
896 DCHECK(!surface_id_.is_null()); | 851 DCHECK(delegated_frame_host_); |
897 scoped_refptr<cc::Layer> layer = | 852 delegated_frame_host_->RequestCopyOfSurface( |
898 CreateSurfaceLayer(surface_id_, texture_size_in_layer_); | 853 compositor, src_subrect_in_pixel, |
899 layer->SetHideLayerAndSubtree(true); | 854 base::Bind(&PrepareTextureCopyOutputResult, dst_size_in_pixel, |
900 compositor->AttachLayerForReadback(layer); | 855 preferred_color_type, start_time, callback)); |
901 | |
902 std::unique_ptr<cc::CopyOutputRequest> request = | |
903 cc::CopyOutputRequest::CreateRequest( | |
904 base::Bind(&PrepareTextureCopyOutputResult, | |
905 weak_ptr_factory_.GetWeakPtr(), layer, dst_size_in_pixel, | |
906 preferred_color_type, start_time, callback)); | |
907 | |
908 if (!src_subrect_in_pixel.IsEmpty()) | |
909 request->set_area(src_subrect_in_pixel); | |
910 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | |
911 } | 856 } |
912 | 857 |
913 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 858 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
914 const gfx::Rect& src_subrect, | 859 const gfx::Rect& src_subrect, |
915 const scoped_refptr<media::VideoFrame>& target, | 860 const scoped_refptr<media::VideoFrame>& target, |
916 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 861 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
917 NOTIMPLEMENTED(); | 862 NOTIMPLEMENTED(); |
918 callback.Run(gfx::Rect(), false); | 863 callback.Run(gfx::Rect(), false); |
919 } | 864 } |
920 | 865 |
(...skipping 30 matching lines...) Expand all Loading... | |
951 const cc::ReturnedResourceArray& resources) { | 896 const cc::ReturnedResourceArray& resources) { |
952 if (resources.empty()) | 897 if (resources.empty()) |
953 return; | 898 return; |
954 std::copy(resources.begin(), resources.end(), | 899 std::copy(resources.begin(), resources.end(), |
955 std::back_inserter(surface_returned_resources_)); | 900 std::back_inserter(surface_returned_resources_)); |
956 if (ack_callbacks_.empty()) | 901 if (ack_callbacks_.empty()) |
957 SendReclaimCompositorResources(last_output_surface_id_, | 902 SendReclaimCompositorResources(last_output_surface_id_, |
958 false /* is_swap_ack */); | 903 false /* is_swap_ack */); |
959 } | 904 } |
960 | 905 |
961 void RenderWidgetHostViewAndroid::SetBeginFrameSource( | |
962 cc::BeginFrameSource* begin_frame_source) { | |
963 // TODO(tansell): Hook this up. | |
964 } | |
965 | |
966 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | |
967 RemoveLayers(); | |
968 if (!surface_id_.is_null()) { | |
969 DCHECK(surface_factory_.get()); | |
970 cc::SurfaceId surface_id; | |
971 std::swap(surface_id, surface_id_); | |
972 surface_factory_->Destroy(surface_id); | |
973 } | |
974 view_.SetLayer(nullptr); | |
975 } | |
976 | |
977 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( | 906 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
978 uint32_t output_surface_id) { | 907 uint32_t output_surface_id) { |
979 if (output_surface_id == last_output_surface_id_) | 908 if (output_surface_id == last_output_surface_id_) |
980 return; | 909 return; |
981 DestroyDelegatedContent(); | 910 |
982 surface_factory_.reset(); | 911 delegated_frame_host_->OutputSurfaceChanged(); |
912 | |
983 if (!surface_returned_resources_.empty()) | 913 if (!surface_returned_resources_.empty()) |
984 SendReclaimCompositorResources(last_output_surface_id_, | 914 SendReclaimCompositorResources(last_output_surface_id_, |
985 false /* is_swap_ack */); | 915 false /* is_swap_ack */); |
986 | 916 |
987 last_output_surface_id_ = output_surface_id; | 917 last_output_surface_id_ = output_surface_id; |
988 } | 918 } |
989 | 919 |
990 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | |
991 cc::CompositorFrame frame) { | |
992 cc::SurfaceManager* manager = | |
993 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); | |
994 if (!surface_factory_) { | |
995 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | |
996 } | |
997 if (surface_id_.is_null() || | |
998 texture_size_in_layer_ != current_surface_size_ || | |
999 location_bar_content_translation_ != | |
1000 frame.metadata.location_bar_content_translation || | |
1001 current_viewport_selection_ != frame.metadata.selection) { | |
1002 RemoveLayers(); | |
1003 if (!surface_id_.is_null()) | |
1004 surface_factory_->Destroy(surface_id_); | |
1005 surface_id_ = id_allocator_->GenerateId(); | |
1006 surface_factory_->Create(surface_id_); | |
1007 view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_)); | |
1008 | |
1009 DCHECK(view_.GetLayer()); | |
1010 | |
1011 current_surface_size_ = texture_size_in_layer_; | |
1012 location_bar_content_translation_ = | |
1013 frame.metadata.location_bar_content_translation; | |
1014 current_viewport_selection_ = frame.metadata.selection; | |
1015 AttachLayers(); | |
1016 } | |
1017 | |
1018 cc::SurfaceFactory::DrawCallback ack_callback = | |
1019 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | |
1020 weak_ptr_factory_.GetWeakPtr()); | |
1021 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | |
1022 ack_callback); | |
1023 } | |
1024 | |
1025 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 920 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
1026 uint32_t output_surface_id, | 921 uint32_t output_surface_id, |
1027 cc::CompositorFrame frame) { | 922 cc::CompositorFrame frame) { |
1028 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 923 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1029 DCHECK(frame.delegated_frame_data); | 924 DCHECK(frame.delegated_frame_data); |
925 DCHECK(delegated_frame_host_); | |
1030 | 926 |
1031 if (locks_on_frame_count_ > 0) { | 927 if (locks_on_frame_count_ > 0) { |
1032 DCHECK(HasValidFrame()); | 928 DCHECK(HasValidFrame()); |
1033 RetainFrame(output_surface_id, std::move(frame)); | 929 RetainFrame(output_surface_id, std::move(frame)); |
1034 return; | 930 return; |
1035 } | 931 } |
1036 | 932 |
1037 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); | 933 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); |
1038 | 934 |
1039 cc::RenderPass* root_pass = | 935 cc::RenderPass* root_pass = |
1040 frame.delegated_frame_data->render_pass_list.back().get(); | 936 frame.delegated_frame_data->render_pass_list.back().get(); |
1041 texture_size_in_layer_ = root_pass->output_rect.size(); | 937 current_surface_size_ = root_pass->output_rect.size(); |
1042 | 938 |
1043 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 939 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
1044 | 940 |
1045 CheckOutputSurfaceChanged(output_surface_id); | 941 CheckOutputSurfaceChanged(output_surface_id); |
1046 bool has_content = !texture_size_in_layer_.IsEmpty(); | 942 bool has_content = !current_surface_size_.IsEmpty(); |
1047 | 943 |
1048 base::Closure ack_callback = | 944 base::Closure ack_callback = |
1049 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 945 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
1050 weak_ptr_factory_.GetWeakPtr(), output_surface_id, | 946 weak_ptr_factory_.GetWeakPtr(), output_surface_id, |
1051 true /* is_swap_ack */); | 947 true /* is_swap_ack */); |
1052 | 948 |
1053 ack_callbacks_.push(ack_callback); | 949 ack_callbacks_.push(ack_callback); |
1054 | 950 |
1055 if (!has_content) { | 951 if (!has_content) { |
1056 DestroyDelegatedContent(); | 952 delegated_frame_host_->DestroyDelegatedContent(); |
1057 } else { | 953 } else { |
1058 SubmitCompositorFrame(std::move(frame)); | 954 cc::SurfaceFactory::DrawCallback ack_callback = |
1059 view_.GetLayer()->SetIsDrawable(true); | 955 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
1060 view_.GetLayer()->SetContentsOpaque(true); | 956 weak_ptr_factory_.GetWeakPtr()); |
1061 view_.GetLayer()->SetBounds(texture_size_in_layer_); | 957 delegated_frame_host_->SubmitCompositorFrame(std::move(frame), |
958 ack_callback); | |
1062 } | 959 } |
1063 | 960 |
1064 if (host_->is_hidden()) | 961 if (host_->is_hidden()) |
1065 RunAckCallbacks(); | 962 RunAckCallbacks(); |
1066 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 963 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
1067 | 964 |
1068 // As the metadata update may trigger view invalidation, always call it after | 965 // As the metadata update may trigger view invalidation, always call it after |
1069 // any potential compositor scheduling. | 966 // any potential compositor scheduling. |
1070 OnFrameMetadataUpdated(std::move(metadata)); | 967 OnFrameMetadataUpdated(std::move(metadata)); |
1071 } | 968 } |
1072 | 969 |
1073 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 970 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
1074 uint32_t output_surface_id, | 971 uint32_t output_surface_id, |
1075 cc::CompositorFrame frame) { | 972 cc::CompositorFrame frame) { |
1076 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); | 973 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); |
1077 } | 974 } |
1078 | 975 |
1079 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 976 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
1080 DestroyDelegatedContent(); | 977 if (delegated_frame_host_) |
978 delegated_frame_host_->DestroyDelegatedContent(); | |
1081 } | 979 } |
1082 | 980 |
1083 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, | 981 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, |
1084 cc::CompositorFrame frame) { | 982 cc::CompositorFrame frame) { |
1085 DCHECK(locks_on_frame_count_); | 983 DCHECK(locks_on_frame_count_); |
1086 | 984 |
1087 // Store the incoming frame so that it can be swapped when all the locks have | 985 // Store the incoming frame so that it can be swapped when all the locks have |
1088 // been released. If there is already a stored frame, then replace and skip | 986 // been released. If there is already a stored frame, then replace and skip |
1089 // the previous one but make sure we still eventually send the ACK. Holding | 987 // the previous one but make sure we still eventually send the ACK. Holding |
1090 // the ACK also blocks the renderer when its max_frames_pending is reached. | 988 // the ACK also blocks the renderer when its max_frames_pending is reached. |
(...skipping 28 matching lines...) Expand all Loading... | |
1119 BrowserThread::PostTask( | 1017 BrowserThread::PostTask( |
1120 BrowserThread::UI, FROM_HERE, | 1018 BrowserThread::UI, FROM_HERE, |
1121 base::Bind( | 1019 base::Bind( |
1122 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, | 1020 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, |
1123 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), | 1021 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), |
1124 base::Passed(&frame_metadata))); | 1022 base::Passed(&frame_metadata))); |
1125 } | 1023 } |
1126 } | 1024 } |
1127 | 1025 |
1128 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { | 1026 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { |
1129 if (view_.GetLayer()) | 1027 if (delegated_frame_host_) |
1130 view_.GetLayer()->SetContentsOpaque(!enabled); | 1028 delegated_frame_host_->SetContentsOpaque(!enabled); |
1131 } | 1029 } |
1132 | 1030 |
1133 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { | 1031 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
1134 // The synchronous (WebView) compositor does not have a proper browser | 1032 // The synchronous (WebView) compositor does not have a proper browser |
1135 // compositor with which to drive animations. | 1033 // compositor with which to drive animations. |
1136 return using_browser_compositor_; | 1034 return using_browser_compositor_; |
1137 } | 1035 } |
1138 | 1036 |
1139 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | 1037 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { |
1140 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); | 1038 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 content_view_core_->GetContext().obj())); | 1089 content_view_core_->GetContext().obj())); |
1192 } | 1090 } |
1193 | 1091 |
1194 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1092 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1195 const gfx::Rect& src_subrect_in_pixel, | 1093 const gfx::Rect& src_subrect_in_pixel, |
1196 const gfx::Size& dst_size_in_pixel, | 1094 const gfx::Size& dst_size_in_pixel, |
1197 const ReadbackRequestCallback& callback, | 1095 const ReadbackRequestCallback& callback, |
1198 const SkColorType color_type) { | 1096 const SkColorType color_type) { |
1199 gfx::Size input_size_in_pixel; | 1097 gfx::Size input_size_in_pixel; |
1200 if (src_subrect_in_pixel.IsEmpty()) | 1098 if (src_subrect_in_pixel.IsEmpty()) |
1201 input_size_in_pixel = texture_size_in_layer_; | 1099 input_size_in_pixel = current_surface_size_; |
1202 else | 1100 else |
1203 input_size_in_pixel = src_subrect_in_pixel.size(); | 1101 input_size_in_pixel = src_subrect_in_pixel.size(); |
1204 | 1102 |
1205 gfx::Size output_size_in_pixel; | 1103 gfx::Size output_size_in_pixel; |
1206 if (dst_size_in_pixel.IsEmpty()) | 1104 if (dst_size_in_pixel.IsEmpty()) |
1207 output_size_in_pixel = input_size_in_pixel; | 1105 output_size_in_pixel = input_size_in_pixel; |
1208 else | 1106 else |
1209 output_size_in_pixel = dst_size_in_pixel; | 1107 output_size_in_pixel = dst_size_in_pixel; |
1210 int output_width = output_size_in_pixel.width(); | 1108 int output_width = output_size_in_pixel.width(); |
1211 int output_height = output_size_in_pixel.height(); | 1109 int output_height = output_size_in_pixel.height(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1284 } | 1182 } |
1285 | 1183 |
1286 void RenderWidgetHostViewAndroid::ShowInternal() { | 1184 void RenderWidgetHostViewAndroid::ShowInternal() { |
1287 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; | 1185 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; |
1288 if (!show) | 1186 if (!show) |
1289 return; | 1187 return; |
1290 | 1188 |
1291 if (!host_ || !host_->is_hidden()) | 1189 if (!host_ || !host_->is_hidden()) |
1292 return; | 1190 return; |
1293 | 1191 |
1294 if (view_.GetLayer()) | 1192 view_.GetLayer()->SetHideLayerAndSubtree(false); |
1295 view_.GetLayer()->SetHideLayerAndSubtree(false); | |
1296 | 1193 |
1297 frame_evictor_->SetVisible(true); | 1194 frame_evictor_->SetVisible(true); |
1298 | 1195 |
1299 if (overscroll_controller_) | 1196 if (overscroll_controller_) |
1300 overscroll_controller_->Enable(); | 1197 overscroll_controller_->Enable(); |
1301 | 1198 |
1302 host_->WasShown(ui::LatencyInfo()); | 1199 host_->WasShown(ui::LatencyInfo()); |
1303 | 1200 |
1304 if (content_view_core_) { | 1201 if (content_view_core_) { |
1305 StartObservingRootWindow(); | 1202 StartObservingRootWindow(); |
1306 RequestVSyncUpdate(BEGIN_FRAME); | 1203 RequestVSyncUpdate(BEGIN_FRAME); |
1307 } | 1204 } |
1308 } | 1205 } |
1309 | 1206 |
1310 void RenderWidgetHostViewAndroid::HideInternal() { | 1207 void RenderWidgetHostViewAndroid::HideInternal() { |
1311 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) | 1208 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) |
1312 << "Hide called when the widget should be shown."; | 1209 << "Hide called when the widget should be shown."; |
1313 | 1210 |
1314 // Only preserve the frontbuffer if the activity was stopped while the | 1211 // Only preserve the frontbuffer if the activity was stopped while the |
1315 // window is still visible. This avoids visual artificts when transitioning | 1212 // window is still visible. This avoids visual artificts when transitioning |
1316 // between activities. | 1213 // between activities. |
1317 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; | 1214 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; |
1318 | 1215 |
1319 // Only stop observing the root window if the widget has been explicitly | 1216 // Only stop observing the root window if the widget has been explicitly |
1320 // hidden and the frontbuffer is being cleared. This allows window visibility | 1217 // hidden and the frontbuffer is being cleared. This allows window visibility |
1321 // notifications to eventually clear the frontbuffer. | 1218 // notifications to eventually clear the frontbuffer. |
1322 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; | 1219 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; |
1323 | 1220 |
1324 if (hide_frontbuffer) { | 1221 if (hide_frontbuffer) { |
1325 if (view_.GetLayer() && locks_on_frame_count_ == 0) | 1222 if (locks_on_frame_count_ == 0) |
1326 view_.GetLayer()->SetHideLayerAndSubtree(true); | 1223 view_.GetLayer()->SetHideLayerAndSubtree(true); |
1327 | 1224 |
1328 frame_evictor_->SetVisible(false); | 1225 frame_evictor_->SetVisible(false); |
1329 } | 1226 } |
1330 | 1227 |
1331 if (stop_observing_root_window) { | 1228 if (stop_observing_root_window) { |
1332 DCHECK(!is_showing_); | 1229 DCHECK(!is_showing_); |
1333 StopObservingRootWindow(); | 1230 StopObservingRootWindow(); |
1334 } | 1231 } |
1335 | 1232 |
1336 if (!host_ || host_->is_hidden()) | 1233 if (!host_ || host_->is_hidden()) |
1337 return; | 1234 return; |
1338 | 1235 |
1339 if (overscroll_controller_) | 1236 if (overscroll_controller_) |
1340 overscroll_controller_->Disable(); | 1237 overscroll_controller_->Disable(); |
1341 | 1238 |
1342 RunAckCallbacks(); | 1239 RunAckCallbacks(); |
1343 | 1240 |
1344 // Inform the renderer that we are being hidden so it can reduce its resource | 1241 // Inform the renderer that we are being hidden so it can reduce its resource |
1345 // utilization. | 1242 // utilization. |
1346 host_->WasHidden(); | 1243 host_->WasHidden(); |
1347 } | 1244 } |
1348 | 1245 |
1349 void RenderWidgetHostViewAndroid::AttachLayers() { | |
1350 if (!content_view_core_) | |
1351 return; | |
1352 if (!view_.GetLayer()) | |
1353 return; | |
1354 | |
1355 content_view_core_->AttachLayer(view_.GetLayer()); | |
1356 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_); | |
1357 } | |
1358 | |
1359 void RenderWidgetHostViewAndroid::RemoveLayers() { | |
1360 if (!content_view_core_) | |
1361 return; | |
1362 | |
1363 if (!view_.GetLayer()) | |
1364 return; | |
1365 | |
1366 content_view_core_->RemoveLayer(view_.GetLayer()); | |
1367 } | |
1368 | |
1369 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { | 1246 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { |
1370 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1247 bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
1371 outstanding_vsync_requests_ |= requests; | 1248 outstanding_vsync_requests_ |= requests; |
1372 | 1249 |
1373 // Note that if we're not currently observing the root window, outstanding | 1250 // Note that if we're not currently observing the root window, outstanding |
1374 // vsync requests will be pushed if/when we resume observing in | 1251 // vsync requests will be pushed if/when we resume observing in |
1375 // |StartObservingRootWindow()|. | 1252 // |StartObservingRootWindow()|. |
1376 if (observing_root_window_ && should_request_vsync) | 1253 if (observing_root_window_ && should_request_vsync) |
1377 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1254 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
1378 } | 1255 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1445 } | 1322 } |
1446 | 1323 |
1447 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { | 1324 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { |
1448 if (content_view_core_) | 1325 if (content_view_core_) |
1449 content_view_core_->RequestDisallowInterceptTouchEvent(); | 1326 content_view_core_->RequestDisallowInterceptTouchEvent(); |
1450 } | 1327 } |
1451 | 1328 |
1452 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { | 1329 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { |
1453 DCHECK_EQ(locks_on_frame_count_, 0u); | 1330 DCHECK_EQ(locks_on_frame_count_, 0u); |
1454 frame_evictor_->DiscardedFrame(); | 1331 frame_evictor_->DiscardedFrame(); |
1455 if (view_.GetLayer()) | 1332 if (delegated_frame_host_) |
1456 DestroyDelegatedContent(); | 1333 delegated_frame_host_->DestroyDelegatedContent(); |
1457 } | 1334 } |
1458 | 1335 |
1459 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 1336 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
1460 const gfx::Size& desired_size) { | 1337 const gfx::Size& desired_size) { |
1461 NOTREACHED(); | 1338 NOTREACHED(); |
1462 return false; | 1339 return false; |
1463 } | 1340 } |
1464 | 1341 |
1465 // TODO(jrg): Find out the implications and answer correctly here, | 1342 // TODO(jrg): Find out the implications and answer correctly here, |
1466 // as we are returning the WebView and not root window bounds. | 1343 // as we are returning the WebView and not root window bounds. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 | 1528 |
1652 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { | 1529 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { |
1653 return cached_background_color_; | 1530 return cached_background_color_; |
1654 } | 1531 } |
1655 | 1532 |
1656 void RenderWidgetHostViewAndroid::DidOverscroll( | 1533 void RenderWidgetHostViewAndroid::DidOverscroll( |
1657 const DidOverscrollParams& params) { | 1534 const DidOverscrollParams& params) { |
1658 if (sync_compositor_) | 1535 if (sync_compositor_) |
1659 sync_compositor_->DidOverscroll(params); | 1536 sync_compositor_->DidOverscroll(params); |
1660 | 1537 |
1661 if (!content_view_core_ || !view_.GetLayer() || !is_showing_) | 1538 if (!content_view_core_ || !is_showing_) |
1539 return; | |
1540 | |
1541 if (delegated_frame_host_ && delegated_frame_host_->HasDelegatedContent()) | |
no sievers
2016/08/16 18:32:59
You meant the opposite right?
I'm actually not su
Khushal
2016/08/16 20:36:57
Done.
| |
1662 return; | 1542 return; |
1663 | 1543 |
1664 if (overscroll_controller_) | 1544 if (overscroll_controller_) |
1665 overscroll_controller_->OnOverscrolled(params); | 1545 overscroll_controller_->OnOverscrolled(params); |
1666 } | 1546 } |
1667 | 1547 |
1668 void RenderWidgetHostViewAndroid::DidStopFlinging() { | 1548 void RenderWidgetHostViewAndroid::DidStopFlinging() { |
1669 if (content_view_core_) | 1549 if (content_view_core_) |
1670 content_view_core_->DidStopFlinging(); | 1550 content_view_core_->DidStopFlinging(); |
1671 } | 1551 } |
1672 | 1552 |
1673 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { | 1553 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { |
1674 if (id_allocator_) | 1554 if (!delegated_frame_host_) |
1675 return id_allocator_->client_id(); | 1555 return 0; |
1676 return 0; | 1556 |
1557 return delegated_frame_host_->GetSurfaceClientId(); | |
1677 } | 1558 } |
1678 | 1559 |
1679 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1560 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1680 ContentViewCoreImpl* content_view_core) { | 1561 ContentViewCoreImpl* content_view_core) { |
1681 DCHECK(!content_view_core || !content_view_core_ || | 1562 DCHECK(!content_view_core || !content_view_core_ || |
1682 (content_view_core_ == content_view_core)); | 1563 (content_view_core_ == content_view_core)); |
1683 RemoveLayers(); | |
1684 StopObservingRootWindow(); | 1564 StopObservingRootWindow(); |
1685 | 1565 |
1686 bool resize = false; | 1566 bool resize = false; |
1687 if (content_view_core != content_view_core_) { | 1567 if (content_view_core != content_view_core_) { |
1688 overscroll_controller_.reset(); | 1568 overscroll_controller_.reset(); |
1689 selection_controller_.reset(); | 1569 selection_controller_.reset(); |
1690 ReleaseLocksOnSurface(); | 1570 ReleaseLocksOnSurface(); |
1691 // TODO(yusufo) : Get rid of the below conditions and have a better handling | 1571 // TODO(yusufo) : Get rid of the below conditions and have a better handling |
1692 // for resizing after crbug.com/628302 is handled. | 1572 // for resizing after crbug.com/628302 is handled. |
1693 bool is_size_initialized = !content_view_core | 1573 bool is_size_initialized = !content_view_core |
1694 || content_view_core->GetViewportSizeDip().width() != 0 | 1574 || content_view_core->GetViewportSizeDip().width() != 0 |
1695 || content_view_core->GetViewportSizeDip().height() != 0; | 1575 || content_view_core->GetViewportSizeDip().height() != 0; |
1696 if (content_view_core_ || is_size_initialized) | 1576 if (content_view_core_ || is_size_initialized) |
1697 resize = true; | 1577 resize = true; |
1698 if (content_view_core_) { | 1578 if (content_view_core_) { |
1699 content_view_core_->RemoveObserver(this); | 1579 content_view_core_->RemoveObserver(this); |
1700 view_.RemoveFromParent(); | 1580 view_.RemoveFromParent(); |
1581 view_.GetLayer()->RemoveFromParent(); | |
1701 } | 1582 } |
1702 if (content_view_core) { | 1583 if (content_view_core) { |
1703 content_view_core->AddObserver(this); | 1584 content_view_core->AddObserver(this); |
1704 content_view_core->GetViewAndroid()->AddChild(&view_); | 1585 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid(); |
1586 parent_view->AddChild(&view_); | |
1587 parent_view->GetLayer()->AddChild(view_.GetLayer()); | |
1705 } | 1588 } |
1706 content_view_core_ = content_view_core; | 1589 content_view_core_ = content_view_core; |
1707 } | 1590 } |
1708 | 1591 |
1709 BrowserAccessibilityManager* manager = NULL; | 1592 BrowserAccessibilityManager* manager = NULL; |
1710 if (host_) | 1593 if (host_) |
1711 manager = host_->GetRootBrowserAccessibilityManager(); | 1594 manager = host_->GetRootBrowserAccessibilityManager(); |
1712 if (manager) { | 1595 if (manager) { |
1713 base::android::ScopedJavaLocalRef<jobject> obj; | 1596 base::android::ScopedJavaLocalRef<jobject> obj; |
1714 if (content_view_core_) | 1597 if (content_view_core_) |
1715 obj = content_view_core_->GetJavaObject(); | 1598 obj = content_view_core_->GetJavaObject(); |
1716 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1599 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
1717 } | 1600 } |
1718 | 1601 |
1719 AttachLayers(); | |
1720 if (!content_view_core_) { | 1602 if (!content_view_core_) { |
1721 sync_compositor_.reset(); | 1603 sync_compositor_.reset(); |
1722 return; | 1604 return; |
1723 } | 1605 } |
1724 | 1606 |
1725 if (is_showing_) | 1607 if (is_showing_) |
1726 StartObservingRootWindow(); | 1608 StartObservingRootWindow(); |
1727 | 1609 |
1728 if (resize) | 1610 if (resize) |
1729 WasResized(); | 1611 WasResized(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1854 | 1736 |
1855 void RenderWidgetHostViewAndroid::OnActivityStarted() { | 1737 void RenderWidgetHostViewAndroid::OnActivityStarted() { |
1856 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); | 1738 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); |
1857 DCHECK(observing_root_window_); | 1739 DCHECK(observing_root_window_); |
1858 is_window_activity_started_ = true; | 1740 is_window_activity_started_ = true; |
1859 ShowInternal(); | 1741 ShowInternal(); |
1860 } | 1742 } |
1861 | 1743 |
1862 void RenderWidgetHostViewAndroid::OnLostResources() { | 1744 void RenderWidgetHostViewAndroid::OnLostResources() { |
1863 ReleaseLocksOnSurface(); | 1745 ReleaseLocksOnSurface(); |
1864 if (view_.GetLayer()) | 1746 if (delegated_frame_host_) |
1865 DestroyDelegatedContent(); | 1747 delegated_frame_host_->DestroyDelegatedContent(); |
1866 DCHECK(ack_callbacks_.empty()); | 1748 DCHECK(ack_callbacks_.empty()); |
1867 } | 1749 } |
1868 | 1750 |
1869 // TODO(wjmaclean): There is significant overlap between | 1751 // TODO(wjmaclean): There is significant overlap between |
1870 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in | 1752 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in |
1871 // this file, and the versions in surface_utils.cc. They should | 1753 // this file, and the versions in surface_utils.cc. They should |
1872 // be merged. See https://crbug.com/582955 | 1754 // be merged. See https://crbug.com/582955 |
1873 | 1755 |
1874 // static | 1756 // static |
1875 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1757 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1876 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva, | |
1877 scoped_refptr<cc::Layer> readback_layer, | |
1878 const gfx::Size& dst_size_in_pixel, | 1758 const gfx::Size& dst_size_in_pixel, |
1879 SkColorType color_type, | 1759 SkColorType color_type, |
1880 const base::TimeTicks& start_time, | 1760 const base::TimeTicks& start_time, |
1881 const ReadbackRequestCallback& callback, | 1761 const ReadbackRequestCallback& callback, |
1882 std::unique_ptr<cc::CopyOutputResult> result) { | 1762 std::unique_ptr<cc::CopyOutputResult> result) { |
1883 base::ScopedClosureRunner scoped_callback_runner( | 1763 base::ScopedClosureRunner scoped_callback_runner( |
1884 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1764 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1885 TRACE_EVENT0("cc", | 1765 TRACE_EVENT0("cc", |
1886 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1766 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1887 readback_layer->RemoveFromParent(); | |
1888 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1767 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1889 return; | 1768 return; |
1890 cc::TextureMailbox texture_mailbox; | 1769 cc::TextureMailbox texture_mailbox; |
1891 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | 1770 std::unique_ptr<cc::SingleReleaseCallback> release_callback; |
1892 result->TakeTexture(&texture_mailbox, &release_callback); | 1771 result->TakeTexture(&texture_mailbox, &release_callback); |
1893 DCHECK(texture_mailbox.IsTexture()); | 1772 DCHECK(texture_mailbox.IsTexture()); |
1894 if (!texture_mailbox.IsTexture()) | 1773 if (!texture_mailbox.IsTexture()) |
1895 return; | 1774 return; |
1896 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | 1775 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); |
1897 if (!gl_helper) | 1776 if (!gl_helper) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1974 case ui::MotionEvent::ACTION_UP: | 1853 case ui::MotionEvent::ACTION_UP: |
1975 case ui::MotionEvent::ACTION_POINTER_UP: | 1854 case ui::MotionEvent::ACTION_POINTER_UP: |
1976 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1855 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
1977 delta.InMicroseconds(), 1, 1000000, 50); | 1856 delta.InMicroseconds(), 1, 1000000, 50); |
1978 default: | 1857 default: |
1979 return; | 1858 return; |
1980 } | 1859 } |
1981 } | 1860 } |
1982 | 1861 |
1983 } // namespace content | 1862 } // namespace content |
OLD | NEW |