Coverage Report

Created: 2024-05-20 07:14

/src/skia/include/private/chromium/Slug.h
Line
Count
Source (jump to first uncovered line)
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
18
class SkCanvas;
19
class SkData;
20
class SkPaint;
21
class SkReadBuffer;
22
class SkStrikeClient;
23
class SkTextBlob;
24
class SkWriteBuffer;
25
struct SkDeserialProcs;
26
struct SkPoint;
27
28
namespace sktext::gpu {
29
// Slug encapsulates an SkTextBlob at a specific origin, using a specific paint. It can be
30
// manipulated using matrix and clip changes to the canvas. If the canvas is transformed, then
31
// the Slug will also transform with smaller glyphs using bi-linear interpolation to render. You
32
// can think of a Slug as making a rubber stamp out of a SkTextBlob.
33
class SK_API Slug : public SkRefCnt {
34
public:
35
    // Return nullptr if the blob would not draw. This is not because of clipping, but because of
36
    // some paint optimization. The Slug is captured as if drawn using drawTextBlob.
37
    static sk_sp<Slug> ConvertBlob(
38
            SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint);
39
40
    // Serialize the slug.
41
    sk_sp<SkData> serialize() const;
42
    size_t serialize(void* buffer, size_t size) const;
43
44
    // Set the client parameter to the appropriate SkStrikeClient when typeface ID translation
45
    // is needed.
46
    static sk_sp<Slug> Deserialize(const void* data,
47
                                   size_t size,
48
                                   const SkStrikeClient* client = nullptr);
49
    static sk_sp<Slug> MakeFromBuffer(SkReadBuffer& buffer);
50
51
    // Allows clients to deserialize SkPictures that contain slug data
52
    static void AddDeserialProcs(SkDeserialProcs* procs, const SkStrikeClient* client = nullptr);
53
54
    // Draw the Slug obeying the canvas's mapping and clipping.
55
    void draw(SkCanvas* canvas, const SkPaint& paint) const;
56
57
    virtual SkRect sourceBounds() const = 0;
58
    virtual SkRect sourceBoundsWithOrigin () const = 0;
59
60
    virtual void doFlatten(SkWriteBuffer&) const = 0;
61
62
0
    uint32_t uniqueID() const { return fUniqueID; }
63
64
private:
65
    static uint32_t NextUniqueID();
66
    const uint32_t  fUniqueID{NextUniqueID()};
67
};
68
69
70
}  // namespace sktext::gpu
71
72
#endif  // sktext_gpu_Slug_DEFINED