Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Slug.h
Go to the documentation of this file.
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"
14
15#include <cstddef>
16#include <cstdint>
17
18class SkCanvas;
19class SkData;
20class SkPaint;
21class SkReadBuffer;
22class SkStrikeClient;
23class SkTextBlob;
24class SkWriteBuffer;
25struct SkDeserialProcs;
26struct SkPoint;
27
28namespace 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.
33class SK_API Slug : public SkRefCnt {
34public:
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 uint32_t uniqueID() const { return fUniqueID; }
63
64private:
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
#define SK_API
Definition SkAPI.h:35
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
virtual void doFlatten(SkWriteBuffer &) const =0
virtual SkRect sourceBounds() const =0
uint32_t uniqueID() const
Definition Slug.h:62
virtual SkRect sourceBoundsWithOrigin() const =0
const Paint & paint
static const uint8_t buffer[]