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

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: 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 08ca11e128025445d355c026ae12b3265e4af132..2876c3fdaffffccd88d31f2b4efefa3b9720331f 100644
--- a/chrome/renderer/chrome_render_frame_observer.cc
+++ b/chrome/renderer/chrome_render_frame_observer.cc
@@ -43,6 +43,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"
@@ -70,6 +71,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;
msarett1 2017/06/21 04:18:15 I'm glad this is false. "true" is fairly awkward
Daniel Park 2017/06/22 01:11:35 I'm a little unsure of how to proceed with regards
+
namespace {
// If the source image is null or occupies less area than
@@ -190,6 +195,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;
@@ -215,8 +221,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);
« chrome/common/thumbnail_capturer.mojom ('K') | « chrome/renderer/chrome_render_frame_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698