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

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: Rebased to ToT! 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 } 619 }
619 620
620 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { 621 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) {
621 RenderWidgetHostViewBase::SetBackground(background); 622 RenderWidgetHostViewBase::SetBackground(background);
622 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); 623 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
623 } 624 }
624 625
625 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 626 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
626 const gfx::Rect& src_subrect, 627 const gfx::Rect& src_subrect,
627 const gfx::Size& dst_size, 628 const gfx::Size& dst_size,
628 const base::Callback<void(bool, const SkBitmap&)>& callback) { 629 const base::Callback<void(bool, const SkBitmap&)>& callback,
630 bool readback_config_rgb565) {
629 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { 631 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) {
630 callback.Run(false, SkBitmap()); 632 callback.Run(false, SkBitmap());
631 return; 633 return;
632 } 634 }
633 635 ImageTransportFactoryAndroid* factory =
636 ImageTransportFactoryAndroid::GetInstance();
637 GLHelper* gl_helper = factory->GetGLHelper();
638 if (!gl_helper)
639 return;
640 bool check_rgb565_support = gl_helper->CanUseRgb565Readback();
641 if (readback_config_rgb565 && !check_rgb565_support) {
642 LOG(ERROR) << "Readbackformat rgb565 not supported";
643 callback.Run(false, SkBitmap());
644 return;
645 }
634 const gfx::Display& display = 646 const gfx::Display& display =
635 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 647 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
636 float device_scale_factor = display.device_scale_factor(); 648 float device_scale_factor = display.device_scale_factor();
637 649
638 DCHECK_EQ(device_scale_factor, 650 DCHECK_EQ(device_scale_factor,
639 ui::GetImageScale(GetScaleFactorForView(this))); 651 ui::GetImageScale(GetScaleFactorForView(this)));
640 652
641 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); 653 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size);
642 gfx::Rect src_subrect_in_pixel = 654 gfx::Rect src_subrect_in_pixel =
643 ConvertRectToPixel(device_scale_factor, src_subrect); 655 ConvertRectToPixel(device_scale_factor, src_subrect);
644 656
645 if (using_synchronous_compositor_) { 657 if (using_synchronous_compositor_) {
646 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); 658 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback);
647 return; 659 return;
648 } 660 }
649
650 scoped_ptr<cc::CopyOutputRequest> request; 661 scoped_ptr<cc::CopyOutputRequest> request;
651 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { 662 if (src_subrect_in_pixel.size() == dst_size_in_pixel) {
652 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( 663 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind(
653 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, 664 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult,
654 dst_size_in_pixel, 665 dst_size_in_pixel,
655 callback)); 666 callback));
656 } else { 667 } else {
657 request = cc::CopyOutputRequest::CreateRequest(base::Bind( 668 request = cc::CopyOutputRequest::CreateRequest(base::Bind(
658 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, 669 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult,
659 dst_size_in_pixel, 670 dst_size_in_pixel,
671 readback_config_rgb565,
660 callback)); 672 callback));
661 } 673 }
662 request->set_area(src_subrect_in_pixel); 674 request->set_area(src_subrect_in_pixel);
663 layer_->RequestCopyOfOutput(request.Pass()); 675 layer_->RequestCopyOfOutput(request.Pass());
664 } 676 }
665 677
666 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 678 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
667 const gfx::Rect& src_subrect, 679 const gfx::Rect& src_subrect,
668 const scoped_refptr<media::VideoFrame>& target, 680 const scoped_refptr<media::VideoFrame>& target,
669 const base::Callback<void(bool)>& callback) { 681 const base::Callback<void(bool)>& callback) {
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 texture_layer_->SetIsDrawable(false); 1365 texture_layer_->SetIsDrawable(false);
1354 if (delegated_renderer_layer_.get()) 1366 if (delegated_renderer_layer_.get())
1355 DestroyDelegatedContent(); 1367 DestroyDelegatedContent();
1356 texture_id_in_layer_ = 0; 1368 texture_id_in_layer_ = 0;
1357 RunAckCallbacks(); 1369 RunAckCallbacks();
1358 } 1370 }
1359 1371
1360 // static 1372 // static
1361 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1373 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1362 const gfx::Size& dst_size_in_pixel, 1374 const gfx::Size& dst_size_in_pixel,
1375 bool readback_config_rgb565,
1363 const base::Callback<void(bool, const SkBitmap&)>& callback, 1376 const base::Callback<void(bool, const SkBitmap&)>& callback,
1364 scoped_ptr<cc::CopyOutputResult> result) { 1377 scoped_ptr<cc::CopyOutputResult> result) {
1365 DCHECK(result->HasTexture()); 1378 DCHECK(result->HasTexture());
1366 base::ScopedClosureRunner scoped_callback_runner( 1379 base::ScopedClosureRunner scoped_callback_runner(
1367 base::Bind(callback, false, SkBitmap())); 1380 base::Bind(callback, false, SkBitmap()));
1368 1381
1369 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) 1382 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1370 return; 1383 return;
1371 1384
1372 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 1385 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1373 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 1386 SkBitmap::Config bitmap_config = readback_config_rgb565 ?
1374 dst_size_in_pixel.width(), dst_size_in_pixel.height(), 1387 SkBitmap::kRGB_565_Config :
1388 SkBitmap::kARGB_8888_Config;
1389 bitmap->setConfig(bitmap_config,
1390 dst_size_in_pixel.width(),
1391 dst_size_in_pixel.height(),
1375 0, kOpaque_SkAlphaType); 1392 0, kOpaque_SkAlphaType);
1376 if (!bitmap->allocPixels()) 1393 if (!bitmap->allocPixels())
1377 return; 1394 return;
1378 1395
1379 ImageTransportFactoryAndroid* factory = 1396 ImageTransportFactoryAndroid* factory =
1380 ImageTransportFactoryAndroid::GetInstance(); 1397 ImageTransportFactoryAndroid::GetInstance();
1381 GLHelper* gl_helper = factory->GetGLHelper(); 1398 GLHelper* gl_helper = factory->GetGLHelper();
1382 if (!gl_helper) 1399 if (!gl_helper)
1383 return; 1400 return;
1384 1401
(...skipping 10 matching lines...) Expand all
1395 1412
1396 ignore_result(scoped_callback_runner.Release()); 1413 ignore_result(scoped_callback_runner.Release());
1397 1414
1398 gl_helper->CropScaleReadbackAndCleanMailbox( 1415 gl_helper->CropScaleReadbackAndCleanMailbox(
1399 texture_mailbox.name(), 1416 texture_mailbox.name(),
1400 texture_mailbox.sync_point(), 1417 texture_mailbox.sync_point(),
1401 result->size(), 1418 result->size(),
1402 gfx::Rect(result->size()), 1419 gfx::Rect(result->size()),
1403 dst_size_in_pixel, 1420 dst_size_in_pixel,
1404 pixels, 1421 pixels,
1422 readback_config_rgb565,
1405 base::Bind(&CopyFromCompositingSurfaceFinished, 1423 base::Bind(&CopyFromCompositingSurfaceFinished,
1406 callback, 1424 callback,
1407 base::Passed(&release_callback), 1425 base::Passed(&release_callback),
1408 base::Passed(&bitmap), 1426 base::Passed(&bitmap),
1409 base::Passed(&bitmap_pixels_lock))); 1427 base::Passed(&bitmap_pixels_lock)));
1410 } 1428 }
1411 1429
1412 // static 1430 // static
1413 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( 1431 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult(
1414 const gfx::Size& dst_size_in_pixel, 1432 const gfx::Size& dst_size_in_pixel,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 // RenderWidgetHostView, public: 1470 // RenderWidgetHostView, public:
1453 1471
1454 // static 1472 // static
1455 RenderWidgetHostView* 1473 RenderWidgetHostView*
1456 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1474 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1457 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1475 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1458 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1476 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1459 } 1477 }
1460 1478
1461 } // namespace content 1479 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698