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

Unified Diff: cc/debug/picture_debug_util.cc

Issue 2895953003: Use SkJpegEncoder in gfx jpeg_codec (Closed)
Patch Set: Remove brackets 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: cc/debug/picture_debug_util.cc
diff --git a/cc/debug/picture_debug_util.cc b/cc/debug/picture_debug_util.cc
index f20715fc2960ffab9312f8998090caa18ee9eaf5..1174cb8fc403c864ed05ff3dd04fe9edaca6ad88 100644
--- a/cc/debug/picture_debug_util.cc
+++ b/cc/debug/picture_debug_util.cc
@@ -28,23 +28,19 @@ class BitmapSerializer : public SkPixelSerializer {
bool onUseEncodedData(const void* data, size_t len) override { return true; }
SkData* onEncode(const SkPixmap& pixmap) override {
- const SkImageInfo& info = pixmap.info();
- const void* pixels = pixmap.addr();
- size_t row_bytes = pixmap.rowBytes();
- const int kJpegQuality = 80;
std::vector<unsigned char> data;
// If bitmap is opaque, encode as JPEG.
// Otherwise encode as PNG.
bool encoding_succeeded = false;
- if (info.isOpaque()) {
- DCHECK_LE(row_bytes,
- static_cast<size_t>(std::numeric_limits<int>::max()));
- encoding_succeeded = gfx::JPEGCodec::Encode(
- reinterpret_cast<const unsigned char*>(pixels),
- gfx::JPEGCodec::FORMAT_SkBitmap, info.width(), info.height(),
- static_cast<int>(row_bytes), kJpegQuality, &data);
+ if (pixmap.isOpaque()) {
+ constexpr int kJpegQuality = 80;
+ encoding_succeeded = gfx::JPEGCodec::Encode(pixmap, kJpegQuality, &data);
} else {
+ const SkImageInfo& info = pixmap.info();
+ const void* pixels = pixmap.addr();
+ size_t row_bytes = pixmap.rowBytes();
+
SkBitmap bm;
// The cast is ok, since we only read the bm.
if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) {

Powered by Google App Engine
This is Rietveld 408576698