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

Unified Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 2943363003: Fixing transparent pixels appearing black when rendered for the context menu. (Closed)
Patch Set: rebase Created 3 years, 6 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
Index: chrome/renderer/chrome_render_frame_observer.cc
diff --git a/chrome/renderer/chrome_render_frame_observer.cc b/chrome/renderer/chrome_render_frame_observer.cc
index 7b13a729d2054f82d74661c2571f1bcb84d10db1..5a880c0e97853993658b8df9c0892e2f6d7cbc46 100644
--- a/chrome/renderer/chrome_render_frame_observer.cc
+++ b/chrome/renderer/chrome_render_frame_observer.cc
@@ -45,6 +45,7 @@
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/jpeg_codec.h"
+#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/size_f.h"
#include "url/gurl.h"
@@ -72,6 +73,10 @@ static const char kTranslateCaptureText[] = "Translate.CaptureText";
// the refresh delay is less than this value (in seconds).
static const double kLocationChangeIntervalInSeconds = 10;
+// For the context menu, we want to keep transparency as is instead of
+// replacing transparent pixels with black ones
+static const bool kDiscardTransparencyForContextMenu = false;
+
namespace {
// If the source image is null or occupies less area than
@@ -194,6 +199,7 @@ void ChromeRenderFrameObserver::RequestReloadImageForContextNode() {
void ChromeRenderFrameObserver::RequestThumbnailForContextNode(
int32_t thumbnail_min_area_pixels,
const gfx::Size& thumbnail_max_size_pixels,
+ bool use_png_codec,
const RequestThumbnailForContextNodeCallback& callback) {
WebNode context_node = render_frame()->GetWebFrame()->ContextMenuNode();
SkBitmap thumbnail;
@@ -219,8 +225,16 @@ void ChromeRenderFrameObserver::RequestThumbnailForContextNode(
std::vector<uint8_t> thumbnail_data;
constexpr int kDefaultQuality = 90;
std::vector<unsigned char> data;
- if (gfx::JPEGCodec::Encode(bitmap, kDefaultQuality, &data)) {
- thumbnail_data.swap(data);
+
+ if (use_png_codec) {
+ if (gfx::PNGCodec::EncodeBGRASkBitmap(
+ bitmap, kDiscardTransparencyForContextMenu, &data)) {
+ thumbnail_data.swap(data);
+ }
+ } else {
+ if (gfx::JPEGCodec::Encode(bitmap, kDefaultQuality, &data)) {
+ thumbnail_data.swap(data);
+ }
}
callback.Run(thumbnail_data, original_size);

Powered by Google App Engine
This is Rietveld 408576698