47#include <initializer_list>
59 Barrier(
int threadCount) : fThreadCount(threadCount) { }
62 while (fThreadCount > 0) { }
66 std::atomic<int> fThreadCount;
71std::tuple<SkZip<const SkPackedGlyphID, const SkPoint>,
90 case GlyphAction::kAccept: {
92 boundingRect = skglyph::rect_union(boundingRect, glyphBounds);
93 acceptedBuffer[acceptedSize++] = std::make_tuple(packedID, glyphBounds.
leftTop());
96 case GlyphAction::kReject:
97 rejectedBuffer[rejectedSize++] = std::make_tuple(glyphID,
pos);
104 return {acceptedBuffer.
first(acceptedSize),
105 rejectedBuffer.
first(rejectedSize),
106 boundingRect.
rect()};
118 font.setSubpixel(
true);
119 font.setTypeface(typeface);
123 for (
int c =
' '; c <
'z'; c++) {
124 glyphs[c] = font.unicharToGlyph(c);
125 pos[c] = {30.0f * c + 30, 30.0f};
127 constexpr size_t glyphCount =
'z' -
' ';
139 for (
int tries = 0; tries < 100; tries++) {
143 auto perThread = [&](
int threadIndex) {
144 barrier.waitForAll();
146 auto local = data.subspan(threadIndex * 2, data.size() -
kThreadCount * 2);
147 for (
int i = 0; i < 100; i++) {
152 acceptedPackedGlyphIDs.
resize(glyphCount);
153 acceptedPositions.
resize(glyphCount);
154 const auto acceptedBuffer =
SkMakeZip(acceptedPackedGlyphIDs, acceptedPositions);
159 rejectedGlyphIDs.
resize(glyphCount);
160 rejectedPositions.
resize(glyphCount);
161 const auto rejectedBuffer =
SkMakeZip(rejectedGlyphIDs, rejectedPositions);
165 auto [accepted, rejected, bounds] =
180 glyph->fAdvanceX = 10;
181 glyph->fAdvanceY = 11;
182 glyph->fLeft = -1 - uniquify;
194 return strike->
glyph(packedID);
199 std::vector<SkGlyph> imagesToSend;
200 std::vector<SkGlyph> pathsToSend;
201 std::vector<SkGlyph> drawablesToSend;
206 SkGlyph maskGlyph{maskPackedGlyphID};
209 static constexpr uint8_t
X = 0xff;
210 static constexpr uint8_t O = 0x00;
211 uint8_t imageData[][8] = {
222 maskGlyph.setImage(&alloc, imageData);
223 imagesToSend.emplace_back(maskGlyph);
227 SkGlyph pathGlyph{pathPackedGlyphID};
230 path.addRect(pathGlyph.rect());
231 pathGlyph.setPath(&alloc, &path,
false);
232 pathsToSend.emplace_back(pathGlyph);
236 SkGlyph drawableGlyph{drawablePackedGlyphID};
238 class TestDrawable final :
public SkDrawable {
256 drawableGlyph.setDrawable(&alloc, drawable);
259 drawablesToSend.emplace_back(drawableGlyph);
264 auto data = writeBuffer.snapshotAsData();
275 strike->mergeFromBuffer(readBuffer);
static bool SkIsFinite(T x, Pack... values)
static std::tuple< SkZip< const SkPackedGlyphID, const SkPoint >, SkZip< SkGlyphID, SkPoint >, SkRect > prepare_for_mask_drawing(StrikeForGPU *strike, SkZip< const SkGlyphID, const SkPoint > source, SkZip< SkPackedGlyphID, SkPoint > acceptedBuffer, SkZip< SkGlyphID, SkPoint > rejectedBuffer)
@ kUnknown_SkPixelGeometry
constexpr auto SkMakeZip(Ts &&... ts)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
void drawRect(const SkRect &rect, const SkPaint &paint)
virtual SkRect onGetBounds()=0
virtual void onDraw(SkCanvas *)=0
virtual size_t onApproximateBytesUsed()
static std::unique_ptr< SkExecutor > MakeFIFOThreadPool(int threads=0, bool allowBorrowing=true)
static constexpr SkFontStyle Italic()
@ kAntiAlias
may have transparent pixels on glyph edges
skglyph::GlyphAction actionFor(skglyph::ActionType actionType) const
SkGlyphRect offset(SkScalar x, SkScalar y) const
static void SetGlyph(SkGlyph *glyph)
bool setPathHasBeenCalled() const
SkGlyphID getGlyphID() const
bool setDrawableHasBeenCalled() const
bool setImageHasBeenCalled() const
const SkPath * path() const
SkDrawable * drawable() const
const void * image() const
static const SkMatrix & I()
static SkStrikeSpec MakeMask(const SkFont &font, const SkPaint &paint, const SkSurfaceProps &surfaceProps, SkScalerContextFlags scalerContextFlags, const SkMatrix &deviceMatrix)
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
std::unique_ptr< SkScalerContext > createScalerContext() const
sk_sp< SkStrike > findOrCreateStrike() const
static SkGlyph * GetGlyph(SkStrike *strike, SkPackedGlyphID packedID)
static void FlattenGlyphsByType(SkWriteBuffer &buffer, SkSpan< SkGlyph > images, SkSpan< SkGlyph > paths, SkSpan< SkGlyph > drawables)
SkGlyph * glyph(SkGlyphDigest) SK_REQUIRES(fStrikeLock)
void batch(int N, std::function< void(int)> fn)
constexpr SkZip first(size_t n) const
void resize(size_t count)
virtual SkGlyphDigest digestFor(skglyph::ActionType, SkPackedGlyphID)=0
static constexpr uint64_t kThreadCount
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
constexpr float y() const
constexpr float x() const