Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: content/browser/frame_host/navigation_entry_screenshot_manager.cc

Issue 136453009: Fix for Issue 331895: Make gesturenav screenshot greyscale (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing memory leak Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gfx/codec/png_codec.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigation_entry_screenshot_manager.cc
diff --git a/content/browser/frame_host/navigation_entry_screenshot_manager.cc b/content/browser/frame_host/navigation_entry_screenshot_manager.cc
index 0b955fc6d7c5aca41e1a07b02b0a42f5c7fffe66..b2bf429dc0a6c66a34266a5267ed62267a8aacb6 100644
--- a/content/browser/frame_host/navigation_entry_screenshot_manager.cc
+++ b/content/browser/frame_host/navigation_entry_screenshot_manager.cc
@@ -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, SK_Scalar1, SK_Scalar1, &paint);
+ // Encode the a8Bitmap to grayscale PNG treating alpha as color intensity
+ if (gfx::PNGCodec::EncodeA8SkBitmap(a8Bitmap, &data))
data_ = new base::RefCountedBytes(data);
}
« no previous file with comments | « no previous file | ui/gfx/codec/png_codec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698