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#ifndef SkStrikeInterface_DEFINED
9#define SkStrikeInterface_DEFINED
10
11#include "include/core/SkPaint.h"
12#include "include/core/SkPoint.h"
13#include "include/core/SkTypes.h"
14#include "src/core/SkGlyph.h"
15#include "src/core/SkSpan.h"
16
17#include <memory>
18
19class SkDescriptor;
20class SkDrawableGlyphBuffer;
21class SkGlyph;
22class SkMaskFilter;
23class SkPathEffect;
24class SkSourceGlyphBuffer;
25class SkTypeface;
26struct SkGlyphPositionRoundingSpec;
27struct SkScalerContextEffects;
28
29class SkStrikeForGPU {
30public:
31 virtual ~SkStrikeForGPU() = default;
32 virtual const SkDescriptor& getDescriptor() const = 0;
33
34 virtual void prepareForMaskDrawing(
35 SkDrawableGlyphBuffer* drawables, SkSourceGlyphBuffer* rejects) = 0;
36
37 virtual void prepareForSDFTDrawing(
38 SkDrawableGlyphBuffer* drawables, SkSourceGlyphBuffer* rejects) = 0;
39
40 virtual void prepareForPathDrawing(
41 SkDrawableGlyphBuffer* drawables, SkSourceGlyphBuffer* rejects) = 0;
42
43 virtual const SkGlyphPositionRoundingSpec& roundingSpec() const = 0;
44
45 // Used with SkScopedStrikeForGPU to take action at the end of a scope.
46 virtual void onAboutToExitScope() = 0;
47
48 // Common categories for glyph types used by GPU.
49 static bool CanDrawAsMask(const SkGlyph& glyph);
50 static bool CanDrawAsSDFT(const SkGlyph& glyph);
51 static bool CanDrawAsPath(const SkGlyph& glyph);
52 static bool FitsInAtlas(const SkGlyph& glyph);
53
54
55 struct Deleter {
56 void operator()(SkStrikeForGPU* ptr) const {
57 ptr->onAboutToExitScope();
58 }
59 };
60};
61
62using SkScopedStrikeForGPU = std::unique_ptr<SkStrikeForGPU, SkStrikeForGPU::Deleter>;
63
64class SkStrikeForGPUCacheInterface {
65public:
66 virtual ~SkStrikeForGPUCacheInterface() = default;
67 virtual SkScopedStrikeForGPU findOrCreateScopedStrike(const SkDescriptor& desc,
68 const SkScalerContextEffects& effects,
69 const SkTypeface& typeface) = 0;
70};
71#endif //SkStrikeInterface_DEFINED
72