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

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

Issue 1113573002: Maintain minimal error response. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 5 years, 7 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
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 "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // resize the view on Android. 427 // resize the view on Android.
428 default_size_ = size; 428 default_size_ = size;
429 } 429 }
430 430
431 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 431 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
432 SetSize(rect.size()); 432 SetSize(rect.size());
433 } 433 }
434 434
435 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( 435 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
436 float scale, 436 float scale,
437 SkColorType color_type, 437 SkColorType color_type,
no sievers 2015/05/07 18:11:53 nit: change it here too and in content_view_core_i
sivag 2015/05/08 10:12:46 Done.
438 gfx::Rect src_subrect, 438 gfx::Rect src_subrect,
439 ReadbackRequestCallback& result_callback) { 439 ReadbackRequestCallback& result_callback) {
440 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { 440 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
441 result_callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); 441 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
442 return; 442 return;
443 } 443 }
444 gfx::Size bounds = layer_->bounds(); 444 gfx::Size bounds = layer_->bounds();
445 if (src_subrect.IsEmpty()) 445 if (src_subrect.IsEmpty())
446 src_subrect = gfx::Rect(bounds); 446 src_subrect = gfx::Rect(bounds);
447 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); 447 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
448 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); 448 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
449 const gfx::Display& display = 449 const gfx::Display& display =
450 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 450 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
451 float device_scale_factor = display.device_scale_factor(); 451 float device_scale_factor = display.device_scale_factor();
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { 911 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) {
912 RenderWidgetHostViewBase::SetBackgroundColor(color); 912 RenderWidgetHostViewBase::SetBackgroundColor(color);
913 host_->SetBackgroundOpaque(GetBackgroundOpaque()); 913 host_->SetBackgroundOpaque(GetBackgroundOpaque());
914 OnDidChangeBodyBackgroundColor(color); 914 OnDidChangeBodyBackgroundColor(color);
915 } 915 }
916 916
917 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 917 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
918 const gfx::Rect& src_subrect, 918 const gfx::Rect& src_subrect,
919 const gfx::Size& dst_size, 919 const gfx::Size& dst_size,
920 ReadbackRequestCallback& callback, 920 ReadbackRequestCallback& callback,
921 const SkColorType color_type) { 921 const SkColorType preferred_color_type) {
922 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); 922 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface");
923 if (!host_ || host_->is_hidden()) { 923 if (!host_ || host_->is_hidden()) {
924 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 924 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
925 return; 925 return;
926 } 926 }
927 base::TimeTicks start_time = base::TimeTicks::Now(); 927 base::TimeTicks start_time = base::TimeTicks::Now();
928 if (using_browser_compositor_ && !IsSurfaceAvailableForCopy()) { 928 if (using_browser_compositor_ && !IsSurfaceAvailableForCopy()) {
929 callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); 929 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
930 return; 930 return;
931 } 931 }
932 const gfx::Display& display = 932 const gfx::Display& display =
933 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 933 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
934 float device_scale_factor = display.device_scale_factor(); 934 float device_scale_factor = display.device_scale_factor();
935 gfx::Size dst_size_in_pixel = 935 gfx::Size dst_size_in_pixel =
936 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 936 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
937 gfx::Rect src_subrect_in_pixel = 937 gfx::Rect src_subrect_in_pixel =
938 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); 938 gfx::ConvertRectToPixel(device_scale_factor, src_subrect);
939 939
940 if (!using_browser_compositor_) { 940 if (!using_browser_compositor_) {
941 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 941 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
942 color_type); 942 preferred_color_type);
943 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 943 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
944 base::TimeTicks::Now() - start_time); 944 base::TimeTicks::Now() - start_time);
945 return; 945 return;
946 } 946 }
947 947
948 scoped_ptr<cc::CopyOutputRequest> request; 948 scoped_ptr<cc::CopyOutputRequest> request;
949 scoped_refptr<cc::Layer> readback_layer; 949 scoped_refptr<cc::Layer> readback_layer;
950 DCHECK(content_view_core_window_android_); 950 DCHECK(content_view_core_window_android_);
951 ui::WindowAndroidCompositor* compositor = 951 ui::WindowAndroidCompositor* compositor =
952 content_view_core_window_android_->GetCompositor(); 952 content_view_core_window_android_->GetCompositor();
953 DCHECK(compositor); 953 DCHECK(compositor);
954 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 954 DCHECK(frame_provider_.get() || !surface_id_.is_null());
955 scoped_refptr<cc::Layer> layer = CreateDelegatedLayer(); 955 scoped_refptr<cc::Layer> layer = CreateDelegatedLayer();
956 DCHECK(layer); 956 DCHECK(layer);
957 layer->SetHideLayerAndSubtree(true); 957 layer->SetHideLayerAndSubtree(true);
958 compositor->AttachLayerForReadback(layer); 958 compositor->AttachLayerForReadback(layer);
959 959
960 readback_layer = layer; 960 readback_layer = layer;
961 request = cc::CopyOutputRequest::CreateRequest( 961 request = cc::CopyOutputRequest::CreateRequest(
962 base::Bind(&RenderWidgetHostViewAndroid:: 962 base::Bind(&RenderWidgetHostViewAndroid::
963 PrepareTextureCopyOutputResultForDelegatedReadback, 963 PrepareTextureCopyOutputResultForDelegatedReadback,
964 dst_size_in_pixel, 964 dst_size_in_pixel, preferred_color_type, start_time,
965 color_type, 965 readback_layer, callback));
966 start_time,
967 readback_layer,
968 callback));
969 if (!src_subrect_in_pixel.IsEmpty()) 966 if (!src_subrect_in_pixel.IsEmpty())
970 request->set_area(src_subrect_in_pixel); 967 request->set_area(src_subrect_in_pixel);
971 readback_layer->RequestCopyOfOutput(request.Pass()); 968 readback_layer->RequestCopyOfOutput(request.Pass());
972 } 969 }
973 970
974 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 971 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
975 const gfx::Rect& src_subrect, 972 const gfx::Rect& src_subrect,
976 const scoped_refptr<media::VideoFrame>& target, 973 const scoped_refptr<media::VideoFrame>& target,
977 const base::Callback<void(bool)>& callback) { 974 const base::Callback<void(bool)>& callback) {
978 NOTIMPLEMENTED(); 975 NOTIMPLEMENTED();
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 GLHelper* gl_helper = GetPostReadbackGLHelper(); 1884 GLHelper* gl_helper = GetPostReadbackGLHelper();
1888 if (!gl_helper) 1885 if (!gl_helper)
1889 return; 1886 return;
1890 if (!gl_helper->IsReadbackConfigSupported(color_type)) 1887 if (!gl_helper->IsReadbackConfigSupported(color_type))
1891 color_type = kRGBA_8888_SkColorType; 1888 color_type = kRGBA_8888_SkColorType;
1892 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 1889 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1893 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(), 1890 if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(),
1894 output_size_in_pixel.height(), 1891 output_size_in_pixel.height(),
1895 color_type, 1892 color_type,
1896 kOpaque_SkAlphaType))) { 1893 kOpaque_SkAlphaType))) {
1894 scoped_callback_runner.Reset(
1895 base::Bind(callback, SkBitmap(), READBACK_BITMAP_ALLOCATION_FAILURE));
1897 return; 1896 return;
1898 } 1897 }
1899 1898
1900 1899
1901 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( 1900 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock(
1902 new SkAutoLockPixels(*bitmap)); 1901 new SkAutoLockPixels(*bitmap));
1903 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); 1902 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
1904 1903
1905 cc::TextureMailbox texture_mailbox; 1904 cc::TextureMailbox texture_mailbox;
1906 scoped_ptr<cc::SingleReleaseCallback> release_callback; 1905 scoped_ptr<cc::SingleReleaseCallback> release_callback;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 results->orientationAngle = display.RotationAsDegree(); 1966 results->orientationAngle = display.RotationAsDegree();
1968 results->orientationType = 1967 results->orientationType =
1969 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); 1968 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
1970 gfx::DeviceDisplayInfo info; 1969 gfx::DeviceDisplayInfo info;
1971 results->depth = info.GetBitsPerPixel(); 1970 results->depth = info.GetBitsPerPixel();
1972 results->depthPerComponent = info.GetBitsPerComponent(); 1971 results->depthPerComponent = info.GetBitsPerComponent();
1973 results->isMonochrome = (results->depthPerComponent == 0); 1972 results->isMonochrome = (results->depthPerComponent == 0);
1974 } 1973 }
1975 1974
1976 } // namespace content 1975 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698