• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRRect.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSize.h"
16 #include "include/core/SkString.h"
17 #include "include/core/SkTypes.h"
18 
19 class DRRectGM : public skiagm::GM {
20 public:
DRRectGM()21     DRRectGM() {}
22 
23 protected:
24 
onShortName()25     SkString onShortName() override {
26         return SkString("drrect");
27     }
28 
onISize()29     SkISize onISize() override {
30         return SkISize::Make(640, 480);
31     }
32 
onDraw(SkCanvas * canvas)33     void onDraw(SkCanvas* canvas) override {
34         SkPaint paint;
35         paint.setAntiAlias(true);
36 
37         SkRRect outers[4];
38         // like squares/circles, to exercise fast-cases in GPU
39         SkRect r = { 0, 0, 100, 100 };
40         SkVector radii[4] = {
41             { 0, 0 }, { 30, 1 }, { 10, 40 }, { 40, 40 }
42         };
43 
44         const SkScalar dx = r.width() + 16;
45         const SkScalar dy = r.height() + 16;
46 
47         outers[0].setRect(r);
48         outers[1].setOval(r);
49         outers[2].setRectXY(r, 20, 20);
50         outers[3].setRectRadii(r, radii);
51 
52         SkRRect inners[5];
53         r.inset(25, 25);
54 
55         inners[0].setEmpty();
56         inners[1].setRect(r);
57         inners[2].setOval(r);
58         inners[3].setRectXY(r, 20, 20);
59         inners[4].setRectRadii(r, radii);
60 
61         canvas->translate(16, 16);
62         for (size_t j = 0; j < SK_ARRAY_COUNT(inners); ++j) {
63             for (size_t i = 0; i < SK_ARRAY_COUNT(outers); ++i) {
64                 canvas->save();
65                 canvas->translate(dx * j, dy * i);
66                 canvas->drawDRRect(outers[i], inners[j], paint);
67                 canvas->restore();
68             }
69         }
70     }
71 
72 private:
73     using INHERITED = GM;
74 };
75 
76 DEF_GM( return new DRRectGM; )
77