Revert of adding gm to use random scaler context (patchset #4 id:60001 of https://codereview.chromium.org/1268853008/)

Reason for revert:
breaking bots

Original issue's description:
> adding gm to use random scaler context
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/853336c532504b3436d7dcbf252419f00c79066d

TBR=bsalomon@google.com,joshualitt@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1259033004
This commit is contained in:
joshualitt 2015-07-31 15:10:31 -07:00 committed by Commit bot
parent f96bee384d
commit d164a710c7
2 changed files with 50 additions and 133 deletions

View File

@ -1,132 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkStream.h"
#include "SkSurface.h"
#include "SkTextBlob.h"
#include "SkTypeface.h"
#include "../src/fonts/SkRandomScalerContext.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
namespace skiagm {
class TextBlobRandomFont : public GM {
public:
// This gm tests that textblobs can be translated and scaled with a font that returns random
// but deterministic masks
TextBlobRandomFont() { }
protected:
void onOnceBeforeDraw() override {
SkTextBlobBuilder builder;
const char* text = "The quick brown fox jumps over the lazy dog.";
// make textbloben
SkPaint paint;
paint.setTextSize(32);
paint.setLCDRenderText(true);
// Setup our random scaler context
SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-serif",
SkTypeface::kBold));
if (NULL == orig) {
orig.reset(SkTypeface::RefDefault());
}
SkAutoTUnref<SkTypeface> random(SkNEW_ARGS(SkRandomTypeface, (orig, paint, false)));
paint.setTypeface(random);
SkRect bounds;
paint.measureText(text, strlen(text), &bounds);
SkScalar yOffset = bounds.height();
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
// A8
paint.setSubpixelText(false);
paint.setLCDRenderText(false);
sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 32);
// build
fBlob.reset(builder.build());
}
SkString onShortName() override {
return SkString("textblobrandomfont");
}
SkISize onISize() override {
return SkISize::Make(kWidth, kHeight);
}
void onDraw(SkCanvas* canvas) override {
// This GM exists to test a specific feature of the GPU backend.
if (NULL == canvas->getGrContext()) {
this->drawGpuOnlyMessage(canvas);
return;
}
canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorWHITE));
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props));
if (surface) {
SkPaint paint;
paint.setAntiAlias(true);
SkCanvas* c = surface->getCanvas();
int stride = SkScalarCeilToInt(fBlob->bounds().height() / 2) + 10;
int yOffset = stride;
for (int i = 0; i < 10; i++) {
// fiddle the canvas to force regen of textblobs
canvas->rotate(i % 2 ? 0.0f : -0.05f);
canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint);
yOffset += stride;
// This will draw as black boxes
c->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint);
surface->draw(canvas, 0, 0, nullptr);
// free gpu resources and verify
yOffset += stride;
canvas->getGrContext()->freeGpuResources();
canvas->drawTextBlob(fBlob, 10, SkIntToScalar(yOffset), paint);
yOffset += stride;
}
} else {
const char* text = "This test requires a surface";
size_t len = strlen(text);
SkPaint paint;
canvas->drawText(text, len, 10, 100, paint);
}
}
private:
SkAutoTUnref<const SkTextBlob> fBlob;
static const int kWidth = 1000;
static const int kHeight = 1000;
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return SkNEW(TextBlobRandomFont); )
}
#endif

View File

@ -28,6 +28,7 @@ protected:
private: private:
SkRandomTypeface* fFace; SkRandomTypeface* fFace;
SkScalerContext* fProxy; SkScalerContext* fProxy;
SkMatrix fMatrix;
bool fFakeIt; bool fFakeIt;
}; };
@ -40,7 +41,28 @@ SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDes
: SkScalerContext(face, desc) : SkScalerContext(face, desc)
, fFace(face) , fFace(face)
, fFakeIt(fakeIt) { , fFakeIt(fakeIt) {
fProxy = face->proxy()->createScalerContext(desc); size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec);
SkAutoDescriptor ad(descSize);
SkDescriptor* newDesc = ad.getDesc();
newDesc->init();
void* entry = newDesc->addEntry(kRec_SkDescriptorTag,
sizeof(SkScalerContext::Rec), &fRec);
{
SkScalerContext::Rec* rec = (SkScalerContext::Rec*)entry;
rec->fTextSize = STD_SIZE;
rec->fPreScaleX = SK_Scalar1;
rec->fPreSkewX = 0;
rec->fPost2x2[0][0] = rec->fPost2x2[1][1] = SK_Scalar1;
rec->fPost2x2[1][0] = rec->fPost2x2[0][1] = 0;
}
SkASSERT(descSize == newDesc->getLength());
newDesc->computeChecksum();
fProxy = face->proxy()->createScalerContext(newDesc);
fRec.getSingleMatrix(&fMatrix);
fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE);
} }
SkRandomScalerContext::~SkRandomScalerContext() { SkRandomScalerContext::~SkRandomScalerContext() {
@ -57,6 +79,12 @@ uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) {
void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) { void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) {
fProxy->getAdvance(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);
} }
void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
@ -82,8 +110,15 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
return; return;
} }
if (SkMask::kARGB32_Format == format) { 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; SkPath path;
fProxy->getPath(*glyph, &path); fProxy->getPath(*glyph, &path);
path.transform(fMatrix);
SkRect storage; SkRect storage;
const SkPaint& paint = fFace->paint(); const SkPaint& paint = fFace->paint();
@ -160,6 +195,7 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
SkCanvas canvas(bm); SkCanvas canvas(bm);
canvas.translate(-SkIntToScalar(glyph.fLeft), canvas.translate(-SkIntToScalar(glyph.fLeft),
-SkIntToScalar(glyph.fTop)); -SkIntToScalar(glyph.fTop));
canvas.concat(fMatrix);
canvas.drawPath(path, fFace->paint()); canvas.drawPath(path, fFace->paint());
} else { } else {
fProxy->forceGenerateImageFromPath(); fProxy->forceGenerateImageFromPath();
@ -173,10 +209,23 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) {
fProxy->getPath(glyph, path); fProxy->getPath(glyph, path);
path->transform(fMatrix);
} }
void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
fProxy->getFontMetrics(metrics); fProxy->getFontMetrics(metrics);
if (metrics) {
SkScalar scale = fMatrix.getScaleY();
metrics->fTop = SkScalarMul(metrics->fTop, scale);
metrics->fAscent = SkScalarMul(metrics->fAscent, scale);
metrics->fDescent = SkScalarMul(metrics->fDescent, scale);
metrics->fBottom = SkScalarMul(metrics->fBottom, scale);
metrics->fLeading = SkScalarMul(metrics->fLeading, scale);
metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale);
metrics->fXMin = SkScalarMul(metrics->fXMin, scale);
metrics->fXMax = SkScalarMul(metrics->fXMax, scale);
metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale);
}
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////