1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "gm/gm.h" 9cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h" 10cb93a386Sopenharmony_ci#include "include/core/SkPath.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ciconstexpr int kSize = 1000; 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ci// Makes sure PathInnerTriangulateOp uses correct stencil settings when there is a clip in the 15cb93a386Sopenharmony_ci// stencil buffer. 16cb93a386Sopenharmony_cistatic void draw_clipped_flower(SkCanvas* canvas, SkPathFillType fillType) { 17cb93a386Sopenharmony_ci canvas->clear(SK_ColorCYAN); 18cb93a386Sopenharmony_ci SkPath clip; 19cb93a386Sopenharmony_ci clip.setFillType(SkPathFillType::kWinding); 20cb93a386Sopenharmony_ci constexpr static int kGridCount = 50; 21cb93a386Sopenharmony_ci constexpr static float kCellSize = (float)kSize / kGridCount; 22cb93a386Sopenharmony_ci for (int y = 0; y < kGridCount; ++y) { 23cb93a386Sopenharmony_ci clip.addRect(0, y * kCellSize, kSize, (y + 1) * kCellSize, SkPathDirection(y & 1)); 24cb93a386Sopenharmony_ci } 25cb93a386Sopenharmony_ci for (int x = 0; x < kGridCount; ++x) { 26cb93a386Sopenharmony_ci clip.addRect(x * kCellSize, 0, (x + 1) * kCellSize, kSize, SkPathDirection(x & 1)); 27cb93a386Sopenharmony_ci } 28cb93a386Sopenharmony_ci canvas->clipPath(clip); 29cb93a386Sopenharmony_ci SkPath flower; 30cb93a386Sopenharmony_ci flower.setFillType(fillType); 31cb93a386Sopenharmony_ci flower.moveTo(1, 0); 32cb93a386Sopenharmony_ci constexpr static int kNumPetals = 9; 33cb93a386Sopenharmony_ci for (int i = 1; i <= kNumPetals; ++i) { 34cb93a386Sopenharmony_ci float c = 2*SK_ScalarPI*(i - .5f) / kNumPetals; 35cb93a386Sopenharmony_ci float theta = 2*SK_ScalarPI*i / kNumPetals; 36cb93a386Sopenharmony_ci flower.quadTo(cosf(c)*2, sinf(c)*2, cosf(theta), sinf(theta)); 37cb93a386Sopenharmony_ci } 38cb93a386Sopenharmony_ci flower.close(); 39cb93a386Sopenharmony_ci flower.addArc(SkRect::MakeLTRB(-.75f, -.75f, .75f, .75f), 0, 360); 40cb93a386Sopenharmony_ci canvas->translate(kSize/2.f, kSize/2.f); 41cb93a386Sopenharmony_ci canvas->scale(kSize/3.f, kSize/3.f); 42cb93a386Sopenharmony_ci SkPaint p; 43cb93a386Sopenharmony_ci p.setAntiAlias(true); 44cb93a386Sopenharmony_ci p.setColor(SK_ColorMAGENTA); 45cb93a386Sopenharmony_ci canvas->drawPath(flower, p); 46cb93a386Sopenharmony_ci} 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ciDEF_SIMPLE_GM(largeclippedpath_winding, canvas, kSize, kSize) { 49cb93a386Sopenharmony_ci draw_clipped_flower(canvas, SkPathFillType::kWinding); 50cb93a386Sopenharmony_ci} 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ciDEF_SIMPLE_GM(largeclippedpath_evenodd, canvas, kSize, kSize) { 53cb93a386Sopenharmony_ci draw_clipped_flower(canvas, SkPathFillType::kEvenOdd); 54cb93a386Sopenharmony_ci} 55