xref: /aosp_15_r20/external/skia/docs/examples/draw_patch.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker // Copyright 2020 Google LLC.
2*c8dee2aaSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3*c8dee2aaSAndroid Build Coastguard Worker #include "tools/fiddle/examples.h"
4*c8dee2aaSAndroid Build Coastguard Worker REG_FIDDLE(draw_patch, 350, 350, false, 6) {
5*c8dee2aaSAndroid Build Coastguard Worker // draw_patch
draw(SkCanvas * canvas)6*c8dee2aaSAndroid Build Coastguard Worker void draw(SkCanvas* canvas) {
7*c8dee2aaSAndroid Build Coastguard Worker     canvas->clear(SK_ColorWHITE);
8*c8dee2aaSAndroid Build Coastguard Worker     SkPaint p;
9*c8dee2aaSAndroid Build Coastguard Worker     p.setAntiAlias(true);
10*c8dee2aaSAndroid Build Coastguard Worker     const SkColor colors[] = {SK_ColorRED,     SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE,
11*c8dee2aaSAndroid Build Coastguard Worker                               SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW};
12*c8dee2aaSAndroid Build Coastguard Worker     const SkPoint pts[] = {{100.f / 4.f, 0.f}, {3.f * 100.f / 4.f, 100.f}};
13*c8dee2aaSAndroid Build Coastguard Worker     p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors),
14*c8dee2aaSAndroid Build Coastguard Worker                                              SkTileMode::kMirror));
15*c8dee2aaSAndroid Build Coastguard Worker     const SkPoint cubics[] = {{100, 100}, {150, 50},  {250, 150}, {300, 100},
16*c8dee2aaSAndroid Build Coastguard Worker                               {250, 150}, {350, 250}, {300, 300}, {250, 250},
17*c8dee2aaSAndroid Build Coastguard Worker                               {150, 350}, {100, 300}, {50, 250},  {150, 150}};
18*c8dee2aaSAndroid Build Coastguard Worker     const SkPoint texCoords[] = {
19*c8dee2aaSAndroid Build Coastguard Worker             {0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f, 100.0f}, {0.0f, 100.0f}};
20*c8dee2aaSAndroid Build Coastguard Worker     canvas->drawPatch(cubics, nullptr, texCoords, SkBlendMode::kSrcOver, p);
21*c8dee2aaSAndroid Build Coastguard Worker }
22*c8dee2aaSAndroid Build Coastguard Worker }  // END FIDDLE
23