Debian Codegraph @

gm/tablemaskfilter.cpp

raw
1 /*
2 * Copyright 2025 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/SkMaskFilter.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkPath.h"
14 #include "include/core/SkPathBuilder.h"
15 #include "include/core/SkSurface.h"
16 #include "include/effects/SkTableMaskFilter.h"
17
18 DEF_SIMPLE_GM(tablemaskfilter, canvas, 400, 400) {
19 SkPaint paint;
20 paint.setStyle(SkPaint::kFill_Style);
21 paint.setColor(SK_ColorBLACK);
22
23 // Add a table mask filter that defines half coverage for all coverage values
24 // except pixels with full coverage.
25 uint8_t table[256];
26 for (int i = 0; i < 256; ++i) {
27 table[i] = 128;
28 }
29 table[255] = 255;
30 paint.setMaskFilter(sk_sp<SkMaskFilter>(SkTableMaskFilter::Create(table)));
31
32 SkPath path = SkPathBuilder()
33 .addRect({38.f, 38.f, 218.f, 218.f})
34 .addOval({38.f, 38.f, 218.f, 218.f}, SkPathDirection::kCCW)
35 .detach();
36
37 canvas->drawPath(path, paint);
38 }