DrawLatticeBench.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "bench/Benchmark.h"
  8. #include "include/core/SkBitmap.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkRect.h"
  11. #include "include/core/SkString.h"
  12. class DrawLatticeBench : public Benchmark {
  13. public:
  14. DrawLatticeBench(int* xDivs, int xCount, int* yDivs, int yCount, const SkISize& srcSize,
  15. const SkRect& dst, const char* desc)
  16. : fSrcSize(srcSize)
  17. , fDst(dst)
  18. {
  19. fLattice.fXDivs = xDivs;
  20. fLattice.fXCount = xCount;
  21. fLattice.fYDivs = yDivs;
  22. fLattice.fYCount = yCount;
  23. fLattice.fRectTypes = nullptr;
  24. fLattice.fBounds = nullptr;
  25. fLattice.fColors = nullptr;
  26. fName = SkStringPrintf("DrawLattice_%s", desc);
  27. }
  28. const char* onGetName() override {
  29. return fName.c_str();
  30. }
  31. SkIPoint onGetSize() override {
  32. return SkIPoint::Make(1000, 1000);
  33. }
  34. bool isSuitableFor(Backend backend) override {
  35. return kRaster_Backend == backend || kGPU_Backend == backend;
  36. }
  37. void onDelayedSetup() override {
  38. fBitmap.allocN32Pixels(fSrcSize.width(), fSrcSize.height());
  39. fBitmap.eraseColor(0x880000FF);
  40. }
  41. void onDraw(int loops, SkCanvas* canvas) override {
  42. for (int i = 0; i < loops; i++) {
  43. canvas->drawBitmapLattice(fBitmap, fLattice, fDst);
  44. }
  45. }
  46. private:
  47. SkISize fSrcSize;
  48. SkCanvas::Lattice fLattice;
  49. SkRect fDst;
  50. SkString fName;
  51. SkBitmap fBitmap;
  52. typedef Benchmark INHERITED;
  53. };
  54. static int gDivs9[2] = { 25, 75, };
  55. DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
  56. SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects9");)
  57. DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
  58. SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects9");)
  59. DEF_BENCH(return new DrawLatticeBench(gDivs9, 2, gDivs9, 2, SkISize::Make(100, 100),
  60. SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects9");)
  61. static int gDivs15[4] = { 15, 45, 55, 85, };
  62. DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
  63. SkRect::MakeWH(250.0f, 250.0f), "Src100_Dst250_Rects15");)
  64. DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
  65. SkRect::MakeWH(500.0f, 500.0f), "Src100_Dst500_Rects15");)
  66. DEF_BENCH(return new DrawLatticeBench(gDivs15, 4, gDivs15, 4, SkISize::Make(100, 100),
  67. SkRect::MakeWH(1000.0f, 1000.0f), "Src100_Dst1000_Rects15");)