2016-11-16 15:15:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkBlurMask.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2016-11-16 15:15:23 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-11-16 15:15:23 +00:00
|
|
|
#define WIDTH 800
|
|
|
|
#define HEIGHT 800
|
|
|
|
|
|
|
|
static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
|
|
|
|
const SkPaint& paint, const SkPaint& blurPaint,
|
|
|
|
const SkPaint& clearPaint) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665));
|
|
|
|
canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint);
|
|
|
|
// draw as blurred to push glyph to be too large for atlas
|
|
|
|
canvas->drawTextBlob(blob, 0, 256, blurPaint);
|
|
|
|
canvas->drawTextBlob(blob, 0, 477, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test ensures that glyphs that are too large for the atlas
|
|
|
|
// are both translated and clipped correctly.
|
|
|
|
class ClipErrorGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
ClipErrorGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override { return SkString("cliperror"); }
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); }
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 256);
|
2016-11-16 15:15:23 +00:00
|
|
|
|
|
|
|
// setup up maskfilter
|
|
|
|
const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
|
|
|
|
|
|
|
|
SkPaint blurPaint(paint);
|
2018-03-14 17:01:17 +00:00
|
|
|
blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, kSigma));
|
2016-11-16 15:15:23 +00:00
|
|
|
|
2018-12-22 22:37:30 +00:00
|
|
|
const char text[] = "hambur";
|
|
|
|
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
2016-11-16 15:15:23 +00:00
|
|
|
|
|
|
|
SkPaint clearPaint(paint);
|
|
|
|
clearPaint.setColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 0);
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
|
|
|
|
draw_text(canvas, blob, paint, blurPaint, clearPaint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0, 256);
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
|
|
|
|
draw_text(canvas, blob, paint, blurPaint, clearPaint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2016-11-16 15:15:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new ClipErrorGM;)
|