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 sktext_gpu_Slug_DEFINED
9#define sktext_gpu_Slug_DEFINED
10
11#include "include/core/SkRect.h"
12#include "include/core/SkRefCnt.h"
13#include "include/private/base/SkAPI.h"
14
15#include <cstddef>
16#include <cstdint>
17
18class SkCanvas;
19class SkData;
20class SkPaint;
21class SkReadBuffer;
22class SkStrikeClient;
23class SkTextBlob;
24class SkWriteBuffer;
25struct SkPoint;
26
27namespace sktext::gpu {
28// Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be
29// manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then
30// the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You
31// can think of a Slug as making a rubber stamp out of a SkTextBlob.
32class SK_API Slug : public SkRefCnt {
33public:
34 // Return nullptr if the blob would not draw. This is not because of clipping, but because of
35 // some paint optimization. The Slug is captured as if drawn using drawTextBlob.
36 static sk_sp<Slug> ConvertBlob(
37 SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint);
38
39 // Serialize the slug.
40 sk_sp<SkData> serialize() const;
41 size_t serialize(void* buffer, size_t size) const;
42
43 // Set the client parameter to the appropriate SkStrikeClient when typeface ID translation
44 // is needed.
45 static sk_sp<Slug> Deserialize(
46 const void* data, size_t size, const SkStrikeClient* client = nullptr);
47 static sk_sp<Slug> MakeFromBuffer(SkReadBuffer& buffer);
48
49
50 // Draw the Slug obeying the canvas's mapping and clipping.
51 void draw(SkCanvas* canvas) const;
52
53 virtual SkRect sourceBounds() const = 0;
54 virtual SkRect sourceBoundsWithOrigin () const = 0;
55
56 // The paint passed into ConvertBlob; this paint is used instead of the paint resulting from
57 // the call to aboutToDraw because when we call draw(), the initial paint is needed to call
58 // aboutToDraw again to get the layer right.
59 virtual const SkPaint& initialPaint() const = 0;
60
61 virtual void doFlatten(SkWriteBuffer&) const = 0;
62
63 uint32_t uniqueID() const { return fUniqueID; }
64
65private:
66 static uint32_t NextUniqueID();
67 const uint32_t fUniqueID{NextUniqueID()};
68};
69} // namespace sktext::gpu
70
71#endif // sktext_gpu_Slug_DEFINED
72

source code of flutter_engine/third_party/skia/include/private/chromium/Slug.h