0

Rename PdfMetafileSkia to MetafileSkia

Since we use this class for both MSKP and PDF data processing, rename
its name to MetafileSkia. Similarly, rename the util files and test
files accordingly.

TBR=jam@chromium.org,dcheng@chromium.org

Change-Id: I295a106e1f48cb0110c5d8eb8539d1080e689c05
Reviewed-on: https://chromium-review.googlesource.com/1184157
Reviewed-by: Wei Li <weili@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585287}
This commit is contained in:
Wei Li
2018-08-22 22:41:17 +00:00
committed by Commit Bot
parent 75282ee158
commit ab75477f3e
23 changed files with 145 additions and 157 deletions

@ -36,7 +36,7 @@
#include "mojo/public/cpp/system/platform_handle.h"
#include "printing/backend/print_backend.h"
#include "printing/backend/print_backend_consts.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/metafile_skia.h"
#include "printing/print_job_constants.h"
#include "printing/printed_document.h"
#include "printing/units.h"
@ -112,7 +112,7 @@ class ArcPrintServiceFactory
// This creates a Metafile instance which is a wrapper around a byte buffer at
// this point.
std::unique_ptr<printing::PdfMetafileSkia> ReadFileOnBlockingTaskRunner(
std::unique_ptr<printing::MetafileSkia> ReadFileOnBlockingTaskRunner(
base::File file,
size_t data_size) {
// TODO(vkuzkokov) Can we make give pipe to CUPS directly?
@ -127,7 +127,7 @@ std::unique_ptr<printing::PdfMetafileSkia> ReadFileOnBlockingTaskRunner(
file.Close();
auto metafile = std::make_unique<printing::PdfMetafileSkia>();
auto metafile = std::make_unique<printing::MetafileSkia>();
if (!metafile->InitFromData(buf.data(), buf.size())) {
LOG(ERROR) << "Failed to initialize PDF metafile";
return nullptr;
@ -448,7 +448,7 @@ class PrintJobHostImpl : public mojom::PrintJobHost,
}
// Store Metafile and start printing if PrintJob is created as well.
void OnFileRead(std::unique_ptr<printing::PdfMetafileSkia> metafile) {
void OnFileRead(std::unique_ptr<printing::MetafileSkia> metafile) {
metafile_ = std::move(metafile);
StartPrintingIfReady();
}
@ -481,7 +481,7 @@ class PrintJobHostImpl : public mojom::PrintJobHost,
mojom::PrintJobInstancePtr instance_;
ArcPrintServiceImpl* const service_;
chromeos::CupsPrintJobManager* const job_manager_;
std::unique_ptr<printing::PdfMetafileSkia> metafile_;
std::unique_ptr<printing::MetafileSkia> metafile_;
scoped_refptr<printing::PrintJob> job_;
chromeos::CupsPrintJob* cups_job_;
content::NotificationRegistrar registrar_;

@ -47,7 +47,7 @@
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/system/buffer.h"
#include "printing/buildflags/buildflags.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/metafile_skia.h"
#include "printing/print_settings.h"
#include "printing/printed_document.h"
#include "ui/base/l10n/l10n_util.h"
@ -163,8 +163,7 @@ void PrintViewManagerBase::PrintDocument(
print_job_->StartConversionToNativeFormat(print_data, page_size, content_area,
offsets);
#else
std::unique_ptr<PdfMetafileSkia> metafile =
std::make_unique<PdfMetafileSkia>();
std::unique_ptr<MetafileSkia> metafile = std::make_unique<MetafileSkia>();
CHECK(metafile->InitFromData(print_data->front(), print_data->size()));
// Update the rendered document. It will send notifications to the listener.

@ -17,7 +17,7 @@
#include "components/printing/common/printing_param_traits_macros.h"
#include "ipc/ipc_message_macros.h"
#include "printing/buildflags/buildflags.h"
#include "printing/common/pdf_metafile_utils.h"
#include "printing/common/metafile_utils.h"
#include "printing/page_range.h"
#include "printing/page_size_margins.h"
#include "printing/print_job_constants.h"
@ -444,7 +444,7 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
#if defined(OS_ANDROID)
// Asks the browser to create a temporary file for the renderer to fill
// in resulting PdfMetafileSkia in printing.
// in resulting MetafileSkia in printing.
IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting,
int /* render_frame_id */,
base::FileDescriptor /* temp file fd */,

@ -19,6 +19,7 @@ static_library("renderer") {
"//content/public/renderer",
"//net",
"//printing",
"//printing/common",
"//third_party/blink/public:blink",
"//third_party/blink/public/common",
"//ui/base",

@ -35,8 +35,8 @@
#include "mojo/public/cpp/system/platform_handle.h"
#include "net/base/escape.h"
#include "printing/buildflags/buildflags.h"
#include "printing/metafile_skia.h"
#include "printing/metafile_skia_wrapper.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/units.h"
#include "third_party/blink/public/common/frame/sandbox_flags.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h"
@ -1302,7 +1302,7 @@ bool PrintRenderFrameHelper::CreatePreviewDocument() {
bool PrintRenderFrameHelper::RenderPreviewPage(
int page_number,
const PrintMsg_Print_Params& print_params) {
PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile();
MetafileSkia* initial_render_metafile = print_preview_context_.metafile();
base::TimeTicks begin_time = base::TimeTicks::Now();
double scale_factor = GetScaleFactor(print_params.scale_factor,
!print_preview_context_.IsModifiable());
@ -1323,7 +1323,7 @@ bool PrintRenderFrameHelper::RenderPreviewPage(
// contains the rendering for just this one page. Then the browser can update
// the user visible print preview one page at a time, instead of waiting for
// the entire document to be rendered.
std::unique_ptr<PdfMetafileSkia> metafile =
std::unique_ptr<MetafileSkia> metafile =
initial_render_metafile->GetMetafileForCurrentPage(
print_params.printed_doc_type);
return PreviewPageRendered(page_number, std::move(metafile));
@ -1333,7 +1333,7 @@ bool PrintRenderFrameHelper::FinalizePrintReadyDocument() {
DCHECK(!is_print_ready_metafile_sent_);
print_preview_context_.FinalizePrintReadyDocument();
PdfMetafileSkia* metafile = print_preview_context_.metafile();
MetafileSkia* metafile = print_preview_context_.metafile();
PrintHostMsg_DidPreviewDocument_Params preview_params;
if (!CopyMetafileDataToReadOnlySharedMem(*metafile,
@ -1451,7 +1451,7 @@ void PrintRenderFrameHelper::OnPrintFrameContent(
if (!weak_this)
return;
PdfMetafileSkia metafile(SkiaDocumentType::MSKP, params.document_cookie);
MetafileSkia metafile(SkiaDocumentType::MSKP, params.document_cookie);
gfx::Size area_size = params.printable_area.size();
// Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas.
@ -1694,8 +1694,8 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty())
return false;
PdfMetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
MetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
CHECK(metafile.Init());
PrintHostMsg_DidPrintDocument_Params page_params;
@ -1957,7 +1957,7 @@ void PrintRenderFrameHelper::PrintPageInternal(
int page_count,
double scale_factor,
blink::WebLocalFrame* frame,
PdfMetafileSkia* metafile,
MetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi) {
double css_scale_factor = scale_factor;
@ -2031,7 +2031,7 @@ void PrintRenderFrameHelper::PrintPageInternal(
#endif // !defined(OS_MACOSX)
bool PrintRenderFrameHelper::CopyMetafileDataToReadOnlySharedMem(
const PdfMetafileSkia& metafile,
const MetafileSkia& metafile,
PrintHostMsg_DidPrintContent_Params* params) {
uint32_t buf_size = metafile.GetDataSize();
if (buf_size == 0)
@ -2161,7 +2161,7 @@ bool PrintRenderFrameHelper::CheckForCancel() {
bool PrintRenderFrameHelper::PreviewPageRendered(
int page_number,
std::unique_ptr<PdfMetafileSkia> metafile) {
std::unique_ptr<MetafileSkia> metafile) {
DCHECK_GE(page_number, FIRST_PAGE_INDEX);
DCHECK(metafile);
DCHECK(print_preview_context_.IsModifiable());
@ -2235,7 +2235,7 @@ bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
return false;
}
metafile_ = std::make_unique<PdfMetafileSkia>(doc_type, document_cookie);
metafile_ = std::make_unique<MetafileSkia>(doc_type, document_cookie);
CHECK(metafile_->Init());
current_page_index_ = 0;
@ -2381,7 +2381,7 @@ int PrintRenderFrameHelper::PrintPreviewContext::total_page_count() const {
return total_page_count_;
}
PdfMetafileSkia* PrintRenderFrameHelper::PrintPreviewContext::metafile() {
MetafileSkia* PrintRenderFrameHelper::PrintPreviewContext::metafile() {
DCHECK(IsRendering());
return metafile_.get();
}

@ -19,7 +19,7 @@
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h"
#include "printing/buildflags/buildflags.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/common/metafile_utils.h"
#include "third_party/blink/public/web/web_node.h"
#include "third_party/blink/public/web/web_print_params.h"
#include "ui/gfx/geometry/size.h"
@ -54,6 +54,7 @@ class WebView;
namespace printing {
struct PageSizeMargins;
class MetafileSkia;
class PrepareFrameAndViewForPrint;
// Stores reference to frame using WebVew and unique name.
@ -293,7 +294,7 @@ class PrintRenderFrameHelper
int page_count,
double scale_factor,
blink::WebLocalFrame* frame,
PdfMetafileSkia* metafile,
MetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi);
@ -311,7 +312,7 @@ class PrintRenderFrameHelper
// Helper methods -----------------------------------------------------------
bool CopyMetafileDataToReadOnlySharedMem(
const PdfMetafileSkia& metafile,
const MetafileSkia& metafile,
PrintHostMsg_DidPrintContent_Params* params);
// Helper method to get page layout in points and fit to page if needed.
@ -329,9 +330,6 @@ class PrintRenderFrameHelper
const PrintMsg_PrintPages_Params& params,
int page_count);
// Helper function to find document type.
static SkiaDocumentType GetDocType(const PrintMsg_Print_Params& params);
// Given the |device| and |canvas| to draw on, prints the appropriate headers
// and footers using strings from |header_footer_info| on to the canvas.
static void PrintHeaderAndFooter(cc::PaintCanvas* canvas,
@ -368,7 +366,7 @@ class PrintRenderFrameHelper
// |metafile| is the rendered page and should be valid.
// Returns true if print preview should continue, false on failure.
bool PreviewPageRendered(int page_number,
std::unique_ptr<PdfMetafileSkia> metafile);
std::unique_ptr<MetafileSkia> metafile);
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings);
@ -455,7 +453,7 @@ class PrintRenderFrameHelper
const blink::WebNode& prepared_node() const;
int total_page_count() const;
PdfMetafileSkia* metafile();
MetafileSkia* metafile();
int last_error() const;
private:
@ -476,7 +474,7 @@ class PrintRenderFrameHelper
blink::WebNode source_node_;
std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
std::unique_ptr<PdfMetafileSkia> metafile_;
std::unique_ptr<MetafileSkia> metafile_;
// Total page count in the renderer.
int total_page_count_ = 0;

@ -10,6 +10,7 @@
#include "build/build_config.h"
#include "components/printing/common/print_messages.h"
#include "printing/buildflags/buildflags.h"
#include "printing/metafile_skia.h"
#include "printing/metafile_skia_wrapper.h"
#if defined(OS_ANDROID)
@ -53,8 +54,8 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty())
return false;
PdfMetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
MetafileSkia metafile(print_params.printed_doc_type,
print_params.document_cookie);
CHECK(metafile.Init());
for (int page_number : printed_pages) {

@ -14,6 +14,7 @@
#include "cc/paint/paint_canvas.h"
#include "components/printing/common/print_messages.h"
#include "printing/buildflags/buildflags.h"
#include "printing/metafile_skia.h"
#include "printing/metafile_skia_wrapper.h"
#include "printing/page_size_margins.h"
#include "third_party/blink/public/web/web_local_frame.h"
@ -26,7 +27,7 @@ void PrintRenderFrameHelper::PrintPageInternal(
int page_count,
double scale_factor,
blink::WebLocalFrame* frame,
PdfMetafileSkia* metafile,
MetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_rect_in_dpi) {
double css_scale_factor = scale_factor;

@ -11,7 +11,7 @@
#include "build/build_config.h"
#include "components/printing/common/print_messages.h"
#include "ipc/ipc_message_utils.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/metafile_skia.h"
#include "printing/units.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -213,7 +213,7 @@ void MockPrinter::PrintPage(
#if defined(OS_MACOSX)
printing::PdfMetafileCg metafile;
#else
printing::PdfMetafileSkia metafile;
printing::MetafileSkia metafile;
#endif
metafile.InitFromData(metafile_data.memory(), content.data_size);
printing::Image image(metafile);

@ -15,7 +15,7 @@
#include "components/services/pdf_compositor/public/cpp/pdf_service_mojo_types.h"
#include "components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "printing/common/pdf_metafile_utils.h"
#include "printing/common/metafile_utils.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDocument.h"
#include "third_party/skia/include/core/SkSerialProcs.h"

@ -136,8 +136,8 @@
#if BUILDFLAG(ENABLE_PRINTING)
// nogncheck because dependency on //printing is conditional upon
// enable_basic_printing flags.
#include "printing/metafile_skia.h" // nogncheck
#include "printing/metafile_skia_wrapper.h" // nogncheck
#include "printing/pdf_metafile_skia.h" // nogncheck
#endif
#if defined(OS_CHROMEOS)
@ -374,7 +374,7 @@ class PluginInstanceLockTarget : public MouseLockDispatcher::LockTarget {
};
void PrintPDFOutput(PP_Resource print_output,
printing::PdfMetafileSkia* metafile) {
printing::MetafileSkia* metafile) {
#if BUILDFLAG(ENABLE_PRINTING)
DCHECK(metafile);
@ -2006,7 +2006,7 @@ void PepperPluginInstanceImpl::PrintPage(int page_number,
DCHECK(plugin_print_interface_);
// |canvas| should always have an associated metafile.
printing::PdfMetafileSkia* metafile =
printing::MetafileSkia* metafile =
printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
DCHECK(metafile);

@ -99,7 +99,7 @@ class ScopedPPVar;
}
namespace printing {
class PdfMetafileSkia;
class MetafileSkia;
}
namespace content {
@ -791,7 +791,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
//
// The metafile to save into, which is guaranteed to be valid between a
// successful PrintBegin call and a PrintEnd call.
printing::PdfMetafileSkia* metafile_;
printing::MetafileSkia* metafile_;
// An array of page ranges.
std::vector<PP_PrintPageNumberRange_Dev> ranges_;

@ -55,8 +55,8 @@
#if BUILDFLAG(ENABLE_PRINTING)
// nogncheck because dependency on //printing is conditional upon
// enable_basic_printing flags.
#include "printing/metafile_skia.h" // nogncheck
#include "printing/metafile_skia_wrapper.h" // nogncheck
#include "printing/pdf_metafile_skia.h" // nogncheck
#endif
namespace content {
@ -909,7 +909,7 @@ SkBitmap* RenderFrameProxy::GetSadPageBitmap() {
uint32_t RenderFrameProxy::Print(const blink::WebRect& rect,
cc::PaintCanvas* canvas) {
#if BUILDFLAG(ENABLE_PRINTING)
printing::PdfMetafileSkia* metafile =
printing::MetafileSkia* metafile =
printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
DCHECK(metafile);

@ -35,6 +35,8 @@ component("printing") {
"emf_win.h",
"metafile.cc",
"metafile.h",
"metafile_skia.cc",
"metafile_skia.h",
"metafile_skia_wrapper.cc",
"metafile_skia_wrapper.h",
"native_drawing_context.h",
@ -49,8 +51,6 @@ component("printing") {
"page_size_margins.h",
"pdf_metafile_cg_mac.cc",
"pdf_metafile_cg_mac.h",
"pdf_metafile_skia.cc",
"pdf_metafile_skia.h",
"pdf_render_settings.h",
"print_dialog_gtk_interface.h",
"print_job_constants.cc",
@ -264,12 +264,12 @@ static_library("test_support") {
test("printing_unittests") {
sources = [
"emf_win_unittest.cc",
"metafile_skia_unittest.cc",
"nup_parameters_unittest.cc",
"page_number_unittest.cc",
"page_range_unittest.cc",
"page_setup_unittest.cc",
"pdf_metafile_cg_mac_unittest.cc",
"pdf_metafile_skia_unittest.cc",
"printing_context_win_unittest.cc",
"printing_test.h",
"printing_utils_unittest.cc",

@ -4,8 +4,8 @@
source_set("common") {
sources = [
"pdf_metafile_utils.cc",
"pdf_metafile_utils.h",
"metafile_utils.cc",
"metafile_utils.h",
]
deps = [

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/common/pdf_metafile_utils.h"
#include "printing/common/metafile_utils.h"
#include "base/time/time.h"
#include "third_party/skia/include/core/SkCanvas.h"

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_COMMON_PDF_METAFILE_UTILS_H_
#define PRINTING_COMMON_PDF_METAFILE_UTILS_H_
#ifndef PRINTING_COMMON_METAFILE_UTILS_H_
#define PRINTING_COMMON_METAFILE_UTILS_H_
#include <map>
#include <string>
@ -42,4 +42,4 @@ SkDeserialProcs DeserializationProcs(DeserializationContext* ctx);
} // namespace printing
#endif // PRINTING_COMMON_PDF_METAFILE_UTILS_H_
#endif // PRINTING_COMMON_METAFILE_UTILS_H_

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/pdf_metafile_skia.h"
#include "printing/metafile_skia.h"
#include <algorithm>
#include <map>
@ -38,9 +38,7 @@
namespace {
bool WriteAssetToBuffer(const SkStreamAsset* asset,
void* buffer,
size_t size) {
bool WriteAssetToBuffer(const SkStreamAsset* asset, void* buffer, size_t size) {
// Calling duplicate() keeps original asset state unchanged.
std::unique_ptr<SkStreamAsset> assetCopy(asset->duplicate());
size_t length = assetCopy->getLength();
@ -66,14 +64,11 @@ struct Page {
sk_sp<cc::PaintRecord> content;
};
// TODO(weili): Remove pdf from struct name and field names since it is used for
// other formats as well. Also change member variable names to
// conform with our style guide.
struct PdfMetafileSkiaData {
struct MetafileSkiaData {
cc::PaintRecorder recorder; // Current recording
std::vector<Page> pages;
std::unique_ptr<SkStreamAsset> pdf_data;
std::unique_ptr<SkStreamAsset> data_stream;
ContentToProxyIdMap subframe_content_info;
std::map<uint32_t, sk_sp<SkPicture>> subframe_pics;
int document_cookie = 0;
@ -90,36 +85,35 @@ struct PdfMetafileSkiaData {
#endif
};
PdfMetafileSkia::PdfMetafileSkia()
: data_(std::make_unique<PdfMetafileSkiaData>()) {
MetafileSkia::MetafileSkia() : data_(std::make_unique<MetafileSkiaData>()) {
data_->type = SkiaDocumentType::PDF;
}
PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type, int document_cookie)
: data_(std::make_unique<PdfMetafileSkiaData>()) {
MetafileSkia::MetafileSkia(SkiaDocumentType type, int document_cookie)
: data_(std::make_unique<MetafileSkiaData>()) {
data_->type = type;
data_->document_cookie = document_cookie;
}
PdfMetafileSkia::~PdfMetafileSkia() = default;
MetafileSkia::~MetafileSkia() = default;
bool PdfMetafileSkia::Init() {
bool MetafileSkia::Init() {
return true;
}
// TODO(halcanary): Create a Metafile class that only stores data.
// Metafile::InitFromData is orthogonal to what the rest of
// PdfMetafileSkia does.
bool PdfMetafileSkia::InitFromData(const void* src_buffer,
size_t src_buffer_size) {
data_->pdf_data = std::make_unique<SkMemoryStream>(
// MetafileSkia does.
bool MetafileSkia::InitFromData(const void* src_buffer,
size_t src_buffer_size) {
data_->data_stream = std::make_unique<SkMemoryStream>(
src_buffer, src_buffer_size, true /* copy_data? */);
return true;
}
void PdfMetafileSkia::StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor) {
void MetafileSkia::StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK_GT(page_size.width(), 0);
DCHECK_GT(page_size.height(), 0);
DCHECK_GT(scale_factor, 0.0f);
@ -147,7 +141,7 @@ void PdfMetafileSkia::StartPage(const gfx::Size& page_size,
// http://crbug.com/469656
}
cc::PaintCanvas* PdfMetafileSkia::GetVectorCanvasForNewPage(
cc::PaintCanvas* MetafileSkia::GetVectorCanvasForNewPage(
const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor) {
@ -155,7 +149,7 @@ cc::PaintCanvas* PdfMetafileSkia::GetVectorCanvasForNewPage(
return data_->recorder.getRecordingCanvas();
}
bool PdfMetafileSkia::FinishPage() {
bool MetafileSkia::FinishPage() {
if (!data_->recorder.getRecordingCanvas())
return false;
@ -171,9 +165,9 @@ bool PdfMetafileSkia::FinishPage() {
return true;
}
bool PdfMetafileSkia::FinishDocument() {
bool MetafileSkia::FinishDocument() {
// If we've already set the data in InitFromData, leave it be.
if (data_->pdf_data)
if (data_->data_stream)
return false;
if (data_->recorder.getRecordingCanvas())
@ -192,9 +186,8 @@ bool PdfMetafileSkia::FinishDocument() {
// It is safe to use base::Unretained(this) because the callback
// is only used by |canvas| in the following loop which has shorter
// lifetime than |this|.
custom_callback =
base::BindRepeating(&PdfMetafileSkia::CustomDataToSkPictureCallback,
base::Unretained(this));
custom_callback = base::BindRepeating(
&MetafileSkia::CustomDataToSkPictureCallback, base::Unretained(this));
break;
}
@ -206,20 +199,20 @@ bool PdfMetafileSkia::FinishDocument() {
}
doc->close();
data_->pdf_data = stream.detachAsStream();
data_->data_stream = stream.detachAsStream();
return true;
}
void PdfMetafileSkia::FinishFrameContent() {
void MetafileSkia::FinishFrameContent() {
// Sanity check to make sure we print the entire frame as a single page
// content.
DCHECK_EQ(data_->pages.size(), 1u);
// Also make sure it is in skia multi-picture document format.
DCHECK_EQ(data_->type, SkiaDocumentType::MSKP);
DCHECK(!data_->pdf_data);
DCHECK(!data_->data_stream);
cc::PlaybackParams::CustomDataRasterCallback custom_callback =
base::BindRepeating(&PdfMetafileSkia::CustomDataToSkPictureCallback,
base::BindRepeating(&MetafileSkia::CustomDataToSkPictureCallback,
base::Unretained(this));
sk_sp<SkPicture> pic = ToSkPicture(data_->pages[0].content,
SkRect::MakeSize(data_->pages[0].size),
@ -227,24 +220,23 @@ void PdfMetafileSkia::FinishFrameContent() {
SkSerialProcs procs = SerializationProcs(&data_->subframe_content_info);
SkDynamicMemoryWStream stream;
pic->serialize(&stream, &procs);
data_->pdf_data = stream.detachAsStream();
data_->data_stream = stream.detachAsStream();
}
uint32_t PdfMetafileSkia::GetDataSize() const {
if (!data_->pdf_data)
uint32_t MetafileSkia::GetDataSize() const {
if (!data_->data_stream)
return 0;
return base::checked_cast<uint32_t>(data_->pdf_data->getLength());
return base::checked_cast<uint32_t>(data_->data_stream->getLength());
}
bool PdfMetafileSkia::GetData(void* dst_buffer,
uint32_t dst_buffer_size) const {
if (!data_->pdf_data)
bool MetafileSkia::GetData(void* dst_buffer, uint32_t dst_buffer_size) const {
if (!data_->data_stream)
return false;
return WriteAssetToBuffer(data_->pdf_data.get(), dst_buffer,
return WriteAssetToBuffer(data_->data_stream.get(), dst_buffer,
base::checked_cast<size_t>(dst_buffer_size));
}
gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const {
gfx::Rect MetafileSkia::GetPageBounds(unsigned int page_number) const {
if (page_number < data_->pages.size()) {
SkSize size = data_->pages[page_number].size;
return gfx::Rect(gfx::ToRoundedInt(size.width()),
@ -253,24 +245,23 @@ gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const {
return gfx::Rect();
}
unsigned int PdfMetafileSkia::GetPageCount() const {
unsigned int MetafileSkia::GetPageCount() const {
return base::checked_cast<unsigned int>(data_->pages.size());
}
printing::NativeDrawingContext PdfMetafileSkia::context() const {
printing::NativeDrawingContext MetafileSkia::context() const {
NOTREACHED();
return nullptr;
}
#if defined(OS_WIN)
bool PdfMetafileSkia::Playback(printing::NativeDrawingContext hdc,
const RECT* rect) const {
bool MetafileSkia::Playback(printing::NativeDrawingContext hdc,
const RECT* rect) const {
NOTREACHED();
return false;
}
bool PdfMetafileSkia::SafePlayback(printing::NativeDrawingContext hdc) const {
bool MetafileSkia::SafePlayback(printing::NativeDrawingContext hdc) const {
NOTREACHED();
return false;
}
@ -283,29 +274,29 @@ bool PdfMetafileSkia::SafePlayback(printing::NativeDrawingContext hdc) const {
should do something like the following CL in PluginInstance::PrintPDFOutput:
http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plugin_instance.cc
*/
bool PdfMetafileSkia::RenderPage(unsigned int page_number,
CGContextRef context,
const CGRect rect,
const MacRenderPageParams& params) const {
bool MetafileSkia::RenderPage(unsigned int page_number,
CGContextRef context,
const CGRect rect,
const MacRenderPageParams& params) const {
DCHECK_GT(GetDataSize(), 0U);
if (data_->pdf_cg.GetDataSize() == 0) {
if (GetDataSize() == 0)
return false;
size_t length = data_->pdf_data->getLength();
size_t length = data_->data_stream->getLength();
std::vector<uint8_t> buffer(length);
(void)WriteAssetToBuffer(data_->pdf_data.get(), &buffer[0], length);
(void)WriteAssetToBuffer(data_->data_stream.get(), &buffer[0], length);
data_->pdf_cg.InitFromData(&buffer[0], length);
}
return data_->pdf_cg.RenderPage(page_number, context, rect, params);
}
#endif
bool PdfMetafileSkia::SaveTo(base::File* file) const {
bool MetafileSkia::SaveTo(base::File* file) const {
if (GetDataSize() == 0U)
return false;
// Calling duplicate() keeps original asset state unchanged.
std::unique_ptr<SkStreamAsset> asset(data_->pdf_data->duplicate());
std::unique_ptr<SkStreamAsset> asset(data_->data_stream->duplicate());
static constexpr size_t kMaximumBufferSize = 1024 * 1024;
std::vector<char> buffer(std::min(kMaximumBufferSize, asset->getLength()));
@ -323,12 +314,11 @@ bool PdfMetafileSkia::SaveTo(base::File* file) const {
return true;
}
std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
std::unique_ptr<MetafileSkia> MetafileSkia::GetMetafileForCurrentPage(
SkiaDocumentType type) {
// If we only ever need the metafile for the last page, should we
// only keep a handle on one PaintRecord?
auto metafile =
std::make_unique<PdfMetafileSkia>(type, data_->document_cookie);
auto metafile = std::make_unique<MetafileSkia>(type, data_->document_cookie);
if (data_->pages.size() == 0)
return metafile;
@ -345,8 +335,8 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
return metafile;
}
uint32_t PdfMetafileSkia::CreateContentForRemoteFrame(const gfx::Rect& rect,
int render_proxy_id) {
uint32_t MetafileSkia::CreateContentForRemoteFrame(const gfx::Rect& rect,
int render_proxy_id) {
// Create a place holder picture.
sk_sp<SkPicture> pic = SkPicture::MakePlaceholder(
SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()));
@ -361,32 +351,32 @@ uint32_t PdfMetafileSkia::CreateContentForRemoteFrame(const gfx::Rect& rect,
return content_id;
}
int PdfMetafileSkia::GetDocumentCookie() const {
int MetafileSkia::GetDocumentCookie() const {
return data_->document_cookie;
}
const ContentToProxyIdMap& PdfMetafileSkia::GetSubframeContentInfo() const {
const ContentToProxyIdMap& MetafileSkia::GetSubframeContentInfo() const {
return data_->subframe_content_info;
}
void PdfMetafileSkia::AppendPage(const SkSize& page_size,
sk_sp<cc::PaintRecord> record) {
void MetafileSkia::AppendPage(const SkSize& page_size,
sk_sp<cc::PaintRecord> record) {
data_->pages.emplace_back(page_size, std::move(record));
}
void PdfMetafileSkia::AppendSubframeInfo(uint32_t content_id,
int proxy_id,
sk_sp<SkPicture> pic_holder) {
void MetafileSkia::AppendSubframeInfo(uint32_t content_id,
int proxy_id,
sk_sp<SkPicture> pic_holder) {
data_->subframe_content_info[content_id] = proxy_id;
data_->subframe_pics[content_id] = pic_holder;
}
SkStreamAsset* PdfMetafileSkia::GetPdfData() const {
return data_->pdf_data.get();
SkStreamAsset* MetafileSkia::GetPdfData() const {
return data_->data_stream.get();
}
void PdfMetafileSkia::CustomDataToSkPictureCallback(SkCanvas* canvas,
uint32_t content_id) {
void MetafileSkia::CustomDataToSkPictureCallback(SkCanvas* canvas,
uint32_t content_id) {
// Check whether this is the one we need to handle.
if (!base::ContainsKey(data_->subframe_content_info, content_id))
return;

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_PDF_METAFILE_SKIA_H_
#define PRINTING_PDF_METAFILE_SKIA_H_
#ifndef PRINTING_METAFILE_SKIA_H_
#define PRINTING_METAFILE_SKIA_H_
#include <stdint.h>
@ -13,7 +13,7 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "cc/paint/paint_canvas.h"
#include "printing/common/pdf_metafile_utils.h"
#include "printing/common/metafile_utils.h"
#include "printing/metafile.h"
#include "skia/ext/platform_canvas.h"
@ -23,18 +23,17 @@
namespace printing {
struct PdfMetafileSkiaData;
struct MetafileSkiaData;
// This class uses Skia graphics library to generate a PDF or MSKP document.
// TODO(thestig): Rename to MetafileSkia.
class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
class PRINTING_EXPORT MetafileSkia : public Metafile {
public:
// Default constructor, for SkiaDocumentType::PDF type only.
// TODO(weili): we should split up this use case into a different class, see
// comments before InitFromData()'s implementation.
PdfMetafileSkia();
PdfMetafileSkia(SkiaDocumentType type, int document_cookie);
~PdfMetafileSkia() override;
MetafileSkia();
MetafileSkia(SkiaDocumentType type, int document_cookie);
~MetafileSkia() override;
// Metafile methods.
bool Init() override;
@ -73,13 +72,13 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
void FinishFrameContent();
// Return a new metafile containing just the current page in draft mode.
std::unique_ptr<PdfMetafileSkia> GetMetafileForCurrentPage(
std::unique_ptr<MetafileSkia> GetMetafileForCurrentPage(
SkiaDocumentType type);
// This method calls StartPage and then returns an appropriate
// PlatformCanvas implementation bound to the context created by
// StartPage or NULL on error. The PaintCanvas pointer that
// is returned is owned by this PdfMetafileSkia object and does not
// is returned is owned by this MetafileSkia object and does not
// need to be ref()ed or unref()ed. The canvas will remain valid
// until FinishPage() or FinishDocument() is called.
cc::PaintCanvas* GetVectorCanvasForNewPage(const gfx::Size& page_size,
@ -97,7 +96,7 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
const ContentToProxyIdMap& GetSubframeContentInfo() const;
private:
FRIEND_TEST_ALL_PREFIXES(PdfMetafileSkiaTest, TestFrameContent);
FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, TestFrameContent);
// The following three functions are used for tests only.
void AppendPage(const SkSize& page_size, sk_sp<cc::PaintRecord> record);
@ -110,11 +109,11 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
// data holder with corresponding place holder SkPicture.
void CustomDataToSkPictureCallback(SkCanvas* canvas, uint32_t content_id);
std::unique_ptr<PdfMetafileSkiaData> data_;
std::unique_ptr<MetafileSkiaData> data_;
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
DISALLOW_COPY_AND_ASSIGN(MetafileSkia);
};
} // namespace printing
#endif // PRINTING_PDF_METAFILE_SKIA_H_
#endif // PRINTING_METAFILE_SKIA_H_

@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/pdf_metafile_skia.h"
#include "printing/metafile_skia.h"
#include "cc/paint/paint_record.h"
#include "printing/common/pdf_metafile_utils.h"
#include "printing/common/metafile_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
namespace printing {
TEST(PdfMetafileSkiaTest, TestFrameContent) {
TEST(MetafileSkiaTest, TestFrameContent) {
constexpr int kPictureSideLen = 100;
constexpr int kPageSideLen = 150;
@ -31,7 +31,7 @@ TEST(PdfMetafileSkiaTest, TestFrameContent) {
SkSize page_size = SkSize::Make(kPageSideLen, kPageSideLen);
// Finish creating the entire metafile.
PdfMetafileSkia metafile(SkiaDocumentType::MSKP, 1);
MetafileSkia metafile(SkiaDocumentType::MSKP, 1);
metafile.AppendPage(page_size, std::move(record));
metafile.AppendSubframeInfo(content_id, 2, std::move(pic_holder));
metafile.FinishFrameContent();

@ -16,7 +16,7 @@ const char kMetafileKey[] = "CrMetafile";
// static
void MetafileSkiaWrapper::SetMetafileOnCanvas(cc::PaintCanvas* canvas,
PdfMetafileSkia* metafile) {
MetafileSkia* metafile) {
sk_sp<MetafileSkiaWrapper> wrapper;
// Can't use sk_make_sp<>() because the constructor is private.
if (metafile)
@ -27,7 +27,7 @@ void MetafileSkiaWrapper::SetMetafileOnCanvas(cc::PaintCanvas* canvas,
}
// static
PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
MetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
cc::PaintCanvas* canvas) {
SkMetaData& meta = canvas->getMetaData();
SkRefCnt* value;
@ -37,8 +37,7 @@ PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
}
MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile)
: metafile_(metafile) {
}
MetafileSkiaWrapper::MetafileSkiaWrapper(MetafileSkia* metafile)
: metafile_(metafile) {}
} // namespace printing

@ -11,23 +11,23 @@
namespace printing {
class PdfMetafileSkia;
class MetafileSkia;
// A wrapper class with static methods to set and retrieve a PdfMetafileSkia
// A wrapper class with static methods to set and retrieve a MetafileSkia
// on an SkCanvas. The ownership of the metafile is not affected and it
// is the caller's responsibility to ensure that the metafile remains valid
// as long as the canvas.
class PRINTING_EXPORT MetafileSkiaWrapper : public SkRefCnt {
public:
static void SetMetafileOnCanvas(cc::PaintCanvas* canvas,
PdfMetafileSkia* metafile);
MetafileSkia* metafile);
static PdfMetafileSkia* GetMetafileFromCanvas(cc::PaintCanvas* canvas);
static MetafileSkia* GetMetafileFromCanvas(cc::PaintCanvas* canvas);
private:
explicit MetafileSkiaWrapper(PdfMetafileSkia* metafile);
explicit MetafileSkiaWrapper(MetafileSkia* metafile);
PdfMetafileSkia* metafile_;
MetafileSkia* metafile_;
};
} // namespace printing

@ -291,7 +291,7 @@ PrintingContext::Result PrintingContextWin::NewPage() {
DCHECK(context_);
DCHECK(in_print_job_);
// Intentional No-op. PdfMetafileSkia::SafePlayback takes care of calling
// Intentional No-op. MetafileSkia::SafePlayback takes care of calling
// ::StartPage().
return OK;
@ -302,7 +302,7 @@ PrintingContext::Result PrintingContextWin::PageDone() {
return CANCEL;
DCHECK(in_print_job_);
// Intentional No-op. PdfMetafileSkia::SafePlayback takes care of calling
// Intentional No-op. MetafileSkia::SafePlayback takes care of calling
// ::EndPage().
return OK;