2021-11-19 18:16:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrSlug_DEFINED
|
|
|
|
#define GrSlug_DEFINED
|
|
|
|
|
2022-02-22 14:59:48 +00:00
|
|
|
#include "include/core/SkData.h"
|
2021-11-19 18:16:23 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
|
|
|
|
class SkCanvas;
|
2022-01-31 16:59:45 +00:00
|
|
|
class SkMatrix;
|
2021-11-19 18:16:23 +00:00
|
|
|
class SkPaint;
|
|
|
|
class SkTextBlob;
|
2022-03-01 21:15:02 +00:00
|
|
|
class SkReadBuffer;
|
2022-02-17 20:35:11 +00:00
|
|
|
class SkStrikeClient;
|
2022-02-11 17:36:29 +00:00
|
|
|
class SkWriteBuffer;
|
2021-11-19 18:16:23 +00:00
|
|
|
|
2021-12-09 21:19:08 +00:00
|
|
|
// You can use GrSlug to simulate drawTextBlob by defining the following at compile time.
|
|
|
|
// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG
|
2022-02-17 19:58:33 +00:00
|
|
|
// You can use GrSlug serialization to simulate drawTextBlob by defining the following:
|
|
|
|
// SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE
|
2021-12-09 21:19:08 +00:00
|
|
|
// For Skia, add this to your args.gn file.
|
|
|
|
// extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"]
|
|
|
|
|
2022-01-31 16:59:45 +00:00
|
|
|
// Internal infrastructure for using SubRuns.
|
|
|
|
class SK_API GrTextReferenceFrame : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
~GrTextReferenceFrame() override;
|
|
|
|
virtual const SkMatrix& initialPositionMatrix() const = 0;
|
|
|
|
};
|
|
|
|
|
2021-11-19 18:16:23 +00:00
|
|
|
// 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.
|
2022-01-31 16:59:45 +00:00
|
|
|
class SK_API GrSlug : public GrTextReferenceFrame {
|
2021-11-19 18:16:23 +00:00
|
|
|
public:
|
|
|
|
~GrSlug() override;
|
|
|
|
// Return nullptr if the blob would not draw. This is not because of clipping, but because of
|
|
|
|
// some paint optimization. The GrSlug is captured as if drawn using drawTextBlob.
|
|
|
|
static sk_sp<GrSlug> ConvertBlob(
|
|
|
|
SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint);
|
|
|
|
|
2022-02-22 14:59:48 +00:00
|
|
|
// Serialize the slug.
|
|
|
|
sk_sp<SkData> serialize() const;
|
2022-02-22 18:44:58 +00:00
|
|
|
size_t serialize(void* buffer, size_t size) const;
|
2022-02-22 14:59:48 +00:00
|
|
|
|
|
|
|
// Set the client parameter to the appropriate SkStrikeClient when typeface ID translation
|
|
|
|
// is needed.
|
|
|
|
static sk_sp<GrSlug> Deserialize(
|
|
|
|
const void* data, size_t size, const SkStrikeClient* client = nullptr);
|
2022-03-01 21:15:02 +00:00
|
|
|
static sk_sp<GrSlug> MakeFromBuffer(SkReadBuffer& buffer);
|
|
|
|
|
2022-02-17 20:35:11 +00:00
|
|
|
|
2021-11-19 18:16:23 +00:00
|
|
|
// Draw the GrSlug obeying the canvas's mapping and clipping.
|
2022-03-15 16:13:02 +00:00
|
|
|
void draw(SkCanvas* canvas) const;
|
2021-11-19 18:16:23 +00:00
|
|
|
|
|
|
|
virtual SkRect sourceBounds() const = 0;
|
|
|
|
virtual const SkPaint& paint() const = 0;
|
2022-02-22 14:59:48 +00:00
|
|
|
|
|
|
|
virtual void doFlatten(SkWriteBuffer&) const = 0;
|
2022-03-01 21:15:02 +00:00
|
|
|
|
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
static uint32_t NextUniqueID();
|
|
|
|
const uint32_t fUniqueID{NextUniqueID()};
|
2021-11-19 18:16:23 +00:00
|
|
|
};
|
|
|
|
#endif // GrSlug_DEFINED
|