OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkRefCnt.h" | 8 #include "SkRefCnt.h" |
9 #include "SkTypeface.h" | 9 #include "SkTypeface.h" |
10 #include "SkTypefaceCache.h" | 10 #include "SkTypefaceCache.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #ifdef SK_BUILD_FOR_ANDROID | 24 #ifdef SK_BUILD_FOR_ANDROID |
25 sk_sp<SkTypeface> t3(SkTypeface::MakeFromName("non-existent-font", SkFontSty
le())); | 25 sk_sp<SkTypeface> t3(SkTypeface::MakeFromName("non-existent-font", SkFontSty
le())); |
26 REPORTER_ASSERT(reporter, nullptr == t3); | 26 REPORTER_ASSERT(reporter, nullptr == t3); |
27 #endif | 27 #endif |
28 } | 28 } |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 class SkEmptyTypeface : public SkTypeface { | 32 class SkEmptyTypeface : public SkTypeface { |
33 public: | 33 public: |
34 static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new
SkEmptyTypeface(id)); } | 34 static sk_sp<SkTypeface> Create() { return sk_sp<SkTypeface>(new SkEmptyType
face()); } |
35 protected: | 35 protected: |
36 SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { } | 36 SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { } |
37 | 37 |
38 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr;
} | 38 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr;
} |
39 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, | 39 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, |
40 const SkDescriptor*) const override { | 40 const SkDescriptor*) const override { |
41 return nullptr; | 41 return nullptr; |
42 } | 42 } |
43 void onFilterRec(SkScalerContextRec*) const override { } | 43 void onFilterRec(SkScalerContextRec*) const override { } |
44 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 44 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
45 PerGlyphInfo, | 45 PerGlyphInfo, |
46 const uint32_t*, uint32_t) const override { retu
rn nullptr; } | 46 const uint32_t*, uint32_t) const override { retu
rn nullptr; } |
(...skipping 22 matching lines...) Expand all Loading... |
69 return false; | 69 return false; |
70 } | 70 } |
71 static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) { | 71 static int count(skiatest::Reporter* reporter, const SkTypefaceCache& cache) { |
72 int count = 0; | 72 int count = 0; |
73 SkTypeface* none = cache.findByProcAndRef(count_proc, &count); | 73 SkTypeface* none = cache.findByProcAndRef(count_proc, &count); |
74 REPORTER_ASSERT(reporter, none == nullptr); | 74 REPORTER_ASSERT(reporter, none == nullptr); |
75 return count; | 75 return count; |
76 } | 76 } |
77 | 77 |
78 DEF_TEST(TypefaceCache, reporter) { | 78 DEF_TEST(TypefaceCache, reporter) { |
79 sk_sp<SkTypeface> t1(SkEmptyTypeface::Create(1)); | 79 sk_sp<SkTypeface> t1(SkEmptyTypeface::Create()); |
80 { | 80 { |
81 SkTypefaceCache cache; | 81 SkTypefaceCache cache; |
82 REPORTER_ASSERT(reporter, count(reporter, cache) == 0); | 82 REPORTER_ASSERT(reporter, count(reporter, cache) == 0); |
83 { | 83 { |
84 sk_sp<SkTypeface> t0(SkEmptyTypeface::Create(0)); | 84 sk_sp<SkTypeface> t0(SkEmptyTypeface::Create()); |
85 cache.add(t0.get()); | 85 cache.add(t0.get()); |
86 REPORTER_ASSERT(reporter, count(reporter, cache) == 1); | 86 REPORTER_ASSERT(reporter, count(reporter, cache) == 1); |
87 cache.add(t1.get()); | 87 cache.add(t1.get()); |
88 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); | 88 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); |
89 cache.purgeAll(); | 89 cache.purgeAll(); |
90 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); | 90 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); |
91 } | 91 } |
92 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); | 92 REPORTER_ASSERT(reporter, count(reporter, cache) == 2); |
93 cache.purgeAll(); | 93 cache.purgeAll(); |
94 REPORTER_ASSERT(reporter, count(reporter, cache) == 1); | 94 REPORTER_ASSERT(reporter, count(reporter, cache) == 1); |
95 } | 95 } |
96 REPORTER_ASSERT(reporter, t1->unique()); | 96 REPORTER_ASSERT(reporter, t1->unique()); |
97 } | 97 } |
OLD | NEW |