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 "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 | 961 |
962 readback_layer = delegated_layer; | 962 readback_layer = delegated_layer; |
963 request = cc::CopyOutputRequest::CreateRequest( | 963 request = cc::CopyOutputRequest::CreateRequest( |
964 base::Bind(&RenderWidgetHostViewAndroid:: | 964 base::Bind(&RenderWidgetHostViewAndroid:: |
965 PrepareTextureCopyOutputResultForDelegatedReadback, | 965 PrepareTextureCopyOutputResultForDelegatedReadback, |
966 dst_size_in_pixel, | 966 dst_size_in_pixel, |
967 color_type, | 967 color_type, |
968 start_time, | 968 start_time, |
969 readback_layer, | 969 readback_layer, |
970 callback)); | 970 callback)); |
971 request->set_area(src_subrect_in_pixel); | 971 if (!src_subrect_in_pixel.IsEmpty()) |
972 request->set_area(src_subrect_in_pixel); | |
972 readback_layer->RequestCopyOfOutput(request.Pass()); | 973 readback_layer->RequestCopyOfOutput(request.Pass()); |
973 } | 974 } |
974 | 975 |
975 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 976 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
976 const gfx::Rect& src_subrect, | 977 const gfx::Rect& src_subrect, |
977 const scoped_refptr<media::VideoFrame>& target, | 978 const scoped_refptr<media::VideoFrame>& target, |
978 const base::Callback<void(bool)>& callback) { | 979 const base::Callback<void(bool)>& callback) { |
979 NOTIMPLEMENTED(); | 980 NOTIMPLEMENTED(); |
980 callback.Run(false); | 981 callback.Run(false); |
981 } | 982 } |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 // Use the activity context (instead of the application context) to ensure | 1276 // Use the activity context (instead of the application context) to ensure |
1276 // proper handle theming. | 1277 // proper handle theming. |
1277 content_view_core_->GetContext().obj())); | 1278 content_view_core_->GetContext().obj())); |
1278 } | 1279 } |
1279 | 1280 |
1280 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1281 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1281 const gfx::Rect& src_subrect_in_pixel, | 1282 const gfx::Rect& src_subrect_in_pixel, |
1282 const gfx::Size& dst_size_in_pixel, | 1283 const gfx::Size& dst_size_in_pixel, |
1283 ReadbackRequestCallback& callback, | 1284 ReadbackRequestCallback& callback, |
1284 const SkColorType color_type) { | 1285 const SkColorType color_type) { |
1286 gfx::Size output_size_in_pixel; | |
1287 if (dst_size_in_pixel.IsEmpty()) | |
1288 output_size_in_pixel = src_subrect_in_pixel.size(); | |
no sievers
2014/12/18 19:23:20
So we don't handle |src_subrect_in_pixel| being em
eustas
2014/12/18 19:59:17
Ooops! I'll take a closer look at this case.
Thank
| |
1289 else | |
1290 output_size_in_pixel = dst_size_in_pixel; | |
1291 int output_width = output_size_in_pixel.width(); | |
1292 int output_height = output_size_in_pixel.height(); | |
1293 | |
1285 SynchronousCompositor* compositor = | 1294 SynchronousCompositor* compositor = |
1286 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1295 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1287 host_->GetRoutingID()); | 1296 host_->GetRoutingID()); |
1288 if (!compositor) { | 1297 if (!compositor) { |
1289 callback.Run(SkBitmap(), READBACK_FAILED); | 1298 callback.Run(SkBitmap(), READBACK_FAILED); |
1290 return; | 1299 return; |
1291 } | 1300 } |
1292 | 1301 |
1293 SkBitmap bitmap; | 1302 SkBitmap bitmap; |
1294 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1303 bitmap.allocPixels(SkImageInfo::Make(output_width, |
1295 dst_size_in_pixel.height(), | 1304 output_height, |
1296 color_type, | 1305 color_type, |
1297 kPremul_SkAlphaType)); | 1306 kPremul_SkAlphaType)); |
1298 SkCanvas canvas(bitmap); | 1307 SkCanvas canvas(bitmap); |
1299 canvas.scale( | 1308 canvas.scale( |
1300 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 1309 (float)output_width / (float)src_subrect_in_pixel.width(), |
1301 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 1310 (float)output_height / (float)src_subrect_in_pixel.height()); |
1302 compositor->DemandDrawSw(&canvas); | 1311 compositor->DemandDrawSw(&canvas); |
1303 callback.Run(bitmap, READBACK_SUCCESS); | 1312 callback.Run(bitmap, READBACK_SUCCESS); |
1304 } | 1313 } |
1305 | 1314 |
1306 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1315 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1307 const cc::CompositorFrameMetadata& frame_metadata) { | 1316 const cc::CompositorFrameMetadata& frame_metadata) { |
1308 | 1317 |
1309 // Disable double tap zoom for pages that have a width=device-width or | 1318 // Disable double tap zoom for pages that have a width=device-width or |
1310 // narrower viewport (indicating that this is a mobile-optimized or responsive | 1319 // narrower viewport (indicating that this is a mobile-optimized or responsive |
1311 // web design, so text will be legible without zooming). Also disable | 1320 // web design, so text will be legible without zooming). Also disable |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1795 ReadbackRequestCallback& callback, | 1804 ReadbackRequestCallback& callback, |
1796 scoped_ptr<cc::CopyOutputResult> result) { | 1805 scoped_ptr<cc::CopyOutputResult> result) { |
1797 base::ScopedClosureRunner scoped_callback_runner( | 1806 base::ScopedClosureRunner scoped_callback_runner( |
1798 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1807 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1799 TRACE_EVENT0("cc", | 1808 TRACE_EVENT0("cc", |
1800 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1809 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1801 | 1810 |
1802 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1811 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1803 return; | 1812 return; |
1804 | 1813 |
1814 gfx::Size output_size_in_pixel; | |
1815 if (dst_size_in_pixel.IsEmpty()) | |
1816 output_size_in_pixel = result->size(); | |
1817 else | |
1818 output_size_in_pixel = dst_size_in_pixel; | |
1819 | |
1805 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1820 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1806 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1821 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
1807 dst_size_in_pixel.height(), | 1822 output_size_in_pixel.height(), |
1808 color_type, | 1823 color_type, |
1809 kOpaque_SkAlphaType))) { | 1824 kOpaque_SkAlphaType))) { |
1810 return; | 1825 return; |
1811 } | 1826 } |
1812 | 1827 |
1813 GLHelper* gl_helper = GetPostReadbackGLHelper(); | 1828 GLHelper* gl_helper = GetPostReadbackGLHelper(); |
1814 if (!gl_helper || !gl_helper->IsReadbackConfigSupported(color_type)) | 1829 if (!gl_helper || !gl_helper->IsReadbackConfigSupported(color_type)) |
1815 return; | 1830 return; |
1816 | 1831 |
1817 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1832 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1818 new SkAutoLockPixels(*bitmap)); | 1833 new SkAutoLockPixels(*bitmap)); |
1819 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1834 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
1820 | 1835 |
1821 cc::TextureMailbox texture_mailbox; | 1836 cc::TextureMailbox texture_mailbox; |
1822 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1837 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
1823 result->TakeTexture(&texture_mailbox, &release_callback); | 1838 result->TakeTexture(&texture_mailbox, &release_callback); |
1824 DCHECK(texture_mailbox.IsTexture()); | 1839 DCHECK(texture_mailbox.IsTexture()); |
1825 if (!texture_mailbox.IsTexture()) | 1840 if (!texture_mailbox.IsTexture()) |
1826 return; | 1841 return; |
1827 | 1842 |
1828 ignore_result(scoped_callback_runner.Release()); | 1843 ignore_result(scoped_callback_runner.Release()); |
1829 | 1844 |
1830 gl_helper->CropScaleReadbackAndCleanMailbox( | 1845 gl_helper->CropScaleReadbackAndCleanMailbox( |
1831 texture_mailbox.mailbox(), | 1846 texture_mailbox.mailbox(), |
1832 texture_mailbox.sync_point(), | 1847 texture_mailbox.sync_point(), |
1833 result->size(), | 1848 result->size(), |
1834 gfx::Rect(result->size()), | 1849 gfx::Rect(result->size()), |
1835 dst_size_in_pixel, | 1850 output_size_in_pixel, |
1836 pixels, | 1851 pixels, |
1837 color_type, | 1852 color_type, |
1838 base::Bind(&CopyFromCompositingSurfaceFinished, | 1853 base::Bind(&CopyFromCompositingSurfaceFinished, |
1839 callback, | 1854 callback, |
1840 base::Passed(&release_callback), | 1855 base::Passed(&release_callback), |
1841 base::Passed(&bitmap), | 1856 base::Passed(&bitmap), |
1842 start_time, | 1857 start_time, |
1843 base::Passed(&bitmap_pixels_lock)), | 1858 base::Passed(&bitmap_pixels_lock)), |
1844 GLHelper::SCALER_QUALITY_GOOD); | 1859 GLHelper::SCALER_QUALITY_GOOD); |
1845 } | 1860 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1898 results->orientationAngle = display.RotationAsDegree(); | 1913 results->orientationAngle = display.RotationAsDegree(); |
1899 results->orientationType = | 1914 results->orientationType = |
1900 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1915 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1901 gfx::DeviceDisplayInfo info; | 1916 gfx::DeviceDisplayInfo info; |
1902 results->depth = info.GetBitsPerPixel(); | 1917 results->depth = info.GetBitsPerPixel(); |
1903 results->depthPerComponent = info.GetBitsPerComponent(); | 1918 results->depthPerComponent = info.GetBitsPerComponent(); |
1904 results->isMonochrome = (results->depthPerComponent == 0); | 1919 results->isMonochrome = (results->depthPerComponent == 0); |
1905 } | 1920 } |
1906 | 1921 |
1907 } // namespace content | 1922 } // namespace content |
OLD | NEW |