simplerect.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2016 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/SkRect.h"
  11. #include "include/core/SkScalar.h"
  12. #include "include/core/SkSize.h"
  13. #include "include/core/SkString.h"
  14. #include "include/utils/SkRandom.h"
  15. #include "tools/ToolUtils.h"
  16. class SimpleRectGM : public skiagm::GM {
  17. public:
  18. SimpleRectGM() {}
  19. protected:
  20. SkString onShortName() override {
  21. SkString name;
  22. name.printf("simplerect");
  23. return name;
  24. }
  25. SkISize onISize() override {
  26. return SkISize::Make(800, 800);
  27. }
  28. void onDraw(SkCanvas* canvas) override {
  29. canvas->translate(1, 1); // want to exercise non-identity ctm performance
  30. const SkScalar min = -20;
  31. const SkScalar max = 800;
  32. const SkScalar size = 20;
  33. SkRandom rand;
  34. SkPaint paint;
  35. for (int i = 0; i < 10000; i++) {
  36. paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24)));
  37. SkScalar x = rand.nextRangeScalar(min, max);
  38. SkScalar y = rand.nextRangeScalar(min, max);
  39. SkScalar w = rand.nextRangeScalar(0, size);
  40. SkScalar h = rand.nextRangeScalar(0, size);
  41. canvas->drawRect(SkRect::MakeXYWH(x, y, w, h), paint);
  42. }
  43. }
  44. bool onAnimate(double nanos) override { return true; }
  45. private:
  46. typedef GM INHERITED;
  47. };
  48. DEF_GM(return new SimpleRectGM;)