Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
|
robertphillips
2015/05/11 19:15:26
BD style ?
| |
| 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 | |
|
robertphillips
2015/05/11 19:15:26
Don't think we need Resources.h either.
| |
| 10 #include "Resources.h" | |
| 11 #include "SkCanvas.h" | |
|
robertphillips
2015/05/11 19:15:26
SkStream.h ?
| |
| 12 #include "SkStream.h" | |
| 13 #include "SkSurface.h" | |
| 14 #include "SkTextBlob.h" | |
| 15 #include "SkTypeface.h" | |
| 16 | |
| 17 // This tests that we don't try to reuse textblobs from the GPU textblob cache a cross pixel geometry | |
| 18 // changes when we have LCD. crbug/486744 | |
| 19 namespace skiagm { | |
| 20 class TextBlobGeometryChange : public GM { | |
| 21 public: | |
| 22 TextBlobGeometryChange() { } | |
| 23 | |
| 24 protected: | |
| 25 SkString onShortName() override { | |
| 26 return SkString("textblobgeometrychange"); | |
| 27 } | |
| 28 | |
| 29 SkISize onISize() override { | |
| 30 return SkISize::Make(kWidth, kHeight); | |
| 31 } | |
| 32 | |
| 33 void onDraw(SkCanvas* canvas) override { | |
| 34 const char text[] = "Hamburgefons"; | |
| 35 | |
| 36 SkPaint paint; | |
| 37 sk_tool_utils::set_portable_typeface(&paint); | |
| 38 paint.setTextSize(20); | |
| 39 paint.setAntiAlias(true); | |
| 40 paint.setLCDRenderText(true); | |
| 41 | |
| 42 SkTextBlobBuilder builder; | |
| 43 | |
| 44 sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10); | |
| 45 | |
| 46 SkAutoTUnref<const SkTextBlob> blob(builder.build()); | |
| 47 | |
| 48 SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); | |
| 49 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | |
| 50 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info, &props)); | |
| 51 if (surface) { | |
| 52 SkCanvas* c = surface->getCanvas(); | |
| 53 | |
| 54 // LCD text on white background | |
| 55 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight / 2); | |
| 56 SkPaint rectPaint; | |
| 57 rectPaint.setColor(0xffffffff); | |
| 58 canvas->drawRect(rect, rectPaint); | |
| 59 canvas->drawTextBlob(blob.get(), 10, 50, paint); | |
| 60 | |
| 61 // This should not look garbled | |
|
robertphillips
2015/05/11 19:15:26
since we should disable LCD text in this case (i.e
| |
| 62 c->clear(0x00ffffff); | |
| 63 c->drawTextBlob(blob.get(), 10, 150, paint); | |
| 64 surface->draw(canvas, 0, 0, nullptr); | |
| 65 } else { | |
| 66 const char* text = "This test requires a surface"; | |
| 67 size_t len = strlen(text); | |
| 68 SkPaint paint; | |
| 69 canvas->drawText(text, len, 10, 100, paint); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 static const int kWidth = 200; | |
| 75 static const int kHeight = 200; | |
| 76 | |
| 77 typedef GM INHERITED; | |
| 78 }; | |
| 79 | |
| 80 ////////////////////////////////////////////////////////////////////////////// | |
| 81 | |
| 82 DEF_GM( return SkNEW(TextBlobGeometryChange); ) | |
| 83 } | |
| OLD | NEW |