Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 88033002: Add RGB565 Texture readback support in gl_helper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected indentation. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 texture_id_in_layer_, 298 texture_id_in_layer_,
299 texture_size_in_layer_, 299 texture_size_in_layer_,
300 bitmap.size(), 300 bitmap.size(),
301 true, 301 true,
302 GLHelper::SCALER_QUALITY_FAST); 302 GLHelper::SCALER_QUALITY_FAST);
303 if (texture == 0) 303 if (texture == 0)
304 return false; 304 return false;
305 305
306 helper->ReadbackTextureSync(texture, 306 helper->ReadbackTextureSync(texture,
307 gfx::Rect(bitmap.size()), 307 gfx::Rect(bitmap.size()),
308 static_cast<unsigned char*> (bitmap.pixels())); 308 static_cast<unsigned char*> (bitmap.pixels()),
309 SkBitmap::kARGB_8888_Config);
309 310
310 blink::WebGraphicsContext3D* context = 311 blink::WebGraphicsContext3D* context =
311 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); 312 ImageTransportFactoryAndroid::GetInstance()->GetContext3D();
312 context->deleteTexture(texture); 313 context->deleteTexture(texture);
313 314
314 return true; 315 return true;
315 } 316 }
316 317
317 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 318 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
318 if (!content_view_core_) 319 if (!content_view_core_)
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 } 615 }
615 616
616 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { 617 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) {
617 RenderWidgetHostViewBase::SetBackground(background); 618 RenderWidgetHostViewBase::SetBackground(background);
618 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); 619 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
619 } 620 }
620 621
621 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 622 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
622 const gfx::Rect& src_subrect, 623 const gfx::Rect& src_subrect,
623 const gfx::Size& dst_size, 624 const gfx::Size& dst_size,
624 const base::Callback<void(bool, const SkBitmap&)>& callback) { 625 const base::Callback<void(bool, const SkBitmap&)>& callback,
626 bool readback_config_rgb565) {
625 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { 627 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) {
626 callback.Run(false, SkBitmap()); 628 callback.Run(false, SkBitmap());
627 return; 629 return;
628 } 630 }
629 631 ImageTransportFactoryAndroid* factory =
632 ImageTransportFactoryAndroid::GetInstance();
633 GLHelper* gl_helper = factory->GetGLHelper();
634 if (!gl_helper)
635 return;
636 bool check_rgb565_support = gl_helper->CanUseRgb565Readback();
637 if (readback_config_rgb565 && !check_rgb565_support) {
638 LOG(ERROR) << "Readbackformat rgb565 not supported";
639 callback.Run(false, SkBitmap());
640 return;
641 }
630 const gfx::Display& display = 642 const gfx::Display& display =
631 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 643 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
632 float device_scale_factor = display.device_scale_factor(); 644 float device_scale_factor = display.device_scale_factor();
633 645
634 DCHECK_EQ(device_scale_factor, 646 DCHECK_EQ(device_scale_factor,
635 ui::GetImageScale(GetScaleFactorForView(this))); 647 ui::GetImageScale(GetScaleFactorForView(this)));
636 648
637 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); 649 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size);
638 gfx::Rect src_subrect_in_pixel = 650 gfx::Rect src_subrect_in_pixel =
639 ConvertRectToPixel(device_scale_factor, src_subrect); 651 ConvertRectToPixel(device_scale_factor, src_subrect);
640 652
641 if (using_synchronous_compositor_) { 653 if (using_synchronous_compositor_) {
642 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); 654 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback);
643 return; 655 return;
644 } 656 }
645
646 scoped_ptr<cc::CopyOutputRequest> request; 657 scoped_ptr<cc::CopyOutputRequest> request;
647 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { 658 if (src_subrect_in_pixel.size() == dst_size_in_pixel) {
648 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( 659 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind(
649 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, 660 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult,
650 dst_size_in_pixel, 661 dst_size_in_pixel,
651 callback)); 662 callback));
652 } else { 663 } else {
653 request = cc::CopyOutputRequest::CreateRequest(base::Bind( 664 request = cc::CopyOutputRequest::CreateRequest(base::Bind(
654 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, 665 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult,
655 dst_size_in_pixel, 666 dst_size_in_pixel,
667 readback_config_rgb565,
656 callback)); 668 callback));
657 } 669 }
658 request->set_area(src_subrect_in_pixel); 670 request->set_area(src_subrect_in_pixel);
659 layer_->RequestCopyOfOutput(request.Pass()); 671 layer_->RequestCopyOfOutput(request.Pass());
660 } 672 }
661 673
662 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 674 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
663 const gfx::Rect& src_subrect, 675 const gfx::Rect& src_subrect,
664 const scoped_refptr<media::VideoFrame>& target, 676 const scoped_refptr<media::VideoFrame>& target,
665 const base::Callback<void(bool)>& callback) { 677 const base::Callback<void(bool)>& callback) {
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 texture_layer_->SetIsDrawable(false); 1361 texture_layer_->SetIsDrawable(false);
1350 if (delegated_renderer_layer_.get()) 1362 if (delegated_renderer_layer_.get())
1351 DestroyDelegatedContent(); 1363 DestroyDelegatedContent();
1352 texture_id_in_layer_ = 0; 1364 texture_id_in_layer_ = 0;
1353 RunAckCallbacks(); 1365 RunAckCallbacks();
1354 } 1366 }
1355 1367
1356 // static 1368 // static
1357 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1369 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1358 const gfx::Size& dst_size_in_pixel, 1370 const gfx::Size& dst_size_in_pixel,
1371 bool readback_config_rgb565,
1359 const base::Callback<void(bool, const SkBitmap&)>& callback, 1372 const base::Callback<void(bool, const SkBitmap&)>& callback,
1360 scoped_ptr<cc::CopyOutputResult> result) { 1373 scoped_ptr<cc::CopyOutputResult> result) {
1361 DCHECK(result->HasTexture()); 1374 DCHECK(result->HasTexture());
1362 base::ScopedClosureRunner scoped_callback_runner( 1375 base::ScopedClosureRunner scoped_callback_runner(
1363 base::Bind(callback, false, SkBitmap())); 1376 base::Bind(callback, false, SkBitmap()));
1364 1377
1365 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) 1378 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1366 return; 1379 return;
1367 1380
1368 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 1381 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1369 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 1382 SkBitmap::Config bitmap_config = readback_config_rgb565 ?
1370 dst_size_in_pixel.width(), dst_size_in_pixel.height(), 1383 SkBitmap::kRGB_565_Config :
1384 SkBitmap::kARGB_8888_Config;
1385 bitmap->setConfig(bitmap_config,
1386 dst_size_in_pixel.width(),
1387 dst_size_in_pixel.height(),
1371 0, kOpaque_SkAlphaType); 1388 0, kOpaque_SkAlphaType);
1372 if (!bitmap->allocPixels()) 1389 if (!bitmap->allocPixels())
1373 return; 1390 return;
1374 1391
1375 ImageTransportFactoryAndroid* factory = 1392 ImageTransportFactoryAndroid* factory =
1376 ImageTransportFactoryAndroid::GetInstance(); 1393 ImageTransportFactoryAndroid::GetInstance();
1377 GLHelper* gl_helper = factory->GetGLHelper(); 1394 GLHelper* gl_helper = factory->GetGLHelper();
1378 if (!gl_helper) 1395 if (!gl_helper)
1379 return; 1396 return;
1380 1397
(...skipping 10 matching lines...) Expand all
1391 1408
1392 ignore_result(scoped_callback_runner.Release()); 1409 ignore_result(scoped_callback_runner.Release());
1393 1410
1394 gl_helper->CropScaleReadbackAndCleanMailbox( 1411 gl_helper->CropScaleReadbackAndCleanMailbox(
1395 texture_mailbox.name(), 1412 texture_mailbox.name(),
1396 texture_mailbox.sync_point(), 1413 texture_mailbox.sync_point(),
1397 result->size(), 1414 result->size(),
1398 gfx::Rect(result->size()), 1415 gfx::Rect(result->size()),
1399 dst_size_in_pixel, 1416 dst_size_in_pixel,
1400 pixels, 1417 pixels,
1418 readback_config_rgb565,
1401 base::Bind(&CopyFromCompositingSurfaceFinished, 1419 base::Bind(&CopyFromCompositingSurfaceFinished,
1402 callback, 1420 callback,
1403 base::Passed(&release_callback), 1421 base::Passed(&release_callback),
1404 base::Passed(&bitmap), 1422 base::Passed(&bitmap),
1405 base::Passed(&bitmap_pixels_lock))); 1423 base::Passed(&bitmap_pixels_lock)));
1406 } 1424 }
1407 1425
1408 // static 1426 // static
1409 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( 1427 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult(
1410 const gfx::Size& dst_size_in_pixel, 1428 const gfx::Size& dst_size_in_pixel,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 // RenderWidgetHostView, public: 1466 // RenderWidgetHostView, public:
1449 1467
1450 // static 1468 // static
1451 RenderWidgetHostView* 1469 RenderWidgetHostView*
1452 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1470 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1453 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1471 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1454 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1472 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1455 } 1473 }
1456 1474
1457 } // namespace content 1475 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698