Skip to content

Commit

Permalink
chrome.gpuBenchmarking.printPagesToXPS
Browse files Browse the repository at this point in the history
BUG=chromium:616763

Review-Url: https://codereview.chromium.org/2413753003
Cr-Commit-Position: refs/heads/master@{#429662}
  • Loading branch information
HalCanary authored and Commit bot committed Nov 3, 2016
1 parent f07ac87 commit f35e994
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
47 changes: 31 additions & 16 deletions content/renderer/gpu/gpu_benchmarking_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,29 @@ static void PrintDocument(blink::WebFrame* frame, SkDocument* doc) {
frame->printEnd();
}

static void PrintDocumentTofile(v8::Isolate* isolate,
const std::string& filename,
sk_sp<SkDocument> (*make_doc)(SkWStream*)) {
GpuBenchmarkingContext context;
if (!context.Init(true))
return;

base::FilePath path = base::FilePath::FromUTF8Unsafe(filename);
if (!base::PathIsWritable(path.DirName())) {
std::string msg("Path is not writable: ");
msg.append(path.DirName().MaybeAsASCII());
isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(
isolate, msg.c_str(), v8::String::kNormalString, msg.length())));
return;
}
SkFILEWStream wStream(path.MaybeAsASCII().c_str());
sk_sp<SkDocument> doc = make_doc(&wStream);
if (doc) {
context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true);
PrintDocument(context.web_frame(), doc.get());
doc->close();
}
}
} // namespace

gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin};
Expand Down Expand Up @@ -520,6 +543,8 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder(
.SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture)
.SetMethod("printPagesToSkPictures",
&GpuBenchmarking::PrintPagesToSkPictures)
.SetMethod("printPagesToXPS",
&GpuBenchmarking::PrintPagesToXPS)
.SetValue("DEFAULT_INPUT", 0)
.SetValue("TOUCH_INPUT", 1)
.SetValue("MOUSE_INPUT", 2)
Expand Down Expand Up @@ -564,23 +589,13 @@ void GpuBenchmarking::SetRasterizeOnlyVisibleContent() {

void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate,
const std::string& filename) {
GpuBenchmarkingContext context;
if (!context.Init(true))
return;
PrintDocumentTofile(isolate, filename, &SkMakeMultiPictureDocument);
}

base::FilePath path = base::FilePath::FromUTF8Unsafe(filename);
if (!base::PathIsWritable(path.DirName())) {
std::string msg("Path is not writable: ");
msg.append(path.DirName().MaybeAsASCII());
isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(
isolate, msg.c_str(), v8::String::kNormalString, msg.length())));
return;
}
SkFILEWStream wStream(path.MaybeAsASCII().c_str());
sk_sp<SkDocument> doc = SkMakeMultiPictureDocument(&wStream);
context.web_frame()->view()->settings()->setShouldPrintBackgrounds(true);
PrintDocument(context.web_frame(), doc.get());
doc->close();
void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate,
const std::string& filename) {
PrintDocumentTofile(isolate, filename,
[](SkWStream* s) { return SkDocument::MakeXPS(s); });
}

void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate,
Expand Down
2 changes: 2 additions & 0 deletions content/renderer/gpu/gpu_benchmarking_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class GpuBenchmarking : public gin::Wrappable<GpuBenchmarking> {
void PrintToSkPicture(v8::Isolate* isolate, const std::string& dirname);
void PrintPagesToSkPictures(v8::Isolate* isolate,
const std::string& filename);
void PrintPagesToXPS(v8::Isolate* isolate,
const std::string& filename);
bool GestureSourceTypeSupported(int gesture_source_type);
bool SmoothScrollBy(gin::Arguments* args);
bool SmoothDrag(gin::Arguments* args);
Expand Down
6 changes: 4 additions & 2 deletions skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ component("skia") {
"//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
"//third_party/skia/src/sfnt/SkOTTable_name.cpp",
"//third_party/skia/src/sfnt/SkOTUtils.cpp",
"//third_party/skia/src/xps/SkDocument_XPS.cpp",
"//third_party/skia/src/xps/SkDocument_XPS_None.cpp",
"//third_party/skia/src/xps/SkXPSDevice.cpp",
]

if (is_mac) {
Expand Down Expand Up @@ -309,6 +312,7 @@ component("skia") {
# Keeping _win.cpp
"//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
]
libs = [ "fontsub.lib" ]
} else {
sources -= [
# Keeping _pthread.cpp
Expand All @@ -321,8 +325,6 @@ component("skia") {
if (is_win) {
sources -= [
#windows
"//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp",
"//third_party/skia/src/utils/win/SkIStream.cpp",
"//third_party/skia/src/utils/win/SkWGL_win.cpp",
]
}
Expand Down

0 comments on commit f35e994

Please sign in to comment.