1 /* 2 * Copyright 2021 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrSlug_DEFINED 9 #define GrSlug_DEFINED 10 11 #include "include/core/SkRect.h" 12 #include "include/core/SkRefCnt.h" 13 14 class SkCanvas; 15 class SkMatrix; 16 class SkPaint; 17 class SkReadBuffer; 18 class SkTextBlob; 19 class SkStrikeClient; 20 class SkWriteBuffer; 21 22 // You can use GrSlug to simulate drawTextBlob by defining the following at compile time. 23 // SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG 24 // For Skia, add this to your args.gn file. 25 // extra_cflags = ["-D", "SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG"] 26 27 // Internal infrastructure for using SubRuns. 28 class SK_API GrTextReferenceFrame : public SkRefCnt { 29 public: 30 ~GrTextReferenceFrame() override; 31 virtual const SkMatrix& initialPositionMatrix() const = 0; 32 }; 33 34 // GrSlug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be 35 // manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then 36 // the GrSlug will also transform with smaller glyphs using bi-linear interpolation to render. You 37 // can think of a GrSlug as making a rubber stamp out of a SkTextBlob. 38 class SK_API GrSlug : public GrTextReferenceFrame { 39 public: 40 ~GrSlug() override; 41 // Return nullptr if the blob would not draw. This is not because of clipping, but because of 42 // some paint optimization. The GrSlug is captured as if drawn using drawTextBlob. 43 static sk_sp<GrSlug> ConvertBlob( 44 SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint); 45 46 // Set the client parameter to nullptr if no typeface ID translation is needed. 47 static sk_sp<GrSlug> MakeFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client); 48 49 // Draw the GrSlug obeying the canvas's mapping and clipping. 50 void draw(SkCanvas* canvas); 51 52 // Serialize the slug. 53 virtual void flatten(SkWriteBuffer&) const = 0; 54 55 virtual SkRect sourceBounds() const = 0; 56 virtual const SkPaint& paint() const = 0; 57 }; 58 #endif // GrSlug_DEFINED 59