Skip to content

Commit

Permalink
[Payments] Use PNG codec directly
Browse files Browse the repository at this point in the history
Note that there is a warning for the interface CreateFrom1xBitmap that
WARNING: The resulting image will be pixelated when painted on a high
density display.

Change-Id: I59011a994a5766999e1af64f7082542cbde88dc6
Reviewed-on: https://chromium-review.googlesource.com/1188743
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585939}
  • Loading branch information
gogerald authored and Commit Bot committed Aug 24, 2018
1 parent f24bc21 commit 7b13c53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions content/browser/payments/payment_app_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/codec/png_codec.h"
#include "url/gurl.h"
#include "url/origin.h"

Expand Down Expand Up @@ -106,12 +106,13 @@ std::unique_ptr<StoredPaymentApp> ToStoredPaymentApp(const std::string& input) {
if (!app_proto.icon().empty()) {
std::string icon_raw_data;
base::Base64Decode(app_proto.icon(), &icon_raw_data);
app->icon = std::make_unique<SkBitmap>();
// Note that the icon has been decoded to PNG raw data regardless of the
// original icon format that was downloaded.
gfx::Image icon_image = gfx::Image::CreateFrom1xPNGBytes(
bool success = gfx::PNGCodec::Decode(
reinterpret_cast<const unsigned char*>(icon_raw_data.data()),
icon_raw_data.size());
app->icon = std::make_unique<SkBitmap>(icon_image.AsBitmap());
icon_raw_data.size(), app->icon.get());
DCHECK(success);
}

return app;
Expand Down
10 changes: 6 additions & 4 deletions content/browser/payments/payment_app_info_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "content/public/browser/manifest_icon_downloader.h"
#include "content/public/common/console_message_level.h"
#include "third_party/blink/public/common/manifest/manifest_icon_selector.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/codec/png_codec.h"
#include "url/origin.h"

namespace content {
Expand Down Expand Up @@ -262,10 +262,12 @@ void PaymentAppInfoFetcher::SelfDeleteFetcher::OnIconFetched(
return;
}

gfx::Image decoded_image = gfx::Image::CreateFrom1xBitmap(icon);
scoped_refptr<base::RefCountedMemory> raw_data = decoded_image.As1xPNGBytes();
std::vector<unsigned char> bitmap_data;
bool success = gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &bitmap_data);
DCHECK(success);
base::Base64Encode(
base::StringPiece(raw_data->front_as<char>(), raw_data->size()),
base::StringPiece(reinterpret_cast<const char*>(&bitmap_data[0]),
bitmap_data.size()),
&(fetched_payment_app_info_->icon));
RunCallbackAndDestroy();
}
Expand Down
11 changes: 6 additions & 5 deletions content/browser/payments/payment_instrument_icon_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include "content/public/browser/manifest_icon_downloader.h"
#include "third_party/blink/public/common/manifest/manifest_icon_selector.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/codec/png_codec.h"

namespace content {
namespace {
Expand Down Expand Up @@ -54,11 +53,13 @@ void OnIconFetched(
return;
}

gfx::Image decoded_image = gfx::Image::CreateFrom1xBitmap(bitmap);
scoped_refptr<base::RefCountedMemory> raw_data = decoded_image.As1xPNGBytes();
std::vector<unsigned char> bitmap_data;
bool success = gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data);
DCHECK(success);
std::string encoded_data;
base::Base64Encode(
base::StringPiece(raw_data->front_as<char>(), raw_data->size()),
base::StringPiece(reinterpret_cast<const char*>(&bitmap_data[0]),
bitmap_data.size()),
&encoded_data);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::BindOnce(std::move(callback), encoded_data));
Expand Down

0 comments on commit 7b13c53

Please sign in to comment.