1 /* 2 * Copyright 2017 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 "SkCanvas.h" 9 #include "SkPaint.h" 10 #include "SkRRect.h" 11 #include "gm.h" 12 13 DEF_SIMPLE_GM(drrect_small_inner, canvas, 170, 610) { 14 SkPaint paint; 15 paint.setAntiAlias(true); 16 static constexpr SkScalar kOuterRadius = 35.f; 17 auto outer = SkRRect::MakeOval(SkRect::MakeXYWH(0, 0, 2 * kOuterRadius, 2 * kOuterRadius)); 18 canvas->translate(10.f, 10.f); 19 canvas->save(); 20 for (bool offcenter : {false, true}) { 21 for (bool oval : {false, true}) { 22 for (SkScalar innerRadiusX : {1.f, 0.5f, 0.1f, .01f}) { 23 SkScalar innerRadiusY = innerRadiusX; 24 if (oval) { 25 innerRadiusY *= 0.95f; 26 } 27 SkScalar tx = kOuterRadius - innerRadiusX; 28 SkScalar ty = kOuterRadius - innerRadiusY; 29 if (offcenter) { 30 tx += 1.f; 31 } 32 auto inner = SkRRect::MakeOval( 33 SkRect::MakeXYWH(tx, ty, 2 * innerRadiusX, 2 * innerRadiusY)); 34 canvas->drawDRRect(outer, inner, paint); 35 canvas->translate(0, 2 * kOuterRadius + 5); 36 } 37 } 38 canvas->restore(); 39 canvas->translate(2 * kOuterRadius + 2, 0); 40 } 41 canvas->restore(); 42 } 43