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 4cfa531c1b4a1ac295f02da092bf7d6216592de7..db3383aab3b233c49456d0a0578753f6f2d25635 100644 |
--- a/content/browser/compositor/delegated_frame_host.cc |
+++ b/content/browser/compositor/delegated_frame_host.cc |
@@ -19,6 +19,9 @@ |
#include "media/base/video_frame.h" |
#include "media/base/video_util.h" |
#include "skia/ext/image_operations.h" |
+#include "third_party/skia/include/core/SkCanvas.h" |
+#include "third_party/skia/include/core/SkPaint.h" |
+#include "third_party/skia/include/effects/SkLumaColorFilter.h" |
#include "ui/gfx/frame_time.h" |
namespace content { |
@@ -136,7 +139,8 @@ void DelegatedFrameHost::CopyFromCompositingSurface( |
const base::Callback<void(bool, const SkBitmap&)>& callback, |
const SkColorType color_type) { |
// Only ARGB888 and RGB565 supported as of now. |
- bool format_support = ((color_type == kRGB_565_SkColorType) || |
+ bool format_support = ((color_type == kAlpha_8_SkColorType) || |
+ (color_type == kRGB_565_SkColorType) || |
(color_type == kN32_SkColorType)); |
DCHECK(format_support); |
if (!CanCopyToBitmap()) { |
@@ -591,7 +595,7 @@ void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
const SkColorType color_type, |
const base::Callback<void(bool, const SkBitmap&)>& callback, |
scoped_ptr<cc::CopyOutputResult> result) { |
- if (color_type != kN32_SkColorType) { |
+ if (color_type != kN32_SkColorType && color_type != kAlpha_8_SkColorType) { |
sky
2014/08/25 23:28:18
Why do we support 565 on 143, but not here?
mfomitchev
2014/08/26 14:33:03
565 is supported by the hardware path (PrepareText
|
NOTIMPLEMENTED(); |
callback.Run(false, SkBitmap()); |
return; |
@@ -599,12 +603,42 @@ void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
DCHECK(result->HasBitmap()); |
scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
DCHECK(source); |
- SkBitmap bitmap = skia::ImageOperations::Resize( |
- *source, |
- skia::ImageOperations::RESIZE_BEST, |
- dst_size_in_pixel.width(), |
- dst_size_in_pixel.height()); |
- callback.Run(true, bitmap); |
+ 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(scaled_bitmap.colorType() == kN32_SkColorType); |
sky
2014/08/25 23:28:19
DCHECK_EQ
mfomitchev
2014/08/26 14:33:03
Done.
|
+ callback.Run(true, scaled_bitmap); |
+ return; |
+ } |
+ DCHECK_EQ(color_type, kAlpha_8_SkColorType); |
sky
2014/08/25 23:28:18
Is this because ImageOperations::Resize is always
mfomitchev
2014/08/26 14:33:03
The source bitmap is N32 to begin with. The softwa
|
+ if (scaled_bitmap.colorType() == kAlpha_8_SkColorType) { |
+ callback.Run(true, scaled_bitmap); |
+ return; |
+ } |
+ // Paint |scaledBitmap| to alpha-only |a8Bitmap|. |
+ SkBitmap grayscale_bitmap; |
+ bool success = grayscale_bitmap.allocPixels( |
+ SkImageInfo::MakeA8(scaled_bitmap.width(), scaled_bitmap.height())); |
+ if (!success) { |
+ callback.Run(false, SkBitmap()); |
+ 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(true, grayscale_bitmap); |
} |
// static |
@@ -623,6 +657,7 @@ void DelegatedFrameHost::ReturnSubscriberTexture( |
dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); |
} |
+// static |
void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( |
base::WeakPtr<DelegatedFrameHost> dfh, |
const base::Callback<void(bool)>& callback, |