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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 | 964 |
965 readback_layer = delegated_layer; | 965 readback_layer = delegated_layer; |
966 request = cc::CopyOutputRequest::CreateRequest( | 966 request = cc::CopyOutputRequest::CreateRequest( |
967 base::Bind(&RenderWidgetHostViewAndroid:: | 967 base::Bind(&RenderWidgetHostViewAndroid:: |
968 PrepareTextureCopyOutputResultForDelegatedReadback, | 968 PrepareTextureCopyOutputResultForDelegatedReadback, |
969 dst_size_in_pixel, | 969 dst_size_in_pixel, |
970 color_type, | 970 color_type, |
971 start_time, | 971 start_time, |
972 readback_layer, | 972 readback_layer, |
973 callback)); | 973 callback)); |
974 request->set_area(src_subrect_in_pixel); | 974 if (!src_subrect_in_pixel.IsEmpty()) |
| 975 request->set_area(src_subrect_in_pixel); |
975 readback_layer->RequestCopyOfOutput(request.Pass()); | 976 readback_layer->RequestCopyOfOutput(request.Pass()); |
976 } | 977 } |
977 | 978 |
978 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 979 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
979 const gfx::Rect& src_subrect, | 980 const gfx::Rect& src_subrect, |
980 const scoped_refptr<media::VideoFrame>& target, | 981 const scoped_refptr<media::VideoFrame>& target, |
981 const base::Callback<void(bool)>& callback) { | 982 const base::Callback<void(bool)>& callback) { |
982 NOTIMPLEMENTED(); | 983 NOTIMPLEMENTED(); |
983 callback.Run(false); | 984 callback.Run(false); |
984 } | 985 } |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 // Use the activity context (instead of the application context) to ensure | 1279 // Use the activity context (instead of the application context) to ensure |
1279 // proper handle theming. | 1280 // proper handle theming. |
1280 content_view_core_->GetContext().obj())); | 1281 content_view_core_->GetContext().obj())); |
1281 } | 1282 } |
1282 | 1283 |
1283 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1284 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1284 const gfx::Rect& src_subrect_in_pixel, | 1285 const gfx::Rect& src_subrect_in_pixel, |
1285 const gfx::Size& dst_size_in_pixel, | 1286 const gfx::Size& dst_size_in_pixel, |
1286 ReadbackRequestCallback& callback, | 1287 ReadbackRequestCallback& callback, |
1287 const SkColorType color_type) { | 1288 const SkColorType color_type) { |
| 1289 gfx::Size input_size_in_pixel; |
| 1290 if (src_subrect_in_pixel.IsEmpty()) |
| 1291 input_size_in_pixel = content_size_in_layer_; |
| 1292 else |
| 1293 input_size_in_pixel = src_subrect_in_pixel.size(); |
| 1294 |
| 1295 gfx::Size output_size_in_pixel; |
| 1296 if (dst_size_in_pixel.IsEmpty()) |
| 1297 output_size_in_pixel = input_size_in_pixel; |
| 1298 else |
| 1299 output_size_in_pixel = dst_size_in_pixel; |
| 1300 int output_width = output_size_in_pixel.width(); |
| 1301 int output_height = output_size_in_pixel.height(); |
| 1302 |
1288 SynchronousCompositor* compositor = | 1303 SynchronousCompositor* compositor = |
1289 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1304 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1290 host_->GetRoutingID()); | 1305 host_->GetRoutingID()); |
1291 if (!compositor) { | 1306 if (!compositor) { |
1292 callback.Run(SkBitmap(), READBACK_FAILED); | 1307 callback.Run(SkBitmap(), READBACK_FAILED); |
1293 return; | 1308 return; |
1294 } | 1309 } |
1295 | 1310 |
1296 SkBitmap bitmap; | 1311 SkBitmap bitmap; |
1297 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1312 bitmap.allocPixels(SkImageInfo::Make(output_width, |
1298 dst_size_in_pixel.height(), | 1313 output_height, |
1299 color_type, | 1314 color_type, |
1300 kPremul_SkAlphaType)); | 1315 kPremul_SkAlphaType)); |
1301 SkCanvas canvas(bitmap); | 1316 SkCanvas canvas(bitmap); |
1302 canvas.scale( | 1317 canvas.scale( |
1303 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 1318 (float)output_width / (float)input_size_in_pixel.width(), |
1304 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 1319 (float)output_height / (float)input_size_in_pixel.height()); |
1305 compositor->DemandDrawSw(&canvas); | 1320 compositor->DemandDrawSw(&canvas); |
1306 callback.Run(bitmap, READBACK_SUCCESS); | 1321 callback.Run(bitmap, READBACK_SUCCESS); |
1307 } | 1322 } |
1308 | 1323 |
1309 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1324 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1310 const cc::CompositorFrameMetadata& frame_metadata) { | 1325 const cc::CompositorFrameMetadata& frame_metadata) { |
1311 | 1326 |
1312 // Disable double tap zoom for pages that have a width=device-width or | 1327 // Disable double tap zoom for pages that have a width=device-width or |
1313 // narrower viewport (indicating that this is a mobile-optimized or responsive | 1328 // narrower viewport (indicating that this is a mobile-optimized or responsive |
1314 // web design, so text will be legible without zooming). Also disable | 1329 // web design, so text will be legible without zooming). Also disable |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 ReadbackRequestCallback& callback, | 1813 ReadbackRequestCallback& callback, |
1799 scoped_ptr<cc::CopyOutputResult> result) { | 1814 scoped_ptr<cc::CopyOutputResult> result) { |
1800 base::ScopedClosureRunner scoped_callback_runner( | 1815 base::ScopedClosureRunner scoped_callback_runner( |
1801 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1816 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1802 TRACE_EVENT0("cc", | 1817 TRACE_EVENT0("cc", |
1803 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1818 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1804 | 1819 |
1805 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1820 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1806 return; | 1821 return; |
1807 | 1822 |
| 1823 gfx::Size output_size_in_pixel; |
| 1824 if (dst_size_in_pixel.IsEmpty()) |
| 1825 output_size_in_pixel = result->size(); |
| 1826 else |
| 1827 output_size_in_pixel = dst_size_in_pixel; |
| 1828 |
1808 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1829 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1809 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1830 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
1810 dst_size_in_pixel.height(), | 1831 output_size_in_pixel.height(), |
1811 color_type, | 1832 color_type, |
1812 kOpaque_SkAlphaType))) { | 1833 kOpaque_SkAlphaType))) { |
1813 return; | 1834 return; |
1814 } | 1835 } |
1815 | 1836 |
1816 GLHelper* gl_helper = GetPostReadbackGLHelper(); | 1837 GLHelper* gl_helper = GetPostReadbackGLHelper(); |
1817 if (!gl_helper || !gl_helper->IsReadbackConfigSupported(color_type)) | 1838 if (!gl_helper || !gl_helper->IsReadbackConfigSupported(color_type)) |
1818 return; | 1839 return; |
1819 | 1840 |
1820 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1841 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1821 new SkAutoLockPixels(*bitmap)); | 1842 new SkAutoLockPixels(*bitmap)); |
1822 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1843 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
1823 | 1844 |
1824 cc::TextureMailbox texture_mailbox; | 1845 cc::TextureMailbox texture_mailbox; |
1825 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1846 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
1826 result->TakeTexture(&texture_mailbox, &release_callback); | 1847 result->TakeTexture(&texture_mailbox, &release_callback); |
1827 DCHECK(texture_mailbox.IsTexture()); | 1848 DCHECK(texture_mailbox.IsTexture()); |
1828 if (!texture_mailbox.IsTexture()) | 1849 if (!texture_mailbox.IsTexture()) |
1829 return; | 1850 return; |
1830 | 1851 |
1831 ignore_result(scoped_callback_runner.Release()); | 1852 ignore_result(scoped_callback_runner.Release()); |
1832 | 1853 |
1833 gl_helper->CropScaleReadbackAndCleanMailbox( | 1854 gl_helper->CropScaleReadbackAndCleanMailbox( |
1834 texture_mailbox.mailbox(), | 1855 texture_mailbox.mailbox(), |
1835 texture_mailbox.sync_point(), | 1856 texture_mailbox.sync_point(), |
1836 result->size(), | 1857 result->size(), |
1837 gfx::Rect(result->size()), | 1858 gfx::Rect(result->size()), |
1838 dst_size_in_pixel, | 1859 output_size_in_pixel, |
1839 pixels, | 1860 pixels, |
1840 color_type, | 1861 color_type, |
1841 base::Bind(&CopyFromCompositingSurfaceFinished, | 1862 base::Bind(&CopyFromCompositingSurfaceFinished, |
1842 callback, | 1863 callback, |
1843 base::Passed(&release_callback), | 1864 base::Passed(&release_callback), |
1844 base::Passed(&bitmap), | 1865 base::Passed(&bitmap), |
1845 start_time, | 1866 start_time, |
1846 base::Passed(&bitmap_pixels_lock)), | 1867 base::Passed(&bitmap_pixels_lock)), |
1847 GLHelper::SCALER_QUALITY_GOOD); | 1868 GLHelper::SCALER_QUALITY_GOOD); |
1848 } | 1869 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 results->orientationAngle = display.RotationAsDegree(); | 1922 results->orientationAngle = display.RotationAsDegree(); |
1902 results->orientationType = | 1923 results->orientationType = |
1903 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1924 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1904 gfx::DeviceDisplayInfo info; | 1925 gfx::DeviceDisplayInfo info; |
1905 results->depth = info.GetBitsPerPixel(); | 1926 results->depth = info.GetBitsPerPixel(); |
1906 results->depthPerComponent = info.GetBitsPerComponent(); | 1927 results->depthPerComponent = info.GetBitsPerComponent(); |
1907 results->isMonochrome = (results->depthPerComponent == 0); | 1928 results->isMonochrome = (results->depthPerComponent == 0); |
1908 } | 1929 } |
1909 | 1930 |
1910 } // namespace content | 1931 } // namespace content |
OLD | NEW |