introduce GrTextReferenceFrame
Introduce GrTextReferenceFrame and use it in TransformedMaskSubRun and TransformedMaskSubRunSlug. This will allow these to SubRuns to be combined in the future. In addition, move fAlloc to first field in Slug to avoid use after free problems. Change-Id: Ib4f791389cf9b3c2a0f2e0fd802eccdea4841d1f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/502301 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
7ae31fad84
commit
9cc63f805a
@ -12,6 +12,7 @@
|
||||
#include "include/core/SkRefCnt.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkMatrix;
|
||||
class SkPaint;
|
||||
class SkTextBlob;
|
||||
|
||||
@ -20,11 +21,18 @@ class SkTextBlob;
|
||||
// For Skia, add this to your args.gn file.
|
||||
// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"]
|
||||
|
||||
// Internal infrastructure for using SubRuns.
|
||||
class SK_API GrTextReferenceFrame : public SkRefCnt {
|
||||
public:
|
||||
~GrTextReferenceFrame() override;
|
||||
virtual const SkMatrix& initialPositionMatrix() const = 0;
|
||||
};
|
||||
|
||||
// GrSlug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be
|
||||
// manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then
|
||||
// the GrSlug will also transform with smaller glyphs using bi-linear interpolation to render. You
|
||||
// can think of a GrSlug as making a rubber stamp out of a SkTextBlob.
|
||||
class SK_API GrSlug : public SkRefCnt {
|
||||
class SK_API GrSlug : public GrTextReferenceFrame {
|
||||
public:
|
||||
~GrSlug() override;
|
||||
// Return nullptr if the blob would not draw. This is not because of clipping, but because of
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include "include/core/SkCanvas.h"
|
||||
|
||||
GrTextReferenceFrame::~GrTextReferenceFrame() = default;
|
||||
|
||||
GrSlug::~GrSlug() = default;
|
||||
sk_sp<GrSlug> GrSlug::ConvertBlob(
|
||||
SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint) {
|
||||
|
@ -1065,8 +1065,8 @@ class TransformedMaskSubRun final : public GrSubRun, public GrBlobSubRun, public
|
||||
public:
|
||||
using VertexData = TransformedMaskVertexFiller::PositionAndExtent;
|
||||
|
||||
TransformedMaskSubRun(GrMaskFormat format,
|
||||
GrTextBlob* blob,
|
||||
TransformedMaskSubRun(GrTextReferenceFrame* referenceFrame,
|
||||
GrMaskFormat format,
|
||||
SkScalar strikeToSourceScale,
|
||||
const SkRect& bounds,
|
||||
SkSpan<const VertexData> vertexData,
|
||||
@ -1119,7 +1119,7 @@ private:
|
||||
|
||||
const TransformedMaskVertexFiller fVertexFiller;
|
||||
|
||||
GrTextBlob* fBlob;
|
||||
GrTextReferenceFrame* const fReferenceFrame;
|
||||
|
||||
// The bounds in source space. The bounds are the joined rectangles of all the glyphs.
|
||||
const SkRect fVertexBounds;
|
||||
@ -1130,14 +1130,14 @@ private:
|
||||
mutable GlyphVector fGlyphs;
|
||||
};
|
||||
|
||||
TransformedMaskSubRun::TransformedMaskSubRun(GrMaskFormat format,
|
||||
GrTextBlob* blob,
|
||||
TransformedMaskSubRun::TransformedMaskSubRun(GrTextReferenceFrame* referenceFrame,
|
||||
GrMaskFormat format,
|
||||
SkScalar strikeToSourceScale,
|
||||
const SkRect& bounds,
|
||||
SkSpan<const VertexData> vertexData,
|
||||
GlyphVector&& glyphs)
|
||||
: fVertexFiller{format, 0, strikeToSourceScale}
|
||||
, fBlob{blob}
|
||||
, fReferenceFrame{referenceFrame}
|
||||
, fVertexBounds{bounds}
|
||||
, fVertexData{vertexData}
|
||||
, fGlyphs{std::move(glyphs)} { }
|
||||
@ -1167,7 +1167,7 @@ GrSubRunOwner TransformedMaskSubRun::Make(const SkZip<SkGlyphVariant, SkPoint>&
|
||||
});
|
||||
|
||||
return alloc->makeUnique<TransformedMaskSubRun>(
|
||||
format, blob, strikeToSourceScale, bounds, vertexData,
|
||||
blob, format, strikeToSourceScale, bounds, vertexData,
|
||||
GlyphVector::Make(std::move(strike), drawables.get<0>(), alloc));
|
||||
}
|
||||
|
||||
@ -1203,7 +1203,7 @@ TransformedMaskSubRun::makeAtlasTextOp(const GrClip* clip,
|
||||
drawMatrix,
|
||||
drawOrigin,
|
||||
SkIRect::MakeEmpty(),
|
||||
sk_ref_sp<GrTextBlob>(fBlob),
|
||||
sk_ref_sp(fReferenceFrame),
|
||||
drawingColor,
|
||||
sdc->arenaAlloc());
|
||||
|
||||
@ -1221,7 +1221,7 @@ TransformedMaskSubRun::makeAtlasTextOp(const GrClip* clip,
|
||||
// If we are not scaling the cache entry to be larger, than a cache with smaller glyphs may be
|
||||
// better.
|
||||
bool TransformedMaskSubRun::canReuse(const SkPaint& paint, const SkMatrix& positionMatrix) const {
|
||||
if (fBlob->initialPositionMatrix().getMaxScale() < 1) {
|
||||
if (fReferenceFrame->initialPositionMatrix().getMaxScale() < 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -2624,7 +2624,7 @@ public:
|
||||
SkScalar strikeToSourceScale, const SkFont& runFont, SkScalar minScale,
|
||||
SkScalar maxScale) override;
|
||||
|
||||
const SkMatrix& initialPositionMatrix() const { return fInitialPositionMatrix; }
|
||||
const SkMatrix& initialPositionMatrix() const override { return fInitialPositionMatrix; }
|
||||
SkPoint origin() const { return fOrigin; }
|
||||
|
||||
// Change memory management to handle the data after Slug, but in the same allocation
|
||||
@ -2634,11 +2634,13 @@ public:
|
||||
void* operator new(size_t, void* p) { return p; }
|
||||
|
||||
private:
|
||||
// The allocator must come first because it needs to be destroyed last. Other fields of this
|
||||
// structure may have pointers into it.
|
||||
GrSubRunAllocator fAlloc;
|
||||
const SkRect fSourceBounds;
|
||||
const SkPaint fPaint;
|
||||
const SkMatrix fInitialPositionMatrix;
|
||||
const SkPoint fOrigin;
|
||||
GrSubRunAllocator fAlloc;
|
||||
GrSubRunList fSubRuns;
|
||||
};
|
||||
|
||||
@ -2647,11 +2649,11 @@ Slug::Slug(SkRect sourceBounds,
|
||||
const SkMatrix& positionMatrix,
|
||||
SkPoint origin,
|
||||
int allocSize)
|
||||
: fSourceBounds{sourceBounds}
|
||||
: fAlloc {SkTAddOffset<char>(this, sizeof(Slug)), allocSize, allocSize/2}
|
||||
, fSourceBounds{sourceBounds}
|
||||
, fPaint{paint}
|
||||
, fInitialPositionMatrix{positionMatrix}
|
||||
, fOrigin{origin}
|
||||
, fAlloc {SkTAddOffset<char>(this, sizeof(Slug)), allocSize, allocSize/2} { }
|
||||
, fOrigin{origin} { }
|
||||
|
||||
void Slug::surfaceDraw(SkCanvas* canvas, const GrClip* clip, const SkMatrixProvider& viewMatrix,
|
||||
skgpu::v1::SurfaceDrawContext* sdc) {
|
||||
@ -3336,7 +3338,7 @@ class TransformedMaskSubRunSlug final : public GrSubRun, public GrAtlasSubRun {
|
||||
public:
|
||||
using VertexData = TransformedMaskVertexFiller::PositionAndExtent;
|
||||
|
||||
TransformedMaskSubRunSlug(Slug* slug,
|
||||
TransformedMaskSubRunSlug(GrTextReferenceFrame* referenceFrame,
|
||||
GrMaskFormat format,
|
||||
SkScalar strikeToSourceScale,
|
||||
const SkRect& bounds,
|
||||
@ -3381,7 +3383,7 @@ private:
|
||||
// The rectangle that surrounds all the glyph bounding boxes in device space.
|
||||
SkRect deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const;
|
||||
const TransformedMaskVertexFiller fVertexFiller;
|
||||
Slug* const fSlug;
|
||||
GrTextReferenceFrame* const fReferenceFrame;
|
||||
|
||||
// The bounds in source space. The bounds are the joined rectangles of all the glyphs.
|
||||
const SkRect fVertexBounds;
|
||||
@ -3393,14 +3395,14 @@ private:
|
||||
};
|
||||
|
||||
TransformedMaskSubRunSlug::TransformedMaskSubRunSlug(
|
||||
Slug* slug,
|
||||
GrTextReferenceFrame* referenceFrame,
|
||||
GrMaskFormat format,
|
||||
SkScalar strikeToSourceScale,
|
||||
const SkRect& bounds,
|
||||
SkSpan<const VertexData> vertexData,
|
||||
GlyphVector&& glyphs)
|
||||
: fVertexFiller{format, 0, strikeToSourceScale}
|
||||
, fSlug{slug}
|
||||
, fReferenceFrame{referenceFrame}
|
||||
, fVertexBounds{bounds}
|
||||
, fVertexData{vertexData}
|
||||
, fGlyphs{std::move(glyphs)} { }
|
||||
@ -3466,7 +3468,7 @@ TransformedMaskSubRunSlug::makeAtlasTextOp(const GrClip* clip,
|
||||
drawMatrix,
|
||||
drawOrigin,
|
||||
SkIRect::MakeEmpty(),
|
||||
sk_ref_sp<Slug>(fSlug),
|
||||
sk_ref_sp(fReferenceFrame),
|
||||
drawingColor,
|
||||
sdc->arenaAlloc());
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "include/core/SkPoint3.h"
|
||||
#include "include/core/SkRefCnt.h"
|
||||
#include "include/private/chromium/GrSlug.h"
|
||||
#include "src/core/SkGlyphRunPainter.h"
|
||||
#include "src/core/SkIPoint16.h"
|
||||
#include "src/core/SkMaskFilterBase.h"
|
||||
@ -165,7 +166,7 @@ private:
|
||||
// with.
|
||||
//
|
||||
//
|
||||
class GrTextBlob final : public SkRefCnt, public SkGlyphRunPainterInterface {
|
||||
class GrTextBlob final : public GrTextReferenceFrame, public SkGlyphRunPainterInterface {
|
||||
public:
|
||||
|
||||
// Key is not used as part of a hash map, so the hash is never taken. It's only used in a
|
||||
@ -220,7 +221,7 @@ public:
|
||||
|
||||
void addKey(const Key& key);
|
||||
bool hasPerspective() const;
|
||||
const SkMatrix& initialPositionMatrix() const { return fInitialPositionMatrix; }
|
||||
const SkMatrix& initialPositionMatrix() const override { return fInitialPositionMatrix; }
|
||||
bool supportBilerpAtlas() const { return fSupportBilerpAtlas; }
|
||||
|
||||
std::tuple<SkScalar, SkScalar> scaleBounds() const { return {fMaxMinScale, fMinMaxScale}; }
|
||||
|
Loading…
Reference in New Issue
Block a user