Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: src/fonts/SkGScalerContext.cpp

Issue 1863013003: Pass effects directly to fontcache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: name the empty effects Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/fonts/SkGScalerContext.h ('k') | src/fonts/SkRandomScalerContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkDescriptor.h"
8 #include "SkGScalerContext.h" 9 #include "SkGScalerContext.h"
9 #include "SkGlyph.h" 10 #include "SkGlyph.h"
10 #include "SkPath.h" 11 #include "SkPath.h"
11 #include "SkCanvas.h" 12 #include "SkCanvas.h"
12 13
14 #define STD_SIZE 1
15
13 class SkGScalerContext : public SkScalerContext { 16 class SkGScalerContext : public SkScalerContext {
14 public: 17 public:
15 SkGScalerContext(SkGTypeface*, const SkDescriptor*); 18 SkGScalerContext(SkGTypeface* face, const SkScalerContextEffects& effects,
16 virtual ~SkGScalerContext(); 19 const SkDescriptor* desc)
20 : SkScalerContext(face, effects, desc)
21 , fFace(face)
22 {
23
24 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerCon text::Rec);
25 SkAutoDescriptor ad(descSize);
26 SkDescriptor* newDesc = ad.getDesc();
27
28 newDesc->init();
29 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
30 sizeof(SkScalerContext::Rec), &fRec);
31 {
32 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
33 rec->fTextSize = STD_SIZE;
34 rec->fPreScaleX = SK_Scalar1;
35 rec->fPreSkewX = 0;
36 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
37 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
38 }
39 SkASSERT(descSize == newDesc->getLength());
40 newDesc->computeChecksum();
41
42 fProxy = face->proxy()->createScalerContext(effects, newDesc);
43
44 fRec.getSingleMatrix(&fMatrix);
45 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
46 }
47 virtual ~SkGScalerContext() { delete fProxy; }
17 48
18 protected: 49 protected:
19 unsigned generateGlyphCount() override; 50 unsigned generateGlyphCount() override;
20 uint16_t generateCharToGlyph(SkUnichar) override; 51 uint16_t generateCharToGlyph(SkUnichar) override;
21 void generateAdvance(SkGlyph*) override; 52 void generateAdvance(SkGlyph*) override;
22 void generateMetrics(SkGlyph*) override; 53 void generateMetrics(SkGlyph*) override;
23 void generateImage(const SkGlyph&) override; 54 void generateImage(const SkGlyph&) override;
24 void generatePath(const SkGlyph&, SkPath*) override; 55 void generatePath(const SkGlyph&, SkPath*) override;
25 void generateFontMetrics(SkPaint::FontMetrics*) override; 56 void generateFontMetrics(SkPaint::FontMetrics*) override;
26 57
27 private: 58 private:
28 SkGTypeface* fFace; 59 SkGTypeface* fFace;
29 SkScalerContext* fProxy; 60 SkScalerContext* fProxy;
30 SkMatrix fMatrix; 61 SkMatrix fMatrix;
31 }; 62 };
32 63
33 #define STD_SIZE 1
34
35 #include "SkDescriptor.h"
36
37 SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc)
38 : SkScalerContext(face, desc)
39 , fFace(face)
40 {
41
42 size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext ::Rec);
43 SkAutoDescriptor ad(descSize);
44 SkDescriptor* newDesc = ad.getDesc();
45
46 newDesc->init();
47 void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
48 sizeof(SkScalerContext::Rec), &fRec);
49 {
50 SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
51 rec->fTextSize = STD_SIZE;
52 rec->fPreScaleX = SK_Scalar1;
53 rec->fPreSkewX = 0;
54 rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
55 rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
56 }
57 SkASSERT(descSize == newDesc->getLength());
58 newDesc->computeChecksum();
59
60 fProxy = face->proxy()->createScalerContext(newDesc);
61
62 fRec.getSingleMatrix(&fMatrix);
63 fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
64 }
65
66 SkGScalerContext::~SkGScalerContext() { delete fProxy; }
67
68 unsigned SkGScalerContext::generateGlyphCount() { 64 unsigned SkGScalerContext::generateGlyphCount() {
69 return fProxy->getGlyphCount(); 65 return fProxy->getGlyphCount();
70 } 66 }
71 67
72 uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) { 68 uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) {
73 return fProxy->charToGlyphID(uni); 69 return fProxy->charToGlyphID(uni);
74 } 70 }
75 71
76 void SkGScalerContext::generateAdvance(SkGlyph* glyph) { 72 void SkGScalerContext::generateAdvance(SkGlyph* glyph) {
77 fProxy->getAdvance(glyph); 73 fProxy->getAdvance(glyph);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 153
158 SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint) 154 SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint)
159 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) 155 : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
160 , fProxy(SkRef(proxy)) 156 , fProxy(SkRef(proxy))
161 , fPaint(paint) {} 157 , fPaint(paint) {}
162 158
163 SkGTypeface::~SkGTypeface() { 159 SkGTypeface::~SkGTypeface() {
164 fProxy->unref(); 160 fProxy->unref();
165 } 161 }
166 162
167 SkScalerContext* SkGTypeface::onCreateScalerContext( 163 SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects & effects,
168 const SkDescriptor* desc) const { 164 const SkDescriptor* desc) co nst {
169 return new SkGScalerContext(const_cast<SkGTypeface*>(this), desc); 165 return new SkGScalerContext(const_cast<SkGTypeface*>(this), effects, desc);
170 } 166 }
171 167
172 void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const { 168 void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const {
173 fProxy->filterRec(rec); 169 fProxy->filterRec(rec);
174 rec->setHinting(SkPaint::kNo_Hinting); 170 rec->setHinting(SkPaint::kNo_Hinting);
175 rec->fMaskFormat = SkMask::kARGB32_Format; 171 rec->fMaskFormat = SkMask::kARGB32_Format;
176 } 172 }
177 173
178 SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics( 174 SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics(
179 PerGlyphInfo info, 175 PerGlyphInfo info,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 251
256 friend class SkGFontBuilder; 252 friend class SkGFontBuilder;
257 SkGFont(int count, Glyph* array); 253 SkGFont(int count, Glyph* array);
258 }; 254 };
259 255
260 class SkGFontBuilder { 256 class SkGFontBuilder {
261 public: 257 public:
262 258
263 }; 259 };
264 #endif 260 #endif
OLDNEW
« no previous file with comments | « src/fonts/SkGScalerContext.h ('k') | src/fonts/SkRandomScalerContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698