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_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/common/gpu/gpu_messages.h" | 27 #include "content/common/gpu/gpu_messages.h" |
28 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
29 #include "content/port/browser/render_widget_host_view_port.h" | 29 #include "content/port/browser/render_widget_host_view_port.h" |
30 #include "content/public/browser/browser_accessibility_state.h" | 30 #include "content/public/browser/browser_accessibility_state.h" |
31 #include "content/public/browser/native_web_keyboard_event.h" | 31 #include "content/public/browser/native_web_keyboard_event.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/result_codes.h" | 36 #include "content/public/common/result_codes.h" |
| 37 #include "skia/ext/image_operations.h" |
| 38 #include "skia/ext/platform_canvas.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
38 #include "ui/base/keycodes/keyboard_codes.h" | 40 #include "ui/base/keycodes/keyboard_codes.h" |
| 41 #include "ui/gfx/skbitmap_operations.h" |
39 #include "webkit/glue/webcursor.h" | 42 #include "webkit/glue/webcursor.h" |
40 #include "webkit/glue/webpreferences.h" | 43 #include "webkit/glue/webpreferences.h" |
41 #include "webkit/plugins/npapi/webplugin.h" | 44 #include "webkit/plugins/npapi/webplugin.h" |
42 | 45 |
43 #if defined(TOOLKIT_GTK) | 46 #if defined(TOOLKIT_GTK) |
44 #include "content/browser/renderer_host/backing_store_gtk.h" | 47 #include "content/browser/renderer_host/backing_store_gtk.h" |
45 #elif defined(OS_MACOSX) | 48 #elif defined(OS_MACOSX) |
46 #include "content/browser/renderer_host/backing_store_mac.h" | 49 #include "content/browser/renderer_host/backing_store_mac.h" |
47 #endif | 50 #endif |
48 | 51 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 SetView(NULL); | 497 SetView(NULL); |
495 } | 498 } |
496 | 499 |
497 void RenderWidgetHostImpl::SetIsLoading(bool is_loading) { | 500 void RenderWidgetHostImpl::SetIsLoading(bool is_loading) { |
498 is_loading_ = is_loading; | 501 is_loading_ = is_loading; |
499 if (!view_) | 502 if (!view_) |
500 return; | 503 return; |
501 view_->SetIsLoading(is_loading); | 504 view_->SetIsLoading(is_loading); |
502 } | 505 } |
503 | 506 |
504 bool RenderWidgetHostImpl::CopyFromBackingStore(skia::PlatformCanvas* output) { | 507 bool RenderWidgetHostImpl::CopyFromBackingStore(const gfx::Size& dest_size, |
| 508 skia::PlatformCanvas* output) { |
| 509 if (view_ && is_accelerated_compositing_active_) { |
| 510 TRACE_EVENT0("browser", |
| 511 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); |
| 512 gfx::Size result_size = view_->GetViewBounds().size(); |
| 513 if (!dest_size.IsEmpty()) { |
| 514 result_size.SetSize(std::min(result_size.width(), dest_size.width()), |
| 515 std::min(result_size.height(), dest_size.height())); |
| 516 } |
| 517 return view_->CopyFromCompositingSurface(result_size, output); |
| 518 } |
| 519 |
505 BackingStore* backing_store = GetBackingStore(false); | 520 BackingStore* backing_store = GetBackingStore(false); |
506 if (!backing_store) | 521 if (!backing_store) |
507 return false; | 522 return false; |
508 | 523 |
509 return backing_store->CopyFromBackingStore( | 524 TRACE_EVENT0("browser", |
510 gfx::Rect(backing_store->size()), output); | 525 "RenderWidgetHostImpl::CopyFromBackingStore::FromBackingStore"); |
| 526 const gfx::Size backing_store_size = backing_store->size(); |
| 527 gfx::Size result_size = backing_store->size(); |
| 528 if (!dest_size.IsEmpty()) { |
| 529 result_size.SetSize(std::min(result_size.width(), dest_size.width()), |
| 530 std::min(result_size.height(), dest_size.height())); |
| 531 } |
| 532 // When the result size is equal to the backing store size, copy from the |
| 533 // backing store directly to the output canvas. |
| 534 if (result_size == backing_store_size) |
| 535 return backing_store->CopyFromBackingStore(gfx::Rect(result_size), output); |
| 536 |
| 537 // Otherwise, first copy from the backing store to a temporary canvas, then |
| 538 // resize it into the result size. |
| 539 skia::PlatformCanvas temp_canvas; |
| 540 if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store_size), |
| 541 &temp_canvas)) |
| 542 return false; |
| 543 |
| 544 SkBitmap downsampled_bitmap = |
| 545 SkBitmapOperations::DownsampleByTwoUntilSize( |
| 546 skia::GetTopDevice(temp_canvas)->accessBitmap(false), |
| 547 result_size.width(), result_size.height()); |
| 548 SkBitmap result_bitmap = skia::ImageOperations::Resize( |
| 549 downsampled_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |
| 550 dest_size.width(), dest_size.height()); |
| 551 if (!output->initialize(result_size.width(), result_size.height(), true)) |
| 552 return false; |
| 553 output->writePixels(result_bitmap, 0, 0); |
| 554 return true; |
511 } | 555 } |
512 | 556 |
513 #if defined(TOOLKIT_GTK) | 557 #if defined(TOOLKIT_GTK) |
514 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( | 558 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( |
515 const gfx::Rect& dest_rect, GdkWindow* target) { | 559 const gfx::Rect& dest_rect, GdkWindow* target) { |
516 BackingStore* backing_store = GetBackingStore(false); | 560 BackingStore* backing_store = GetBackingStore(false); |
517 if (!backing_store) | 561 if (!backing_store) |
518 return false; | 562 return false; |
519 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( | 563 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( |
520 dest_rect, target); | 564 dest_rect, target); |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 | 1720 |
1677 // static | 1721 // static |
1678 void RenderWidgetHostImpl::AcknowledgePostSubBuffer(int32 route_id, | 1722 void RenderWidgetHostImpl::AcknowledgePostSubBuffer(int32 route_id, |
1679 int gpu_host_id) { | 1723 int gpu_host_id) { |
1680 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1724 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
1681 if (ui_shim) | 1725 if (ui_shim) |
1682 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1726 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
1683 } | 1727 } |
1684 | 1728 |
1685 } // namespace content | 1729 } // namespace content |
OLD | NEW |