2012-10-30 20:26:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2012-10-30 20:26:58 +00:00
|
|
|
|
|
|
|
#define ZOOM 32
|
|
|
|
#define SMALL_W 9
|
|
|
|
#define SMALL_H 3
|
|
|
|
#define REPEAT_LOOP 5
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static sk_sp<SkSurface> new_surface(int width, int height) {
|
|
|
|
return SkSurface::MakeRasterN32Premul(width, height);
|
2012-10-30 20:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_pixel_centers(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
2019-03-20 16:12:10 +00:00
|
|
|
paint.setColor(ToolUtils::color_to_565(0xFF0088FF));
|
2012-10-30 20:26:58 +00:00
|
|
|
paint.setAntiAlias(true);
|
2012-10-31 02:01:18 +00:00
|
|
|
|
2012-10-30 20:26:58 +00:00
|
|
|
for (int y = 0; y < SMALL_H; ++y) {
|
|
|
|
for (int x = 0; x < SMALL_W; ++x) {
|
|
|
|
canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 19:16:53 +00:00
|
|
|
static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) {
|
2012-10-30 20:26:58 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
2012-12-06 21:47:40 +00:00
|
|
|
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
|
2015-06-09 19:16:53 +00:00
|
|
|
surface->getCanvas()->drawPath(path, paint);
|
2021-01-06 13:43:51 +00:00
|
|
|
surface->draw(canvas, 0, 0);
|
2012-10-30 20:26:58 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2015-06-09 19:16:53 +00:00
|
|
|
canvas->drawPath(path, paint);
|
2012-10-30 20:26:58 +00:00
|
|
|
|
|
|
|
draw_pixel_centers(canvas);
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(fatpathfill, canvas,
|
|
|
|
SMALL_W * ZOOM,
|
|
|
|
SMALL_H * ZOOM * REPEAT_LOOP) {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(new_surface(SMALL_W, SMALL_H));
|
2012-10-30 20:26:58 +00:00
|
|
|
|
|
|
|
canvas->scale(ZOOM, ZOOM);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(SK_Scalar1);
|
|
|
|
|
|
|
|
for (int i = 0; i < REPEAT_LOOP; ++i) {
|
|
|
|
SkPath line, path;
|
2015-06-09 19:16:53 +00:00
|
|
|
line.moveTo(1, 2);
|
|
|
|
line.lineTo(SkIntToScalar(4 + i), 1);
|
2012-10-30 20:26:58 +00:00
|
|
|
paint.getFillPath(line, &path);
|
2016-03-24 01:59:25 +00:00
|
|
|
draw_fatpath(canvas, surface.get(), path);
|
2012-10-31 02:01:18 +00:00
|
|
|
|
2012-10-30 20:26:58 +00:00
|
|
|
canvas->translate(0, SMALL_H);
|
|
|
|
}
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|