Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2021003002: LockCompositingSurface to make sure frame is not evicted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, weak_ptr_factory_.GetWeakPtr(),
909 preferred_color_type, start_time, callback)); 906 dst_size_in_pixel, 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 // Make sure the layer doesn't get deleted until we fulfill the request.
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 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 DCHECK(ack_callbacks_.empty()); 1919 DCHECK(ack_callbacks_.empty());
1921 } 1920 }
1922 1921
1923 // TODO(wjmaclean): There is significant overlap between 1922 // TODO(wjmaclean): There is significant overlap between
1924 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in 1923 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in
1925 // this file, and the versions in surface_utils.cc. They should 1924 // this file, and the versions in surface_utils.cc. They should
1926 // be merged. See https://crbug.com/582955 1925 // be merged. See https://crbug.com/582955
1927 1926
1928 // static 1927 // static
1929 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1928 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1929 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva,
1930 const gfx::Size& dst_size_in_pixel, 1930 const gfx::Size& dst_size_in_pixel,
1931 SkColorType color_type, 1931 SkColorType color_type,
1932 const base::TimeTicks& start_time, 1932 const base::TimeTicks& start_time,
1933 const ReadbackRequestCallback& callback, 1933 const ReadbackRequestCallback& callback,
1934 std::unique_ptr<cc::CopyOutputResult> result) { 1934 std::unique_ptr<cc::CopyOutputResult> result) {
1935 base::ScopedClosureRunner scoped_callback_runner( 1935 base::ScopedClosureRunner scoped_callback_runner(
1936 base::Bind(callback, SkBitmap(), READBACK_FAILED)); 1936 base::Bind(callback, SkBitmap(), READBACK_FAILED));
1937 TRACE_EVENT0("cc", 1937 TRACE_EVENT0("cc",
1938 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); 1938 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult");
1939 1939 if (rwhva)
1940 rwhva->UnlockCompositingSurface();
1940 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) 1941 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1941 return; 1942 return;
1943 cc::TextureMailbox texture_mailbox;
1944 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
1945 result->TakeTexture(&texture_mailbox, &release_callback);
1946 DCHECK(texture_mailbox.IsTexture());
1947 if (!texture_mailbox.IsTexture())
1948 return;
1949 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper();
1950 if (!gl_helper)
1951 return;
1952 if (!gl_helper->IsReadbackConfigSupported(color_type))
1953 color_type = kRGBA_8888_SkColorType;
1942 1954
1943 gfx::Size output_size_in_pixel; 1955 gfx::Size output_size_in_pixel;
1944 if (dst_size_in_pixel.IsEmpty()) 1956 if (dst_size_in_pixel.IsEmpty())
1945 output_size_in_pixel = result->size(); 1957 output_size_in_pixel = result->size();
1946 else 1958 else
1947 output_size_in_pixel = dst_size_in_pixel; 1959 output_size_in_pixel = dst_size_in_pixel;
1948 1960
1949 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper();
1950 if (!gl_helper)
1951 return;
1952 if (!gl_helper->IsReadbackConfigSupported(color_type))
1953 color_type = kRGBA_8888_SkColorType;
1954 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); 1961 std::unique_ptr<SkBitmap> bitmap(new SkBitmap);
1955 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), 1962 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(),
1956 output_size_in_pixel.height(), 1963 output_size_in_pixel.height(),
1957 color_type, 1964 color_type,
1958 kOpaque_SkAlphaType))) { 1965 kOpaque_SkAlphaType))) {
1959 scoped_callback_runner.Reset( 1966 scoped_callback_runner.Reset(
1960 base::Bind(callback, SkBitmap(), READBACK_BITMAP_ALLOCATION_FAILURE)); 1967 base::Bind(callback, SkBitmap(), READBACK_BITMAP_ALLOCATION_FAILURE));
1961 return; 1968 return;
1962 } 1969 }
1963 1970
1964 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock( 1971 std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock(
1965 new SkAutoLockPixels(*bitmap)); 1972 new SkAutoLockPixels(*bitmap));
1966 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels()); 1973 uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels());
1967 1974
1968 cc::TextureMailbox texture_mailbox;
1969 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
1970 result->TakeTexture(&texture_mailbox, &release_callback);
1971 DCHECK(texture_mailbox.IsTexture());
1972 if (!texture_mailbox.IsTexture())
1973 return;
1974
1975 ignore_result(scoped_callback_runner.Release()); 1975 ignore_result(scoped_callback_runner.Release());
1976 1976
1977 gl_helper->CropScaleReadbackAndCleanMailbox( 1977 gl_helper->CropScaleReadbackAndCleanMailbox(
1978 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), 1978 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
1979 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, 1979 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type,
1980 base::Bind(&CopyFromCompositingSurfaceFinished, callback, 1980 base::Bind(&CopyFromCompositingSurfaceFinished, callback,
1981 base::Passed(&release_callback), base::Passed(&bitmap), 1981 base::Passed(&release_callback), base::Passed(&bitmap),
1982 start_time, base::Passed(&bitmap_pixels_lock)), 1982 start_time, base::Passed(&bitmap_pixels_lock)),
1983 display_compositor::GLHelper::SCALER_QUALITY_GOOD); 1983 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
1984 } 1984 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 case ui::MotionEvent::ACTION_UP: 2045 case ui::MotionEvent::ACTION_UP:
2046 case ui::MotionEvent::ACTION_POINTER_UP: 2046 case ui::MotionEvent::ACTION_POINTER_UP:
2047 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 2047 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
2048 delta.InMicroseconds(), 1, 1000000, 50); 2048 delta.InMicroseconds(), 1, 1000000, 50);
2049 default: 2049 default:
2050 return; 2050 return;
2051 } 2051 }
2052 } 2052 }
2053 2053
2054 } // namespace content 2054 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698