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

Unified Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 1710553002: Add option for SKP capture without reencoding images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « content/public/common/content_switches.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/gpu/gpu_benchmarking_extension.cc
diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc
index 1eb6ef33c09af37fb66fa8e02df2b9d3e6fa2d0c..fc46e3091a558eadeb35d241183b68dbd2ef78ea 100644
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc
@@ -9,6 +9,7 @@
#include <utility>
#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<void*>(pixmap.addr()),
- pixmap.rowBytes())) {
- std::vector<unsigned char> vector;
- if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) {
+ std::vector<unsigned char> vector;
palmer 2016/02/22 23:12:24 Nit: uint8_t more clearly means "byte" than does u
msarett 2016/02/22 23:19:10 Done :)
+
+ 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<void*>(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();
}
« no previous file with comments | « content/public/common/content_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698