badpaint.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/SkBitmap.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkColor.h"
  11. #include "include/core/SkMatrix.h"
  12. #include "include/core/SkPaint.h"
  13. #include "include/core/SkRect.h"
  14. #include "include/core/SkShader.h"
  15. #include "include/core/SkSize.h"
  16. #include "include/core/SkString.h"
  17. #include "include/private/SkTArray.h"
  18. /** This GM draws with invalid paints. It should draw nothing other than the background. */
  19. class BadPaintGM : public skiagm::GM {
  20. public:
  21. BadPaintGM() {}
  22. protected:
  23. SkString onShortName() override { return SkString("badpaint"); }
  24. SkISize onISize() override { return SkISize::Make(100, 100); }
  25. void onOnceBeforeDraw() override {
  26. SkBitmap emptyBmp;
  27. SkBitmap blueBmp;
  28. blueBmp.allocN32Pixels(10, 10);
  29. blueBmp.eraseColor(SK_ColorBLUE);
  30. SkMatrix badMatrix;
  31. badMatrix.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
  32. // Empty bitmap.
  33. fPaints.push_back().setColor(SK_ColorGREEN);
  34. fPaints.back().setShader(emptyBmp.makeShader());
  35. // Non-invertible local matrix.
  36. fPaints.push_back().setColor(SK_ColorGREEN);
  37. fPaints.back().setShader(blueBmp.makeShader(&badMatrix));
  38. }
  39. void onDraw(SkCanvas* canvas) override {
  40. SkRect rect = SkRect::MakeXYWH(10, 10, 80, 80);
  41. for (int i = 0; i < fPaints.count(); ++i) {
  42. canvas->drawRect(rect, fPaints[i]);
  43. }
  44. }
  45. private:
  46. SkTArray<SkPaint> fPaints;
  47. typedef skiagm::GM INHERITED;
  48. };
  49. /////////////////////////////////////////////////////////////////////////////////////
  50. DEF_GM(return new BadPaintGM;)