* Copyright 2018 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 SkGlyphRunPainter_DEFINED
#define SkGlyphRunPainter_DEFINED
#include "include/core/SkSurfaceProps.h"
#include "src/core/SkDistanceFieldGen.h"
#include "src/core/SkGlyphRun.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkTextBlobPriv.h"
#if SK_SUPPORT_GPU
#include "src/gpu/text/GrTextContext.h"
class GrColorSpaceInfo;
class GrRenderTargetContext;
#endif
class SkGlyphRunPainterInterface;
class SkStrikeSpec;
class SkStrikeCommon {
public:
static SkVector PixelRounding(bool isSubpixel, SkAxisAlignment axisAlignment);
static constexpr uint16_t kSkSideTooBigForAtlas = 256;
};
class SkGlyphRunListPainter {
public:
SkGlyphRunListPainter(const SkSurfaceProps& props,
SkColorType colorType,
SkColorSpace* cs,
SkStrikeCacheInterface* strikeCache);
#if SK_SUPPORT_GPU
SkGlyphRunListPainter(const SkSurfaceProps&, const GrColorSpaceInfo&);
explicit SkGlyphRunListPainter(const GrRenderTargetContext& renderTargetContext);
#endif
class BitmapDevicePainter {
public:
virtual ~BitmapDevicePainter() = default;
virtual void paintPaths(SkSpan<const SkPathPos> pathsAndPositions,
SkScalar scale,
const SkPaint& paint) const = 0;
virtual void paintMasks(SkSpan<const SkMask> masks, const SkPaint& paint) const = 0;
};
void drawForBitmapDevice(
const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix,
const BitmapDevicePainter* bitmapDevice);
#if SK_SUPPORT_GPU
void processGlyphRunList(const SkGlyphRunList& glyphRunList,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
bool contextSupportsDistanceFieldText,
const GrTextContext::Options& options,
SkGlyphRunPainterInterface* process);
#endif
private:
SkGlyphRunListPainter(const SkSurfaceProps& props, SkColorType colorType,
SkScalerContextFlags flags, SkStrikeCacheInterface* strikeCache);
struct ScopedBuffers {
ScopedBuffers(SkGlyphRunListPainter* painter, int size);
~ScopedBuffers();
SkGlyphRunListPainter* fPainter;
};
ScopedBuffers SK_WARN_UNUSED_RESULT ensureBuffers(const SkGlyphRunList& glyphRunList);
ScopedBuffers SK_WARN_UNUSED_RESULT ensureBuffers(const SkGlyphRun& glyphRun);
* @param fARGBPositions in source space
* @param fARGBGlyphsIDs the glyphs to process
* @param fGlyphPos used as scratch space
* @param maxSourceGlyphDimension the longest dimension of any glyph as if all fARGBGlyphsIDs
* were drawn in source space (as if viewMatrix were identity)
*/
void processARGBFallback(SkScalar maxSourceGlyphDimension,
const SkPaint& runPaint,
const SkFont& runFont,
const SkMatrix& viewMatrix,
SkGlyphRunPainterInterface* process);
static SkSpan<const SkPackedGlyphID> DeviceSpacePackedGlyphIDs(
SkStrikeInterface* strike,
const SkMatrix& viewMatrix,
const SkPoint& origin,
int n,
const SkGlyphID* glyphIDs,
const SkPoint* positions,
SkPoint* mappedPositions,
SkPackedGlyphID* results);
static SkSpan<const SkPackedGlyphID> SourceSpacePackedGlyphIDs(
const SkPoint& origin,
int n,
const SkGlyphID* glyphIDs,
const SkPoint* positions,
SkPoint* mappedPositions,
SkPackedGlyphID* results);
const SkSurfaceProps fDeviceProps;
const SkSurfaceProps fBitmapFallbackProps;
const SkColorType fColorType;
const SkScalerContextFlags fScalerContextFlags;
SkStrikeCacheInterface* const fStrikeCache;
int fMaxRunSize{0};
SkAutoTMalloc<SkPoint> fPositions;
SkAutoTMalloc<SkPackedGlyphID> fPackedGlyphIDs;
SkAutoTMalloc<SkGlyphPos> fGlyphPos;
std::vector<SkGlyphPos> fPaths;
std::vector<SkGlyphID> fARGBGlyphsIDs;
std::vector<SkPoint> fARGBPositions;
};
class SkGlyphRunPainterInterface {
public:
virtual ~SkGlyphRunPainterInterface() = default;
virtual void startRun(const SkGlyphRun& glyphRun, bool useSDFT) = 0;
virtual void processDeviceMasks(SkSpan<const SkGlyphPos> masks,
const SkStrikeSpec& strikeSpec) = 0;
virtual void processSourcePaths(SkSpan<const SkGlyphPos> paths,
const SkStrikeSpec& strikeSpec) = 0;
virtual void processDevicePaths(SkSpan<const SkGlyphPos> paths) = 0;
virtual void processSourceSDFT(SkSpan<const SkGlyphPos> masks,
const SkStrikeSpec& strikeSpec,
const SkFont& runFont,
SkScalar minScale,
SkScalar maxScale,
bool hasWCoord) = 0;
virtual void processSourceFallback(SkSpan<const SkGlyphPos> masks,
const SkStrikeSpec& strikeSpec,
bool hasW) = 0;
virtual void processDeviceFallback(SkSpan<const SkGlyphPos> masks,
const SkStrikeSpec& strikeSpec) = 0;
};
#endif