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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
15 #include "cc/output/compositor_frame_ack.h" | 15 #include "cc/output/compositor_frame_ack.h" |
| 16 #include "cc/output/copy_output_request.h" |
| 17 #include "cc/output/copy_output_result.h" |
16 #include "cc/resources/texture_mailbox.h" | 18 #include "cc/resources/texture_mailbox.h" |
17 #include "content/browser/accessibility/browser_accessibility_manager.h" | 19 #include "content/browser/accessibility/browser_accessibility_manager.h" |
18 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 20 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
19 #include "content/browser/renderer_host/backing_store_aura.h" | 21 #include "content/browser/renderer_host/backing_store_aura.h" |
20 #include "content/browser/renderer_host/dip_util.h" | 22 #include "content/browser/renderer_host/dip_util.h" |
21 #include "content/browser/renderer_host/overscroll_controller.h" | 23 #include "content/browser/renderer_host/overscroll_controller.h" |
22 #include "content/browser/renderer_host/render_view_host_delegate.h" | 24 #include "content/browser/renderer_host/render_view_host_delegate.h" |
23 #include "content/browser/renderer_host/render_widget_host_impl.h" | 25 #include "content/browser/renderer_host/render_widget_host_impl.h" |
24 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h" | 26 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_aura.h" |
25 #include "content/browser/renderer_host/ui_events_helper.h" | 27 #include "content/browser/renderer_host/ui_events_helper.h" |
26 #include "content/browser/renderer_host/web_input_event_aura.h" | 28 #include "content/browser/renderer_host/web_input_event_aura.h" |
27 #include "content/common/gpu/client/gl_helper.h" | 29 #include "content/common/gpu/client/gl_helper.h" |
28 #include "content/common/gpu/gpu_messages.h" | 30 #include "content/common/gpu/gpu_messages.h" |
29 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
30 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 32 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
31 #include "content/port/browser/render_widget_host_view_port.h" | 33 #include "content/port/browser/render_widget_host_view_port.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
35 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
37 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
38 #include "media/base/video_util.h" | 40 #include "media/base/video_util.h" |
| 41 #include "skia/ext/image_operations.h" |
39 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 42 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
40 #include "third_party/WebKit/public/web/WebInputEvent.h" | 43 #include "third_party/WebKit/public/web/WebInputEvent.h" |
41 #include "third_party/WebKit/public/web/WebScreenInfo.h" | 44 #include "third_party/WebKit/public/web/WebScreenInfo.h" |
42 #include "ui/aura/client/activation_client.h" | 45 #include "ui/aura/client/activation_client.h" |
43 #include "ui/aura/client/aura_constants.h" | 46 #include "ui/aura/client/aura_constants.h" |
44 #include "ui/aura/client/cursor_client.h" | 47 #include "ui/aura/client/cursor_client.h" |
45 #include "ui/aura/client/cursor_client_observer.h" | 48 #include "ui/aura/client/cursor_client_observer.h" |
46 #include "ui/aura/client/focus_client.h" | 49 #include "ui/aura/client/focus_client.h" |
47 #include "ui/aura/client/screen_position_client.h" | 50 #include "ui/aura/client/screen_position_client.h" |
48 #include "ui/aura/client/stacking_client.h" | 51 #include "ui/aura/client/stacking_client.h" |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 | 944 |
942 void RenderWidgetHostViewAura::Blur() { | 945 void RenderWidgetHostViewAura::Blur() { |
943 window_->Blur(); | 946 window_->Blur(); |
944 } | 947 } |
945 | 948 |
946 bool RenderWidgetHostViewAura::HasFocus() const { | 949 bool RenderWidgetHostViewAura::HasFocus() const { |
947 return window_->HasFocus(); | 950 return window_->HasFocus(); |
948 } | 951 } |
949 | 952 |
950 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { | 953 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const { |
951 return current_surface_.get() || current_software_frame_.IsValid() || | 954 return window_->layer()->has_external_content(); |
952 !!host_->GetBackingStore(false); | |
953 } | 955 } |
954 | 956 |
955 void RenderWidgetHostViewAura::Show() { | 957 void RenderWidgetHostViewAura::Show() { |
956 window_->Show(); | 958 window_->Show(); |
957 } | 959 } |
958 | 960 |
959 void RenderWidgetHostViewAura::Hide() { | 961 void RenderWidgetHostViewAura::Hide() { |
960 window_->Hide(); | 962 window_->Hide(); |
961 } | 963 } |
962 | 964 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1160 |
1159 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( | 1161 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( |
1160 const gfx::Size& size) { | 1162 const gfx::Size& size) { |
1161 return new BackingStoreAura(host_, size); | 1163 return new BackingStoreAura(host_, size); |
1162 } | 1164 } |
1163 | 1165 |
1164 void RenderWidgetHostViewAura::CopyFromCompositingSurface( | 1166 void RenderWidgetHostViewAura::CopyFromCompositingSurface( |
1165 const gfx::Rect& src_subrect, | 1167 const gfx::Rect& src_subrect, |
1166 const gfx::Size& dst_size, | 1168 const gfx::Size& dst_size, |
1167 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 1169 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
1168 | 1170 if (!IsSurfaceAvailableForCopy()) { |
1169 base::ScopedClosureRunner scoped_callback_runner( | 1171 callback.Run(false, SkBitmap()); |
1170 base::Bind(callback, false, SkBitmap())); | |
1171 if (!current_surface_.get()) | |
1172 return; | 1172 return; |
| 1173 } |
1173 | 1174 |
1174 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 1175 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
1175 SkBitmap output; | 1176 scoped_ptr<cc::CopyOutputRequest> request = |
1176 output.setConfig(SkBitmap::kARGB_8888_Config, | 1177 cc::CopyOutputRequest::CreateRequest(base::Bind( |
1177 dst_size_in_pixel.width(), dst_size_in_pixel.height()); | 1178 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResult, |
1178 if (!output.allocPixels()) | 1179 dst_size_in_pixel, |
1179 return; | 1180 callback)); |
1180 output.setIsOpaque(true); | 1181 request->set_area(src_subrect); |
1181 | 1182 window_->layer()->RequestCopyOfOutput(request.Pass()); |
1182 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
1183 GLHelper* gl_helper = factory->GetGLHelper(); | |
1184 if (!gl_helper) | |
1185 return; | |
1186 | |
1187 unsigned char* addr = static_cast<unsigned char*>(output.getPixels()); | |
1188 scoped_callback_runner.Release(); | |
1189 // Wrap the callback with an internal handler so that we can inject our | |
1190 // own completion handlers (where we can try to free the frontbuffer). | |
1191 base::Callback<void(bool)> wrapper_callback = base::Bind( | |
1192 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished, | |
1193 output, | |
1194 callback); | |
1195 | |
1196 // Convert |src_subrect| from the views coordinate (upper-left origin) into | |
1197 // the OpenGL coordinate (lower-left origin). | |
1198 gfx::Rect src_subrect_in_gl = src_subrect; | |
1199 src_subrect_in_gl.set_y(GetViewBounds().height() - src_subrect.bottom()); | |
1200 | |
1201 gfx::Rect src_subrect_in_pixel = | |
1202 ConvertRectToPixel(current_surface_->device_scale_factor(), | |
1203 src_subrect_in_gl); | |
1204 gl_helper->CropScaleReadbackAndCleanTexture( | |
1205 current_surface_->PrepareTexture(), | |
1206 current_surface_->size(), | |
1207 src_subrect_in_pixel, | |
1208 dst_size_in_pixel, | |
1209 addr, | |
1210 wrapper_callback); | |
1211 } | 1183 } |
1212 | 1184 |
1213 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame( | 1185 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame( |
1214 const gfx::Rect& src_subrect, | 1186 const gfx::Rect& src_subrect, |
1215 const scoped_refptr<media::VideoFrame>& target, | 1187 const scoped_refptr<media::VideoFrame>& target, |
1216 const base::Callback<void(bool)>& callback) { | 1188 const base::Callback<void(bool)>& callback) { |
1217 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 1189 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
1218 | 1190 |
1219 if (!current_surface_.get()) | 1191 if (!current_surface_.get()) |
1220 return; | 1192 return; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't | 1730 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't |
1759 // matter what is returned here as GetBackingStore is the only caller of this | 1731 // matter what is returned here as GetBackingStore is the only caller of this |
1760 // method. TODO(jbates) implement this if other Aura code needs it. | 1732 // method. TODO(jbates) implement this if other Aura code needs it. |
1761 return false; | 1733 return false; |
1762 } | 1734 } |
1763 | 1735 |
1764 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor( | 1736 void RenderWidgetHostViewAura::SetSurfaceNotInUseByCompositor( |
1765 scoped_refptr<ui::Texture>) { | 1737 scoped_refptr<ui::Texture>) { |
1766 } | 1738 } |
1767 | 1739 |
1768 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceFinished( | 1740 // static |
1769 const SkBitmap& bitmap, | 1741 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResult( |
| 1742 const gfx::Size& dst_size_in_pixel, |
1770 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1743 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1744 scoped_ptr<cc::CopyOutputResult> result) { |
| 1745 if (result->IsEmpty() || result->size().IsEmpty()) { |
| 1746 callback.Run(false, SkBitmap()); |
| 1747 return; |
| 1748 } |
| 1749 |
| 1750 if (result->HasTexture()) { |
| 1751 PrepareTextureCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); |
| 1752 return; |
| 1753 } |
| 1754 |
| 1755 DCHECK(result->HasBitmap()); |
| 1756 PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); |
| 1757 } |
| 1758 |
| 1759 static void CopyFromCompositingSurfaceFinished( |
| 1760 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1761 scoped_ptr<SkBitmap> bitmap, |
| 1762 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
1771 bool result) { | 1763 bool result) { |
1772 callback.Run(result, bitmap); | 1764 bitmap_pixels_lock.reset(); |
| 1765 callback.Run(result, *bitmap); |
| 1766 } |
| 1767 |
| 1768 // static |
| 1769 void RenderWidgetHostViewAura::PrepareTextureCopyOutputResult( |
| 1770 const gfx::Size& dst_size_in_pixel, |
| 1771 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1772 scoped_ptr<cc::CopyOutputResult> result) { |
| 1773 base::ScopedClosureRunner scoped_callback_runner( |
| 1774 base::Bind(callback, false, SkBitmap())); |
| 1775 |
| 1776 DCHECK(result->HasTexture()); |
| 1777 if (!result->HasTexture()) |
| 1778 return; |
| 1779 |
| 1780 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 1781 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 1782 dst_size_in_pixel.width(), dst_size_in_pixel.height()); |
| 1783 if (!bitmap->allocPixels()) |
| 1784 return; |
| 1785 bitmap->setIsOpaque(true); |
| 1786 |
| 1787 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1788 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1789 if (!gl_helper) |
| 1790 return; |
| 1791 |
| 1792 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 1793 new SkAutoLockPixels(*bitmap)); |
| 1794 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 1795 |
| 1796 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture(); |
| 1797 DCHECK(texture_mailbox->IsTexture()); |
| 1798 if (!texture_mailbox->IsTexture()) |
| 1799 return; |
| 1800 |
| 1801 scoped_callback_runner.Release(); |
| 1802 |
| 1803 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 1804 texture_mailbox->name(), |
| 1805 texture_mailbox->sync_point(), |
| 1806 result->size(), |
| 1807 gfx::Rect(result->size()), |
| 1808 dst_size_in_pixel, |
| 1809 pixels, |
| 1810 base::Bind(&CopyFromCompositingSurfaceFinished, |
| 1811 callback, |
| 1812 base::Passed(&bitmap), |
| 1813 base::Passed(&bitmap_pixels_lock))); |
| 1814 } |
| 1815 |
| 1816 // static |
| 1817 void RenderWidgetHostViewAura::PrepareBitmapCopyOutputResult( |
| 1818 const gfx::Size& dst_size_in_pixel, |
| 1819 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1820 scoped_ptr<cc::CopyOutputResult> result) { |
| 1821 DCHECK(result->HasBitmap()); |
| 1822 |
| 1823 base::ScopedClosureRunner scoped_callback_runner( |
| 1824 base::Bind(callback, false, SkBitmap())); |
| 1825 if (!result->HasBitmap()) |
| 1826 return; |
| 1827 |
| 1828 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
| 1829 DCHECK(source); |
| 1830 if (!source) |
| 1831 return; |
| 1832 |
| 1833 scoped_callback_runner.Release(); |
| 1834 |
| 1835 SkBitmap bitmap = skia::ImageOperations::Resize( |
| 1836 *source, |
| 1837 skia::ImageOperations::RESIZE_BEST, |
| 1838 dst_size_in_pixel.width(), |
| 1839 dst_size_in_pixel.height()); |
| 1840 callback.Run(true, bitmap); |
1773 } | 1841 } |
1774 | 1842 |
1775 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { | 1843 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { |
1776 GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL); | 1844 GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL); |
1777 } | 1845 } |
1778 | 1846 |
1779 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() { | 1847 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() { |
1780 return window_->GetToplevelWindow()->GetBoundsInScreen(); | 1848 return window_->GetToplevelWindow()->GetBoundsInScreen(); |
1781 } | 1849 } |
1782 | 1850 |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3016 RenderWidgetHost* widget) { | 3084 RenderWidgetHost* widget) { |
3017 return new RenderWidgetHostViewAura(widget); | 3085 return new RenderWidgetHostViewAura(widget); |
3018 } | 3086 } |
3019 | 3087 |
3020 // static | 3088 // static |
3021 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3089 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3022 GetScreenInfoForWindow(results, NULL); | 3090 GetScreenInfoForWindow(results, NULL); |
3023 } | 3091 } |
3024 | 3092 |
3025 } // namespace content | 3093 } // namespace content |
OLD | NEW |