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