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

Unified Diff: src/fonts/SkRandomScalerContext.cpp

Issue 1267623004: Revert of Modifying TextBlobCacheTest to use SkRandomScalerContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/fonts/SkRandomScalerContext.cpp
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index 9a68e503762d7e50323ee59c0432516198e50e4c..2bfa289937fadc070072c1f09b1565f850925baf 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -9,11 +9,10 @@
#include "SkGlyph.h"
#include "SkPath.h"
#include "SkCanvas.h"
-#include "SkRasterizer.h"
class SkRandomScalerContext : public SkScalerContext {
public:
- SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*, bool fFakeIt);
+ SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*);
virtual ~SkRandomScalerContext();
protected:
@@ -29,18 +28,15 @@
SkRandomTypeface* fFace;
SkScalerContext* fProxy;
SkMatrix fMatrix;
- bool fFakeIt;
};
#define STD_SIZE 1
#include "SkDescriptor.h"
-SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDescriptor* desc,
- bool fakeIt)
+SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDescriptor* desc)
: SkScalerContext(face, desc)
- , fFace(face)
- , fFakeIt(fakeIt) {
+ , fFace(face) {
size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
SkAutoDescriptor ad(descSize);
SkDescriptor* newDesc = ad.getDesc();
@@ -88,10 +84,34 @@
}
void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
+ fProxy->getAdvance(glyph);
+
+ SkVector advance;
+ fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
+ SkFixedToScalar(glyph->fAdvanceY), &advance);
+ glyph->fAdvanceX = SkScalarToFixed(advance.fX);
+ glyph->fAdvanceY = SkScalarToFixed(advance.fY);
+
+ SkPath path;
+ fProxy->getPath(*glyph, &path);
+ path.transform(fMatrix);
+
+ SkRect storage;
+ const SkPaint& paint = fFace->paint();
+ const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
+ &storage,
+ SkPaint::kFill_Style);
+ SkIRect ibounds;
+ newBounds.roundOut(&ibounds);
+ glyph->fLeft = ibounds.fLeft;
+ glyph->fTop = ibounds.fTop;
+ glyph->fWidth = ibounds.width();
+ glyph->fHeight = ibounds.height();
+
// Here we will change the mask format of the glyph
// NOTE this is being overridden by the base class
SkMask::Format format;
- switch (glyph->getGlyphID() % 3) {
+ switch (glyph->getGlyphID() % 6) {
case 0:
format = SkMask::kLCD16_Format;
break;
@@ -101,77 +121,28 @@
case 2:
format = SkMask::kARGB32_Format;
break;
+ default:
+ // we will fiddle with these in generate image
+ format = (SkMask::Format)MASK_FORMAT_UNKNOWN;
}
glyph->fMaskFormat = format;
- fProxy->getMetrics(glyph);
-
- if (SkMask::kARGB32_Format == format) {
- SkVector advance;
- fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
- SkFixedToScalar(glyph->fAdvanceY), &advance);
- glyph->fAdvanceX = SkScalarToFixed(advance.fX);
- glyph->fAdvanceY = SkScalarToFixed(advance.fY);
-
- SkPath path;
- fProxy->getPath(*glyph, &path);
- path.transform(fMatrix);
-
- SkRect storage;
- const SkPaint& paint = fFace->paint();
- const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
- &storage,
- SkPaint::kFill_Style);
- SkIRect ibounds;
- newBounds.roundOut(&ibounds);
- glyph->fLeft = ibounds.fLeft;
- glyph->fTop = ibounds.fTop;
- glyph->fWidth = ibounds.width();
- glyph->fHeight = ibounds.height();
- } else {
- SkPath devPath, fillPath;
- SkMatrix fillToDevMatrix;
-
- this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
-
- // just use devPath
- const SkIRect ir = devPath.getBounds().roundOut();
-
- if (ir.isEmpty() || !ir.is16Bit()) {
- glyph->fLeft = 0;
- glyph->fTop = 0;
- glyph->fWidth = 0;
- glyph->fHeight = 0;
- return;
- }
- glyph->fLeft = ir.fLeft;
- glyph->fTop = ir.fTop;
- glyph->fWidth = SkToU16(ir.width());
- glyph->fHeight = SkToU16(ir.height());
-
- if (glyph->fWidth > 0) {
- switch (glyph->fMaskFormat) {
- case SkMask::kLCD16_Format:
- glyph->fWidth += 2;
- glyph->fLeft -= 1;
- break;
- default:
- break;
- }
- }
- }
}
void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
- switch (glyph.getGlyphID() % 3) {
+ switch (glyph.getGlyphID() % 6) {
case 0:
+ case 1:
+ case 2:
+ break;
+ case 3:
format = SkMask::kLCD16_Format;
break;
- case 1:
+ case 4:
format = SkMask::kA8_Format;
break;
- case 2:
+ case 5:
format = SkMask::kARGB32_Format;
break;
}
@@ -179,28 +150,24 @@
// if the format is ARGB, we just draw the glyph from path ourselves. Otherwise, we force
// our proxy context to generate the image from paths.
- if (!fFakeIt) {
- if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
- SkPath path;
- fProxy->getPath(glyph, &path);
-
- SkBitmap bm;
- bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight),
- glyph.fImage, glyph.rowBytes());
- bm.eraseColor(0);
-
- SkCanvas canvas(bm);
- canvas.translate(-SkIntToScalar(glyph.fLeft),
- -SkIntToScalar(glyph.fTop));
- canvas.concat(fMatrix);
- canvas.drawPath(path, fFace->paint());
- } else {
- fProxy->forceGenerateImageFromPath();
- fProxy->getImage(glyph);
- fProxy->forceOffGenerateImageFromPath();
- }
+ if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
+ SkPath path;
+ fProxy->getPath(glyph, &path);
+
+ SkBitmap bm;
+ bm.installPixels(SkImageInfo::MakeN32Premul(glyph.fWidth, glyph.fHeight),
+ glyph.fImage, glyph.rowBytes());
+ bm.eraseColor(0);
+
+ SkCanvas canvas(bm);
+ canvas.translate(-SkIntToScalar(glyph.fLeft),
+ -SkIntToScalar(glyph.fTop));
+ canvas.concat(fMatrix);
+ canvas.drawPath(path, fFace->paint());
} else {
- sk_bzero(glyph.fImage, glyph.computeImageSize());
+ this->forceGenerateImageFromPath();
+ fProxy->getImage(glyph);
+ this->forceOffGenerateImageFromPath();
}
}
@@ -229,11 +196,10 @@
#include "SkTypefaceCache.h"
-SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt)
+SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint)
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
, fProxy(SkRef(proxy))
- , fPaint(paint)
- , fFakeIt(fakeIt) {}
+ , fPaint(paint) {}
SkRandomTypeface::~SkRandomTypeface() {
fProxy->unref();
@@ -241,7 +207,7 @@
SkScalerContext* SkRandomTypeface::onCreateScalerContext(
const SkDescriptor* desc) const {
- return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this), desc, fFakeIt));
+ return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this), desc));
}
void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698