2015-05-11 20:04:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#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/SkSurface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkSurfaceProps.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"
|
|
|
|
#include "tools/ToolUtils.h"
|
2015-05-11 20:04:28 +00:00
|
|
|
|
|
|
|
// This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
|
|
|
|
// changes when we have LCD. crbug/486744
|
|
|
|
namespace skiagm {
|
|
|
|
class TextBlobGeometryChange : public GM {
|
|
|
|
public:
|
|
|
|
TextBlobGeometryChange() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("textblobgeometrychange");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
const char text[] = "Hamburgefons";
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 20);
|
2018-12-23 03:29:45 +00:00
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
2015-05-11 20:04:28 +00:00
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
|
2015-05-11 20:04:28 +00:00
|
|
|
|
2016-09-13 17:00:23 +00:00
|
|
|
sk_sp<SkTextBlob> blob(builder.make());
|
2015-05-11 20:04:28 +00:00
|
|
|
|
2016-08-30 14:07:59 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
|
2016-07-26 18:36:05 +00:00
|
|
|
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
|
2019-03-20 16:12:10 +00:00
|
|
|
auto surface = ToolUtils::makeSurface(canvas, info, &props);
|
2016-04-06 20:57:38 +00:00
|
|
|
SkCanvas* c = surface->getCanvas();
|
|
|
|
|
|
|
|
// LCD text on white background
|
|
|
|
SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
|
|
|
|
SkPaint rectPaint;
|
|
|
|
rectPaint.setColor(0xffffffff);
|
|
|
|
canvas->drawRect(rect, rectPaint);
|
2018-12-23 03:29:45 +00:00
|
|
|
canvas->drawTextBlob(blob, 10, 50, SkPaint());
|
2016-04-06 20:57:38 +00:00
|
|
|
|
|
|
|
// This should not look garbled since we should disable LCD text in this case
|
|
|
|
// (i.e., unknown pixel geometry)
|
|
|
|
c->clear(0x00ffffff);
|
2018-12-23 03:29:45 +00:00
|
|
|
c->drawTextBlob(blob, 10, 150, SkPaint());
|
2021-01-06 13:43:51 +00:00
|
|
|
surface->draw(canvas, 0, 0);
|
2015-05-11 20:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kWidth = 200;
|
|
|
|
static constexpr int kHeight = 200;
|
2015-05-11 20:04:28 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2015-05-11 20:04:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TextBlobGeometryChange;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|