Commit 39d52aa5 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Revert "Add support for OOPIF printing in renderer"

This reverts commit ef052a2f.

Reason for revert: this (with the previous CL 648979) brpoke builds for devices that do not have CUPS.

Original change's description:
> Add support for OOPIF printing in renderer
> 
> These mainly include painting placeholders for cross process subframes,
> sending messages to browser to inform printing such subframes,
> serialization and deserialization of printed content, and compositing
> these contents into the final result.
> 
> The high level design doc is at goo.gl/CF1RUy, and browser side change
> is at https:/crrev.com/c/822155.
> 
> BUG=455764
> 
> Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
> Change-Id: I15066f46da41d416356cad7392efb669b5f9f024
> Reviewed-on: https://chromium-review.googlesource.com/838512
> Reviewed-by: Khushal <khushalsagar@chromium.org>
> Reviewed-by: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
> Reviewed-by: vmpstr <vmpstr@chromium.org>
> Commit-Queue: Wei Li <weili@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#537243}

TBR=dcheng@chromium.org,thestig@chromium.org,weili@chromium.org,vmpstr@chromium.org,alexmos@chromium.org,khushalsagar@chromium.org

Change-Id: I58a03469bf216957f190e23a3795de472ca58402
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 455764, 813246
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Reviewed-on: https://chromium-review.googlesource.com/924486Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537484}
parent 8bfb0b04
...@@ -344,7 +344,15 @@ void SkiaPaintCanvas::drawTextBlob(scoped_refptr<PaintTextBlob> blob, ...@@ -344,7 +344,15 @@ void SkiaPaintCanvas::drawTextBlob(scoped_refptr<PaintTextBlob> blob,
} }
void SkiaPaintCanvas::drawPicture(sk_sp<const PaintRecord> record) { void SkiaPaintCanvas::drawPicture(sk_sp<const PaintRecord> record) {
drawPicture(record, PlaybackParams::CustomDataRasterCallback()); auto did_draw_op_cb =
context_flushes_.enable
? base::BindRepeating(&SkiaPaintCanvas::FlushAfterDrawIfNeeded,
base::Unretained(this))
: PlaybackParams::DidDrawOpCallback();
PlaybackParams params(image_provider_, canvas_->getTotalMatrix(),
PlaybackParams::CustomDataRasterCallback(),
did_draw_op_cb);
record->Playback(canvas_, params);
} }
bool SkiaPaintCanvas::isClipEmpty() const { bool SkiaPaintCanvas::isClipEmpty() const {
...@@ -377,19 +385,6 @@ void SkiaPaintCanvas::Annotate(AnnotationType type, ...@@ -377,19 +385,6 @@ void SkiaPaintCanvas::Annotate(AnnotationType type,
} }
} }
void SkiaPaintCanvas::drawPicture(
sk_sp<const PaintRecord> record,
PlaybackParams::CustomDataRasterCallback custom_raster_callback) {
auto did_draw_op_cb =
context_flushes_.enable
? base::BindRepeating(&SkiaPaintCanvas::FlushAfterDrawIfNeeded,
base::Unretained(this))
: PlaybackParams::DidDrawOpCallback();
PlaybackParams params(image_provider_, canvas_->getTotalMatrix(),
custom_raster_callback, did_draw_op_cb);
record->Playback(canvas_, params);
}
void SkiaPaintCanvas::FlushAfterDrawIfNeeded() { void SkiaPaintCanvas::FlushAfterDrawIfNeeded() {
if (!context_flushes_.enable) if (!context_flushes_.enable)
return; return;
......
...@@ -135,12 +135,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas { ...@@ -135,12 +135,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas {
using PaintCanvas::drawImage; using PaintCanvas::drawImage;
using PaintCanvas::drawPicture; using PaintCanvas::drawPicture;
// Same as the above drawPicture() except using the given custom data
// raster callback.
void drawPicture(
sk_sp<const PaintRecord> record,
PlaybackParams::CustomDataRasterCallback custom_raster_callback);
private: private:
// We always need skia shaders since the ops will be played on an SkCanvas. // We always need skia shaders since the ops will be played on an SkCanvas.
static const bool kCreateSkiaShaders; static const bool kCreateSkiaShaders;
......
...@@ -126,7 +126,8 @@ std::unique_ptr<printing::PdfMetafileSkia> ReadFileOnBlockingTaskRunner( ...@@ -126,7 +126,8 @@ std::unique_ptr<printing::PdfMetafileSkia> ReadFileOnBlockingTaskRunner(
file.Close(); file.Close();
auto metafile = std::make_unique<printing::PdfMetafileSkia>(); auto metafile = std::make_unique<printing::PdfMetafileSkia>(
printing::SkiaDocumentType::PDF);
if (!metafile->InitFromData(buf.data(), buf.size())) { if (!metafile->InitFromData(buf.data(), buf.size())) {
LOG(ERROR) << "Failed to initialize PDF metafile"; LOG(ERROR) << "Failed to initialize PDF metafile";
return nullptr; return nullptr;
......
...@@ -227,12 +227,15 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeContent) { ...@@ -227,12 +227,15 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeContent) {
WaitUntilMessagesReceived(); WaitUntilMessagesReceived();
} }
// TODO(weili): Enabled the following tests when the render side change is
// completed.
// Printing frame content with a cross-site iframe which also has a cross-site // Printing frame content with a cross-site iframe which also has a cross-site
// iframe. The site reference chain is a.com --> b.com --> c.com. // iframe. The site reference chain is a.com --> b.com --> c.com.
// This test passes when both cross-site frames are printed and their // This test passes when both cross-site frames are printed and their
// responses which are checked in // responses which are checked in
// TestPrintFrameContentMsgFilter::CheckMessage(). // TestPrintFrameContentMsgFilter::CheckMessage().
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) { IN_PROC_BROWSER_TEST_F(PrintBrowserTest, DISABLED_PrintSubframeChain) {
ASSERT_TRUE(embedded_test_server()->Started()); ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL( GURL url(embedded_test_server()->GetURL(
"/printing/content_with_iframe_chain.html")); "/printing/content_with_iframe_chain.html"));
...@@ -279,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) { ...@@ -279,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeChain) {
// This test passes when both cross-site frames are printed and send back // This test passes when both cross-site frames are printed and send back
// responses which are checked in // responses which are checked in
// TestPrintFrameContentMsgFilter::CheckMessage(). // TestPrintFrameContentMsgFilter::CheckMessage().
IN_PROC_BROWSER_TEST_F(PrintBrowserTest, PrintSubframeABA) { IN_PROC_BROWSER_TEST_F(PrintBrowserTest, DISABLED_PrintSubframeABA) {
ASSERT_TRUE(embedded_test_server()->Started()); ASSERT_TRUE(embedded_test_server()->Started());
GURL url(embedded_test_server()->GetURL( GURL url(embedded_test_server()->GetURL(
"a.com", "/printing/content_with_iframe_loop.html")); "a.com", "/printing/content_with_iframe_loop.html"));
......
...@@ -193,7 +193,7 @@ void PrintViewManagerBase::PrintDocument( ...@@ -193,7 +193,7 @@ void PrintViewManagerBase::PrintDocument(
} }
#else #else
std::unique_ptr<PdfMetafileSkia> metafile = std::unique_ptr<PdfMetafileSkia> metafile =
std::make_unique<PdfMetafileSkia>(); std::make_unique<PdfMetafileSkia>(SkiaDocumentType::PDF);
CHECK(metafile->InitFromData(print_data->front(), print_data->size())); CHECK(metafile->InitFromData(print_data->front(), print_data->size()));
// Update the rendered document. It will send notifications to the listener. // Update the rendered document. It will send notifications to the listener.
......
...@@ -30,7 +30,9 @@ uint64_t GenerateFrameGuid(int process_id, int frame_id) { ...@@ -30,7 +30,9 @@ uint64_t GenerateFrameGuid(int process_id, int frame_id) {
namespace printing { namespace printing {
PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents) PrintCompositeClient::PrintCompositeClient(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), for_preview_(false) {} : for_preview_(false) {
DCHECK(web_contents);
}
PrintCompositeClient::~PrintCompositeClient() {} PrintCompositeClient::~PrintCompositeClient() {}
...@@ -89,6 +91,7 @@ void PrintCompositeClient::DoCompositePageToPdf( ...@@ -89,6 +91,7 @@ void PrintCompositeClient::DoCompositePageToPdf(
const ContentToProxyIdMap& subframe_content_info, const ContentToProxyIdMap& subframe_content_info,
mojom::PdfCompositor::CompositePageToPdfCallback callback) { mojom::PdfCompositor::CompositePageToPdfCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
auto& compositor = GetCompositeRequest(document_cookie); auto& compositor = GetCompositeRequest(document_cookie);
DCHECK(data_size); DCHECK(data_size);
......
...@@ -1221,8 +1221,7 @@ bool PrintRenderFrameHelper::CreatePreviewDocument() { ...@@ -1221,8 +1221,7 @@ bool PrintRenderFrameHelper::CreatePreviewDocument() {
const std::vector<int>& pages = print_pages_params_->pages; const std::vector<int>& pages = print_pages_params_->pages;
if (!print_preview_context_.CreatePreviewDocument( if (!print_preview_context_.CreatePreviewDocument(
std::move(prep_frame_view_), pages, print_params.printed_doc_type, std::move(prep_frame_view_), pages, print_params.printed_doc_type)) {
print_params.document_cookie)) {
return false; return false;
} }
...@@ -1432,7 +1431,7 @@ void PrintRenderFrameHelper::OnPrintFrameContent( ...@@ -1432,7 +1431,7 @@ void PrintRenderFrameHelper::OnPrintFrameContent(
if (!weak_this) if (!weak_this)
return; return;
PdfMetafileSkia metafile(SkiaDocumentType::MSKP, params.document_cookie); PdfMetafileSkia metafile(SkiaDocumentType::MSKP);
gfx::Rect area(params.printable_area.width(), params.printable_area.height()); gfx::Rect area(params.printable_area.width(), params.printable_area.height());
// Since GetVectorCanvasForNewPage() starts a new recording, it will return // Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas. // a valid canvas.
...@@ -1470,7 +1469,6 @@ void PrintRenderFrameHelper::OnPrintFrameContent( ...@@ -1470,7 +1469,6 @@ void PrintRenderFrameHelper::OnPrintFrameContent(
DLOG(ERROR) << "CopyMetafileDataToSharedMem failed"; DLOG(ERROR) << "CopyMetafileDataToSharedMem failed";
return; return;
} }
Send(new PrintHostMsg_DidPrintFrameContent( Send(new PrintHostMsg_DidPrintFrameContent(
routing_id(), params.document_cookie, printed_frame_params)); routing_id(), params.document_cookie, printed_frame_params));
...@@ -1670,8 +1668,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame, ...@@ -1670,8 +1668,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty()) if (printed_pages.empty())
return false; return false;
PdfMetafileSkia metafile(print_params.printed_doc_type, PdfMetafileSkia metafile(print_params.printed_doc_type);
print_params.document_cookie);
CHECK(metafile.Init()); CHECK(metafile.Init());
PrintHostMsg_DidPrintDocument_Params page_params; PrintHostMsg_DidPrintDocument_Params page_params;
...@@ -2031,7 +2028,6 @@ bool PrintRenderFrameHelper::CopyMetafileDataToReadOnlySharedMem( ...@@ -2031,7 +2028,6 @@ bool PrintRenderFrameHelper::CopyMetafileDataToReadOnlySharedMem(
&params->metafile_data_handle, nullptr, nullptr); &params->metafile_data_handle, nullptr, nullptr);
DCHECK_EQ(MOJO_RESULT_OK, result); DCHECK_EQ(MOJO_RESULT_OK, result);
params->data_size = metafile.GetDataSize(); params->data_size = metafile.GetDataSize();
params->subframe_content_info = metafile.GetSubframeContentInfo();
return true; return true;
} }
...@@ -2199,8 +2195,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() { ...@@ -2199,8 +2195,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() {
bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument( bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame, std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages, const std::vector<int>& pages,
SkiaDocumentType doc_type, SkiaDocumentType doc_type) {
int document_cookie) {
DCHECK_EQ(INITIALIZED, state_); DCHECK_EQ(INITIALIZED, state_);
state_ = RENDERING; state_ = RENDERING;
...@@ -2215,7 +2210,7 @@ bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument( ...@@ -2215,7 +2210,7 @@ bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
return false; return false;
} }
metafile_ = std::make_unique<PdfMetafileSkia>(doc_type, document_cookie); metafile_ = std::make_unique<PdfMetafileSkia>(doc_type);
CHECK(metafile_->Init()); CHECK(metafile_->Init());
current_page_index_ = 0; current_page_index_ = 0;
......
...@@ -409,8 +409,7 @@ class PrintRenderFrameHelper ...@@ -409,8 +409,7 @@ class PrintRenderFrameHelper
bool CreatePreviewDocument( bool CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame, std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages, const std::vector<int>& pages,
SkiaDocumentType doc_type, SkiaDocumentType doc_type);
int document_cookie);
// Called after a page gets rendered. |page_time| is how long the // Called after a page gets rendered. |page_time| is how long the
// rendering took. // rendering took.
......
...@@ -53,8 +53,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame, ...@@ -53,8 +53,7 @@ bool PrintRenderFrameHelper::PrintPagesNative(blink::WebLocalFrame* frame,
if (printed_pages.empty()) if (printed_pages.empty())
return false; return false;
PdfMetafileSkia metafile(print_params.printed_doc_type, PdfMetafileSkia metafile(print_params.printed_doc_type);
print_params.document_cookie);
CHECK(metafile.Init()); CHECK(metafile.Init());
for (int page_number : printed_pages) { for (int page_number : printed_pages) {
......
...@@ -179,7 +179,8 @@ mojom::PdfCompositor::Status PdfCompositorImpl::CompositeToPdf( ...@@ -179,7 +179,8 @@ mojom::PdfCompositor::Status PdfCompositorImpl::CompositeToPdf(
} }
std::vector<SkDocumentPage> pages(page_count); std::vector<SkDocumentPage> pages(page_count);
SkDeserialProcs procs = DeserializationProcs(&subframes); // TODO(weili): Change the default functions to actual implementation.
SkDeserialProcs procs;
if (!SkMultiPictureDocumentRead(&stream, pages.data(), page_count, &procs)) { if (!SkMultiPictureDocumentRead(&stream, pages.data(), page_count, &procs)) {
DLOG(ERROR) << "CompositeToPdf: Page reading failed."; DLOG(ERROR) << "CompositeToPdf: Page reading failed.";
return mojom::PdfCompositor::Status::CONTENT_FORMAT_ERROR; return mojom::PdfCompositor::Status::CONTENT_FORMAT_ERROR;
...@@ -210,7 +211,6 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) { ...@@ -210,7 +211,6 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) {
// The content of this frame should be available. // The content of this frame should be available.
auto iter = frame_info_map_.find(frame_guid); auto iter = frame_info_map_.find(frame_guid);
DCHECK(iter != frame_info_map_.end()); DCHECK(iter != frame_info_map_.end());
std::unique_ptr<FrameInfo>& frame_info = iter->second; std::unique_ptr<FrameInfo>& frame_info = iter->second;
frame_info->composited = true; frame_info->composited = true;
...@@ -221,7 +221,8 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) { ...@@ -221,7 +221,8 @@ sk_sp<SkPicture> PdfCompositorImpl::CompositeSubframe(uint64_t frame_guid) {
// Composite the entire frame. // Composite the entire frame.
SkMemoryStream stream(iter->second->serialized_content->memory(), SkMemoryStream stream(iter->second->serialized_content->memory(),
iter->second->serialized_content->mapped_size()); iter->second->serialized_content->mapped_size());
SkDeserialProcs procs = DeserializationProcs(&subframes); // TODO(weili): Change the default functions to actual implementation.
SkDeserialProcs procs;
iter->second->content = SkPicture::MakeFromStream(&stream, &procs); iter->second->content = SkPicture::MakeFromStream(&stream, &procs);
return iter->second->content; return iter->second->content;
} }
......
...@@ -213,7 +213,7 @@ void MockPrinter::PrintPage( ...@@ -213,7 +213,7 @@ void MockPrinter::PrintPage(
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
printing::PdfMetafileCg metafile; printing::PdfMetafileCg metafile;
#else #else
printing::PdfMetafileSkia metafile; printing::PdfMetafileSkia metafile(printing::SkiaDocumentType::PDF);
#endif #endif
metafile.InitFromData(metafile_data.memory(), content.data_size); metafile.InitFromData(metafile_data.memory(), content.data_size);
printing::Image image(metafile); printing::Image image(metafile);
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "content/renderer/render_widget.h" #include "content/renderer/render_widget.h"
#include "content/renderer/resource_timing_info_conversions.h" #include "content/renderer/resource_timing_info_conversions.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "printing/features/features.h"
#include "third_party/WebKit/public/common/feature_policy/feature_policy.h" #include "third_party/WebKit/public/common/feature_policy/feature_policy.h"
#include "third_party/WebKit/public/common/frame/frame_policy.h" #include "third_party/WebKit/public/common/frame/frame_policy.h"
#include "third_party/WebKit/public/platform/URLConversion.h" #include "third_party/WebKit/public/platform/URLConversion.h"
...@@ -51,13 +50,6 @@ ...@@ -51,13 +50,6 @@
#include "content/renderer/mus/renderer_window_tree_client.h" #include "content/renderer/mus/renderer_window_tree_client.h"
#endif #endif
#if BUILDFLAG(ENABLE_PRINTING)
// nogncheck because dependency on //printing is conditional upon
// enable_basic_printing or enable_print_preview flags.
#include "printing/metafile_skia_wrapper.h" // nogncheck
#include "printing/pdf_metafile_skia.h" // nogncheck
#endif
namespace content { namespace content {
namespace { namespace {
...@@ -804,25 +796,4 @@ SkBitmap* RenderFrameProxy::GetSadPageBitmap() { ...@@ -804,25 +796,4 @@ SkBitmap* RenderFrameProxy::GetSadPageBitmap() {
return GetContentClient()->renderer()->GetSadWebViewBitmap(); return GetContentClient()->renderer()->GetSadWebViewBitmap();
} }
uint32_t RenderFrameProxy::Print(const blink::WebRect& rect,
blink::WebCanvas* canvas) {
#if BUILDFLAG(ENABLE_PRINTING)
printing::PdfMetafileSkia* metafile =
printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas);
DCHECK(metafile);
// Create a place holder content for the remote frame so it can be replaced
// with actual content later.
uint32_t content_id =
metafile->CreateContentForRemoteFrame(rect, routing_id_);
// Inform browser to print the remote subframe.
Send(new FrameHostMsg_PrintCrossProcessSubframe(
routing_id_, rect, metafile->GetDocumentCookie()));
return content_id;
#else
return 0;
#endif
}
} // namespace content } // namespace content
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "ipc/ipc_listener.h" #include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/common/feature_policy/feature_policy.h" #include "third_party/WebKit/public/common/feature_policy/feature_policy.h"
#include "third_party/WebKit/public/platform/WebCanvas.h"
#include "third_party/WebKit/public/platform/WebFocusType.h" #include "third_party/WebKit/public/platform/WebFocusType.h"
#include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
#include "third_party/WebKit/public/web/WebRemoteFrame.h" #include "third_party/WebKit/public/web/WebRemoteFrame.h"
...@@ -194,7 +193,6 @@ class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener, ...@@ -194,7 +193,6 @@ class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
blink::WebLocalFrame* source) override; blink::WebLocalFrame* source) override;
void FrameFocused() override; void FrameFocused() override;
base::UnguessableToken GetDevToolsFrameToken() override; base::UnguessableToken GetDevToolsFrameToken() override;
uint32_t Print(const blink::WebRect& rect, blink::WebCanvas* canvas) override;
// IPC handlers // IPC handlers
void OnDidStartLoading(); void OnDidStartLoading();
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#include "printing/common/pdf_metafile_utils.h" #include "printing/common/pdf_metafile_utils.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkTime.h" #include "third_party/skia/include/core/SkTime.h"
namespace { namespace {
...@@ -27,15 +24,6 @@ SkTime::DateTime TimeToSkTime(base::Time time) { ...@@ -27,15 +24,6 @@ SkTime::DateTime TimeToSkTime(base::Time time) {
return skdate; return skdate;
} }
sk_sp<SkPicture> GetEmptyPicture() {
SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(100, 100);
// Add some ops whose net effects equal to a noop.
canvas->save();
canvas->restore();
return rec.finishRecordingAsPicture();
}
} // namespace } // namespace
namespace printing { namespace printing {
...@@ -54,50 +42,4 @@ sk_sp<SkDocument> MakePdfDocument(const std::string& creator, ...@@ -54,50 +42,4 @@ sk_sp<SkDocument> MakePdfDocument(const std::string& creator,
return SkDocument::MakePDF(stream, metadata); return SkDocument::MakePDF(stream, metadata);
} }
sk_sp<SkData> SerializeOopPicture(SkPicture* pic, void* ctx) {
const ContentToProxyIdMap* context =
reinterpret_cast<const ContentToProxyIdMap*>(ctx);
uint32_t pic_id = pic->uniqueID();
auto iter = context->find(pic_id);
if (iter == context->end())
return nullptr;
return SkData::MakeWithCopy(&pic_id, sizeof(pic_id));
}
sk_sp<SkPicture> DeserializeOopPicture(const void* data,
size_t length,
void* ctx) {
uint32_t pic_id;
if (length < sizeof(pic_id)) {
NOTREACHED(); // Should not happen if the content is as written.
return GetEmptyPicture();
}
memcpy(&pic_id, data, sizeof(pic_id));
auto* context = reinterpret_cast<DeserializationContext*>(ctx);
auto iter = context->find(pic_id);
if (iter == context->end()) {
// When we don't have the out-of-process picture available, we return
// an empty picture. Returning a nullptr will cause the deserialization
// crash.
return GetEmptyPicture();
}
return iter->second;
}
SkSerialProcs SerializationProcs(SerializationContext* ctx) {
SkSerialProcs procs;
procs.fPictureProc = SerializeOopPicture;
procs.fPictureCtx = ctx;
return procs;
}
SkDeserialProcs DeserializationProcs(DeserializationContext* ctx) {
SkDeserialProcs procs;
procs.fPictureProc = DeserializeOopPicture;
procs.fPictureCtx = ctx;
return procs;
}
} // namespace printing } // namespace printing
...@@ -8,11 +8,9 @@ ...@@ -8,11 +8,9 @@
#include <map> #include <map>
#include <string> #include <string>
#include "base/containers/flat_map.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkDocument.h" #include "third_party/skia/include/core/SkDocument.h"
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkStream.h"
namespace printing { namespace printing {
...@@ -26,20 +24,9 @@ enum class SkiaDocumentType { ...@@ -26,20 +24,9 @@ enum class SkiaDocumentType {
MAX = MSKP MAX = MSKP
}; };
// Stores the mapping between a content's unique id and its actual content.
using DeserializationContext = base::flat_map<uint32_t, sk_sp<SkPicture>>;
// Stores the mapping between content's unique id and its corresponding frame
// proxy id.
using SerializationContext = ContentToProxyIdMap;
sk_sp<SkDocument> MakePdfDocument(const std::string& creator, sk_sp<SkDocument> MakePdfDocument(const std::string& creator,
SkWStream* stream); SkWStream* stream);
SkSerialProcs SerializationProcs(SerializationContext* ctx);
SkDeserialProcs DeserializationProcs(DeserializationContext* ctx);
} // namespace printing } // namespace printing
#endif // PRINTING_COMMON_PDF_METAFILE_UTILS_H_ #endif // PRINTING_COMMON_PDF_METAFILE_UTILS_H_
...@@ -9,17 +9,12 @@ ...@@ -9,17 +9,12 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/stl_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "cc/paint/paint_record.h" #include "cc/paint/paint_record.h"
#include "cc/paint/paint_recorder.h" #include "cc/paint/paint_recorder.h"
#include "cc/paint/skia_paint_canvas.h" #include "cc/paint/skia_paint_canvas.h"
#include "printing/print_settings.h" #include "printing/print_settings.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSerialProcs.h" #include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkStream.h"
// Note that headers in third_party/skia/src are fragile. This is // Note that headers in third_party/skia/src are fragile. This is
...@@ -67,16 +62,12 @@ struct Page { ...@@ -67,16 +62,12 @@ struct Page {
}; };
// TODO(weili): Remove pdf from struct name and field names since it is used for // 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 // other formats as well.
// conform with our style guide.
struct PdfMetafileSkiaData { struct PdfMetafileSkiaData {
cc::PaintRecorder recorder_; // Current recording cc::PaintRecorder recorder_; // Current recording
std::vector<Page> pages_; std::vector<Page> pages_;
std::unique_ptr<SkStreamAsset> pdf_data_; std::unique_ptr<SkStreamAsset> pdf_data_;
ContentToProxyIdMap subframe_content_info_;
std::map<uint32_t, sk_sp<SkPicture>> subframe_pics_;
int document_cookie_ = 0;
// The scale factor is used because Blink occasionally calls // The scale factor is used because Blink occasionally calls
// PaintCanvas::getTotalMatrix() even though the total matrix is not as // PaintCanvas::getTotalMatrix() even though the total matrix is not as
...@@ -90,15 +81,9 @@ struct PdfMetafileSkiaData { ...@@ -90,15 +81,9 @@ struct PdfMetafileSkiaData {
#endif #endif
}; };
PdfMetafileSkia::PdfMetafileSkia() PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type)
: data_(std::make_unique<PdfMetafileSkiaData>()) {
data_->type_ = SkiaDocumentType::PDF;
}
PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type, int document_cookie)
: data_(std::make_unique<PdfMetafileSkiaData>()) { : data_(std::make_unique<PdfMetafileSkiaData>()) {
data_->type_ = type; data_->type_ = type;
data_->document_cookie_ = document_cookie;
} }
PdfMetafileSkia::~PdfMetafileSkia() = default; PdfMetafileSkia::~PdfMetafileSkia() = default;
...@@ -181,27 +166,19 @@ bool PdfMetafileSkia::FinishDocument() { ...@@ -181,27 +166,19 @@ bool PdfMetafileSkia::FinishDocument() {
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;
sk_sp<SkDocument> doc; sk_sp<SkDocument> doc;
cc::PlaybackParams::CustomDataRasterCallback custom_callback;
switch (data_->type_) { switch (data_->type_) {
case SkiaDocumentType::PDF: case SkiaDocumentType::PDF:
doc = MakePdfDocument(printing::GetAgent(), &stream); doc = MakePdfDocument(printing::GetAgent(), &stream);
break; break;
case SkiaDocumentType::MSKP: case SkiaDocumentType::MSKP:
SkSerialProcs procs = SerializationProcs(&data_->subframe_content_info_); doc = SkMakeMultiPictureDocument(&stream);
doc = SkMakeMultiPictureDocument(&stream, &procs);
// 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));
break; break;
} }
for (const Page& page : data_->pages_) { for (const Page& page : data_->pages_) {
cc::SkiaPaintCanvas canvas( cc::SkiaPaintCanvas canvas(
doc->beginPage(page.size_.width(), page.size_.height())); doc->beginPage(page.size_.width(), page.size_.height()));
canvas.drawPicture(page.content_, custom_callback); canvas.drawPicture(page.content_);
doc->endPage(); doc->endPage();
} }
doc->close(); doc->close();
...@@ -221,7 +198,7 @@ void PdfMetafileSkia::FinishFrameContent() { ...@@ -221,7 +198,7 @@ void PdfMetafileSkia::FinishFrameContent() {
SkDynamicMemoryWStream stream; SkDynamicMemoryWStream stream;
sk_sp<SkPicture> pic = ToSkPicture(data_->pages_[0].content_, sk_sp<SkPicture> pic = ToSkPicture(data_->pages_[0].content_,
SkRect::MakeSize(data_->pages_[0].size_)); SkRect::MakeSize(data_->pages_[0].size_));
SkSerialProcs procs = SerializationProcs(&data_->subframe_content_info_); SkSerialProcs procs;
pic->serialize(&stream, &procs); pic->serialize(&stream, &procs);
data_->pdf_data_ = stream.detachAsStream(); data_->pdf_data_ = stream.detachAsStream();
} }
...@@ -323,8 +300,7 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage( ...@@ -323,8 +300,7 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
SkiaDocumentType type) { SkiaDocumentType type) {
// If we only ever need the metafile for the last page, should we // If we only ever need the metafile for the last page, should we
// only keep a handle on one PaintRecord? // only keep a handle on one PaintRecord?
auto metafile = auto metafile = std::make_unique<PdfMetafileSkia>(type);
std::make_unique<PdfMetafileSkia>(type, data_->document_cookie_);
if (data_->pages_.size() == 0) if (data_->pages_.size() == 0)
return metafile; return metafile;
...@@ -332,8 +308,6 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage( ...@@ -332,8 +308,6 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
return metafile; return metafile;
metafile->data_->pages_.push_back(data_->pages_.back()); metafile->data_->pages_.push_back(data_->pages_.back());
metafile->data_->subframe_content_info_ = data_->subframe_content_info_;
metafile->data_->subframe_pics_ = data_->subframe_pics_;
if (!metafile->FinishDocument()) // Generate PDF. if (!metafile->FinishDocument()) // Generate PDF.
metafile.reset(); metafile.reset();
...@@ -341,44 +315,4 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage( ...@@ -341,44 +315,4 @@ std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
return metafile; return metafile;
} }
uint32_t PdfMetafileSkia::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()));
// Store the map between content id and the proxy id.
uint32_t content_id = pic->uniqueID();
DCHECK(!base::ContainsKey(data_->subframe_content_info_, content_id));
data_->subframe_content_info_[content_id] = render_proxy_id;
// Store the picture content.
data_->subframe_pics_[content_id] = pic;
return content_id;
}
int PdfMetafileSkia::GetDocumentCookie() const {
return data_->document_cookie_;
}
const ContentToProxyIdMap& PdfMetafileSkia::GetSubframeContentInfo() const {
return data_->subframe_content_info_;
}
void PdfMetafileSkia::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;
auto it = data_->subframe_pics_.find(content_id);
DCHECK(it != data_->subframe_pics_.end());
// Found the picture, draw it on canvas.
sk_sp<SkPicture> pic = it->second;
SkRect rect = pic->cullRect();
SkMatrix matrix = SkMatrix::MakeTrans(rect.x(), rect.y());
canvas->drawPicture(it->second, &matrix, nullptr);
}
} // namespace printing } // namespace printing
...@@ -28,11 +28,7 @@ struct PdfMetafileSkiaData; ...@@ -28,11 +28,7 @@ struct PdfMetafileSkiaData;
// TODO(thestig): Rename to MetafileSkia. // TODO(thestig): Rename to MetafileSkia.
class PRINTING_EXPORT PdfMetafileSkia : public Metafile { class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
public: public:
// Default constructor, for SkiaDocumentType::PDF type only. explicit PdfMetafileSkia(SkiaDocumentType type);
// 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; ~PdfMetafileSkia() override;
// Metafile methods. // Metafile methods.
...@@ -85,21 +81,7 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile { ...@@ -85,21 +81,7 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
const gfx::Rect& content_area, const gfx::Rect& content_area,
const float& scale_factor); const float& scale_factor);
// This is used for painting content of out-of-process subframes.
// For such a subframe, since the content is in another process, we create a
// place holder picture now, and replace it with actual content by pdf
// compositor service later.
uint32_t CreateContentForRemoteFrame(const gfx::Rect& rect,
int render_proxy_id);
int GetDocumentCookie() const;
const ContentToProxyIdMap& GetSubframeContentInfo() const;
private: private:
// Callback function used during page content drawing to replace a custom
// data holder with corresponding place holder SkPicture.
void CustomDataToSkPictureCallback(SkCanvas* canvas, uint32_t content_id);
std::unique_ptr<PdfMetafileSkiaData> data_; std::unique_ptr<PdfMetafileSkiaData> data_;
DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia); DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "core/frame/FrameClient.h" #include "core/frame/FrameClient.h"
#include "core/frame/FrameTypes.h" #include "core/frame/FrameTypes.h"
#include "core/loader/FrameLoaderTypes.h" #include "core/loader/FrameLoaderTypes.h"
#include "public/platform/WebCanvas.h"
#include "public/platform/WebFocusType.h" #include "public/platform/WebFocusType.h"
namespace blink { namespace blink {
...@@ -51,8 +50,6 @@ class RemoteFrameClient : public FrameClient { ...@@ -51,8 +50,6 @@ class RemoteFrameClient : public FrameClient {
virtual void UpdateRenderThrottlingStatus(bool isThrottled, virtual void UpdateRenderThrottlingStatus(bool isThrottled,
bool subtreeThrottled) = 0; bool subtreeThrottled) = 0;
virtual uint32_t Print(const IntRect&, WebCanvas*) const = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -178,9 +178,4 @@ void RemoteFrameClientImpl::UpdateRenderThrottlingStatus( ...@@ -178,9 +178,4 @@ void RemoteFrameClientImpl::UpdateRenderThrottlingStatus(
subtree_throttled); subtree_throttled);
} }
uint32_t RemoteFrameClientImpl::Print(const IntRect& rect,
WebCanvas* canvas) const {
return web_frame_->Client()->Print(rect, canvas);
}
} // namespace blink } // namespace blink
...@@ -44,7 +44,6 @@ class RemoteFrameClientImpl final : public RemoteFrameClient { ...@@ -44,7 +44,6 @@ class RemoteFrameClientImpl final : public RemoteFrameClient {
void SetIsInert(bool) override; void SetIsInert(bool) override;
void UpdateRenderThrottlingStatus(bool is_throttled, void UpdateRenderThrottlingStatus(bool is_throttled,
bool subtree_throttled) override; bool subtree_throttled) override;
uint32_t Print(const IntRect&, WebCanvas*) const override;
WebRemoteFrameImpl* GetWebFrame() const { return web_frame_; } WebRemoteFrameImpl* GetWebFrame() const { return web_frame_; }
......
...@@ -13,10 +13,6 @@ ...@@ -13,10 +13,6 @@
#include "core/intersection_observer/IntersectionObserverEntry.h" #include "core/intersection_observer/IntersectionObserverEntry.h"
#include "core/layout/LayoutEmbeddedContent.h" #include "core/layout/LayoutEmbeddedContent.h"
#include "core/layout/LayoutView.h" #include "core/layout/LayoutView.h"
#include "platform/geometry/IntRect.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/paint/CullRect.h"
#include "platform/graphics/paint/DrawingRecorder.h"
namespace blink { namespace blink {
...@@ -141,26 +137,6 @@ void RemoteFrameView::FrameRectsChanged() { ...@@ -141,26 +137,6 @@ void RemoteFrameView::FrameRectsChanged() {
remote_frame_->Client()->FrameRectsChanged(frame_rect_, screen_space_rect); remote_frame_->Client()->FrameRectsChanged(frame_rect_, screen_space_rect);
} }
void RemoteFrameView::Paint(GraphicsContext& context,
const GlobalPaintFlags flags,
const CullRect& rect) const {
// Painting remote frames is only for printing.
if (!context.Printing())
return;
if (!rect.IntersectsCullRect(FrameRect()))
return;
DrawingRecorder recorder(context, *GetFrame().OwnerLayoutObject(),
DisplayItem::kDocumentBackground);
DCHECK(context.Canvas());
// Inform the remote frame to print.
uint32_t content_id = Print(FrameRect(), context.Canvas());
// Record the place holder id on canvas.
context.Canvas()->recordCustomData(content_id);
}
void RemoteFrameView::UpdateGeometry() { void RemoteFrameView::UpdateGeometry() {
if (LayoutEmbeddedContent* layout = remote_frame_->OwnerLayoutObject()) if (LayoutEmbeddedContent* layout = remote_frame_->OwnerLayoutObject())
layout->UpdateGeometry(*this); layout->UpdateGeometry(*this);
...@@ -265,10 +241,6 @@ bool RemoteFrameView::HasIntrinsicSizingInfo() const { ...@@ -265,10 +241,6 @@ bool RemoteFrameView::HasIntrinsicSizingInfo() const {
return has_intrinsic_sizing_info_; return has_intrinsic_sizing_info_;
} }
uint32_t RemoteFrameView::Print(const IntRect& rect, WebCanvas* canvas) const {
return remote_frame_->Client()->Print(rect, canvas);
}
void RemoteFrameView::Trace(blink::Visitor* visitor) { void RemoteFrameView::Trace(blink::Visitor* visitor) {
visitor->Trace(remote_frame_); visitor->Trace(remote_frame_);
visitor->Trace(visibility_observer_); visitor->Trace(visibility_observer_);
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "core/frame/LocalFrameView.h" #include "core/frame/LocalFrameView.h"
#include "platform/geometry/IntRect.h" #include "platform/geometry/IntRect.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/WebCanvas.h"
namespace blink { namespace blink {
...@@ -45,7 +44,7 @@ class RemoteFrameView final : public GarbageCollectedFinalized<RemoteFrameView>, ...@@ -45,7 +44,7 @@ class RemoteFrameView final : public GarbageCollectedFinalized<RemoteFrameView>,
const IntRect& FrameRect() const override { return frame_rect_; } const IntRect& FrameRect() const override { return frame_rect_; }
void Paint(GraphicsContext&, void Paint(GraphicsContext&,
const GlobalPaintFlags, const GlobalPaintFlags,
const CullRect&) const override; const CullRect&) const override {}
void UpdateGeometry() override; void UpdateGeometry() override;
void Hide() override; void Hide() override;
void Show() override; void Show() override;
...@@ -59,8 +58,6 @@ class RemoteFrameView final : public GarbageCollectedFinalized<RemoteFrameView>, ...@@ -59,8 +58,6 @@ class RemoteFrameView final : public GarbageCollectedFinalized<RemoteFrameView>,
void SetIntrinsicSizeInfo(const IntrinsicSizingInfo& size_info); void SetIntrinsicSizeInfo(const IntrinsicSizingInfo& size_info);
bool HasIntrinsicSizingInfo() const override; bool HasIntrinsicSizingInfo() const override;
uint32_t Print(const IntRect&, WebCanvas*) const;
virtual void Trace(blink::Visitor*); virtual void Trace(blink::Visitor*);
private: private:
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "platform/loader/fetch/ResourceError.h" #include "platform/loader/fetch/ResourceError.h"
#include "platform/wtf/Forward.h" #include "platform/wtf/Forward.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "public/platform/WebCanvas.h"
#include "public/platform/WebFocusType.h" #include "public/platform/WebFocusType.h"
#include "public/platform/WebMenuSourceType.h" #include "public/platform/WebMenuSourceType.h"
#include "public/platform/WebScreenInfo.h" #include "public/platform/WebScreenInfo.h"
...@@ -429,9 +428,6 @@ class CORE_EXPORT EmptyRemoteFrameClient : public RemoteFrameClient { ...@@ -429,9 +428,6 @@ class CORE_EXPORT EmptyRemoteFrameClient : public RemoteFrameClient {
void SetIsInert(bool) override {} void SetIsInert(bool) override {}
void UpdateRenderThrottlingStatus(bool is_throttled, void UpdateRenderThrottlingStatus(bool is_throttled,
bool subtree_throttled) override {} bool subtree_throttled) override {}
uint32_t Print(const IntRect& rect, WebCanvas* canvas) const override {
return 0;
}
// FrameClient implementation. // FrameClient implementation.
bool InShadowTree() const override { return false; } bool InShadowTree() const override { return false; }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef WebRemoteFrameClient_h #ifndef WebRemoteFrameClient_h
#define WebRemoteFrameClient_h #define WebRemoteFrameClient_h
#include "public/platform/WebCanvas.h"
#include "public/platform/WebFocusType.h" #include "public/platform/WebFocusType.h"
#include "public/platform/WebSecurityOrigin.h" #include "public/platform/WebSecurityOrigin.h"
#include "public/web/WebDOMMessageEvent.h" #include "public/web/WebDOMMessageEvent.h"
...@@ -70,13 +69,6 @@ class WebRemoteFrameClient { ...@@ -70,13 +69,6 @@ class WebRemoteFrameClient {
return base::UnguessableToken::Create(); return base::UnguessableToken::Create();
} }
// Print out this frame.
// |rect| is the rectangular area where this frame resides in its parent
// frame.
// |canvas| is the canvas we are printing on.
// Returns the id of the placeholder content.
virtual uint32_t Print(const WebRect& rect, WebCanvas* canvas) { return 0; }
protected: protected:
virtual ~WebRemoteFrameClient() = default; virtual ~WebRemoteFrameClient() = default;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment