textblobgeometrychange.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  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. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkFont.h"
  10. #include "include/core/SkImageInfo.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkRect.h"
  13. #include "include/core/SkRefCnt.h"
  14. #include "include/core/SkScalar.h"
  15. #include "include/core/SkSize.h"
  16. #include "include/core/SkString.h"
  17. #include "include/core/SkSurface.h"
  18. #include "include/core/SkSurfaceProps.h"
  19. #include "include/core/SkTextBlob.h"
  20. #include "include/core/SkTypeface.h"
  21. #include "tools/ToolUtils.h"
  22. // This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
  23. // changes when we have LCD. crbug/486744
  24. namespace skiagm {
  25. class TextBlobGeometryChange : public GM {
  26. public:
  27. TextBlobGeometryChange() { }
  28. protected:
  29. SkString onShortName() override {
  30. return SkString("textblobgeometrychange");
  31. }
  32. SkISize onISize() override {
  33. return SkISize::Make(kWidth, kHeight);
  34. }
  35. void onDraw(SkCanvas* canvas) override {
  36. const char text[] = "Hamburgefons";
  37. SkFont font(ToolUtils::create_portable_typeface(), 20);
  38. font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
  39. SkTextBlobBuilder builder;
  40. ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
  41. sk_sp<SkTextBlob> blob(builder.make());
  42. SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
  43. SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
  44. auto surface = ToolUtils::makeSurface(canvas, info, &props);
  45. SkCanvas* c = surface->getCanvas();
  46. // LCD text on white background
  47. SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
  48. SkPaint rectPaint;
  49. rectPaint.setColor(0xffffffff);
  50. canvas->drawRect(rect, rectPaint);
  51. canvas->drawTextBlob(blob, 10, 50, SkPaint());
  52. // This should not look garbled since we should disable LCD text in this case
  53. // (i.e., unknown pixel geometry)
  54. c->clear(0x00ffffff);
  55. c->drawTextBlob(blob, 10, 150, SkPaint());
  56. surface->draw(canvas, 0, 0, nullptr);
  57. }
  58. private:
  59. static constexpr int kWidth = 200;
  60. static constexpr int kHeight = 200;
  61. typedef GM INHERITED;
  62. };
  63. //////////////////////////////////////////////////////////////////////////////
  64. DEF_GM(return new TextBlobGeometryChange;)
  65. }