stlouisarch.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-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/SkPaint.h"
  10. #include "include/core/SkPath.h"
  11. #include "include/core/SkScalar.h"
  12. #include "include/core/SkSize.h"
  13. #include "include/core/SkString.h"
  14. #include "include/private/SkTArray.h"
  15. namespace skiagm {
  16. // this GM tests hairlines which fill nearly the entire render target
  17. class StLouisArchGM : public GM {
  18. protected:
  19. SkString onShortName() override {
  20. return SkString("stlouisarch");
  21. }
  22. SkISize onISize() override { return SkISize::Make((int)kWidth, (int)kHeight); }
  23. void onOnceBeforeDraw() override {
  24. {
  25. SkPath* bigQuad = &fPaths.push_back();
  26. bigQuad->moveTo(0, 0);
  27. bigQuad->quadTo(kWidth/2, kHeight, kWidth, 0);
  28. }
  29. {
  30. SkPath* degenBigQuad = &fPaths.push_back();
  31. SkScalar yPos = kHeight / 2 + 10;
  32. degenBigQuad->moveTo(0, yPos);
  33. degenBigQuad->quadTo(0, yPos, kWidth, yPos);
  34. }
  35. {
  36. SkPath* bigCubic = &fPaths.push_back();
  37. bigCubic->moveTo(0, 0);
  38. bigCubic->cubicTo(0, kHeight,
  39. kWidth, kHeight,
  40. kWidth, 0);
  41. }
  42. {
  43. SkPath* degenBigCubic = &fPaths.push_back();
  44. SkScalar yPos = kHeight / 2;
  45. degenBigCubic->moveTo(0, yPos);
  46. degenBigCubic->cubicTo(0, yPos,
  47. 0, yPos,
  48. kWidth, yPos);
  49. }
  50. {
  51. SkPath* bigConic = &fPaths.push_back();
  52. bigConic->moveTo(0, 0);
  53. bigConic->conicTo(kWidth/2, kHeight, kWidth, 0, .5);
  54. }
  55. {
  56. SkPath* degenBigConic = &fPaths.push_back();
  57. SkScalar yPos = kHeight / 2 - 10;
  58. degenBigConic->moveTo(0, yPos);
  59. degenBigConic->conicTo(0, yPos, kWidth, yPos, .5);
  60. }
  61. }
  62. void onDraw(SkCanvas* canvas) override {
  63. canvas->save();
  64. canvas->scale(1, -1);
  65. canvas->translate(0, -kHeight);
  66. for (int p = 0; p < fPaths.count(); ++p) {
  67. SkPaint paint;
  68. paint.setARGB(0xff, 0, 0, 0);
  69. paint.setAntiAlias(true);
  70. paint.setStyle(SkPaint::kStroke_Style);
  71. paint.setStrokeWidth(0);
  72. canvas->drawPath(fPaths[p], paint);
  73. }
  74. canvas->restore();
  75. }
  76. const SkScalar kWidth = 256;
  77. const SkScalar kHeight = 256;
  78. private:
  79. SkTArray<SkPath> fPaths;
  80. typedef GM INHERITED;
  81. };
  82. //////////////////////////////////////////////////////////////////////////////
  83. DEF_GM( return new StLouisArchGM; )
  84. }