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 ReadbackResponse response = result ? READBACK_SUCCESS : READBACK_FAILED; |
| 122 callback.Run(*bitmap, response); |
122 } | 123 } |
123 | 124 |
124 ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) { | 125 ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) { |
125 ui::LatencyInfo latency_info; | 126 ui::LatencyInfo latency_info; |
126 // The latency number should only be added if the timestamp is valid. | 127 // The latency number should only be added if the timestamp is valid. |
127 if (event.timeStampSeconds) { | 128 if (event.timeStampSeconds) { |
128 const int64 time_micros = static_cast<int64>( | 129 const int64 time_micros = static_cast<int64>( |
129 event.timeStampSeconds * base::Time::kMicrosecondsPerSecond); | 130 event.timeStampSeconds * base::Time::kMicrosecondsPerSecond); |
130 latency_info.AddLatencyNumberWithTimestamp( | 131 latency_info.AddLatencyNumberWithTimestamp( |
131 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 132 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) { | 233 bool HasMobileViewport(const cc::CompositorFrameMetadata& frame_metadata) { |
233 float window_width_dip = | 234 float window_width_dip = |
234 frame_metadata.page_scale_factor * | 235 frame_metadata.page_scale_factor * |
235 frame_metadata.scrollable_viewport_size.width(); | 236 frame_metadata.scrollable_viewport_size.width(); |
236 float content_width_css = frame_metadata.root_layer_size.width(); | 237 float content_width_css = frame_metadata.root_layer_size.width(); |
237 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon; | 238 return content_width_css <= window_width_dip + kMobileViewportWidthEpsilon; |
238 } | 239 } |
239 | 240 |
240 } // anonymous namespace | 241 } // anonymous namespace |
241 | 242 |
242 ReadbackRequest::ReadbackRequest( | 243 ReadbackRequest::ReadbackRequest(float scale, |
243 float scale, | 244 SkColorType color_type, |
244 SkColorType color_type, | 245 gfx::Rect src_subrect, |
245 gfx::Rect src_subrect, | 246 ReadbackRequestCallback& result_callback) |
246 const base::Callback<void(bool, const SkBitmap&)>& result_callback) | |
247 : scale_(scale), | 247 : scale_(scale), |
248 color_type_(color_type), | 248 color_type_(color_type), |
249 src_subrect_(src_subrect), | 249 src_subrect_(src_subrect), |
250 result_callback_(result_callback) { | 250 result_callback_(result_callback) { |
251 } | 251 } |
252 | 252 |
253 ReadbackRequest::ReadbackRequest() { | 253 ReadbackRequest::ReadbackRequest() { |
254 } | 254 } |
255 | 255 |
256 ReadbackRequest::~ReadbackRequest() { | 256 ReadbackRequest::~ReadbackRequest() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 default_size_ = size; | 373 default_size_ = size; |
374 } | 374 } |
375 | 375 |
376 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 376 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
377 SetSize(rect.size()); | 377 SetSize(rect.size()); |
378 } | 378 } |
379 | 379 |
380 void RenderWidgetHostViewAndroid::AbortPendingReadbackRequests() { | 380 void RenderWidgetHostViewAndroid::AbortPendingReadbackRequests() { |
381 while (!readbacks_waiting_for_frame_.empty()) { | 381 while (!readbacks_waiting_for_frame_.empty()) { |
382 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); | 382 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); |
383 readback_request.GetResultCallback().Run(false, SkBitmap()); | 383 readback_request.GetResultCallback().Run(SkBitmap(), READBACK_FAILED); |
384 readbacks_waiting_for_frame_.pop(); | 384 readbacks_waiting_for_frame_.pop(); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 388 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
389 float scale, | 389 float scale, |
390 SkColorType color_type, | 390 SkColorType color_type, |
391 gfx::Rect src_subrect, | 391 gfx::Rect src_subrect, |
392 CopyFromCompositingSurfaceCallback& result_callback) { | 392 ReadbackRequestCallback& result_callback) { |
393 if (!host_ || host_->is_hidden()) { | 393 if (!host_ || host_->is_hidden()) { |
394 result_callback.Run(false, SkBitmap()); | 394 result_callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
395 return; | 395 return; |
396 } | 396 } |
397 if (!IsSurfaceAvailableForCopy()) { | 397 if (!IsSurfaceAvailableForCopy()) { |
398 // The view is visible, probably the frame has not yet arrived. | 398 // The view is visible, probably the frame has not yet arrived. |
399 // Just add the ReadbackRequest to queue and wait for frame arrival | 399 // Just add the ReadbackRequest to queue and wait for frame arrival |
400 // to get this request processed. | 400 // to get this request processed. |
401 readbacks_waiting_for_frame_.push( | 401 readbacks_waiting_for_frame_.push( |
402 ReadbackRequest(scale, color_type, src_subrect, result_callback)); | 402 ReadbackRequest(scale, color_type, src_subrect, result_callback)); |
403 return; | 403 return; |
404 } | 404 } |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 | 826 |
827 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { | 827 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { |
828 RenderWidgetHostViewBase::SetBackgroundColor(color); | 828 RenderWidgetHostViewBase::SetBackgroundColor(color); |
829 host_->SetBackgroundOpaque(GetBackgroundOpaque()); | 829 host_->SetBackgroundOpaque(GetBackgroundOpaque()); |
830 OnDidChangeBodyBackgroundColor(color); | 830 OnDidChangeBodyBackgroundColor(color); |
831 } | 831 } |
832 | 832 |
833 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 833 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
834 const gfx::Rect& src_subrect, | 834 const gfx::Rect& src_subrect, |
835 const gfx::Size& dst_size, | 835 const gfx::Size& dst_size, |
836 CopyFromCompositingSurfaceCallback& callback, | 836 ReadbackRequestCallback& callback, |
837 const SkColorType color_type) { | 837 const SkColorType color_type) { |
838 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 838 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
839 if ((!host_ || host_->is_hidden()) || | 839 if ((!host_ || host_->is_hidden()) || |
840 !IsReadbackConfigSupported(color_type)) { | 840 !IsReadbackConfigSupported(color_type)) { |
841 callback.Run(false, SkBitmap()); | 841 callback.Run(SkBitmap(), READBACK_FORMAT_NOT_SUPPORTED); |
842 return; | 842 return; |
843 } | 843 } |
844 base::TimeTicks start_time = base::TimeTicks::Now(); | 844 base::TimeTicks start_time = base::TimeTicks::Now(); |
845 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 845 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
846 callback.Run(false, SkBitmap()); | 846 callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
847 return; | 847 return; |
848 } | 848 } |
849 const gfx::Display& display = | 849 const gfx::Display& display = |
850 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 850 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
851 float device_scale_factor = display.device_scale_factor(); | 851 float device_scale_factor = display.device_scale_factor(); |
852 gfx::Size dst_size_in_pixel = | 852 gfx::Size dst_size_in_pixel = |
853 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 853 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
854 gfx::Rect src_subrect_in_pixel = | 854 gfx::Rect src_subrect_in_pixel = |
855 ConvertRectToPixel(device_scale_factor, src_subrect); | 855 ConvertRectToPixel(device_scale_factor, src_subrect); |
856 | 856 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 content_view_core_->GetLayer().get(), | 1186 content_view_core_->GetLayer().get(), |
1187 content_view_core_->GetDpiScale(), | 1187 content_view_core_->GetDpiScale(), |
1188 // Use the activity context (instead of the application context) to ensure | 1188 // Use the activity context (instead of the application context) to ensure |
1189 // proper handle theming. | 1189 // proper handle theming. |
1190 content_view_core_->GetContext().obj())); | 1190 content_view_core_->GetContext().obj())); |
1191 } | 1191 } |
1192 | 1192 |
1193 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1193 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1194 const gfx::Rect& src_subrect_in_pixel, | 1194 const gfx::Rect& src_subrect_in_pixel, |
1195 const gfx::Size& dst_size_in_pixel, | 1195 const gfx::Size& dst_size_in_pixel, |
1196 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1196 ReadbackRequestCallback& callback, |
1197 const SkColorType color_type) { | 1197 const SkColorType color_type) { |
1198 SynchronousCompositor* compositor = | 1198 SynchronousCompositor* compositor = |
1199 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1199 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1200 host_->GetRoutingID()); | 1200 host_->GetRoutingID()); |
1201 if (!compositor) { | 1201 if (!compositor) { |
1202 callback.Run(false, SkBitmap()); | 1202 callback.Run(SkBitmap(), READBACK_FAILED); |
1203 return; | 1203 return; |
1204 } | 1204 } |
1205 | 1205 |
1206 SkBitmap bitmap; | 1206 SkBitmap bitmap; |
1207 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1207 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1208 dst_size_in_pixel.height(), | 1208 dst_size_in_pixel.height(), |
1209 color_type, | 1209 color_type, |
1210 kPremul_SkAlphaType)); | 1210 kPremul_SkAlphaType)); |
1211 SkCanvas canvas(bitmap); | 1211 SkCanvas canvas(bitmap); |
1212 canvas.scale( | 1212 canvas.scale( |
1213 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 1213 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), |
1214 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 1214 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); |
1215 compositor->DemandDrawSw(&canvas); | 1215 compositor->DemandDrawSw(&canvas); |
1216 callback.Run(true, bitmap); | 1216 callback.Run(bitmap, READBACK_SUCCESS); |
1217 } | 1217 } |
1218 | 1218 |
1219 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1219 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1220 const cc::CompositorFrameMetadata& frame_metadata) { | 1220 const cc::CompositorFrameMetadata& frame_metadata) { |
1221 | 1221 |
1222 // Disable double tap zoom for pages that have a width=device-width or | 1222 // Disable double tap zoom for pages that have a width=device-width or |
1223 // narrower viewport (indicating that this is a mobile-optimized or responsive | 1223 // narrower viewport (indicating that this is a mobile-optimized or responsive |
1224 // web design, so text will be legible without zooming). Also disable | 1224 // web design, so text will be legible without zooming). Also disable |
1225 // double tap and pinch for pages that prevent zooming in or out. | 1225 // double tap and pinch for pages that prevent zooming in or out. |
1226 bool has_mobile_viewport = HasMobileViewport(frame_metadata); | 1226 bool has_mobile_viewport = HasMobileViewport(frame_metadata); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 DCHECK(readbacks_waiting_for_frame_.empty()); | 1681 DCHECK(readbacks_waiting_for_frame_.empty()); |
1682 } | 1682 } |
1683 | 1683 |
1684 // static | 1684 // static |
1685 void | 1685 void |
1686 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( | 1686 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( |
1687 const gfx::Size& dst_size_in_pixel, | 1687 const gfx::Size& dst_size_in_pixel, |
1688 const SkColorType color_type, | 1688 const SkColorType color_type, |
1689 const base::TimeTicks& start_time, | 1689 const base::TimeTicks& start_time, |
1690 scoped_refptr<cc::Layer> readback_layer, | 1690 scoped_refptr<cc::Layer> readback_layer, |
1691 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1691 ReadbackRequestCallback& callback, |
1692 scoped_ptr<cc::CopyOutputResult> result) { | 1692 scoped_ptr<cc::CopyOutputResult> result) { |
1693 readback_layer->RemoveFromParent(); | 1693 readback_layer->RemoveFromParent(); |
1694 PrepareTextureCopyOutputResult( | 1694 PrepareTextureCopyOutputResult( |
1695 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); | 1695 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); |
1696 } | 1696 } |
1697 | 1697 |
1698 // static | 1698 // static |
1699 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1699 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1700 const gfx::Size& dst_size_in_pixel, | 1700 const gfx::Size& dst_size_in_pixel, |
1701 const SkColorType color_type, | 1701 const SkColorType color_type, |
1702 const base::TimeTicks& start_time, | 1702 const base::TimeTicks& start_time, |
1703 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1703 ReadbackRequestCallback& callback, |
1704 scoped_ptr<cc::CopyOutputResult> result) { | 1704 scoped_ptr<cc::CopyOutputResult> result) { |
1705 base::ScopedClosureRunner scoped_callback_runner( | 1705 base::ScopedClosureRunner scoped_callback_runner( |
1706 base::Bind(callback, false, SkBitmap())); | 1706 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1707 TRACE_EVENT0("cc", | 1707 TRACE_EVENT0("cc", |
1708 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1708 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1709 | 1709 |
1710 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1710 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1711 return; | 1711 return; |
1712 | 1712 |
1713 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1713 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1714 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1714 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1715 dst_size_in_pixel.height(), | 1715 dst_size_in_pixel.height(), |
1716 color_type, | 1716 color_type, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 results->orientationAngle = display.RotationAsDegree(); | 1808 results->orientationAngle = display.RotationAsDegree(); |
1809 results->orientationType = | 1809 results->orientationType = |
1810 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1810 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1811 gfx::DeviceDisplayInfo info; | 1811 gfx::DeviceDisplayInfo info; |
1812 results->depth = info.GetBitsPerPixel(); | 1812 results->depth = info.GetBitsPerPixel(); |
1813 results->depthPerComponent = info.GetBitsPerComponent(); | 1813 results->depthPerComponent = info.GetBitsPerComponent(); |
1814 results->isMonochrome = (results->depthPerComponent == 0); | 1814 results->isMonochrome = (results->depthPerComponent == 0); |
1815 } | 1815 } |
1816 | 1816 |
1817 } // namespace content | 1817 } // namespace content |
OLD | NEW |