Commit fd59a531 authored by eustas's avatar eustas Committed by Commit bot

Add ability to copy unscaled output pixels.

BUG=427418

Review URL: https://codereview.chromium.org/802343002

Cr-Commit-Position: refs/heads/master@{#309542}
parent 3ffbbd5c
...@@ -180,7 +180,8 @@ void DelegatedFrameHost::CopyFromCompositingSurface( ...@@ -180,7 +180,8 @@ void DelegatedFrameHost::CopyFromCompositingSurface(
output_size, output_size,
color_type, color_type,
callback)); callback));
request->set_area(src_subrect); if (!src_subrect.IsEmpty())
request->set_area(src_subrect);
client_->RequestCopyOfOutput(request.Pass()); client_->RequestCopyOfOutput(request.Pass());
} }
...@@ -569,9 +570,15 @@ void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( ...@@ -569,9 +570,15 @@ void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult(
return; return;
} }
gfx::Size output_size_in_pixel;
if (dst_size_in_pixel.IsEmpty())
output_size_in_pixel = result->size();
else
output_size_in_pixel = dst_size_in_pixel;
if (result->HasTexture()) { if (result->HasTexture()) {
// GPU-accelerated path // GPU-accelerated path
PrepareTextureCopyOutputResult(dst_size_in_pixel, color_type, PrepareTextureCopyOutputResult(output_size_in_pixel, color_type,
callback, callback,
result.Pass()); result.Pass());
return; return;
...@@ -579,7 +586,7 @@ void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( ...@@ -579,7 +586,7 @@ void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult(
DCHECK(result->HasBitmap()); DCHECK(result->HasBitmap());
// Software path // Software path
PrepareBitmapCopyOutputResult(dst_size_in_pixel, color_type, callback, PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback,
result.Pass()); result.Pass());
} }
......
...@@ -971,7 +971,8 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( ...@@ -971,7 +971,8 @@ void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
start_time, start_time,
readback_layer, readback_layer,
callback)); callback));
request->set_area(src_subrect_in_pixel); if (!src_subrect_in_pixel.IsEmpty())
request->set_area(src_subrect_in_pixel);
readback_layer->RequestCopyOfOutput(request.Pass()); readback_layer->RequestCopyOfOutput(request.Pass());
} }
...@@ -1285,6 +1286,20 @@ void RenderWidgetHostViewAndroid::SynchronousCopyContents( ...@@ -1285,6 +1286,20 @@ void RenderWidgetHostViewAndroid::SynchronousCopyContents(
const gfx::Size& dst_size_in_pixel, const gfx::Size& dst_size_in_pixel,
ReadbackRequestCallback& callback, ReadbackRequestCallback& callback,
const SkColorType color_type) { const SkColorType color_type) {
gfx::Size input_size_in_pixel;
if (src_subrect_in_pixel.IsEmpty())
input_size_in_pixel = content_size_in_layer_;
else
input_size_in_pixel = src_subrect_in_pixel.size();
gfx::Size output_size_in_pixel;
if (dst_size_in_pixel.IsEmpty())
output_size_in_pixel = input_size_in_pixel;
else
output_size_in_pixel = dst_size_in_pixel;
int output_width = output_size_in_pixel.width();
int output_height = output_size_in_pixel.height();
SynchronousCompositor* compositor = SynchronousCompositor* compositor =
SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(),
host_->GetRoutingID()); host_->GetRoutingID());
...@@ -1294,14 +1309,14 @@ void RenderWidgetHostViewAndroid::SynchronousCopyContents( ...@@ -1294,14 +1309,14 @@ void RenderWidgetHostViewAndroid::SynchronousCopyContents(
} }
SkBitmap bitmap; SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), bitmap.allocPixels(SkImageInfo::Make(output_width,
dst_size_in_pixel.height(), output_height,
color_type, color_type,
kPremul_SkAlphaType)); kPremul_SkAlphaType));
SkCanvas canvas(bitmap); SkCanvas canvas(bitmap);
canvas.scale( canvas.scale(
(float)dst_size_in_pixel.width() / (float)src_subrect_in_pixel.width(), (float)output_width / (float)input_size_in_pixel.width(),
(float)dst_size_in_pixel.height() / (float)src_subrect_in_pixel.height()); (float)output_height / (float)input_size_in_pixel.height());
compositor->DemandDrawSw(&canvas); compositor->DemandDrawSw(&canvas);
callback.Run(bitmap, READBACK_SUCCESS); callback.Run(bitmap, READBACK_SUCCESS);
} }
...@@ -1805,9 +1820,15 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( ...@@ -1805,9 +1820,15 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
return; return;
gfx::Size output_size_in_pixel;
if (dst_size_in_pixel.IsEmpty())
output_size_in_pixel = result->size();
else
output_size_in_pixel = dst_size_in_pixel;
scoped_ptr<SkBitmap> bitmap(new SkBitmap); scoped_ptr<SkBitmap> bitmap(new SkBitmap);
if (!bitmap->tryAllocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), if (!bitmap->tryAllocPixels(SkImageInfo::Make(output_size_in_pixel.width(),
dst_size_in_pixel.height(), output_size_in_pixel.height(),
color_type, color_type,
kOpaque_SkAlphaType))) { kOpaque_SkAlphaType))) {
return; return;
...@@ -1835,7 +1856,7 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( ...@@ -1835,7 +1856,7 @@ void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
texture_mailbox.sync_point(), texture_mailbox.sync_point(),
result->size(), result->size(),
gfx::Rect(result->size()), gfx::Rect(result->size()),
dst_size_in_pixel, output_size_in_pixel,
pixels, pixels,
color_type, color_type,
base::Bind(&CopyFromCompositingSurfaceFinished, base::Bind(&CopyFromCompositingSurfaceFinished,
......
...@@ -256,10 +256,12 @@ class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView, ...@@ -256,10 +256,12 @@ class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView,
// Copies the contents of the compositing surface, providing a new SkBitmap // Copies the contents of the compositing surface, providing a new SkBitmap
// result via an asynchronously-run |callback|. |src_subrect| is specified in // result via an asynchronously-run |callback|. |src_subrect| is specified in
// layer space coordinates for the current platform (e.g., DIP for Aura/Mac, // layer space coordinates for the current platform (e.g., DIP for Aura/Mac,
// physical for Android), and is the region to be copied from this view. The // physical for Android), and is the region to be copied from this view. When
// copy is then scaled to a SkBitmap of size |dst_size|. |callback| is run // |src_subrect| is empty then the whole surface will be copied. The copy is
// with true on success, false otherwise. A smaller region than |src_subrect| // then scaled to a SkBitmap of size |dst_size|. If |dst_size| is empty then
// may be copied if the underlying surface is smaller than |src_subrect|. // output will be unscaled. |callback| is run with true on success,
// false otherwise. A smaller region than |src_subrect| may be copied
// if the underlying surface is smaller than |src_subrect|.
virtual void CopyFromCompositingSurface(const gfx::Rect& src_subrect, virtual void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
const gfx::Size& dst_size, const gfx::Size& dst_size,
ReadbackRequestCallback& callback, ReadbackRequestCallback& callback,
......
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