* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
*/
#ifndef SkStrike_DEFINED
#define SkStrike_DEFINED
#include "include/core/SkFontMetrics.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkPaint.h"
#include "include/private/SkTHash.h"
#include "include/private/SkTemplates.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkDescriptor.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkGlyphRunPainter.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkStrikeInterface.h"
#include <memory>
This class represents a strike: a specific combination of typeface, size, matrix, etc., and
holds the glyphs for that strike. Calling any of the getGlyphID... methods will
return the requested glyph, either instantly if it is already cached, or by first generating
it and then adding it to the strike.
The strikes are held in a global list, available to all threads. To interact with one, call
either Find{OrCreate}Exclusive().
The Find*Exclusive() method returns SkExclusiveStrikePtr, which releases exclusive ownership
when they go out of scope.
*/
class SkStrike final : public SkStrikeInterface {
public:
SkStrike(const SkDescriptor& desc,
std::unique_ptr<SkScalerContext> scaler,
const SkFontMetrics&);
SkGlyph* glyph(SkPackedGlyphID packedID);
SkGlyph* glyph(SkGlyphID glyphID);
SkGlyph* glyph(SkGlyphID, SkPoint);
SkGlyph* glyphFromPrototype(const SkGlyphPrototype& p, void* image = nullptr);
SkGlyph* glyphOrNull(SkPackedGlyphID id) const;
const void* prepareImage(SkGlyph* glyph);
SkGlyph* mergeGlyphAndImage(SkPackedGlyphID toID, const SkGlyph& from);
const SkPath* preparePath(SkGlyph*);
const SkPath* preparePath(SkGlyph* glyph, const SkPath* path);
*/
unsigned getGlyphCount() const;
int countCachedGlyphs() const;
to the array (if non-null), and set the count to the updated array length.
*/
void findIntercepts(const SkScalar bounds[2], SkScalar scale, SkScalar xPos,
SkGlyph* , SkScalar* array, int* count);
*/
bool belongsToCache(const SkGlyph* glyph) const;
* If set and present, skip over the glyph with vetoID.
*/
const SkGlyph* getCachedGlyphAnySubPix(SkGlyphID,
SkPackedGlyphID vetoID = SkPackedGlyphID()) const;
*/
const SkFontMetrics& getFontMetrics() const {
return fFontMetrics;
}
SkMask::Format getMaskFormat() const {
return fScalerContext->getMaskFormat();
}
bool isSubpixel() const {
return fIsSubpixel;
}
SkVector rounding() const override;
SkIPoint subpixelMask() const override {
return SkIPoint::Make((!fIsSubpixel || fAxisAlignment == kY_SkAxisAlignment) ? 0 : ~0,
(!fIsSubpixel || fAxisAlignment == kX_SkAxisAlignment) ? 0 : ~0);
}
const SkDescriptor& getDescriptor() const override;
SkSpan<const SkGlyph*> metrics(SkSpan<const SkGlyphID> glyphIDs,
const SkGlyph* results[]);
SkSpan<const SkGlyph*> preparePaths(SkSpan<const SkGlyphID> glyphIDs,
const SkGlyph* results[]);
SkSpan<const SkGlyph*> prepareImages(SkSpan<const SkPackedGlyphID> glyphIDs,
const SkGlyph* results[]);
SkSpan<const SkGlyphPos> prepareForDrawingRemoveEmpty(const SkPackedGlyphID packedGlyphIDs[],
const SkPoint positions[],
size_t n,
int maxDimension,
PreparationDetail detail,
SkGlyphPos results[]) override;
void onAboutToExitScope() override;
size_t getMemoryUsed() const { return fMemoryUsed; }
void dump() const;
SkScalerContext* getScalerContext() const { return fScalerContext.get(); }
#ifdef SK_DEBUG
void forceValidate() const;
void validate() const;
#else
void validate() const {}
#endif
class AutoValidate : SkNoncopyable {
public:
AutoValidate(const SkStrike* cache) : fCache(cache) {
if (fCache) {
fCache->validate();
}
}
~AutoValidate() {
if (fCache) {
fCache->validate();
}
}
void forget() {
fCache = nullptr;
}
private:
const SkStrike* fCache;
};
private:
class GlyphMapHashTraits {
public:
static SkPackedGlyphID GetKey(const SkGlyph* glyph) {
return glyph->getPackedID();
}
static uint32_t Hash(SkPackedGlyphID glyphId) {
return glyphId.hash();
}
};
SkGlyph* makeGlyph(SkPackedGlyphID);
enum PathDetail {
kMetricsOnly,
kMetricsAndPath
};
SkSpan<const SkGlyph*> internalPrepare(
SkSpan<const SkGlyphID> glyphIDs,
PathDetail pathDetail,
const SkGlyph** results);
const SkAutoDescriptor fDesc;
const std::unique_ptr<SkScalerContext> fScalerContext;
SkFontMetrics fFontMetrics;
SkTHashTable<SkGlyph*, SkPackedGlyphID, GlyphMapHashTraits> fGlyphMap;
static constexpr size_t kMinGlyphCount = 8;
static constexpr size_t kMinGlyphImageSize = 16 * 8 ;
static constexpr size_t kMinAllocAmount = kMinGlyphImageSize * kMinGlyphCount;
SkArenaAlloc fAlloc {kMinAllocAmount};
size_t fMemoryUsed;
const bool fIsSubpixel;
const SkAxisAlignment fAxisAlignment;
};
#endif