| Index: content/browser/compositor/delegated_frame_host.cc
|
| diff --git a/content/browser/compositor/delegated_frame_host.cc b/content/browser/compositor/delegated_frame_host.cc
|
| index 3125dd520edd37d916449f1a39d141a825b6968b..f381da0eaddfc8f190cda971b0cfb1afac5abd6b 100644
|
| --- a/content/browser/compositor/delegated_frame_host.cc
|
| +++ b/content/browser/compositor/delegated_frame_host.cc
|
| @@ -151,7 +151,7 @@
|
|
|
| scoped_ptr<cc::CopyOutputRequest> request =
|
| cc::CopyOutputRequest::CreateRequest(
|
| - base::Bind(&CopyFromCompositingSurfaceHasResult,
|
| + base::Bind(&DelegatedFrameHost::CopyFromCompositingSurfaceHasResult,
|
| output_size, preferred_color_type, callback));
|
| if (!src_subrect.IsEmpty())
|
| request->set_area(src_subrect);
|
| @@ -593,6 +593,155 @@
|
| }
|
|
|
| // static
|
| +void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult(
|
| + const gfx::Size& dst_size_in_pixel,
|
| + const SkColorType color_type,
|
| + const ReadbackRequestCallback& callback,
|
| + scoped_ptr<cc::CopyOutputResult> result) {
|
| + if (result->IsEmpty() || result->size().IsEmpty()) {
|
| + callback.Run(SkBitmap(), content::READBACK_FAILED);
|
| + 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()) {
|
| + // GPU-accelerated path
|
| + PrepareTextureCopyOutputResult(output_size_in_pixel, color_type, callback,
|
| + std::move(result));
|
| + return;
|
| + }
|
| +
|
| + DCHECK(result->HasBitmap());
|
| + // Software path
|
| + PrepareBitmapCopyOutputResult(output_size_in_pixel, color_type, callback,
|
| + std::move(result));
|
| +}
|
| +
|
| +static void CopyFromCompositingSurfaceFinished(
|
| + const ReadbackRequestCallback& callback,
|
| + scoped_ptr<cc::SingleReleaseCallback> release_callback,
|
| + scoped_ptr<SkBitmap> bitmap,
|
| + scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
|
| + bool result) {
|
| + bitmap_pixels_lock.reset();
|
| +
|
| + gpu::SyncToken sync_token;
|
| + if (result) {
|
| + GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
|
| + if (gl_helper)
|
| + gl_helper->GenerateSyncToken(&sync_token);
|
| + }
|
| + const bool lost_resource = !sync_token.HasData();
|
| + release_callback->Run(sync_token, lost_resource);
|
| +
|
| + callback.Run(*bitmap,
|
| + result ? content::READBACK_SUCCESS : content::READBACK_FAILED);
|
| +}
|
| +
|
| +// static
|
| +void DelegatedFrameHost::PrepareTextureCopyOutputResult(
|
| + const gfx::Size& dst_size_in_pixel,
|
| + const SkColorType color_type,
|
| + const ReadbackRequestCallback& callback,
|
| + scoped_ptr<cc::CopyOutputResult> result) {
|
| + DCHECK(result->HasTexture());
|
| + base::ScopedClosureRunner scoped_callback_runner(
|
| + base::Bind(callback, SkBitmap(), content::READBACK_FAILED));
|
| +
|
| + // TODO(siva.gunturi): We should be able to validate the format here using
|
| + // GLHelper::IsReadbackConfigSupported before we processs the result.
|
| + // See crbug.com/415682 and crbug.com/415131.
|
| + scoped_ptr<SkBitmap> bitmap(new SkBitmap);
|
| + if (!bitmap->tryAllocPixels(SkImageInfo::Make(
|
| + dst_size_in_pixel.width(), dst_size_in_pixel.height(), color_type,
|
| + kOpaque_SkAlphaType))) {
|
| + scoped_callback_runner.Reset(base::Bind(
|
| + callback, SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE));
|
| + return;
|
| + }
|
| +
|
| + ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
|
| + GLHelper* gl_helper = factory->GetGLHelper();
|
| + if (!gl_helper)
|
| + return;
|
| +
|
| + scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock(
|
| + new SkAutoLockPixels(*bitmap));
|
| + uint8_t* pixels = static_cast<uint8_t*>(bitmap->getPixels());
|
| +
|
| + cc::TextureMailbox texture_mailbox;
|
| + scoped_ptr<cc::SingleReleaseCallback> release_callback;
|
| + result->TakeTexture(&texture_mailbox, &release_callback);
|
| + DCHECK(texture_mailbox.IsTexture());
|
| +
|
| + ignore_result(scoped_callback_runner.Release());
|
| +
|
| + gl_helper->CropScaleReadbackAndCleanMailbox(
|
| + texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
|
| + gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type,
|
| + base::Bind(&CopyFromCompositingSurfaceFinished, callback,
|
| + base::Passed(&release_callback), base::Passed(&bitmap),
|
| + base::Passed(&bitmap_pixels_lock)),
|
| + GLHelper::SCALER_QUALITY_GOOD);
|
| +}
|
| +
|
| +// static
|
| +void DelegatedFrameHost::PrepareBitmapCopyOutputResult(
|
| + const gfx::Size& dst_size_in_pixel,
|
| + const SkColorType preferred_color_type,
|
| + const ReadbackRequestCallback& callback,
|
| + scoped_ptr<cc::CopyOutputResult> result) {
|
| + SkColorType color_type = preferred_color_type;
|
| + if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) {
|
| + // Switch back to default colortype if format not supported.
|
| + color_type = kN32_SkColorType;
|
| + }
|
| + DCHECK(result->HasBitmap());
|
| + scoped_ptr<SkBitmap> source = result->TakeBitmap();
|
| + DCHECK(source);
|
| + SkBitmap scaled_bitmap;
|
| + if (source->width() != dst_size_in_pixel.width() ||
|
| + source->height() != dst_size_in_pixel.height()) {
|
| + scaled_bitmap =
|
| + skia::ImageOperations::Resize(*source,
|
| + skia::ImageOperations::RESIZE_BEST,
|
| + dst_size_in_pixel.width(),
|
| + dst_size_in_pixel.height());
|
| + } else {
|
| + scaled_bitmap = *source;
|
| + }
|
| + if (color_type == kN32_SkColorType) {
|
| + DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType);
|
| + callback.Run(scaled_bitmap, READBACK_SUCCESS);
|
| + return;
|
| + }
|
| + DCHECK_EQ(color_type, kAlpha_8_SkColorType);
|
| + // The software path currently always returns N32 bitmap regardless of the
|
| + // |color_type| we ask for.
|
| + DCHECK_EQ(scaled_bitmap.colorType(), kN32_SkColorType);
|
| + // Paint |scaledBitmap| to alpha-only |grayscale_bitmap|.
|
| + SkBitmap grayscale_bitmap;
|
| + bool success = grayscale_bitmap.tryAllocPixels(
|
| + SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height()));
|
| + if (!success) {
|
| + callback.Run(SkBitmap(), content::READBACK_BITMAP_ALLOCATION_FAILURE);
|
| + return;
|
| + }
|
| + SkCanvas canvas(grayscale_bitmap);
|
| + SkPaint paint;
|
| + skia::RefPtr<SkColorFilter> filter =
|
| + skia::AdoptRef(SkLumaColorFilter::Create());
|
| + paint.setColorFilter(filter.get());
|
| + canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint);
|
| + callback.Run(grayscale_bitmap, READBACK_SUCCESS);
|
| +}
|
| +
|
| +// static
|
| void DelegatedFrameHost::ReturnSubscriberTexture(
|
| base::WeakPtr<DelegatedFrameHost> dfh,
|
| scoped_refptr<OwnedMailbox> subscriber_texture,
|
| @@ -898,12 +1047,11 @@
|
|
|
| void DelegatedFrameHost::RequestCopyOfOutput(
|
| scoped_ptr<cc::CopyOutputRequest> request) {
|
| - if (!request_copy_of_output_callback_for_testing_.is_null()) {
|
| + if (!request_copy_of_output_callback_for_testing_.is_null())
|
| request_copy_of_output_callback_for_testing_.Run(std::move(request));
|
| - } else {
|
| + else
|
| client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(
|
| std::move(request));
|
| - }
|
| }
|
|
|
| void DelegatedFrameHost::UnlockResources() {
|
|
|