1 /*
2 * Copyright 2019 Google Inc.
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/core/SkGlyphBuffer.h"
9 #include "src/core/SkGlyphRunPainter.h"
10 #include "src/text/StrikeForGPU.h"
11
reset()12 void SkSourceGlyphBuffer::reset() {
13 fRejectedGlyphIDs.clear();
14 fRejectedPositions.clear();
15 }
16
ensureSize(int size)17 void SkDrawableGlyphBuffer::ensureSize(int size) {
18 if (size > fMaxSize) {
19 fPackedGlyphIDs.reset(size);
20 fPositions.reset(size);
21 fFormats.reset(size);
22 fMaxSize = size;
23 }
24
25 fInputSize = 0;
26 fAcceptedSize = 0;
27 }
28
startSource(const SkZip<const SkGlyphID,const SkPoint> & source)29 void SkDrawableGlyphBuffer::startSource(const SkZip<const SkGlyphID, const SkPoint>& source) {
30 fInputSize = source.size();
31 fAcceptedSize = 0;
32
33 auto positions = source.get<1>();
34 memcpy(fPositions, positions.data(), positions.size() * sizeof(SkPoint));
35
36 // Convert from SkGlyphIDs to SkPackedGlyphIDs.
37 SkPackedGlyphID* packedIDCursor = fPackedGlyphIDs.get();
38 for (auto t : source) {
39 *packedIDCursor++ = SkPackedGlyphID{std::get<0>(t)};
40 }
41 SkDEBUGCODE(fPhase = kInput);
42 }
43
dumpInput() const44 SkString SkDrawableGlyphBuffer::dumpInput() const {
45 SkASSERT(fPhase == kInput);
46
47 SkString msg;
48 for (auto [packedGlyphID, pos]
49 : SkZip<SkPackedGlyphID, SkPoint>{
50 SkToSizeT(fInputSize), fPackedGlyphIDs.get(), fPositions.get()}) {
51 msg.appendf("%s:(%a,%a), ", packedGlyphID.shortDump().c_str(), pos.x(), pos.y());
52 }
53 return msg;
54 }
55
reset()56 void SkDrawableGlyphBuffer::reset() {
57 SkDEBUGCODE(fPhase = kReset);
58 if (fMaxSize > 200) {
59 fPackedGlyphIDs.reset();
60 fPositions.reset();
61 fFormats.reset();
62 fMaxSize = 0;
63 }
64 fInputSize = 0;
65 fAcceptedSize = 0;
66 }
67
68