blob: b86ee3a17eebad902c595861413c4956151a81b1 [file] [log] [blame]
joshualitte4cee1f2015-05-11 13:04:28 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
joshualitte4cee1f2015-05-11 13:04:28 -070010
11#include "SkCanvas.h"
12#include "SkSurface.h"
13#include "SkTextBlob.h"
14
15// This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
16// changes when we have LCD. crbug/486744
17namespace skiagm {
18class TextBlobGeometryChange : public GM {
19public:
20 TextBlobGeometryChange() { }
21
22protected:
23 SkString onShortName() override {
24 return SkString("textblobgeometrychange");
25 }
26
27 SkISize onISize() override {
28 return SkISize::Make(kWidth, kHeight);
29 }
30
31 void onDraw(SkCanvas* canvas) override {
32 const char text[] = "Hamburgefons";
33
34 SkPaint paint;
caryclark1818acb2015-07-24 12:09:25 -070035 sk_tool_utils::set_portable_typeface(&paint);
joshualitte4cee1f2015-05-11 13:04:28 -070036 paint.setTextSize(20);
37 paint.setAntiAlias(true);
38 paint.setLCDRenderText(true);
39
40 SkTextBlobBuilder builder;
41
42 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10);
43
fmalita37283c22016-09-13 10:00:23 -070044 sk_sp<SkTextBlob> blob(builder.make());
joshualitte4cee1f2015-05-11 13:04:28 -070045
brianosman0e22eb82016-08-30 07:07:59 -070046 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
brianosman3a0dbde2016-07-26 11:36:05 -070047 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
mtklein9e65f932016-04-06 13:57:38 -070048 auto surface = canvas->makeSurface(info, &props);
49 if (!surface) {
50 surface = SkSurface::MakeRaster(info, &props);
joshualitte4cee1f2015-05-11 13:04:28 -070051 }
mtklein9e65f932016-04-06 13:57:38 -070052 SkCanvas* c = surface->getCanvas();
53
54 // LCD text on white background
55 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
56 SkPaint rectPaint;
57 rectPaint.setColor(0xffffffff);
58 canvas->drawRect(rect, rectPaint);
fmalita37283c22016-09-13 10:00:23 -070059 canvas->drawTextBlob(blob, 10, 50, paint);
mtklein9e65f932016-04-06 13:57:38 -070060
61 // This should not look garbled since we should disable LCD text in this case
62 // (i.e., unknown pixel geometry)
63 c->clear(0x00ffffff);
fmalita37283c22016-09-13 10:00:23 -070064 c->drawTextBlob(blob, 10, 150, paint);
mtklein9e65f932016-04-06 13:57:38 -070065 surface->draw(canvas, 0, 0, nullptr);
joshualitte4cee1f2015-05-11 13:04:28 -070066 }
67
68private:
mtkleindbfd7ab2016-09-01 11:24:54 -070069 static constexpr int kWidth = 200;
70 static constexpr int kHeight = 200;
joshualitte4cee1f2015-05-11 13:04:28 -070071
72 typedef GM INHERITED;
73};
74
75//////////////////////////////////////////////////////////////////////////////
76
halcanary385fe4d2015-08-26 13:07:48 -070077DEF_GM(return new TextBlobGeometryChange;)
joshualitte4cee1f2015-05-11 13:04:28 -070078}