blob: f84a55fbf4d554e07796cd42934eab48e307f836 [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"
9
10#include "SkCanvas.h"
11#include "SkSurface.h"
12#include "SkTextBlob.h"
13
14// This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
15// changes when we have LCD. crbug/486744
16namespace skiagm {
17class TextBlobGeometryChange : public GM {
18public:
19 TextBlobGeometryChange() { }
20
21protected:
22 SkString onShortName() override {
23 return SkString("textblobgeometrychange");
24 }
25
26 SkISize onISize() override {
27 return SkISize::Make(kWidth, kHeight);
28 }
29
30 void onDraw(SkCanvas* canvas) override {
31 const char text[] = "Hamburgefons";
32
33 SkPaint paint;
caryclark1818acb2015-07-24 12:09:25 -070034 sk_tool_utils::set_portable_typeface(&paint);
joshualitte4cee1f2015-05-11 13:04:28 -070035 paint.setTextSize(20);
36 paint.setAntiAlias(true);
37 paint.setLCDRenderText(true);
38
39 SkTextBlobBuilder builder;
40
41 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10);
42
fmalita37283c22016-09-13 10:00:23 -070043 sk_sp<SkTextBlob> blob(builder.make());
joshualitte4cee1f2015-05-11 13:04:28 -070044
brianosman0e22eb82016-08-30 07:07:59 -070045 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
brianosman3a0dbde2016-07-26 11:36:05 -070046 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
mtklein9e65f932016-04-06 13:57:38 -070047 auto surface = canvas->makeSurface(info, &props);
48 if (!surface) {
49 surface = SkSurface::MakeRaster(info, &props);
joshualitte4cee1f2015-05-11 13:04:28 -070050 }
mtklein9e65f932016-04-06 13:57:38 -070051 SkCanvas* c = surface->getCanvas();
52
53 // LCD text on white background
54 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
55 SkPaint rectPaint;
56 rectPaint.setColor(0xffffffff);
57 canvas->drawRect(rect, rectPaint);
fmalita37283c22016-09-13 10:00:23 -070058 canvas->drawTextBlob(blob, 10, 50, paint);
mtklein9e65f932016-04-06 13:57:38 -070059
60 // This should not look garbled since we should disable LCD text in this case
61 // (i.e., unknown pixel geometry)
62 c->clear(0x00ffffff);
fmalita37283c22016-09-13 10:00:23 -070063 c->drawTextBlob(blob, 10, 150, paint);
mtklein9e65f932016-04-06 13:57:38 -070064 surface->draw(canvas, 0, 0, nullptr);
joshualitte4cee1f2015-05-11 13:04:28 -070065 }
66
67private:
mtkleindbfd7ab2016-09-01 11:24:54 -070068 static constexpr int kWidth = 200;
69 static constexpr int kHeight = 200;
joshualitte4cee1f2015-05-11 13:04:28 -070070
71 typedef GM INHERITED;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
halcanary385fe4d2015-08-26 13:07:48 -070076DEF_GM(return new TextBlobGeometryChange;)
joshualitte4cee1f2015-05-11 13:04:28 -070077}