Commit 1f7be72b authored by Jonathan Backer's avatar Jonathan Backer Committed by Commit Bot

Skip makeImageSnapshot for CopyOutput readback

It doesn't seem to work for the root sk_surface_ with SkDDL. Plus, we
might skip an unnecessary copy. Specifically, when we do a
makeImageSnapshot, we are probably doing a GPU --> GPU memory copy. This
is followed by a GPU --> CPU memory copy to turn the SkImage into a
SkBitmap.  With the new code, Skia may optimize to a single GPU --> CPU
memory copy.

Bug: 911643
Change-Id: Ia456a9bba1a59f7f37134a8642a76064a54bf75f
Reviewed-on: https://chromium-review.googlesource.com/c/1387024Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: Jonathan Backer <backer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618670}
parent dcf112e3
...@@ -352,15 +352,14 @@ void SkiaOutputSurfaceImplOnGpu::CopyOutput( ...@@ -352,15 +352,14 @@ void SkiaOutputSurfaceImplOnGpu::CopyOutput(
auto* surface = id ? offscreen_surfaces_[id].get() : sk_surface_.get(); auto* surface = id ? offscreen_surfaces_[id].get() : sk_surface_.get();
SkBitmap bitmap; SkBitmap bitmap;
if (request->is_scaled()) { SkImageInfo copy_rect_info = SkImageInfo::Make(
// Resolve the source for the scaling input: Initialize a SkPixmap that copy_rect.width(), copy_rect.height(), SkColorType::kN32_SkColorType,
// selects the current RenderPass's output rect within the current canvas SkAlphaType::kPremul_SkAlphaType,
// and provides access to its pixels. surface->getCanvas()->imageInfo().refColorSpace());
SkBitmap render_pass_output; bitmap.allocPixels(copy_rect_info, copy_rect.width() * 4);
sk_sp<SkImage> copy_image = surface->readPixels(bitmap, copy_rect.x(), copy_rect.y());
surface->makeImageSnapshot(RectToSkIRect(copy_rect));
copy_image->asLegacyBitmap(&render_pass_output);
if (request->is_scaled()) {
// Execute the scaling: For downscaling, use the RESIZE_BETTER strategy // Execute the scaling: For downscaling, use the RESIZE_BETTER strategy
// (appropriate for thumbnailing); and, for upscaling, use the RESIZE_BEST // (appropriate for thumbnailing); and, for upscaling, use the RESIZE_BEST
// strategy. Note that processing is only done on the subset of the // strategy. Note that processing is only done on the subset of the
...@@ -373,13 +372,9 @@ void SkiaOutputSurfaceImplOnGpu::CopyOutput( ...@@ -373,13 +372,9 @@ void SkiaOutputSurfaceImplOnGpu::CopyOutput(
is_downscale_in_both_dimensions ? ImageOperations::RESIZE_BETTER is_downscale_in_both_dimensions ? ImageOperations::RESIZE_BETTER
: ImageOperations::RESIZE_BEST; : ImageOperations::RESIZE_BEST;
bitmap = ImageOperations::Resize( bitmap = ImageOperations::Resize(
render_pass_output, method, result_rect.width(), result_rect.height(), bitmap, method, result_rect.width(), result_rect.height(),
SkIRect{result_rect.x(), result_rect.y(), result_rect.right(), SkIRect{result_rect.x(), result_rect.y(), result_rect.right(),
result_rect.bottom()}); result_rect.bottom()});
} else /* if (!request->is_scaled()) */ {
sk_sp<SkImage> copy_image =
surface->makeImageSnapshot(RectToSkIRect(copy_rect));
copy_image->asLegacyBitmap(&bitmap);
} }
// TODO(crbug.com/795132): Plumb color space throughout SkiaRenderer up to the // TODO(crbug.com/795132): Plumb color space throughout SkiaRenderer up to the
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "cc/test/pixel_test_utils.h" #include "cc/test/pixel_test_utils.h"
#include "components/viz/common/features.h"
#include "content/browser/media/capture/content_capture_device_browsertest_base.h" #include "content/browser/media/capture/content_capture_device_browsertest_base.h"
#include "content/browser/media/capture/fake_video_capture_stack.h" #include "content/browser/media/capture/fake_video_capture_stack.h"
#include "content/browser/media/capture/frame_test_util.h" #include "content/browser/media/capture/frame_test_util.h"
...@@ -106,9 +107,12 @@ class AuraWindowVideoCaptureDeviceBrowserTest ...@@ -106,9 +107,12 @@ class AuraWindowVideoCaptureDeviceBrowserTest
#else #else
// viz::SoftwareRenderer does not do color space management. Otherwise // viz::SoftwareRenderer does not do color space management. Otherwise
// (normal case), be strict about color differences. // (normal case), be strict about color differences.
const int max_color_diff = IsSoftwareCompositingTest() // TODO(crbug/795132): SkiaRenderer temporarily uses same code as
? kVeryLooseMaxColorDifference // software compositor. Fix plumbing for SkiaRenderer.
: kMaxColorDifference; const int max_color_diff =
(IsSoftwareCompositingTest() || features::IsUsingSkiaRenderer())
? kVeryLooseMaxColorDifference
: kMaxColorDifference;
#endif #endif
// Determine the average RGB color in the three regions of the frame. // Determine the average RGB color in the three regions of the frame.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment