Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 8 | #include "SkTypeface_remote.h" |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 9 | #include "SkGlyphCache.h" |
Mike Klein | fc6cf92 | 2018-05-23 00:16:47 +0000 | [diff] [blame] | 10 | #include "SkPaint.h" |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 11 | #include "SkRemoteGlyphCache.h" |
| 12 | #include "SkStrikeCache.h" |
| 13 | #include "SkTraceEvent.h" |
Khushal | 38a0843 | 2018-05-02 10:29:37 -0700 | [diff] [blame] | 14 | |
| 15 | SkScalerContextProxy::SkScalerContextProxy(sk_sp<SkTypeface> tf, |
| 16 | const SkScalerContextEffects& effects, |
| 17 | const SkDescriptor* desc, |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 18 | sk_sp<SkStrikeClient::DiscardableHandleManager> manager) |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 19 | : SkScalerContext{std::move(tf), effects, desc} |
| 20 | , fDiscardableManager{std::move(manager)} {} |
Herb Derby | 97be88f | 2018-03-21 16:23:49 -0400 | [diff] [blame] | 21 | |
Herb Derby | 5c0c798 | 2018-06-21 15:15:50 -0400 | [diff] [blame] | 22 | void SkScalerContextProxy::initCache(SkGlyphCache* cache, SkStrikeCache* strikeCache) { |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 23 | SkASSERT(fCache == nullptr); |
| 24 | SkASSERT(cache != nullptr); |
| 25 | |
| 26 | fCache = cache; |
Herb Derby | 5c0c798 | 2018-06-21 15:15:50 -0400 | [diff] [blame] | 27 | fStrikeCache = strikeCache; |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Herb Derby | 97be88f | 2018-03-21 16:23:49 -0400 | [diff] [blame] | 30 | unsigned SkScalerContextProxy::generateGlyphCount() { |
| 31 | SK_ABORT("Should never be called."); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | uint16_t SkScalerContextProxy::generateCharToGlyph(SkUnichar) { |
| 36 | SK_ABORT("Should never be called."); |
| 37 | return 0; |
| 38 | } |
| 39 | |
Ben Wagner | e541645 | 2018-08-09 14:03:42 -0400 | [diff] [blame] | 40 | bool SkScalerContextProxy::generateAdvance(SkGlyph* glyph) { |
| 41 | return false; |
| 42 | } |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 43 | |
| 44 | void SkScalerContextProxy::generateMetrics(SkGlyph* glyph) { |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 45 | TRACE_EVENT1("skia", "generateMetrics", "rec", TRACE_STR_COPY(this->getRec().dump().c_str())); |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 46 | if (this->getProxyTypeface()->isLogging()) { |
| 47 | SkDebugf("GlyphCacheMiss generateMetrics: %s\n", this->getRec().dump().c_str()); |
| 48 | } |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 49 | |
Ben Wagner | e541645 | 2018-08-09 14:03:42 -0400 | [diff] [blame] | 50 | glyph->fMaskFormat = fRec.fMaskFormat; |
| 51 | |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 52 | // Since the scaler context is being called, we don't have the needed data. Try to find a |
| 53 | // fallback before failing. |
| 54 | if (fCache && fCache->belongsToCache(glyph)) { |
| 55 | // First check the original cache, in case there is a sub-pixel pos mismatch. |
| 56 | if (const auto* fallback = |
| 57 | fCache->getCachedGlyphAnySubPix(glyph->getGlyphID(), glyph->getPackedID())) { |
| 58 | fCache->initializeGlyphFromFallback(glyph, *fallback); |
| 59 | fDiscardableManager->notifyCacheMiss( |
| 60 | SkStrikeClient::CacheMissType::kGlyphMetricsFallback); |
| 61 | return; |
| 62 | } |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 63 | |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 64 | // Now check other caches for a desc mismatch. |
Herb Derby | 5c0c798 | 2018-06-21 15:15:50 -0400 | [diff] [blame] | 65 | if (fStrikeCache->desperationSearchForImage(fCache->getDescriptor(), glyph, fCache)) { |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 66 | fDiscardableManager->notifyCacheMiss( |
| 67 | SkStrikeClient::CacheMissType::kGlyphMetricsFallback); |
| 68 | return; |
| 69 | } |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 70 | } |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 71 | |
| 72 | glyph->zeroMetrics(); |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 73 | fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kGlyphMetrics); |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void SkScalerContextProxy::generateImage(const SkGlyph& glyph) { |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 77 | TRACE_EVENT1("skia", "generateImage", "rec", TRACE_STR_COPY(this->getRec().dump().c_str())); |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 78 | if (this->getProxyTypeface()->isLogging()) { |
| 79 | SkDebugf("GlyphCacheMiss generateImage: %s\n", this->getRec().dump().c_str()); |
| 80 | } |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 81 | |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 82 | // There is no desperation search here, because if there was an image to be found it was |
| 83 | // copied over with the metrics search. |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 84 | fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kGlyphImage); |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 85 | } |
| 86 | |
Ben Wagner | 5ddb308 | 2018-03-29 11:18:06 -0400 | [diff] [blame] | 87 | bool SkScalerContextProxy::generatePath(SkGlyphID glyphID, SkPath* path) { |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 88 | TRACE_EVENT1("skia", "generatePath", "rec", TRACE_STR_COPY(this->getRec().dump().c_str())); |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 89 | if (this->getProxyTypeface()->isLogging()) { |
| 90 | SkDebugf("GlyphCacheMiss generatePath: %s\n", this->getRec().dump().c_str()); |
| 91 | } |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 92 | |
| 93 | // Since the scaler context is being called, we don't have the needed data. Try to find a |
| 94 | // fallback before failing. |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 95 | auto desc = SkScalerContext::DescriptorGivenRecAndEffects(this->getRec(), this->getEffects()); |
Khushal | 9dd1e82 | 2018-10-09 13:12:42 -0700 | [diff] [blame] | 96 | bool foundPath = fStrikeCache && fStrikeCache->desperationSearchForPath(*desc, glyphID, path); |
Khushal | 8523b6b | 2018-06-12 11:26:17 -0700 | [diff] [blame] | 97 | fDiscardableManager->notifyCacheMiss(foundPath |
| 98 | ? SkStrikeClient::CacheMissType::kGlyphPathFallback |
| 99 | : SkStrikeClient::CacheMissType::kGlyphPath); |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 100 | return foundPath; |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void SkScalerContextProxy::generateFontMetrics(SkPaint::FontMetrics* metrics) { |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 104 | TRACE_EVENT1( |
| 105 | "skia", "generateFontMetrics", "rec", TRACE_STR_COPY(this->getRec().dump().c_str())); |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 106 | if (this->getProxyTypeface()->isLogging()) { |
| 107 | SkDebugf("GlyphCacheMiss generateFontMetrics: %s\n", this->getRec().dump().c_str()); |
| 108 | SkDEBUGCODE(SkStrikeCache::Dump()); |
| 109 | } |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 110 | |
Herb Derby | 65b7bfc | 2018-06-05 13:32:12 -0400 | [diff] [blame] | 111 | // Font metrics aren't really used for render, so just zero out the data and return. |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 112 | fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kFontMetrics); |
Khushal | d416083 | 2018-05-23 18:16:00 -0700 | [diff] [blame] | 113 | sk_bzero(metrics, sizeof(*metrics)); |
Mike Klein | a8a51ce | 2018-01-09 12:34:11 -0500 | [diff] [blame] | 114 | } |
Herb Derby | feb9fa9 | 2018-06-01 16:47:21 -0400 | [diff] [blame] | 115 | |
| 116 | SkTypefaceProxy* SkScalerContextProxy::getProxyTypeface() const { |
| 117 | return (SkTypefaceProxy*)this->getTypeface(); |
Khushal | fa8ff09 | 2018-06-06 17:46:38 -0700 | [diff] [blame] | 118 | } |