Chromium Code Reviews| 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 |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 host_->SetBackgroundOpaque(GetBackgroundOpaque()); | 863 host_->SetBackgroundOpaque(GetBackgroundOpaque()); |
| 864 UpdateBackgroundColor(color); | 864 UpdateBackgroundColor(color); |
| 865 } | 865 } |
| 866 | 866 |
| 867 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 867 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 868 const gfx::Rect& src_subrect, | 868 const gfx::Rect& src_subrect, |
| 869 const gfx::Size& dst_size, | 869 const gfx::Size& dst_size, |
| 870 const ReadbackRequestCallback& callback, | 870 const ReadbackRequestCallback& callback, |
| 871 const SkColorType preferred_color_type) { | 871 const SkColorType preferred_color_type) { |
| 872 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 872 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
| 873 if (!host_ || host_->is_hidden()) { | 873 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { |
| 874 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 874 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
| 875 return; | 875 return; |
| 876 } | 876 } |
| 877 base::TimeTicks start_time = base::TimeTicks::Now(); | 877 if (!content_view_core_ || !(content_view_core_->GetWindowAndroid())) { |
| 878 if (!IsSurfaceAvailableForCopy()) { | 878 callback.Run(SkBitmap(), READBACK_FAILED); |
| 879 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | |
| 880 return; | 879 return; |
| 881 } | 880 } |
| 881 | |
| 882 base::TimeTicks start_time = base::TimeTicks::Now(); | |
| 882 const display::Display& display = | 883 const display::Display& display = |
| 883 display::Screen::GetScreen()->GetPrimaryDisplay(); | 884 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 884 float device_scale_factor = display.device_scale_factor(); | 885 float device_scale_factor = display.device_scale_factor(); |
| 885 gfx::Size dst_size_in_pixel = | 886 gfx::Size dst_size_in_pixel = |
| 886 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 887 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
| 887 gfx::Rect src_subrect_in_pixel = | 888 gfx::Rect src_subrect_in_pixel = |
| 888 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); | 889 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); |
| 889 | 890 |
| 890 if (!using_browser_compositor_) { | 891 if (!using_browser_compositor_) { |
| 891 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 892 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
| 892 preferred_color_type); | 893 preferred_color_type); |
| 893 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 894 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
| 894 base::TimeTicks::Now() - start_time); | 895 base::TimeTicks::Now() - start_time); |
| 895 return; | 896 return; |
| 896 } | 897 } |
| 897 | 898 |
| 898 if (!content_view_core_ || !(content_view_core_->GetWindowAndroid())) { | |
| 899 callback.Run(SkBitmap(), READBACK_FAILED); | |
| 900 return; | |
| 901 } | |
| 902 ui::WindowAndroidCompositor* compositor = | 899 ui::WindowAndroidCompositor* compositor = |
| 903 content_view_core_->GetWindowAndroid()->GetCompositor(); | 900 content_view_core_->GetWindowAndroid()->GetCompositor(); |
| 904 DCHECK(compositor); | 901 DCHECK(compositor); |
| 905 DCHECK(!surface_id_.is_null()); | 902 DCHECK(!surface_id_.is_null()); |
| 906 std::unique_ptr<cc::CopyOutputRequest> request = | 903 std::unique_ptr<cc::CopyOutputRequest> request = |
| 907 cc::CopyOutputRequest::CreateRequest( | 904 cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 908 base::Bind(&PrepareTextureCopyOutputResult, dst_size_in_pixel, | 905 &PrepareTextureCopyOutputResult, AsWeakPtr(), dst_size_in_pixel, |
| 909 preferred_color_type, start_time, callback)); | 906 preferred_color_type, start_time, callback)); |
| 910 if (!src_subrect_in_pixel.IsEmpty()) | 907 if (!src_subrect_in_pixel.IsEmpty()) |
| 911 request->set_area(src_subrect_in_pixel); | 908 request->set_area(src_subrect_in_pixel); |
| 909 // Lock the surface before placing the CopyOutputRequest. | |
|
no sievers
2016/06/01 22:32:06
nit: I'd say 'Make sure the layer doesn't get dele
sivag
2016/06/02 14:34:50
Done.
| |
| 910 LockCompositingSurface(); | |
| 912 layer_->RequestCopyOfOutput(std::move(request)); | 911 layer_->RequestCopyOfOutput(std::move(request)); |
| 913 } | 912 } |
| 914 | 913 |
| 915 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 914 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
| 916 const gfx::Rect& src_subrect, | 915 const gfx::Rect& src_subrect, |
| 917 const scoped_refptr<media::VideoFrame>& target, | 916 const scoped_refptr<media::VideoFrame>& target, |
| 918 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 917 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 919 NOTIMPLEMENTED(); | 918 NOTIMPLEMENTED(); |
| 920 callback.Run(gfx::Rect(), false); | 919 callback.Run(gfx::Rect(), false); |
| 921 } | 920 } |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1921 DCHECK(ack_callbacks_.empty()); | 1920 DCHECK(ack_callbacks_.empty()); |
| 1922 } | 1921 } |
| 1923 | 1922 |
| 1924 // TODO(wjmaclean): There is significant overlap between | 1923 // TODO(wjmaclean): There is significant overlap between |
| 1925 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in | 1924 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in |
| 1926 // this file, and the versions in surface_utils.cc. They should | 1925 // this file, and the versions in surface_utils.cc. They should |
| 1927 // be merged. See https://crbug.com/582955 | 1926 // be merged. See https://crbug.com/582955 |
| 1928 | 1927 |
| 1929 // static | 1928 // static |
| 1930 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1929 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| 1930 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva, | |
| 1931 const gfx::Size& dst_size_in_pixel, | 1931 const gfx::Size& dst_size_in_pixel, |
| 1932 SkColorType color_type, | 1932 SkColorType color_type, |
| 1933 const base::TimeTicks& start_time, | 1933 const base::TimeTicks& start_time, |
| 1934 const ReadbackRequestCallback& callback, | 1934 const ReadbackRequestCallback& callback, |
| 1935 std::unique_ptr<cc::CopyOutputResult> result) { | 1935 std::unique_ptr<cc::CopyOutputResult> result) { |
| 1936 base::ScopedClosureRunner scoped_callback_runner( | 1936 base::ScopedClosureRunner scoped_callback_runner( |
| 1937 base::Bind(callback, SkBitmap(), READBACK_FAILED)); | 1937 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
| 1938 TRACE_EVENT0("cc", | 1938 TRACE_EVENT0("cc", |
| 1939 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1939 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
| 1940 | 1940 if (!rwhva) |
|
no sievers
2016/06/01 22:32:06
When RWHVA goes away the layer goes away, which me
sivag
2016/06/02 14:34:50
Done.
| |
| 1941 return; | |
| 1942 // Unlock surface after recieving texture as response. | |
| 1943 rwhva->UnlockCompositingSurface(); | |
| 1941 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1944 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
| 1942 return; | 1945 return; |
| 1946 cc::TextureMailbox texture_mailbox; | |
| 1947 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | |
| 1948 result->TakeTexture(&texture_mailbox, &release_callback); | |
| 1949 DCHECK(texture_mailbox.IsTexture()); | |
| 1950 if (!texture_mailbox.IsTexture()) | |
| 1951 return; | |
| 1952 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | |
| 1953 if (!gl_helper) | |
| 1954 return; | |
| 1955 if (!gl_helper->IsReadbackConfigSupported(color_type)) | |
| 1956 color_type = kRGBA_8888_SkColorType; | |
| 1943 | 1957 |
| 1944 gfx::Size output_size_in_pixel; | 1958 gfx::Size output_size_in_pixel; |
| 1945 if (dst_size_in_pixel.IsEmpty()) | 1959 if (dst_size_in_pixel.IsEmpty()) |
| 1946 output_size_in_pixel = result->size(); | 1960 output_size_in_pixel = result->size(); |
| 1947 else | 1961 else |
| 1948 output_size_in_pixel = dst_size_in_pixel; | 1962 output_size_in_pixel = dst_size_in_pixel; |
| 1949 | 1963 |
| 1950 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); | |
| 1951 if (!gl_helper) | |
| 1952 return; | |
| 1953 if (!gl_helper->IsReadbackConfigSupported(color_type)) | |
| 1954 color_type = kRGBA_8888_SkColorType; | |
| 1955 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); | 1964 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
| 1956 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), | 1965 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), |
| 1957 output_size_in_pixel.height(), | 1966 output_size_in_pixel.height(), |
| 1958 color_type, | 1967 color_type, |
| 1959 kOpaque_SkAlphaType))) { | 1968 kOpaque_SkAlphaType))) { |
| 1960 scoped_callback_runner.Reset( | 1969 scoped_callback_runner.Reset( |
| 1961 base::Bind(callback, SkBitmap(), READBACK_BITMAP_ALLOCATION_FAILURE)); | 1970 base::Bind(callback, SkBitmap(), READBACK_BITMAP_ALLOCATION_FAILURE)); |
| 1962 return; | 1971 return; |
| 1963 } | 1972 } |
| 1964 | 1973 |
| 1965 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1974 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 1966 new SkAutoLockPixels(*bitmap)); | 1975 new SkAutoLockPixels(*bitmap)); |
| 1967 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); | 1976 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); |
| 1968 | 1977 |
| 1969 cc::TextureMailbox texture_mailbox; | |
| 1970 std::unique_ptr<cc::SingleReleaseCallback> release_callback; | |
| 1971 result->TakeTexture(&texture_mailbox, &release_callback); | |
| 1972 DCHECK(texture_mailbox.IsTexture()); | |
| 1973 if (!texture_mailbox.IsTexture()) | |
| 1974 return; | |
| 1975 | |
| 1976 ignore_result(scoped_callback_runner.Release()); | 1978 ignore_result(scoped_callback_runner.Release()); |
| 1977 | 1979 |
| 1978 gl_helper->CropScaleReadbackAndCleanMailbox( | 1980 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 1979 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 1981 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
| 1980 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, | 1982 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, |
| 1981 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 1983 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
| 1982 base::Passed(&release_callback), base::Passed(&bitmap), | 1984 base::Passed(&release_callback), base::Passed(&bitmap), |
| 1983 start_time, base::Passed(&bitmap_pixels_lock)), | 1985 start_time, base::Passed(&bitmap_pixels_lock)), |
| 1984 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 1986 display_compositor::GLHelper::SCALER_QUALITY_GOOD); |
| 1985 } | 1987 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2046 case ui::MotionEvent::ACTION_UP: | 2048 case ui::MotionEvent::ACTION_UP: |
| 2047 case ui::MotionEvent::ACTION_POINTER_UP: | 2049 case ui::MotionEvent::ACTION_POINTER_UP: |
| 2048 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 2050 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 2049 delta.InMicroseconds(), 1, 1000000, 50); | 2051 delta.InMicroseconds(), 1, 1000000, 50); |
| 2050 default: | 2052 default: |
| 2051 return; | 2053 return; |
| 2052 } | 2054 } |
| 2053 } | 2055 } |
| 2054 | 2056 |
| 2055 } // namespace content | 2057 } // namespace content |
| OLD | NEW |