Commit 2c483e93 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Inject PaintPreviewTracker

Adds the ability to inject paint_preview::PaintPreviewTracker into
blink::GraphicsContext to act similarly to printing::MetafileSkia.
This class will track various metadata about the Paint Preview
capture process.

Design Doc: go/fdt-design (internal)
Part of Landing: crrev/1786583

Bug: 1008885
Change-Id: Iba2819491bee7b284de62a1bf888aa9486c788cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829277
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Auto-Submit: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703720}
parent 2a7dce7c
...@@ -1451,6 +1451,7 @@ jumbo_component("platform") { ...@@ -1451,6 +1451,7 @@ jumbo_component("platform") {
deps = [ deps = [
":platform_export", ":platform_export",
"//base/allocator:buildflags", "//base/allocator:buildflags",
"//components/paint_preview/common",
"//components/viz/client", "//components/viz/client",
"//components/viz/common", "//components/viz/common",
"//crypto", "//crypto",
......
...@@ -11,6 +11,7 @@ include_rules = [ ...@@ -11,6 +11,7 @@ include_rules = [
"+base/barrier_closure.h", "+base/barrier_closure.h",
"+base/callback_helpers.h", "+base/callback_helpers.h",
"+cc", "+cc",
"+components/paint_preview/common",
"+components/viz/client", "+components/viz/client",
"+components/viz/common", "+components/viz/common",
"+gpu/config", "+gpu/config",
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/paint_preview/common/paint_preview_tracker.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/blink/renderer/platform/fonts/text_run_paint_info.h" #include "third_party/blink/renderer/platform/fonts/text_run_paint_info.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
...@@ -89,12 +90,14 @@ class GraphicsContext::DarkModeFlags final { ...@@ -89,12 +90,14 @@ class GraphicsContext::DarkModeFlags final {
GraphicsContext::GraphicsContext(PaintController& paint_controller, GraphicsContext::GraphicsContext(PaintController& paint_controller,
DisabledMode disable_context_or_painting, DisabledMode disable_context_or_painting,
printing::MetafileSkia* metafile) printing::MetafileSkia* metafile,
paint_preview::PaintPreviewTracker* tracker)
: canvas_(nullptr), : canvas_(nullptr),
paint_controller_(paint_controller), paint_controller_(paint_controller),
paint_state_stack_(), paint_state_stack_(),
paint_state_index_(0), paint_state_index_(0),
metafile_(metafile), metafile_(metafile),
tracker_(tracker),
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
layer_count_(0), layer_count_(0),
disable_destruction_checks_(false), disable_destruction_checks_(false),
...@@ -1368,6 +1371,12 @@ void GraphicsContext::SetURLForRect(const KURL& link, ...@@ -1368,6 +1371,12 @@ void GraphicsContext::SetURLForRect(const KURL& link,
return; return;
DCHECK(canvas_); DCHECK(canvas_);
// Intercept URL rects when painting previews.
if (IsPaintingPreview() && tracker_) {
tracker_->AnnotateLink(link.GetString().Utf8(), dest_rect);
return;
}
sk_sp<SkData> url(SkData::MakeWithCString(link.GetString().Utf8().c_str())); sk_sp<SkData> url(SkData::MakeWithCString(link.GetString().Utf8().c_str()));
canvas_->Annotate(cc::PaintCanvas::AnnotationType::URL, dest_rect, canvas_->Annotate(cc::PaintCanvas::AnnotationType::URL, dest_rect,
std::move(url)); std::move(url));
...@@ -1379,6 +1388,12 @@ void GraphicsContext::SetURLFragmentForRect(const String& dest_name, ...@@ -1379,6 +1388,12 @@ void GraphicsContext::SetURLFragmentForRect(const String& dest_name,
return; return;
DCHECK(canvas_); DCHECK(canvas_);
// Intercept URL rects when painting previews.
if (IsPaintingPreview() && tracker_) {
tracker_->AnnotateLink(dest_name.Utf8(), rect);
return;
}
sk_sp<SkData> sk_dest_name(SkData::MakeWithCString(dest_name.Utf8().c_str())); sk_sp<SkData> sk_dest_name(SkData::MakeWithCString(dest_name.Utf8().c_str()));
canvas_->Annotate(cc::PaintCanvas::AnnotationType::LINK_TO_DESTINATION, rect, canvas_->Annotate(cc::PaintCanvas::AnnotationType::LINK_TO_DESTINATION, rect,
std::move(sk_dest_name)); std::move(sk_dest_name));
......
...@@ -53,6 +53,10 @@ class SkPath; ...@@ -53,6 +53,10 @@ class SkPath;
class SkRRect; class SkRRect;
struct SkRect; struct SkRect;
namespace paint_preview {
class PaintPreviewTracker;
} // namespace paint_preview
namespace blink { namespace blink {
class FloatRect; class FloatRect;
...@@ -74,7 +78,8 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -74,7 +78,8 @@ class PLATFORM_EXPORT GraphicsContext {
explicit GraphicsContext(PaintController&, explicit GraphicsContext(PaintController&,
DisabledMode = kNothingDisabled, DisabledMode = kNothingDisabled,
printing::MetafileSkia* = nullptr); printing::MetafileSkia* = nullptr,
paint_preview::PaintPreviewTracker* = nullptr);
~GraphicsContext(); ~GraphicsContext();
...@@ -161,6 +166,19 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -161,6 +166,19 @@ class PLATFORM_EXPORT GraphicsContext {
bool Printing() const { return printing_; } bool Printing() const { return printing_; }
void SetPrinting(bool printing) { printing_ = printing; } void SetPrinting(bool printing) { printing_ = printing; }
// Returns if the context is saving a paint preview instead of displaying.
// In such cases, clipping should not occur.
bool IsPaintingPreview() const { return is_painting_preview_; }
void SetIsPaintingPreview(bool is_painting_preview) {
is_painting_preview_ = is_painting_preview;
}
// Returns if the context is printing or painting a preview. Many of the
// behaviors required for printing and paint previews are shared.
bool IsPrintingOrPaintingPreview() const {
return Printing() || IsPaintingPreview();
}
SkColorFilter* GetColorFilter() const; SkColorFilter* GetColorFilter() const;
void SetColorFilter(ColorFilter); void SetColorFilter(ColorFilter);
// ---------- End state management methods ----------------- // ---------- End state management methods -----------------
...@@ -498,6 +516,7 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -498,6 +516,7 @@ class PLATFORM_EXPORT GraphicsContext {
PaintRecorder paint_recorder_; PaintRecorder paint_recorder_;
printing::MetafileSkia* metafile_; printing::MetafileSkia* metafile_;
paint_preview::PaintPreviewTracker* tracker_;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
int layer_count_; int layer_count_;
...@@ -512,6 +531,7 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -512,6 +531,7 @@ class PLATFORM_EXPORT GraphicsContext {
DarkModeFilter dark_mode_filter_; DarkModeFilter dark_mode_filter_;
unsigned printing_ : 1; unsigned printing_ : 1;
unsigned is_painting_preview_ : 1;
unsigned in_drawing_recorder_ : 1; unsigned in_drawing_recorder_ : 1;
DISALLOW_COPY_AND_ASSIGN(GraphicsContext); DISALLOW_COPY_AND_ASSIGN(GraphicsContext);
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
namespace blink { namespace blink {
PaintRecordBuilder::PaintRecordBuilder(printing::MetafileSkia* metafile, PaintRecordBuilder::PaintRecordBuilder(
GraphicsContext* containing_context, printing::MetafileSkia* metafile,
PaintController* paint_controller) GraphicsContext* containing_context,
PaintController* paint_controller,
paint_preview::PaintPreviewTracker* tracker)
: paint_controller_(nullptr) { : paint_controller_(nullptr) {
GraphicsContext::DisabledMode disabled_mode = GraphicsContext::DisabledMode disabled_mode =
GraphicsContext::kNothingDisabled; GraphicsContext::kNothingDisabled;
...@@ -30,12 +32,13 @@ PaintRecordBuilder::PaintRecordBuilder(printing::MetafileSkia* metafile, ...@@ -30,12 +32,13 @@ PaintRecordBuilder::PaintRecordBuilder(printing::MetafileSkia* metafile,
paint_controller_->UpdateCurrentPaintChunkProperties( paint_controller_->UpdateCurrentPaintChunkProperties(
base::nullopt, PropertyTreeState::Root()); base::nullopt, PropertyTreeState::Root());
context_ = std::make_unique<GraphicsContext>(*paint_controller_, context_ = std::make_unique<GraphicsContext>(
disabled_mode, metafile); *paint_controller_, disabled_mode, metafile, tracker);
if (containing_context) { if (containing_context) {
context_->SetDarkMode(containing_context->dark_mode_settings()); context_->SetDarkMode(containing_context->dark_mode_settings());
context_->SetDeviceScaleFactor(containing_context->DeviceScaleFactor()); context_->SetDeviceScaleFactor(containing_context->DeviceScaleFactor());
context_->SetPrinting(containing_context->Printing()); context_->SetPrinting(containing_context->Printing());
context_->SetIsPaintingPreview(containing_context->IsPaintingPreview());
} }
} }
......
...@@ -19,12 +19,15 @@ namespace cc { ...@@ -19,12 +19,15 @@ namespace cc {
class PaintCanvas; class PaintCanvas;
} }
namespace paint_preview {
class PaintPreviewTracker;
}
namespace blink { namespace blink {
class GraphicsContext; class GraphicsContext;
class PaintController; class PaintController;
class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient { class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient {
public: public:
// Constructs a new builder for the resulting paint record. If |metadata| // Constructs a new builder for the resulting paint record. If |metadata|
// is specified, that metadata is propagated to the builder's internal canvas. // is specified, that metadata is propagated to the builder's internal canvas.
...@@ -39,7 +42,8 @@ class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient { ...@@ -39,7 +42,8 @@ class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient {
// CompositeAfterPaint. // CompositeAfterPaint.
PaintRecordBuilder(printing::MetafileSkia* metafile = nullptr, PaintRecordBuilder(printing::MetafileSkia* metafile = nullptr,
GraphicsContext* containing_context = nullptr, GraphicsContext* containing_context = nullptr,
PaintController* = nullptr); PaintController* = nullptr,
paint_preview::PaintPreviewTracker* tracker = nullptr);
~PaintRecordBuilder() override; ~PaintRecordBuilder() override;
GraphicsContext& Context() { return *context_; } GraphicsContext& Context() { return *context_; }
......
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