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