Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SlugImpl.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
9
12#include "include/core/SkRect.h"
16#include "src/core/SkDevice.h"
19#include "src/text/GlyphRun.h"
22
23#include <memory>
24#include <utility>
25
26class SkStrikeClient;
27
28namespace sktext::gpu {
29
32 SkRect sourceBounds,
33 SkPoint origin)
34 : fAlloc {std::move(alloc)}
35 , fSubRuns(std::move(subRuns))
36 , fSourceBounds{sourceBounds}
37 , fOrigin{origin} {}
38
40 buffer.writeRect(fSourceBounds);
41 buffer.writePoint(fOrigin);
42 fSubRuns->flattenAllocSizeHint(buffer);
43 fSubRuns->flattenRuns(buffer);
44}
45
47 SkRect sourceBounds = buffer.readRect();
48 if (!buffer.validate(!sourceBounds.isEmpty())) {
49 return nullptr;
50 }
51 SkPoint origin = buffer.readPoint();
53
54 auto [initializer, _, alloc] =
55 SubRunAllocator::AllocateClassMemoryAndArena<SlugImpl>(allocSizeHint);
56
59
60 // Something went wrong while reading.
61 if (!buffer.isValid()) {
62 return nullptr;
63 }
64
65 return sk_sp<SlugImpl>(
66 initializer.initialize(std::move(alloc), std::move(container), sourceBounds, origin));
67}
68
69SkMatrix position_matrix(const SkMatrix& drawMatrix, SkPoint drawOrigin) {
70 SkMatrix position_matrix = drawMatrix;
71 return position_matrix.preTranslate(drawOrigin.x(), drawOrigin.y());
72}
73
75 const sktext::GlyphRunList& glyphRunList,
76 const SkPaint& paint,
77 SkStrikeDeviceInfo strikeDeviceInfo,
79 size_t subRunSizeHint = gpu::SubRunContainer::EstimateAllocSize(glyphRunList);
80 auto [initializer, _, alloc] =
81 SubRunAllocator::AllocateClassMemoryAndArena<SlugImpl>(subRunSizeHint);
82
83 const SkMatrix positionMatrix = position_matrix(viewMatrix, glyphRunList.origin());
84
86 positionMatrix,
87 paint,
88 strikeDeviceInfo,
89 strikeCache,
90 &alloc,
92 "Make Slug");
93
94 sk_sp<SlugImpl> slug = sk_sp<SlugImpl>(initializer.initialize(std::move(alloc),
95 std::move(subRuns),
96 glyphRunList.sourceBounds(),
97 glyphRunList.origin()));
98
99 // There is nothing to draw here. This is particularly a problem with RSX form blobs where a
100 // single space becomes a run with no glyphs.
101 if (slug->fSubRuns->isEmpty()) { return nullptr; }
102
103 return slug;
104}
105
107 SkASSERT(procs);
108 procs->fSlugCtx = const_cast<SkStrikeClient*>(client);
109 procs->fSlugProc = [](SkReadBuffer& buffer, void* ctx) -> sk_sp<Slug> {
110 auto client = static_cast<const SkStrikeClient*>(ctx);
111 return SlugImpl::MakeFromBuffer(buffer, client);
112 };
113}
114
115} // namespace sktext::gpu
static struct Initializer initializer
#define SkASSERT(cond)
Definition SkAssert.h:116
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:263
SkRect sourceBounds() const
Definition GlyphRun.h:115
SkPoint origin() const
Definition GlyphRun.h:114
const gpu::SubRunContainerOwner & subRuns() const
Definition SlugImpl.h:57
void doFlatten(SkWriteBuffer &buffer) const override
Definition SlugImpl.cpp:39
SlugImpl(SubRunAllocator &&alloc, gpu::SubRunContainerOwner subRuns, SkRect sourceBounds, SkPoint origin)
Definition SlugImpl.cpp:30
SkRect sourceBounds() const override
Definition SlugImpl.h:51
SkPoint origin() const
Definition SlugImpl.h:55
static sk_sp< SlugImpl > Make(const SkMatrix &viewMatrix, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint, SkStrikeDeviceInfo strikeDeviceInfo, sktext::StrikeForGPUCacheInterface *strikeCache)
Definition SlugImpl.cpp:74
static sk_sp< Slug > MakeFromBuffer(SkReadBuffer &buffer, const SkStrikeClient *client)
Definition SlugImpl.cpp:46
static void AddDeserialProcs(SkDeserialProcs *procs, const SkStrikeClient *client=nullptr)
Definition SlugImpl.cpp:106
static SubRunContainerOwner MakeInAlloc(const GlyphRunList &glyphRunList, const SkMatrix &positionMatrix, const SkPaint &runPaint, SkStrikeDeviceInfo strikeDeviceInfo, StrikeForGPUCacheInterface *strikeCache, sktext::gpu::SubRunAllocator *alloc, SubRunCreationBehavior creationBehavior, const char *tag)
static size_t EstimateAllocSize(const GlyphRunList &glyphRunList)
static SubRunContainerOwner MakeFromBufferInAlloc(SkReadBuffer &buffer, const SkStrikeClient *client, SubRunAllocator *alloc)
static int AllocSizeHintFromBuffer(SkReadBuffer &buffer)
const Paint & paint
static const uint8_t buffer[]
std::unique_ptr< SubRunContainer, SubRunAllocator::Destroyer > SubRunContainerOwner
SkMatrix position_matrix(const SkMatrix &drawMatrix, SkPoint drawOrigin)
Definition SlugImpl.cpp:69
Definition ref_ptr.h:256
SkSlugProc fSlugProc
constexpr float y() const
constexpr float x() const
bool isEmpty() const
Definition SkRect.h:693