| 1 |
/* |
| 2 |
* Copyright 2010 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 sktext_gpu_Glyph_DEFINED |
| 9 |
#define sktext_gpu_Glyph_DEFINED |
| 10 |
|
| 11 |
#include "src/core/SkGlyph.h" |
| 12 |
#include "src/core/SkMask.h" |
| 13 |
#include "src/gpu/AtlasTypes.h" |
| 14 |
|
| 15 |
namespace sktext::gpu { |
| 16 |
|
| 17 |
struct GlyphEntryKey { |
| 18 |
explicit GlyphEntryKey(SkPackedGlyphID id, skgpu::MaskFormat format) |
| 19 |
: fPackedID(id), fFormat(format) {} |
| 20 |
|
| 21 |
const SkPackedGlyphID fPackedID; |
| 22 |
skgpu::MaskFormat fFormat; |
| 23 |
|
| 24 |
bool operator==(const GlyphEntryKey& that) const { |
| 25 |
return fPackedID == that.fPackedID && fFormat == that.fFormat; |
| 26 |
} |
| 27 |
bool operator!=(const GlyphEntryKey& that) const { |
| 28 |
return !(*this == that); |
| 29 |
} |
| 30 |
|
| 31 |
uint32_t hash() const { |
| 32 |
return fPackedID.hash(); |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
class Glyph { |
| 37 |
public: |
| 38 |
static skgpu::MaskFormat FormatFromSkGlyph(SkMask::Format format) { |
| 39 |
switch (format) { |
| 40 |
case SkMask::kBW_Format: |
| 41 |
case SkMask::kSDF_Format: |
| 42 |
// fall through to kA8 -- we store BW and SDF glyphs in our 8-bit cache |
| 43 |
case SkMask::kA8_Format: |
| 44 |
return skgpu::MaskFormat::kA8; |
| 45 |
case SkMask::k3D_Format: |
| 46 |
return skgpu::MaskFormat::kA8; // ignore the mul and add planes, just use the mask |
| 47 |
case SkMask::kLCD16_Format: |
| 48 |
return skgpu::MaskFormat::kA565; |
| 49 |
case SkMask::kARGB32_Format: |
| 50 |
return skgpu::MaskFormat::kARGB; |
| 51 |
} |
| 52 |
|
| 53 |
SkUNREACHABLE; |
| 54 |
} |
| 55 |
|
| 56 |
explicit Glyph(SkPackedGlyphID packedGlyphID, skgpu::MaskFormat format) |
| 57 |
: fGlyphEntryKey(packedGlyphID, format) {} |
| 58 |
|
| 59 |
const GlyphEntryKey fGlyphEntryKey; |
| 60 |
skgpu::AtlasLocator fAtlasLocator; |
| 61 |
}; |
| 62 |
|
| 63 |
} // namespace sktext::gpu |
| 64 |
|
| 65 |
#endif // sktext_gpu_Glyph_DEFINED |