Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / frame_host / navigation_entry_screenshot_manager.cc
index 0b955fc..08791f9 100644 (file)
@@ -12,6 +12,9 @@
 #include "content/public/browser/render_widget_host.h"
 #include "content/public/browser/render_widget_host_view.h"
 #include "content/public/common/content_switches.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/codec/png_codec.h"
 
 namespace {
@@ -23,7 +26,7 @@ const int kMinScreenshotIntervalMS = 1000;
 
 namespace content {
 
-// Encodes an SkBitmap to PNG data in a worker thread.
+// Converts SkBitmap to grayscale and encodes to PNG data in a worker thread.
 class ScreenshotData : public base::RefCountedThreadSafe<ScreenshotData> {
  public:
   ScreenshotData() {
@@ -49,7 +52,21 @@ class ScreenshotData : public base::RefCountedThreadSafe<ScreenshotData> {
 
   void EncodeOnWorker(const SkBitmap& bitmap) {
     std::vector<unsigned char> data;
-    if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &data))
+    // Paint |bitmap| to a kA8_Config SkBitmap
+    SkBitmap a8Bitmap;
+    a8Bitmap.setConfig(SkBitmap::kA8_Config,
+                       bitmap.width(),
+                       bitmap.height(),
+                       0);
+    a8Bitmap.allocPixels();
+    SkCanvas canvas(a8Bitmap);
+    SkPaint paint;
+    SkColorFilter* filter = SkLumaColorFilter::Create();
+    paint.setColorFilter(filter);
+    filter->unref();
+    canvas.drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint);
+    // Encode the a8Bitmap to grayscale PNG treating alpha as color intensity
+    if (gfx::PNGCodec::EncodeA8SkBitmap(a8Bitmap, &data))
       data_ = new base::RefCountedBytes(data);
   }
 
@@ -117,11 +134,14 @@ void NavigationEntryScreenshotManager::TakeScreenshotImpl(
     NavigationEntryImpl* entry) {
   DCHECK(host && host->GetView());
   DCHECK(entry);
-  host->CopyFromBackingStore(gfx::Rect(),
+  SkBitmap::Config preferred_format = host->PreferredReadbackFormat();
+  host->CopyFromBackingStore(
+      gfx::Rect(),
       host->GetView()->GetViewBounds().size(),
       base::Bind(&NavigationEntryScreenshotManager::OnScreenshotTaken,
                  screenshot_factory_.GetWeakPtr(),
-                 entry->GetUniqueID()));
+                 entry->GetUniqueID()),
+      preferred_format);
 }
 
 void NavigationEntryScreenshotManager::SetMinScreenshotIntervalMS(