From 397e7278792bc30195afebaf23afd6304cd772ff Mon Sep 17 00:00:00 2001 From: msarett Date: Tue, 23 Feb 2016 10:49:17 -0800 Subject: Add option for SKP capture without reencoding images Generating SKPs with this new flag will allow us to obtain a large set of images that is representative of what is common on the web. BUG= Review URL: https://codereview.chromium.org/1710553002 Cr-Commit-Position: refs/heads/master@{#377026} --- content/public/common/content_switches.cc | 6 +++ content/public/common/content_switches.h | 1 + content/renderer/gpu/gpu_benchmarking_extension.cc | 53 ++++++++++++++++++---- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index f4749f7..70363f3 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -801,6 +801,12 @@ const char kSitePerProcess[] = "site-per-process"; // TODO(gab): Get rid of this switch entirely. const char kSkipGpuDataLoading[] = "skip-gpu-data-loading"; +// Skips reencoding bitmaps as PNGs when the encoded data is unavailable +// during SKP capture. This allows for obtaining an accurate sample of +// the types of images on the web, rather than being weighted towards PNGs +// that we have encoded ourselves. +const char kSkipReencodingOnSKPCapture[] = "skip-reencoding-on-skp-capture"; + // Specifies if the browser should start in fullscreen mode, like if the user // had pressed F11 right after startup. const char kStartFullscreen[] = "start-fullscreen"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index e9b4619..fe08255 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -224,6 +224,7 @@ extern const char kShowPaintRects[]; CONTENT_EXPORT extern const char kSingleProcess[]; CONTENT_EXPORT extern const char kSitePerProcess[]; CONTENT_EXPORT extern const char kSkipGpuDataLoading[]; +extern const char kSkipReencodingOnSKPCapture[]; CONTENT_EXPORT extern const char kStartFullscreen[]; CONTENT_EXPORT extern const char kStatsCollectionController[]; CONTENT_EXPORT extern const char kTabCaptureDownscaleQuality[]; diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc index 8a807ff..f471360 100644 --- a/content/renderer/gpu/gpu_benchmarking_extension.cc +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc @@ -9,6 +9,7 @@ #include #include "base/base64.h" +#include "base/command_line.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/macros.h" @@ -21,6 +22,7 @@ #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" #include "content/common/input/synthetic_tap_gesture_params.h" #include "content/public/child/v8_value_converter.h" +#include "content/public/common/content_switches.h" #include "content/public/renderer/chrome_object_extensions_utils.h" #include "content/public/renderer/render_thread.h" #include "content/renderer/gpu/render_widget_compositor.h" @@ -54,19 +56,52 @@ namespace content { namespace { -class PNGSerializer : public SkPixelSerializer { +class EncodingSerializer : public SkPixelSerializer { protected: bool onUseEncodedData(const void* data, size_t len) override { return true; } SkData* onEncode(const SkPixmap& pixmap) override { - SkBitmap bm; - // The const_cast is fine, since we only read from the bitmap. - if (bm.installPixels(pixmap.info(), - const_cast(pixmap.addr()), - pixmap.rowBytes())) { - std::vector vector; - if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { + std::vector vector; + + const base::CommandLine& commandLine = + *base::CommandLine::ForCurrentProcess(); + if (commandLine.HasSwitch(switches::kSkipReencodingOnSKPCapture)) { + // In this case, we just want to store some useful information + // about the image to replace the missing encoded data. + + // First make sure that the data does not accidentally match any + // image signatures. + vector.push_back(0xFF); + vector.push_back(0xFF); + vector.push_back(0xFF); + vector.push_back(0xFF); + + // Save the width and height. + uint32_t width = pixmap.width(); + uint32_t height = pixmap.height(); + vector.push_back(width & 0xFF); + vector.push_back((width >> 8) & 0xFF); + vector.push_back((width >> 16) & 0xFF); + vector.push_back((width >> 24) & 0xFF); + vector.push_back(height & 0xFF); + vector.push_back((height >> 8) & 0xFF); + vector.push_back((height >> 16) & 0xFF); + vector.push_back((height >> 24) & 0xFF); + + // Save any additional information about the bitmap that may be + // interesting. + vector.push_back(pixmap.colorType()); + vector.push_back(pixmap.alphaType()); return SkData::NewWithCopy(&vector.front(), vector.size()); + } else { + SkBitmap bm; + // The const_cast is fine, since we only read from the bitmap. + if (bm.installPixels(pixmap.info(), + const_cast(pixmap.addr()), + pixmap.rowBytes())) { + if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) { + return SkData::NewWithCopy(&vector.front(), vector.size()); + } } } return nullptr; @@ -106,7 +141,7 @@ class SkPictureSerializer { SkFILEWStream file(filepath.c_str()); DCHECK(file.isValid()); - PNGSerializer serializer; + EncodingSerializer serializer; picture->serialize(&file, &serializer); file.fsync(); } -- cgit v1.1