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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrPathRendering.cpp
diff --git a/src/gpu/GrPathRendering.cpp b/src/gpu/GrPathRendering.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..eeb2fbeeeaa9f0075d7fa615c594c40f0f153b24
--- /dev/null
+++ b/src/gpu/GrPathRendering.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrPathRendering.h"
+#include "SkDescriptor.h"
+#include "SkGlyph.h"
+#include "SkMatrix.h"
+#include "SkTypeface.h"
+#include "GrPathRange.h"
+
+class GlyphGenerator : public GrPathRange::PathGenerator {
+public:
+ GlyphGenerator(const SkTypeface& typeface, const SkDescriptor& desc)
+ : fDesc(desc.copy()),
+ fScalerContext(typeface.createScalerContext(fDesc)) {
+ fFlipMatrix.setScale(1, -1);
+ }
+
+ virtual ~GlyphGenerator() {
+ SkDescriptor::Free(fDesc);
+ }
+
+ virtual uint32_t getNumPaths() {
+ return fScalerContext->getGlyphCount();
+ }
+
+ virtual void generatePath(uint32_t glyphID, SkPath* out) {
+ SkGlyph skGlyph;
+ skGlyph.init(SkGlyph::MakeID(glyphID));
+ fScalerContext->getMetrics(&skGlyph);
+
+ fScalerContext->getPath(skGlyph, out);
+ out->transform(fFlipMatrix); // Load glyphs with the inverted y-direction.
+ }
+
+ virtual bool isEqualTo(const SkDescriptor& desc) const {
+ return fDesc->equals(desc);
+ }
+
+private:
+ SkDescriptor* const fDesc;
+ const SkAutoTDelete<SkScalerContext> fScalerContext;
+ SkMatrix fFlipMatrix;
+};
+
+GrPathRange* GrPathRendering::createGlyphs(const SkTypeface* typeface,
+ const SkDescriptor* desc,
+ const SkStrokeRec& stroke) {
+ if (NULL == typeface) {
+ typeface = SkTypeface::GetDefaultTypeface();
+ SkASSERT(NULL != typeface);
+ }
+
+ if (desc) {
+ return this->createPathRange(SkNEW_ARGS(GlyphGenerator, (*typeface, *desc)), stroke);
+ }
+
+ SkScalerContextRec rec;
+ memset(&rec, 0, sizeof(rec));
+ rec.fFontID = typeface->uniqueID();
+ rec.fTextSize = SkPaint::kCanonicalTextSizeForPaths;
+ rec.fPreScaleX = rec.fPost2x2[0][0] = rec.fPost2x2[1][1] = SK_Scalar1;
+ // Don't bake stroke information into the glyphs, we'll let the GPU do the stroking.
+
+ SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1));
+ SkDescriptor* genericDesc = ad.getDesc();
+
+ genericDesc->init();
+ genericDesc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
+ genericDesc->computeChecksum();
+
+ return this->createPathRange(SkNEW_ARGS(GlyphGenerator, (*typeface, *genericDesc)), stroke);
+}

Powered by Google App Engine
This is Rietveld 408576698