/src/skia/src/text/gpu/SlugImpl.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
8 | | #include "src/text/gpu/SlugImpl.h" |
9 | | |
10 | | #include "include/core/SkMatrix.h" |
11 | | #include "include/core/SkPoint.h" |
12 | | #include "include/core/SkRect.h" |
13 | | #include "include/core/SkSerialProcs.h" |
14 | | #include "include/private/base/SkAssert.h" |
15 | | #include "include/private/chromium/Slug.h" |
16 | | #include "src/core/SkDevice.h" |
17 | | #include "src/core/SkReadBuffer.h" |
18 | | #include "src/core/SkWriteBuffer.h" |
19 | | #include "src/text/GlyphRun.h" |
20 | | #include "src/text/gpu/SubRunAllocator.h" |
21 | | #include "src/text/gpu/SubRunContainer.h" |
22 | | |
23 | | #include <memory> |
24 | | #include <utility> |
25 | | |
26 | | class SkStrikeClient; |
27 | | |
28 | | namespace sktext::gpu { |
29 | | |
30 | | SlugImpl::SlugImpl(SubRunAllocator&& alloc, |
31 | | gpu::SubRunContainerOwner subRuns, |
32 | | SkRect sourceBounds, |
33 | | SkPoint origin) |
34 | | : fAlloc {std::move(alloc)} |
35 | | , fSubRuns(std::move(subRuns)) |
36 | | , fSourceBounds{sourceBounds} |
37 | 225 | , fOrigin{origin} {} |
38 | | |
39 | 0 | void SlugImpl::doFlatten(SkWriteBuffer& buffer) const { |
40 | 0 | buffer.writeRect(fSourceBounds); |
41 | 0 | buffer.writePoint(fOrigin); |
42 | 0 | fSubRuns->flattenAllocSizeHint(buffer); |
43 | 0 | fSubRuns->flattenRuns(buffer); |
44 | 0 | } |
45 | | |
46 | 0 | sk_sp<Slug> SlugImpl::MakeFromBuffer(SkReadBuffer& buffer, const SkStrikeClient* client) { |
47 | 0 | SkRect sourceBounds = buffer.readRect(); |
48 | 0 | if (!buffer.validate(!sourceBounds.isEmpty())) { |
49 | 0 | return nullptr; |
50 | 0 | } |
51 | 0 | SkPoint origin = buffer.readPoint(); |
52 | 0 | int allocSizeHint = gpu::SubRunContainer::AllocSizeHintFromBuffer(buffer); |
53 | |
|
54 | 0 | auto [initializer, _, alloc] = |
55 | 0 | SubRunAllocator::AllocateClassMemoryAndArena<SlugImpl>(allocSizeHint); |
56 | |
|
57 | 0 | gpu::SubRunContainerOwner container = |
58 | 0 | gpu::SubRunContainer::MakeFromBufferInAlloc(buffer, client, &alloc); |
59 | | |
60 | | // Something went wrong while reading. |
61 | 0 | if (!buffer.isValid()) { |
62 | 0 | return nullptr; |
63 | 0 | } |
64 | | |
65 | 0 | return sk_sp<SlugImpl>( |
66 | 0 | initializer.initialize(std::move(alloc), std::move(container), sourceBounds, origin)); |
67 | 0 | } |
68 | | |
69 | 225 | SkMatrix position_matrix(const SkMatrix& drawMatrix, SkPoint drawOrigin) { |
70 | 225 | SkMatrix position_matrix = drawMatrix; |
71 | 225 | return position_matrix.preTranslate(drawOrigin.x(), drawOrigin.y()); |
72 | 225 | } |
73 | | |
74 | | sk_sp<SlugImpl> SlugImpl::Make(const SkMatrix& viewMatrix, |
75 | | const sktext::GlyphRunList& glyphRunList, |
76 | | const SkPaint& paint, |
77 | | SkStrikeDeviceInfo strikeDeviceInfo, |
78 | 225 | sktext::StrikeForGPUCacheInterface* strikeCache) { |
79 | 225 | size_t subRunSizeHint = gpu::SubRunContainer::EstimateAllocSize(glyphRunList); |
80 | 225 | auto [initializer, _, alloc] = |
81 | 225 | SubRunAllocator::AllocateClassMemoryAndArena<SlugImpl>(subRunSizeHint); |
82 | | |
83 | 225 | const SkMatrix positionMatrix = position_matrix(viewMatrix, glyphRunList.origin()); |
84 | | |
85 | 225 | auto subRuns = gpu::SubRunContainer::MakeInAlloc(glyphRunList, |
86 | 225 | positionMatrix, |
87 | 225 | paint, |
88 | 225 | strikeDeviceInfo, |
89 | 225 | strikeCache, |
90 | 225 | &alloc, |
91 | 225 | gpu::SubRunContainer::kAddSubRuns, |
92 | 225 | "Make Slug"); |
93 | | |
94 | 225 | sk_sp<SlugImpl> slug = sk_sp<SlugImpl>(initializer.initialize(std::move(alloc), |
95 | 225 | std::move(subRuns), |
96 | 225 | glyphRunList.sourceBounds(), |
97 | 225 | 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 | 225 | if (slug->fSubRuns->isEmpty()) { return nullptr; } |
102 | | |
103 | 54 | return slug; |
104 | 225 | } |
105 | | |
106 | 0 | void Slug::AddDeserialProcs(SkDeserialProcs* procs, const SkStrikeClient* client) { |
107 | 0 | SkASSERT(procs); |
108 | 0 | procs->fSlugCtx = const_cast<SkStrikeClient*>(client); |
109 | 0 | procs->fSlugProc = [](SkReadBuffer& buffer, void* ctx) -> sk_sp<Slug> { |
110 | 0 | auto client = static_cast<const SkStrikeClient*>(ctx); |
111 | 0 | return SlugImpl::MakeFromBuffer(buffer, client); |
112 | 0 | }; Unexecuted instantiation: SlugImpl.cpp:sktext::gpu::Slug::AddDeserialProcs(SkDeserialProcs*, SkStrikeClient const*)::$_0::operator()(SkReadBuffer&, void*) const Unexecuted instantiation: SlugImpl.cpp:sktext::gpu::Slug::AddDeserialProcs(SkDeserialProcs*, SkStrikeClient const*)::$_1::operator()(SkReadBuffer&, void*) const |
113 | 0 | } Unexecuted instantiation: sktext::gpu::Slug::AddDeserialProcs(SkDeserialProcs*, SkStrikeClient const*) Unexecuted instantiation: sktext::gpu::Slug::AddDeserialProcs(SkDeserialProcs*, SkStrikeClient const*) |
114 | | |
115 | | } // namespace sktext::gpu |