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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 default_size_ = size; | 246 default_size_ = size; |
247 WasResized(); | 247 WasResized(); |
248 } | 248 } |
249 | 249 |
250 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 250 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
251 SetSize(rect.size()); | 251 SetSize(rect.size()); |
252 } | 252 } |
253 | 253 |
254 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 254 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
255 float scale, | 255 float scale, |
256 const base::Callback<void(bool, const SkBitmap&)>& result_callback) { | 256 const base::Callback<void(bool, const SkBitmap&)>& result_callback, |
| 257 SkBitmap::Config bitmap_config, |
| 258 const gfx::Rect& bounding_rect, |
| 259 const BitmapAllocator bitmap_allocator) { |
257 if (!IsSurfaceAvailableForCopy()) { | 260 if (!IsSurfaceAvailableForCopy()) { |
258 result_callback.Run(false, SkBitmap()); | 261 result_callback.Run(false, SkBitmap()); |
259 return; | 262 return; |
260 } | 263 } |
261 | 264 |
262 gfx::Size bounds = layer_->bounds(); | 265 gfx::Size bounds = bounding_rect.IsEmpty() ? |
| 266 layer_->bounds() : |
| 267 gfx::Size(bounding_rect.width(), bounding_rect.height()); |
263 gfx::Rect src_subrect(bounds); | 268 gfx::Rect src_subrect(bounds); |
264 const gfx::Display& display = | 269 const gfx::Display& display = |
265 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 270 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
266 float device_scale_factor = display.device_scale_factor(); | 271 float device_scale_factor = display.device_scale_factor(); |
267 DCHECK_GT(device_scale_factor, 0); | 272 DCHECK_GT(device_scale_factor, 0); |
268 gfx::Size dst_size( | 273 gfx::Size dst_size( |
269 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); | 274 gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale / device_scale_factor))); |
| 275 |
| 276 scoped_ptr<SkBitmap> bitmap; |
| 277 if (!bitmap_allocator.is_null()) { |
| 278 SkBitmap* bitmap_ptr = NULL; |
| 279 bitmap_allocator.Run(bitmap_ptr, dst_size, bitmap_config); |
| 280 DCHECK(bitmap_ptr); |
| 281 DCHECK_EQ(bitmap_ptr->width(), bounds.width()); |
| 282 DCHECK_EQ(bitmap_ptr->height(), bounds.height()); |
| 283 DCHECK_EQ(bitmap_ptr->config(), bitmap_config); |
| 284 DCHECK_NE(bitmap_ptr->getPixels(), static_cast<void*>(NULL)); |
| 285 bitmap.reset(bitmap_ptr); |
| 286 } |
| 287 |
270 CopyFromCompositingSurface( | 288 CopyFromCompositingSurface( |
271 src_subrect, dst_size, result_callback, SkBitmap::kARGB_8888_Config); | 289 src_subrect, dst_size, result_callback, bitmap_config, bitmap.Pass()); |
272 } | 290 } |
273 | 291 |
274 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { | 292 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) { |
275 if (!CompositorImpl::IsInitialized() || | 293 if (!CompositorImpl::IsInitialized() || |
276 texture_id_in_layer_ == 0 || | 294 texture_id_in_layer_ == 0 || |
277 texture_size_in_layer_.IsEmpty()) | 295 texture_size_in_layer_.IsEmpty()) |
278 return false; | 296 return false; |
279 | 297 |
280 gfx::JavaBitmap bitmap(jbitmap); | 298 gfx::JavaBitmap bitmap(jbitmap); |
281 | 299 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 632 |
615 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 633 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
616 RenderWidgetHostViewBase::SetBackground(background); | 634 RenderWidgetHostViewBase::SetBackground(background); |
617 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 635 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
618 } | 636 } |
619 | 637 |
620 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 638 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
621 const gfx::Rect& src_subrect, | 639 const gfx::Rect& src_subrect, |
622 const gfx::Size& dst_size, | 640 const gfx::Size& dst_size, |
623 const base::Callback<void(bool, const SkBitmap&)>& callback, | 641 const base::Callback<void(bool, const SkBitmap&)>& callback, |
624 const SkBitmap::Config bitmap_config) { | 642 const SkBitmap::Config bitmap_config, |
| 643 scoped_ptr<SkBitmap> bitmap) { |
625 // Only ARGB888 and RGB565 supported as of now. | 644 // Only ARGB888 and RGB565 supported as of now. |
626 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | 645 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || |
627 (bitmap_config == SkBitmap::kARGB_8888_Config)); | 646 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
628 if (!format_support) { | 647 if (!format_support) { |
629 DCHECK(format_support); | 648 DCHECK(format_support); |
630 callback.Run(false, SkBitmap()); | 649 callback.Run(false, SkBitmap()); |
631 return; | 650 return; |
632 } | 651 } |
633 base::TimeTicks start_time = base::TimeTicks::Now(); | 652 base::TimeTicks start_time = base::TimeTicks::Now(); |
634 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 653 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
(...skipping 26 matching lines...) Expand all Loading... |
661 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 680 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
662 base::TimeTicks::Now() - start_time); | 681 base::TimeTicks::Now() - start_time); |
663 return; | 682 return; |
664 } | 683 } |
665 scoped_ptr<cc::CopyOutputRequest> request = | 684 scoped_ptr<cc::CopyOutputRequest> request = |
666 cc::CopyOutputRequest::CreateRequest(base::Bind( | 685 cc::CopyOutputRequest::CreateRequest(base::Bind( |
667 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 686 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
668 dst_size_in_pixel, | 687 dst_size_in_pixel, |
669 bitmap_config, | 688 bitmap_config, |
670 start_time, | 689 start_time, |
| 690 base::Passed(&bitmap), |
671 callback)); | 691 callback)); |
672 request->set_area(src_subrect_in_pixel); | 692 request->set_area(src_subrect_in_pixel); |
673 layer_->RequestCopyOfOutput(request.Pass()); | 693 layer_->RequestCopyOfOutput(request.Pass()); |
674 } | 694 } |
675 | 695 |
676 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 696 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
677 const gfx::Rect& src_subrect, | 697 const gfx::Rect& src_subrect, |
678 const scoped_refptr<media::VideoFrame>& target, | 698 const scoped_refptr<media::VideoFrame>& target, |
679 const base::Callback<void(bool)>& callback) { | 699 const base::Callback<void(bool)>& callback) { |
680 NOTIMPLEMENTED(); | 700 NOTIMPLEMENTED(); |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 DestroyDelegatedContent(); | 1348 DestroyDelegatedContent(); |
1329 texture_id_in_layer_ = 0; | 1349 texture_id_in_layer_ = 0; |
1330 RunAckCallbacks(); | 1350 RunAckCallbacks(); |
1331 } | 1351 } |
1332 | 1352 |
1333 // static | 1353 // static |
1334 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1354 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1335 const gfx::Size& dst_size_in_pixel, | 1355 const gfx::Size& dst_size_in_pixel, |
1336 const SkBitmap::Config bitmap_config, | 1356 const SkBitmap::Config bitmap_config, |
1337 const base::TimeTicks& start_time, | 1357 const base::TimeTicks& start_time, |
| 1358 scoped_ptr<SkBitmap> bitmap, |
1338 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1359 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1339 scoped_ptr<cc::CopyOutputResult> result) { | 1360 scoped_ptr<cc::CopyOutputResult> result) { |
1340 base::ScopedClosureRunner scoped_callback_runner( | 1361 base::ScopedClosureRunner scoped_callback_runner( |
1341 base::Bind(callback, false, SkBitmap())); | 1362 base::Bind(callback, false, SkBitmap())); |
1342 | 1363 |
1343 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1364 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1344 return; | 1365 return; |
1345 | 1366 |
1346 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1367 if (!bitmap.get()) { |
1347 bitmap->setConfig(bitmap_config, | 1368 bitmap.reset(new SkBitmap); |
1348 dst_size_in_pixel.width(), | 1369 bitmap->setConfig(bitmap_config, |
1349 dst_size_in_pixel.height(), | 1370 dst_size_in_pixel.width(), |
1350 0, kOpaque_SkAlphaType); | 1371 dst_size_in_pixel.height(), |
1351 if (!bitmap->allocPixels()) | 1372 0, kOpaque_SkAlphaType); |
1352 return; | 1373 if (!bitmap->allocPixels()) |
| 1374 return; |
| 1375 } |
1353 | 1376 |
1354 ImageTransportFactoryAndroid* factory = | 1377 ImageTransportFactoryAndroid* factory = |
1355 ImageTransportFactoryAndroid::GetInstance(); | 1378 ImageTransportFactoryAndroid::GetInstance(); |
1356 GLHelper* gl_helper = factory->GetGLHelper(); | 1379 GLHelper* gl_helper = factory->GetGLHelper(); |
1357 if (!gl_helper) | 1380 if (!gl_helper) |
1358 return; | 1381 return; |
1359 | 1382 |
1360 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1383 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1361 new SkAutoLockPixels(*bitmap)); | 1384 new SkAutoLockPixels(*bitmap)); |
1362 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1385 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 // RenderWidgetHostView, public: | 1462 // RenderWidgetHostView, public: |
1440 | 1463 |
1441 // static | 1464 // static |
1442 RenderWidgetHostView* | 1465 RenderWidgetHostView* |
1443 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1466 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1444 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1467 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1445 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1468 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1446 } | 1469 } |
1447 | 1470 |
1448 } // namespace content | 1471 } // namespace content |
OLD | NEW |