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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 const int kKitKatMR2SDKVersion = 19; | 92 const int kKitKatMR2SDKVersion = 19; |
93 | 93 |
94 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 94 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
95 | 95 |
96 // Sends an acknowledgement to the renderer of a processed IME event. | 96 // Sends an acknowledgement to the renderer of a processed IME event. |
97 void SendImeEventAck(RenderWidgetHostImpl* host) { | 97 void SendImeEventAck(RenderWidgetHostImpl* host) { |
98 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); | 98 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); |
99 } | 99 } |
100 | 100 |
101 void CopyFromCompositingSurfaceFinished( | 101 void CopyFromCompositingSurfaceFinished( |
102 const base::Callback<void(bool, const SkBitmap&)>& callback, | 102 ReadbackRequestCallback& callback, |
103 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 103 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
104 scoped_ptr<SkBitmap> bitmap, | 104 scoped_ptr<SkBitmap> bitmap, |
105 const base::TimeTicks& start_time, | 105 const base::TimeTicks& start_time, |
106 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 106 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
107 bool result) { | 107 bool result) { |
108 TRACE_EVENT0( | 108 TRACE_EVENT0( |
109 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); | 109 "cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceFinished"); |
110 bitmap_pixels_lock.reset(); | 110 bitmap_pixels_lock.reset(); |
111 uint32 sync_point = 0; | 111 uint32 sync_point = 0; |
112 if (result) { | 112 if (result) { |
113 GLHelper* gl_helper = | 113 GLHelper* gl_helper = |
114 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | 114 ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); |
115 sync_point = gl_helper->InsertSyncPoint(); | 115 sync_point = gl_helper->InsertSyncPoint(); |
116 } | 116 } |
117 bool lost_resource = sync_point == 0; | 117 bool lost_resource = sync_point == 0; |
118 release_callback->Run(sync_point, lost_resource); | 118 release_callback->Run(sync_point, lost_resource); |
119 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 119 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
120 base::TimeTicks::Now() - start_time); | 120 base::TimeTicks::Now() - start_time); |
121 callback.Run(result, *bitmap); | 121 callback.Run(*bitmap, READBACK_SUCCESS); |
piman
2014/11/07 01:55:42
if result is false, we shouldn't return READBACK_S
sivag
2014/11/07 12:27:41
Done.
| |
122 } | 122 } |
123 | 123 |
124 ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) { | 124 ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) { |
125 ui::LatencyInfo latency_info; | 125 ui::LatencyInfo latency_info; |
126 // The latency number should only be added if the timestamp is valid. | 126 // The latency number should only be added if the timestamp is valid. |
127 if (event.timeStampSeconds) { | 127 if (event.timeStampSeconds) { |
128 const int64 time_micros = static_cast<int64>( | 128 const int64 time_micros = static_cast<int64>( |
129 event.timeStampSeconds * base::Time::kMicrosecondsPerSecond); | 129 event.timeStampSeconds * base::Time::kMicrosecondsPerSecond); |
130 latency_info.AddLatencyNumberWithTimestamp( | 130 latency_info.AddLatencyNumberWithTimestamp( |
131 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 131 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 bool HasMobileViewport(const cc::CompositorFrameMetadata& frame_metadata) { | 232 bool HasMobileViewport(const cc::CompositorFrameMetadata& frame_metadata) { |
233 float window_width_dip = | 233 float window_width_dip = |
234 frame_metadata.page_scale_factor * | 234 frame_metadata.page_scale_factor * |
235 frame_metadata.scrollable_viewport_size.width(); | 235 frame_metadata.scrollable_viewport_size.width(); |
236 float content_width_css = frame_metadata.root_layer_size.width(); | 236 float content_width_css = frame_metadata.root_layer_size.width(); |
237 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon; | 237 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon; |
238 } | 238 } |
239 | 239 |
240 } // anonymous namespace | 240 } // anonymous namespace |
241 | 241 |
242 ReadbackRequest::ReadbackRequest( | 242 ReadbackRequest::ReadbackRequest(float scale, |
243 float scale, | 243 SkColorType color_type, |
244 SkColorType color_type, | 244 gfx::Rect src_subrect, |
245 gfx::Rect src_subrect, | 245 ReadbackRequestCallback& result_callback) |
246 const base::Callback<void(bool, const SkBitmap&)>& result_callback) | |
247 : scale_(scale), | 246 : scale_(scale), |
248 color_type_(color_type), | 247 color_type_(color_type), |
249 src_subrect_(src_subrect), | 248 src_subrect_(src_subrect), |
250 result_callback_(result_callback) { | 249 result_callback_(result_callback) { |
251 } | 250 } |
252 | 251 |
253 ReadbackRequest::ReadbackRequest() { | 252 ReadbackRequest::ReadbackRequest() { |
254 } | 253 } |
255 | 254 |
256 ReadbackRequest::~ReadbackRequest() { | 255 ReadbackRequest::~ReadbackRequest() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 default_size_ = size; | 372 default_size_ = size; |
374 } | 373 } |
375 | 374 |
376 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 375 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
377 SetSize(rect.size()); | 376 SetSize(rect.size()); |
378 } | 377 } |
379 | 378 |
380 void RenderWidgetHostViewAndroid::AbortPendingReadbackRequests() { | 379 void RenderWidgetHostViewAndroid::AbortPendingReadbackRequests() { |
381 while (!readbacks_waiting_for_frame_.empty()) { | 380 while (!readbacks_waiting_for_frame_.empty()) { |
382 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); | 381 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); |
383 readback_request.GetResultCallback().Run(false, SkBitmap()); | 382 readback_request.GetResultCallback().Run(SkBitmap(), READBACK_FAILED); |
384 readbacks_waiting_for_frame_.pop(); | 383 readbacks_waiting_for_frame_.pop(); |
385 } | 384 } |
386 } | 385 } |
387 | 386 |
388 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 387 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
389 float scale, | 388 float scale, |
390 SkColorType color_type, | 389 SkColorType color_type, |
391 gfx::Rect src_subrect, | 390 gfx::Rect src_subrect, |
392 CopyFromCompositingSurfaceCallback& result_callback) { | 391 ReadbackRequestCallback& result_callback) { |
393 if (!host_ || host_->is_hidden()) { | 392 if (!host_ || host_->is_hidden()) { |
394 result_callback.Run(false, SkBitmap()); | 393 result_callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
395 return; | 394 return; |
396 } | 395 } |
397 if (!IsSurfaceAvailableForCopy()) { | 396 if (!IsSurfaceAvailableForCopy()) { |
398 // The view is visible, probably the frame has not yet arrived. | 397 // The view is visible, probably the frame has not yet arrived. |
399 // Just add the ReadbackRequest to queue and wait for frame arrival | 398 // Just add the ReadbackRequest to queue and wait for frame arrival |
400 // to get this request processed. | 399 // to get this request processed. |
401 readbacks_waiting_for_frame_.push( | 400 readbacks_waiting_for_frame_.push( |
402 ReadbackRequest(scale, color_type, src_subrect, result_callback)); | 401 ReadbackRequest(scale, color_type, src_subrect, result_callback)); |
403 return; | 402 return; |
404 } | 403 } |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 | 828 |
830 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { | 829 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { |
831 RenderWidgetHostViewBase::SetBackgroundColor(color); | 830 RenderWidgetHostViewBase::SetBackgroundColor(color); |
832 host_->SetBackgroundOpaque(GetBackgroundOpaque()); | 831 host_->SetBackgroundOpaque(GetBackgroundOpaque()); |
833 OnDidChangeBodyBackgroundColor(color); | 832 OnDidChangeBodyBackgroundColor(color); |
834 } | 833 } |
835 | 834 |
836 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 835 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
837 const gfx::Rect& src_subrect, | 836 const gfx::Rect& src_subrect, |
838 const gfx::Size& dst_size, | 837 const gfx::Size& dst_size, |
839 CopyFromCompositingSurfaceCallback& callback, | 838 ReadbackRequestCallback& callback, |
840 const SkColorType color_type) { | 839 const SkColorType color_type) { |
841 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 840 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
842 if ((!host_ || host_->is_hidden()) || | 841 if ((!host_ || host_->is_hidden()) || |
843 !IsReadbackConfigSupported(color_type)) { | 842 !IsReadbackConfigSupported(color_type)) { |
844 callback.Run(false, SkBitmap()); | 843 callback.Run(SkBitmap(), READBACK_FORMAT_NOT_SUPPORTED); |
845 return; | 844 return; |
846 } | 845 } |
847 base::TimeTicks start_time = base::TimeTicks::Now(); | 846 base::TimeTicks start_time = base::TimeTicks::Now(); |
848 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 847 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
849 callback.Run(false, SkBitmap()); | 848 callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
850 return; | 849 return; |
851 } | 850 } |
852 const gfx::Display& display = | 851 const gfx::Display& display = |
853 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 852 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
854 float device_scale_factor = display.device_scale_factor(); | 853 float device_scale_factor = display.device_scale_factor(); |
855 gfx::Size dst_size_in_pixel = | 854 gfx::Size dst_size_in_pixel = |
856 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 855 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
857 gfx::Rect src_subrect_in_pixel = | 856 gfx::Rect src_subrect_in_pixel = |
858 ConvertRectToPixel(device_scale_factor, src_subrect); | 857 ConvertRectToPixel(device_scale_factor, src_subrect); |
859 | 858 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1189 content_view_core_->GetLayer().get(), | 1188 content_view_core_->GetLayer().get(), |
1190 content_view_core_->GetDpiScale(), | 1189 content_view_core_->GetDpiScale(), |
1191 // Use the activity context (instead of the application context) to ensure | 1190 // Use the activity context (instead of the application context) to ensure |
1192 // proper handle theming. | 1191 // proper handle theming. |
1193 content_view_core_->GetContext().obj())); | 1192 content_view_core_->GetContext().obj())); |
1194 } | 1193 } |
1195 | 1194 |
1196 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1195 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1197 const gfx::Rect& src_subrect_in_pixel, | 1196 const gfx::Rect& src_subrect_in_pixel, |
1198 const gfx::Size& dst_size_in_pixel, | 1197 const gfx::Size& dst_size_in_pixel, |
1199 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1198 ReadbackRequestCallback& callback, |
1200 const SkColorType color_type) { | 1199 const SkColorType color_type) { |
1201 SynchronousCompositor* compositor = | 1200 SynchronousCompositor* compositor = |
1202 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1201 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1203 host_->GetRoutingID()); | 1202 host_->GetRoutingID()); |
1204 if (!compositor) { | 1203 if (!compositor) { |
1205 callback.Run(false, SkBitmap()); | 1204 callback.Run(SkBitmap(), READBACK_FAILED); |
1206 return; | 1205 return; |
1207 } | 1206 } |
1208 | 1207 |
1209 SkBitmap bitmap; | 1208 SkBitmap bitmap; |
1210 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1209 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1211 dst_size_in_pixel.height(), | 1210 dst_size_in_pixel.height(), |
1212 color_type, | 1211 color_type, |
1213 kPremul_SkAlphaType)); | 1212 kPremul_SkAlphaType)); |
1214 SkCanvas canvas(bitmap); | 1213 SkCanvas canvas(bitmap); |
1215 canvas.scale( | 1214 canvas.scale( |
1216 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 1215 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), |
1217 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 1216 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); |
1218 compositor->DemandDrawSw(&canvas); | 1217 compositor->DemandDrawSw(&canvas); |
1219 callback.Run(true, bitmap); | 1218 callback.Run(bitmap, READBACK_SUCCESS); |
1220 } | 1219 } |
1221 | 1220 |
1222 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1221 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1223 const cc::CompositorFrameMetadata& frame_metadata) { | 1222 const cc::CompositorFrameMetadata& frame_metadata) { |
1224 | 1223 |
1225 // Disable double tap zoom for pages that have a width=device-width or | 1224 // Disable double tap zoom for pages that have a width=device-width or |
1226 // narrower viewport (indicating that this is a mobile-optimized or responsive | 1225 // narrower viewport (indicating that this is a mobile-optimized or responsive |
1227 // web design, so text will be legible without zooming). Also disable | 1226 // web design, so text will be legible without zooming). Also disable |
1228 // double tap and pinch for pages that prevent zooming in or out. | 1227 // double tap and pinch for pages that prevent zooming in or out. |
1229 bool has_mobile_viewport = HasMobileViewport(frame_metadata); | 1228 bool has_mobile_viewport = HasMobileViewport(frame_metadata); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1678 void RenderWidgetHostViewAndroid::OnLostResources() { | 1677 void RenderWidgetHostViewAndroid::OnLostResources() { |
1679 ReleaseLocksOnSurface(); | 1678 ReleaseLocksOnSurface(); |
1680 if (layer_.get()) | 1679 if (layer_.get()) |
1681 DestroyDelegatedContent(); | 1680 DestroyDelegatedContent(); |
1682 DCHECK(ack_callbacks_.empty()); | 1681 DCHECK(ack_callbacks_.empty()); |
1683 // We should not loose a frame if we have readback requests pending. | 1682 // We should not loose a frame if we have readback requests pending. |
1684 DCHECK(readbacks_waiting_for_frame_.empty()); | 1683 DCHECK(readbacks_waiting_for_frame_.empty()); |
1685 } | 1684 } |
1686 | 1685 |
1687 // static | 1686 // static |
1688 void | 1687 void RenderWidgetHostViewAndroid:: |
1689 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( | 1688 PrepareTextureCopyOutputResultForDelegatedReadback( |
1690 const gfx::Size& dst_size_in_pixel, | 1689 const gfx::Size& dst_size_in_pixel, |
1691 const SkColorType color_type, | 1690 const SkColorType color_type, |
1692 const base::TimeTicks& start_time, | 1691 const base::TimeTicks& start_time, |
1693 scoped_refptr<cc::Layer> readback_layer, | 1692 scoped_refptr<cc::Layer> readback_layer, |
1694 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1693 ReadbackRequestCallback& callback, |
1695 scoped_ptr<cc::CopyOutputResult> result) { | 1694 scoped_ptr<cc::CopyOutputResult> result) { |
1696 readback_layer->RemoveFromParent(); | 1695 readback_layer->RemoveFromParent(); |
1697 PrepareTextureCopyOutputResult( | 1696 PrepareTextureCopyOutputResult( |
1698 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); | 1697 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); |
1699 } | 1698 } |
1700 | 1699 |
1701 // static | 1700 // static |
1702 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1701 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1703 const gfx::Size& dst_size_in_pixel, | 1702 const gfx::Size& dst_size_in_pixel, |
1704 const SkColorType color_type, | 1703 const SkColorType color_type, |
1705 const base::TimeTicks& start_time, | 1704 const base::TimeTicks& start_time, |
1706 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1705 ReadbackRequestCallback& callback, |
1707 scoped_ptr<cc::CopyOutputResult> result) { | 1706 scoped_ptr<cc::CopyOutputResult> result) { |
1708 base::ScopedClosureRunner scoped_callback_runner( | 1707 base::ScopedClosureRunner scoped_callback_runner( |
1709 base::Bind(callback, false, SkBitmap())); | 1708 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1710 TRACE_EVENT0("cc", | 1709 TRACE_EVENT0("cc", |
1711 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1710 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1712 | 1711 |
1713 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1712 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1714 return; | 1713 return; |
1715 | 1714 |
1716 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1715 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1717 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1716 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1718 dst_size_in_pixel.height(), | 1717 dst_size_in_pixel.height(), |
1719 color_type, | 1718 color_type, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1811 results->orientationAngle = display.RotationAsDegree(); | 1810 results->orientationAngle = display.RotationAsDegree(); |
1812 results->orientationType = | 1811 results->orientationType = |
1813 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1812 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1814 gfx::DeviceDisplayInfo info; | 1813 gfx::DeviceDisplayInfo info; |
1815 results->depth = info.GetBitsPerPixel(); | 1814 results->depth = info.GetBitsPerPixel(); |
1816 results->depthPerComponent = info.GetBitsPerComponent(); | 1815 results->depthPerComponent = info.GetBitsPerComponent(); |
1817 results->isMonochrome = (results->depthPerComponent == 0); | 1816 results->isMonochrome = (results->depthPerComponent == 0); |
1818 } | 1817 } |
1819 | 1818 |
1820 } // namespace content | 1819 } // namespace content |
OLD | NEW |