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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 829 |
830 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { | 830 void RenderWidgetHostViewAndroid::SetBackgroundColor(SkColor color) { |
831 RenderWidgetHostViewBase::SetBackgroundColor(color); | 831 RenderWidgetHostViewBase::SetBackgroundColor(color); |
832 host_->SetBackgroundOpaque(GetBackgroundOpaque()); | 832 host_->SetBackgroundOpaque(GetBackgroundOpaque()); |
833 OnDidChangeBodyBackgroundColor(color); | 833 OnDidChangeBodyBackgroundColor(color); |
834 } | 834 } |
835 | 835 |
836 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 836 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
837 const gfx::Rect& src_subrect, | 837 const gfx::Rect& src_subrect, |
838 const gfx::Size& dst_size, | 838 const gfx::Size& dst_size, |
839 CopyFromCompositingSurfaceCallback& callback, | 839 ReadbackRequestCallback& callback, |
840 const SkColorType color_type) { | 840 const SkColorType color_type) { |
841 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 841 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
842 if ((!host_ || host_->is_hidden()) || | 842 if ((!host_ || host_->is_hidden()) || |
843 !IsReadbackConfigSupported(color_type)) { | 843 !IsReadbackConfigSupported(color_type)) { |
844 callback.Run(false, SkBitmap()); | 844 callback.Run(SkBitmap(), READBACK_FORMAT_NOT_SUPPORTED); |
845 return; | 845 return; |
846 } | 846 } |
847 base::TimeTicks start_time = base::TimeTicks::Now(); | 847 base::TimeTicks start_time = base::TimeTicks::Now(); |
848 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 848 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
849 callback.Run(false, SkBitmap()); | 849 callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
850 return; | 850 return; |
851 } | 851 } |
852 const gfx::Display& display = | 852 const gfx::Display& display = |
853 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 853 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
854 float device_scale_factor = display.device_scale_factor(); | 854 float device_scale_factor = display.device_scale_factor(); |
855 gfx::Size dst_size_in_pixel = | 855 gfx::Size dst_size_in_pixel = |
856 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 856 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
857 gfx::Rect src_subrect_in_pixel = | 857 gfx::Rect src_subrect_in_pixel = |
858 ConvertRectToPixel(device_scale_factor, src_subrect); | 858 ConvertRectToPixel(device_scale_factor, src_subrect); |
859 | 859 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 content_view_core_->GetLayer().get(), | 1189 content_view_core_->GetLayer().get(), |
1190 content_view_core_->GetDpiScale(), | 1190 content_view_core_->GetDpiScale(), |
1191 // Use the activity context (instead of the application context) to ensure | 1191 // Use the activity context (instead of the application context) to ensure |
1192 // proper handle theming. | 1192 // proper handle theming. |
1193 content_view_core_->GetContext().obj())); | 1193 content_view_core_->GetContext().obj())); |
1194 } | 1194 } |
1195 | 1195 |
1196 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1196 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
1197 const gfx::Rect& src_subrect_in_pixel, | 1197 const gfx::Rect& src_subrect_in_pixel, |
1198 const gfx::Size& dst_size_in_pixel, | 1198 const gfx::Size& dst_size_in_pixel, |
1199 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1199 ReadbackRequestCallback& callback, |
1200 const SkColorType color_type) { | 1200 const SkColorType color_type) { |
1201 SynchronousCompositor* compositor = | 1201 SynchronousCompositor* compositor = |
1202 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1202 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1203 host_->GetRoutingID()); | 1203 host_->GetRoutingID()); |
1204 if (!compositor) { | 1204 if (!compositor) { |
1205 callback.Run(false, SkBitmap()); | 1205 callback.Run(SkBitmap(), READBACK_FAILED); |
1206 return; | 1206 return; |
1207 } | 1207 } |
1208 | 1208 |
1209 SkBitmap bitmap; | 1209 SkBitmap bitmap; |
1210 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1210 bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1211 dst_size_in_pixel.height(), | 1211 dst_size_in_pixel.height(), |
1212 color_type, | 1212 color_type, |
1213 kPremul_SkAlphaType)); | 1213 kPremul_SkAlphaType)); |
1214 SkCanvas canvas(bitmap); | 1214 SkCanvas canvas(bitmap); |
1215 canvas.scale( | 1215 canvas.scale( |
1216 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 1216 (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()); | 1217 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); |
1218 compositor->DemandDrawSw(&canvas); | 1218 compositor->DemandDrawSw(&canvas); |
1219 callback.Run(true, bitmap); | 1219 callback.Run(bitmap, READBACK_SUCCESS); |
1220 } | 1220 } |
1221 | 1221 |
1222 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1222 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1223 const cc::CompositorFrameMetadata& frame_metadata) { | 1223 const cc::CompositorFrameMetadata& frame_metadata) { |
1224 | 1224 |
1225 // Disable double tap zoom for pages that have a width=device-width or | 1225 // 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 | 1226 // narrower viewport (indicating that this is a mobile-optimized or responsive |
1227 // web design, so text will be legible without zooming). Also disable | 1227 // web design, so text will be legible without zooming). Also disable |
1228 // double tap and pinch for pages that prevent zooming in or out. | 1228 // double tap and pinch for pages that prevent zooming in or out. |
1229 bool has_mobile_viewport = HasMobileViewport(frame_metadata); | 1229 bool has_mobile_viewport = HasMobileViewport(frame_metadata); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 void RenderWidgetHostViewAndroid::OnLostResources() { | 1678 void RenderWidgetHostViewAndroid::OnLostResources() { |
1679 ReleaseLocksOnSurface(); | 1679 ReleaseLocksOnSurface(); |
1680 if (layer_.get()) | 1680 if (layer_.get()) |
1681 DestroyDelegatedContent(); | 1681 DestroyDelegatedContent(); |
1682 DCHECK(ack_callbacks_.empty()); | 1682 DCHECK(ack_callbacks_.empty()); |
1683 // We should not loose a frame if we have readback requests pending. | 1683 // We should not loose a frame if we have readback requests pending. |
1684 DCHECK(readbacks_waiting_for_frame_.empty()); | 1684 DCHECK(readbacks_waiting_for_frame_.empty()); |
1685 } | 1685 } |
1686 | 1686 |
1687 // static | 1687 // static |
1688 void | 1688 void RenderWidgetHostViewAndroid:: |
1689 RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResultForDelegatedReadback( | 1689 PrepareTextureCopyOutputResultForDelegatedReadback( |
1690 const gfx::Size& dst_size_in_pixel, | 1690 const gfx::Size& dst_size_in_pixel, |
1691 const SkColorType color_type, | 1691 const SkColorType color_type, |
1692 const base::TimeTicks& start_time, | 1692 const base::TimeTicks& start_time, |
1693 scoped_refptr<cc::Layer> readback_layer, | 1693 scoped_refptr<cc::Layer> readback_layer, |
1694 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1694 ReadbackRequestCallback& callback, |
1695 scoped_ptr<cc::CopyOutputResult> result) { | 1695 scoped_ptr<cc::CopyOutputResult> result) { |
1696 readback_layer->RemoveFromParent(); | 1696 readback_layer->RemoveFromParent(); |
1697 PrepareTextureCopyOutputResult( | 1697 PrepareTextureCopyOutputResult( |
1698 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); | 1698 dst_size_in_pixel, color_type, start_time, callback, result.Pass()); |
1699 } | 1699 } |
1700 | 1700 |
1701 // static | 1701 // static |
1702 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1702 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1703 const gfx::Size& dst_size_in_pixel, | 1703 const gfx::Size& dst_size_in_pixel, |
1704 const SkColorType color_type, | 1704 const SkColorType color_type, |
1705 const base::TimeTicks& start_time, | 1705 const base::TimeTicks& start_time, |
1706 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1706 ReadbackRequestCallback& callback, |
1707 scoped_ptr<cc::CopyOutputResult> result) { | 1707 scoped_ptr<cc::CopyOutputResult> result) { |
1708 base::ScopedClosureRunner scoped_callback_runner( | 1708 base::ScopedClosureRunner scoped_callback_runner( |
1709 base::Bind(callback, false, SkBitmap())); | 1709 base::Bind(callback, SkBitmap(), READBACK_FAILED)); |
1710 TRACE_EVENT0("cc", | 1710 TRACE_EVENT0("cc", |
1711 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); | 1711 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); |
1712 | 1712 |
1713 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1713 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1714 return; | 1714 return; |
1715 | 1715 |
1716 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1716 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1717 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), | 1717 if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), |
1718 dst_size_in_pixel.height(), | 1718 dst_size_in_pixel.height(), |
1719 color_type, | 1719 color_type, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 results->orientationAngle = display.RotationAsDegree(); | 1811 results->orientationAngle = display.RotationAsDegree(); |
1812 results->orientationType = | 1812 results->orientationType = |
1813 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1813 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1814 gfx::DeviceDisplayInfo info; | 1814 gfx::DeviceDisplayInfo info; |
1815 results->depth = info.GetBitsPerPixel(); | 1815 results->depth = info.GetBitsPerPixel(); |
1816 results->depthPerComponent = info.GetBitsPerComponent(); | 1816 results->depthPerComponent = info.GetBitsPerComponent(); |
1817 results->isMonochrome = (results->depthPerComponent == 0); | 1817 results->isMonochrome = (results->depthPerComponent == 0); |
1818 } | 1818 } |
1819 | 1819 |
1820 } // namespace content | 1820 } // namespace content |
OLD | NEW |