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