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
8#include "include/core/SkPaint.h"
9#include "src/core/SkRemoteGlyphCache.h"
10#include "src/core/SkScalerCache.h"
11#include "src/core/SkStrikeCache.h"
12#include "src/core/SkTraceEvent.h"
13#include "src/core/SkTypeface_remote.h"
14
15SkScalerContextProxy::SkScalerContextProxy(sk_sp<SkTypeface> tf,
16 const SkScalerContextEffects& effects,
17 const SkDescriptor* desc,
18 sk_sp<SkStrikeClient::DiscardableHandleManager> manager)
19 : SkScalerContext{std::move(tf), effects, desc}
20 , fDiscardableManager{std::move(manager)} {}
21
22unsigned SkScalerContextProxy::generateGlyphCount() {
23 SK_ABORT("Should never be called.");
24}
25
26bool SkScalerContextProxy::generateAdvance(SkGlyph* glyph) {
27 return false;
28}
29
30void SkScalerContextProxy::generateMetrics(SkGlyph* glyph) {
31 TRACE_EVENT1("skia", "generateMetrics", "rec", TRACE_STR_COPY(this->getRec().dump().c_str()));
32 if (this->getProxyTypeface()->isLogging()) {
33 SkDebugf("GlyphCacheMiss generateMetrics: %s\n", this->getRec().dump().c_str());
34 }
35
36 glyph->fMaskFormat = fRec.fMaskFormat;
37 glyph->zeroMetrics();
38 fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kGlyphMetrics);
39}
40
41void SkScalerContextProxy::generateImage(const SkGlyph& glyph) {
42 TRACE_EVENT1("skia", "generateImage", "rec", TRACE_STR_COPY(this->getRec().dump().c_str()));
43 if (this->getProxyTypeface()->isLogging()) {
44 SkDebugf("GlyphCacheMiss generateImage: %s\n", this->getRec().dump().c_str());
45 }
46
47 // There is no desperation search here, because if there was an image to be found it was
48 // copied over with the metrics search.
49 fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kGlyphImage);
50}
51
52bool SkScalerContextProxy::generatePath(SkGlyphID glyphID, SkPath* path) {
53 TRACE_EVENT1("skia", "generatePath", "rec", TRACE_STR_COPY(this->getRec().dump().c_str()));
54 if (this->getProxyTypeface()->isLogging()) {
55 SkDebugf("GlyphCacheMiss generatePath: %s\n", this->getRec().dump().c_str());
56 }
57
58 fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kGlyphPath);
59 return false;
60}
61
62void SkScalerContextProxy::generateFontMetrics(SkFontMetrics* metrics) {
63 TRACE_EVENT1(
64 "skia", "generateFontMetrics", "rec", TRACE_STR_COPY(this->getRec().dump().c_str()));
65 if (this->getProxyTypeface()->isLogging()) {
66 SkDebugf("GlyphCacheMiss generateFontMetrics: %s\n", this->getRec().dump().c_str());
67 SkDEBUGCODE(SkStrikeCache::Dump());
68 }
69
70 // Font metrics aren't really used for render, so just zero out the data and return.
71 fDiscardableManager->notifyCacheMiss(SkStrikeClient::CacheMissType::kFontMetrics);
72 sk_bzero(metrics, sizeof(*metrics));
73}
74
75SkTypefaceProxy* SkScalerContextProxy::getProxyTypeface() const {
76 return (SkTypefaceProxy*)this->getTypeface();
77}
78