| 1 |
/* |
| 2 |
* Copyright 2024 Google LLC. |
| 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/SkImageInfo.h" |
| 11 |
#include "include/core/SkPaint.h" |
| 12 |
#include "include/core/SkSurface.h" |
| 13 |
|
| 14 |
static void draw_small_circle(SkCanvas* canvas, const SkPaint& p, const float radius) { |
| 15 |
SkRect oval = SkRect::MakeLTRB(radius * -1, radius * -1, radius, radius); |
| 16 |
constexpr bool kUseCenter = false; |
| 17 |
constexpr float kDegrees = 360; |
| 18 |
canvas->drawArc(oval, 0, kDegrees, kUseCenter, p); |
| 19 |
} |
| 20 |
|
| 21 |
DEF_SIMPLE_GM(smallcircles, canvas, 425, 425) { |
| 22 |
auto surface = canvas->makeSurface(SkImageInfo::MakeN32Premul(100, 100)); |
| 23 |
if (!surface) { |
| 24 |
surface = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100)); |
| 25 |
} |
| 26 |
SkCanvas* canv = surface->getCanvas(); |
| 27 |
|
| 28 |
canv->translate(5, 5); |
| 29 |
SkPaint p; |
| 30 |
p.setAntiAlias(true); |
| 31 |
p.setStyle(SkPaint::kFill_Style); |
| 32 |
|
| 33 |
// Draw circles |
| 34 |
for (int i = 0; i < 11; ++i) { |
| 35 |
canv->save(); |
| 36 |
for (int j = 0; j < 11; ++j) { |
| 37 |
draw_small_circle(canv, p, 0.8f); |
| 38 |
canv->translate(5.1f, 0.f); |
| 39 |
} |
| 40 |
canv->restore(); |
| 41 |
canv->translate(0.f, 5.1f); |
| 42 |
} |
| 43 |
|
| 44 |
// Scale up image of small circles |
| 45 |
canvas->scale(7, 7); |
| 46 |
auto img = surface->makeImageSnapshot(); |
| 47 |
canvas->drawImage(img, 0, 0); |
| 48 |
} |