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") {
deps = [
":platform_export",
"//base/allocator:buildflags",
"//components/paint_preview/common",
"//components/viz/client",
"//components/viz/common",
"//crypto",
......
......@@ -11,6 +11,7 @@ include_rules = [
"+base/barrier_closure.h",
"+base/callback_helpers.h",
"+cc",
"+components/paint_preview/common",
"+components/viz/client",
"+components/viz/common",
"+gpu/config",
......
......@@ -30,6 +30,7 @@
#include "base/optional.h"
#include "build/build_config.h"
#include "components/paint_preview/common/paint_preview_tracker.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/geometry/float_rect.h"
......@@ -89,12 +90,14 @@ class GraphicsContext::DarkModeFlags final {
GraphicsContext::GraphicsContext(PaintController& paint_controller,
DisabledMode disable_context_or_painting,
printing::MetafileSkia* metafile)
printing::MetafileSkia* metafile,
paint_preview::PaintPreviewTracker* tracker)
: canvas_(nullptr),
paint_controller_(paint_controller),
paint_state_stack_(),
paint_state_index_(0),
metafile_(metafile),
tracker_(tracker),
#if DCHECK_IS_ON()
layer_count_(0),
disable_destruction_checks_(false),
......@@ -1368,6 +1371,12 @@ void GraphicsContext::SetURLForRect(const KURL& link,
return;
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()));
canvas_->Annotate(cc::PaintCanvas::AnnotationType::URL, dest_rect,
std::move(url));
......@@ -1379,6 +1388,12 @@ void GraphicsContext::SetURLFragmentForRect(const String& dest_name,
return;
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()));
canvas_->Annotate(cc::PaintCanvas::AnnotationType::LINK_TO_DESTINATION, rect,
std::move(sk_dest_name));
......
......@@ -53,6 +53,10 @@ class SkPath;
class SkRRect;
struct SkRect;
namespace paint_preview {
class PaintPreviewTracker;
} // namespace paint_preview
namespace blink {
class FloatRect;
......@@ -74,7 +78,8 @@ class PLATFORM_EXPORT GraphicsContext {
explicit GraphicsContext(PaintController&,
DisabledMode = kNothingDisabled,
printing::MetafileSkia* = nullptr);
printing::MetafileSkia* = nullptr,
paint_preview::PaintPreviewTracker* = nullptr);
~GraphicsContext();
......@@ -161,6 +166,19 @@ class PLATFORM_EXPORT GraphicsContext {
bool Printing() const { return 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;
void SetColorFilter(ColorFilter);
// ---------- End state management methods -----------------
......@@ -498,6 +516,7 @@ class PLATFORM_EXPORT GraphicsContext {
PaintRecorder paint_recorder_;
printing::MetafileSkia* metafile_;
paint_preview::PaintPreviewTracker* tracker_;
#if DCHECK_IS_ON()
int layer_count_;
......@@ -512,6 +531,7 @@ class PLATFORM_EXPORT GraphicsContext {
DarkModeFilter dark_mode_filter_;
unsigned printing_ : 1;
unsigned is_painting_preview_ : 1;
unsigned in_drawing_recorder_ : 1;
DISALLOW_COPY_AND_ASSIGN(GraphicsContext);
......
......@@ -10,9 +10,11 @@
namespace blink {
PaintRecordBuilder::PaintRecordBuilder(printing::MetafileSkia* metafile,
GraphicsContext* containing_context,
PaintController* paint_controller)
PaintRecordBuilder::PaintRecordBuilder(
printing::MetafileSkia* metafile,
GraphicsContext* containing_context,
PaintController* paint_controller,
paint_preview::PaintPreviewTracker* tracker)
: paint_controller_(nullptr) {
GraphicsContext::DisabledMode disabled_mode =
GraphicsContext::kNothingDisabled;
......@@ -30,12 +32,13 @@ PaintRecordBuilder::PaintRecordBuilder(printing::MetafileSkia* metafile,
paint_controller_->UpdateCurrentPaintChunkProperties(
base::nullopt, PropertyTreeState::Root());
context_ = std::make_unique<GraphicsContext>(*paint_controller_,
disabled_mode, metafile);
context_ = std::make_unique<GraphicsContext>(
*paint_controller_, disabled_mode, metafile, tracker);
if (containing_context) {
context_->SetDarkMode(containing_context->dark_mode_settings());
context_->SetDeviceScaleFactor(containing_context->DeviceScaleFactor());
context_->SetPrinting(containing_context->Printing());
context_->SetIsPaintingPreview(containing_context->IsPaintingPreview());
}
}
......
......@@ -19,12 +19,15 @@ namespace cc {
class PaintCanvas;
}
namespace paint_preview {
class PaintPreviewTracker;
}
namespace blink {
class GraphicsContext;
class PaintController;
class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient {
public:
// Constructs a new builder for the resulting paint record. If |metadata|
// is specified, that metadata is propagated to the builder's internal canvas.
......@@ -39,7 +42,8 @@ class PLATFORM_EXPORT PaintRecordBuilder final : public DisplayItemClient {
// CompositeAfterPaint.
PaintRecordBuilder(printing::MetafileSkia* metafile = nullptr,
GraphicsContext* containing_context = nullptr,
PaintController* = nullptr);
PaintController* = nullptr,
paint_preview::PaintPreviewTracker* tracker = nullptr);
~PaintRecordBuilder() override;
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