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

Side by Side Diff: src/gpu/GrPathRendering.cpp

Issue 563283004: Use per-typeface sets of glyphs for nvpr text (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_glyphmemorypath
Patch Set: Created 6 years, 3 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 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 "GrPathRendering.h"
9 #include "SkDescriptor.h"
10 #include "SkGlyph.h"
11 #include "SkMatrix.h"
12 #include "SkTypeface.h"
13 #include "GrPathRange.h"
14
15 class GlyphGenerator : public GrPathRange::PathGenerator {
16 public:
17 GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc)
18 : fDesc(desc.copy()),
19 fScalerContext(typeface.createScalerContext(fDesc)) {
20 fFlipMatrix.setScale(1, -1);
21 }
22
23 virtual ~GlyphGenerator() {
24 SkDescriptor::Free(fDesc);
25 }
26
27 virtual uint32_t getNumPaths() {
28 return fScalerContext->getGlyphCount();
29 }
30
31 virtual void generatePath(uint32_t glyphID, SkPath* out) {
32 SkGlyph skGlyph;
33 skGlyph.init(SkGlyph::MakeID(glyphID));
34 fScalerContext->getMetrics(&skGlyph);
35
36 fScalerContext->getPath(skGlyph, out);
37 out->transform(fFlipMatrix); // Load glyphs with the inverted y-directio n.
38 }
39
40 virtual bool isEqualTo(const SkDescriptor& desc) const {
41 return fDesc->equals(desc);
42 }
43
44 private:
45 SkDescriptor* const fDesc;
46 const SkAutoTDelete<SkScalerContext> fScalerContext;
47 SkMatrix fFlipMatrix;
48 };
49
50 GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface,
51 const SkDescriptor* desc,
52 const SkStrokeRec& stroke) {
53 if (NULL == typeface) {
54 typeface = SkTypeface::GetDefaultTypeface();
55 SkASSERT(NULL != typeface);
56 }
57
58 if (desc) {
59 return this->createPathRange(SkNEW_ARGS(GlyphGenerator, (*typeface, *des c)), stroke);
60 }
61
62 SkScalerContextRec rec;
63 memset(&rec, 0, sizeof(rec));
64 rec.fFontID = typeface->uniqueID();
65 rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths;
66 rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1;
67 // Don't bake stroke information into the glyphs, we'll let the GPU do the s troking.
68
69 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1));
70 SkDescriptor* genericDesc = ad.getDesc();
71
72 genericDesc->init();
73 genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
74 genericDesc->computeChecksum();
75
76 return this->createPathRange(SkNEW_ARGS(GlyphGenerator, (*typeface, *generic Desc)), stroke);
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698