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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 WasResized(); | 255 WasResized(); |
256 } | 256 } |
257 | 257 |
258 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 258 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
259 SetSize(rect.size()); | 259 SetSize(rect.size()); |
260 } | 260 } |
261 | 261 |
262 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 262 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
263 float scale, | 263 float scale, |
264 gfx::Size* out_size, | 264 gfx::Size* out_size, |
| 265 bool config_565, |
265 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { | 266 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { |
266 if (!IsSurfaceAvailableForCopy()) { | 267 if (!IsSurfaceAvailableForCopy()) { |
267 result_callback.Run(false, SkBitmap()); | 268 result_callback.Run(false, SkBitmap()); |
268 return; | 269 return; |
269 } | 270 } |
270 | 271 |
271 gfx::Size bounds = layer_->bounds(); | 272 gfx::Size bounds = layer_->bounds(); |
272 gfx::Rect src_subrect(bounds); | 273 gfx::Rect src_subrect(bounds); |
273 const gfx::Display& display = | 274 const gfx::Display& display = |
274 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 275 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
275 float device_scale_factor = display.device_scale_factor(); | 276 float device_scale_factor = display.device_scale_factor(); |
276 DCHECK_GT(device_scale_factor, 0); | 277 DCHECK_GT(device_scale_factor, 0); |
277 gfx::Size dst_size( | 278 gfx::Size dst_size( |
278 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); | 279 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); |
279 *out_size = dst_size; | 280 *out_size = dst_size; |
| 281 SkBitmap::Config config = config_565 ? |
| 282 SkBitmap::kRGB_565_Config : |
| 283 SkBitmap::kARGB_8888_Config; |
280 CopyFromCompositingSurface( | 284 CopyFromCompositingSurface( |
281 src_subrect, dst_size, result_callback, SkBitmap::kARGB_8888_Config); | 285 src_subrect, dst_size, result_callback, config); |
282 } | 286 } |
283 | 287 |
284 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { | 288 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { |
285 if (!CompositorImpl::IsInitialized() || | 289 if (!CompositorImpl::IsInitialized() || |
286 texture_id_in_layer_ == 0 || | 290 texture_id_in_layer_ == 0 || |
287 texture_size_in_layer_.IsEmpty()) | 291 texture_size_in_layer_.IsEmpty()) |
288 return false; | 292 return false; |
289 | 293 |
290 gfx::JavaBitmap bitmap(jbitmap); | 294 gfx::JavaBitmap bitmap(jbitmap); |
291 | 295 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 float device_scale_factor = display.device_scale_factor(); | 667 float device_scale_factor = display.device_scale_factor(); |
664 | 668 |
665 DCHECK_EQ(device_scale_factor, | 669 DCHECK_EQ(device_scale_factor, |
666 ui::GetImageScale(GetScaleFactorForView(this))); | 670 ui::GetImageScale(GetScaleFactorForView(this))); |
667 | 671 |
668 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 672 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
669 gfx::Rect src_subrect_in_pixel = | 673 gfx::Rect src_subrect_in_pixel = |
670 ConvertRectToPixel(device_scale_factor, src_subrect); | 674 ConvertRectToPixel(device_scale_factor, src_subrect); |
671 | 675 |
672 if (using_synchronous_compositor_) { | 676 if (using_synchronous_compositor_) { |
673 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 677 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
| 678 bitmap_config); |
674 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 679 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
675 base::TimeTicks::Now() - start_time); | 680 base::TimeTicks::Now() - start_time); |
676 return; | 681 return; |
677 } | 682 } |
678 scoped_ptr<cc::CopyOutputRequest> request; | 683 scoped_ptr<cc::CopyOutputRequest> request; |
679 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 684 if ((src_subrect_in_pixel.size() == dst_size_in_pixel) && |
| 685 (bitmap_config == SkBitmap::kARGB_8888_Config)) { |
680 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 686 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
681 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 687 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
682 dst_size_in_pixel, | 688 dst_size_in_pixel, |
| 689 bitmap_config, |
683 start_time, | 690 start_time, |
684 callback)); | 691 callback)); |
685 } else { | 692 } else { |
686 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 693 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
687 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 694 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
688 dst_size_in_pixel, | 695 dst_size_in_pixel, |
689 bitmap_config, | 696 bitmap_config, |
690 start_time, | 697 start_time, |
691 callback)); | 698 callback)); |
692 } | 699 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 } | 922 } |
916 } | 923 } |
917 | 924 |
918 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { | 925 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { |
919 layer_->SetContentsOpaque(!enabled); | 926 layer_->SetContentsOpaque(!enabled); |
920 } | 927 } |
921 | 928 |
922 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 929 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
923 const gfx::Rect& src_subrect_in_pixel, | 930 const gfx::Rect& src_subrect_in_pixel, |
924 const gfx::Size& dst_size_in_pixel, | 931 const gfx::Size& dst_size_in_pixel, |
925 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 932 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 933 const SkBitmap::Config config) { |
926 SynchronousCompositor* compositor = | 934 SynchronousCompositor* compositor = |
927 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 935 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
928 host_->GetRoutingID()); | 936 host_->GetRoutingID()); |
929 if (!compositor) { | 937 if (!compositor) { |
930 callback.Run(false, SkBitmap()); | 938 callback.Run(false, SkBitmap()); |
931 return; | 939 return; |
932 } | 940 } |
933 | 941 |
934 SkBitmap bitmap; | 942 SkBitmap bitmap; |
935 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 943 bitmap.setConfig(config, |
936 dst_size_in_pixel.width(), | 944 dst_size_in_pixel.width(), |
937 dst_size_in_pixel.height()); | 945 dst_size_in_pixel.height()); |
938 bitmap.allocPixels(); | 946 bitmap.allocPixels(); |
939 SkCanvas canvas(bitmap); | 947 SkCanvas canvas(bitmap); |
940 canvas.scale( | 948 canvas.scale( |
941 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), | 949 (float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), |
942 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); | 950 (float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); |
943 compositor->DemandDrawSw(&canvas); | 951 compositor->DemandDrawSw(&canvas); |
944 callback.Run(true, bitmap); | 952 callback.Run(true, bitmap); |
945 } | 953 } |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 callback, | 1455 callback, |
1448 base::Passed(&release_callback), | 1456 base::Passed(&release_callback), |
1449 base::Passed(&bitmap), | 1457 base::Passed(&bitmap), |
1450 start_time, | 1458 start_time, |
1451 base::Passed(&bitmap_pixels_lock))); | 1459 base::Passed(&bitmap_pixels_lock))); |
1452 } | 1460 } |
1453 | 1461 |
1454 // static | 1462 // static |
1455 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1463 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1456 const gfx::Size& dst_size_in_pixel, | 1464 const gfx::Size& dst_size_in_pixel, |
| 1465 const SkBitmap::Config config, |
1457 const base::TimeTicks& start_time, | 1466 const base::TimeTicks& start_time, |
1458 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1467 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1459 scoped_ptr<cc::CopyOutputResult> result) { | 1468 scoped_ptr<cc::CopyOutputResult> result) { |
| 1469 if (config != SkBitmap::kARGB_8888_Config) { |
| 1470 NOTIMPLEMENTED(); |
| 1471 callback.Run(false, SkBitmap()); |
| 1472 return; |
| 1473 } |
1460 DCHECK(result->HasBitmap()); | 1474 DCHECK(result->HasBitmap()); |
1461 base::ScopedClosureRunner scoped_callback_runner( | 1475 base::ScopedClosureRunner scoped_callback_runner( |
1462 base::Bind(callback, false, SkBitmap())); | 1476 base::Bind(callback, false, SkBitmap())); |
1463 | 1477 |
1464 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) | 1478 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) |
1465 return; | 1479 return; |
1466 | 1480 |
1467 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 1481 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
1468 DCHECK(source); | 1482 DCHECK(source); |
1469 if (!source) | 1483 if (!source) |
(...skipping 28 matching lines...) Expand all Loading... |
1498 // RenderWidgetHostView, public: | 1512 // RenderWidgetHostView, public: |
1499 | 1513 |
1500 // static | 1514 // static |
1501 RenderWidgetHostView* | 1515 RenderWidgetHostView* |
1502 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1516 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1503 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1517 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1504 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1518 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1505 } | 1519 } |
1506 | 1520 |
1507 } // namespace content | 1521 } // namespace content |
OLD | NEW |