enable pictures to record drawSlug

This should fix many issues that Chrome is seeing. The problem is the
picture recorder had no idea about Slug, so the canvas super class
would try to use the device to draw. This hooks up the recorder
to capture drawSlug into the picture.

I tested this with a specialized gl sink in DM which I'm struggling
to check in. But, it was functional enough to show that this works.

Bug: chromium:1302036
Bug: chromium:1307279
Bug: chromium:1306329
Bug: chromium:1307446

Change-Id: I6a27bf43702400c80b2044433e7b00347f522763
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/525636
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-03-29 11:10:32 -04:00 committed by SkCQ
parent f5ae4c7e15
commit f54d418b01
6 changed files with 42 additions and 0 deletions

View File

@ -67,6 +67,7 @@ class SkTextBlob;
class SkVertices;
namespace skgpu { class Recorder; }
namespace SkRecords { class Draw; }
/** \class SkCanvas
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
@ -2402,6 +2403,7 @@ private:
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
friend class SkOverdrawCanvas;
friend class SkRasterHandleAllocator;
friend class SkRecords::Draw;
template <typename Key>
friend class SkTestCanvas;

View File

@ -3988,6 +3988,7 @@ generated_cc_atom(
"//include/core:SkPicture_hdr",
"//include/core:SkSurface_hdr",
"//include/private:SkTo_hdr",
"//include/private/chromium:GrSlug_hdr",
"//src/utils:SkPatchUtils_hdr",
],
)
@ -4014,6 +4015,7 @@ generated_cc_atom(
"//include/core:SkString_hdr",
"//include/core:SkTextBlob_hdr",
"//include/core:SkVertices_hdr",
"//include/private/chromium:GrSlug_hdr",
],
)

View File

@ -139,6 +139,12 @@ DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
DRAW(DrawRect, drawRect(r.rect, r.paint));
DRAW(DrawRegion, drawRegion(r.region, r.paint));
DRAW(DrawTextBlob, drawTextBlob(r.blob.get(), r.x, r.y, r.paint));
#if SK_SUPPORT_GPU
DRAW(DrawSlug, drawSlug(r.slug.get()));
#else
// Turn draw into a nop.
template <> void Draw::draw(const DrawSlug&) {}
#endif
DRAW(DrawAtlas, drawAtlas(r.atlas.get(), r.xforms, r.texs, r.colors, r.count, r.mode, r.sampling,
r.cull, r.paint));
DRAW(DrawVertices, drawVertices(r.vertices, r.bmode, r.paint));
@ -470,6 +476,17 @@ private:
return this->adjustAndMap(dst, &op.paint);
}
#if SK_SUPPORT_GPU
Bounds bounds(const DrawSlug& op) const {
SkRect dst = op.slug->sourceBounds();
return this->adjustAndMap(dst, &op.slug->paint());
}
#else
Bounds bounds(const DrawSlug& op) const {
return SkRect::MakeEmpty();
}
#endif
Bounds bounds(const DrawDrawable& op) const {
return this->adjustAndMap(op.worstCaseBounds, nullptr);
}

View File

@ -11,6 +11,7 @@
#include "include/core/SkPicture.h"
#include "include/core/SkSurface.h"
#include "include/private/SkTo.h"
#include "include/private/chromium/GrSlug.h"
#include "src/core/SkBigPicture.h"
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkGlyphRun.h"
@ -234,6 +235,12 @@ void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
this->append<SkRecords::DrawTextBlob>(paint, sk_ref_sp(blob), x, y);
}
#if SK_SUPPORT_GPU
void SkRecorder::onDrawSlug(const GrSlug* slug) {
this->append<SkRecords::DrawSlug>(sk_ref_sp(slug));
}
#endif
void SkRecorder::onDrawGlyphRunList(const SkGlyphRunList& glyphRunList, const SkPaint& paint) {
sk_sp<SkTextBlob> blob = sk_ref_sp(glyphRunList.blob());
if (glyphRunList.blob() == nullptr) {

View File

@ -73,6 +73,9 @@ public:
SkScalar x,
SkScalar y,
const SkPaint& paint) override;
#if SK_SUPPORT_GPU
void onDrawSlug(const GrSlug* slug) override;
#endif
void onDrawGlyphRunList(const SkGlyphRunList& glyphRunList, const SkPaint& paint) override;
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkBlendMode,

View File

@ -26,6 +26,10 @@
#include "include/core/SkVertices.h"
#include "src/core/SkDrawShadowInfo.h"
#if SK_SUPPORT_GPU
#include "include/private/chromium/GrSlug.h"
#endif
namespace SkRecords {
// A list of all the types of canvas calls we can record.
@ -74,6 +78,7 @@ namespace SkRecords {
M(DrawRect) \
M(DrawRegion) \
M(DrawTextBlob) \
M(DrawSlug) \
M(DrawAtlas) \
M(DrawVertices) \
M(DrawShadowRec) \
@ -293,6 +298,12 @@ RECORD(DrawTextBlob, kDraw_Tag|kHasText_Tag|kHasPaint_Tag,
sk_sp<const SkTextBlob> blob;
SkScalar x;
SkScalar y);
#if SK_SUPPORT_GPU
RECORD(DrawSlug, kDraw_Tag|kHasText_Tag,
sk_sp<const GrSlug> slug);
#else
RECORD(DrawSlug, 0)
#endif
RECORD(DrawPatch, kDraw_Tag|kHasPaint_Tag,
SkPaint paint;
PODArray<SkPoint> cubics;